140 lines
5.2 KiB
C#
140 lines
5.2 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Xml;
|
|
using Microsoft.SharePoint;
|
|
using Microsoft.SharePoint.Utilities;
|
|
using Microsoft.SharePoint.WebPartPages;
|
|
using Taloyhtio.CondoAutomation.Resources;
|
|
using Taloyhtio.CondoAutomation.Utils;
|
|
using Taloyhtio.CondoUpdate.Common;
|
|
|
|
namespace CondoUpdate.CentralizedNewsForOwners.SetListPermissions
|
|
{
|
|
public class UpdaterImpl : ICondoUpdater
|
|
{
|
|
public event EventHandler<LogEventArgs> OnNotify;
|
|
public void Update(object args)
|
|
{
|
|
string url = args as string;
|
|
if (string.IsNullOrEmpty(url))
|
|
{
|
|
this.warn("Url is empty");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
this.updateImpl(url);
|
|
}
|
|
catch(Exception x)
|
|
{
|
|
this.error("Error occured during updating of Condo '{0}':\n{1}\n{2}", url, x.Message, x.StackTrace);
|
|
}
|
|
}
|
|
|
|
private void updateImpl(string url)
|
|
{
|
|
using (var site = new SPSite(url))
|
|
{
|
|
using (var web = site.OpenWeb())
|
|
{
|
|
if (!web.Exists)
|
|
{
|
|
return;
|
|
}
|
|
var pmcWeb = site.RootWeb;
|
|
|
|
Thread.CurrentThread.CurrentUICulture = new CultureInfo((int) pmcWeb.Language);
|
|
|
|
string landlordsName = SecurityHelper.GetLandlordsGroupName(web);
|
|
string boardMembersName = SecurityHelper.GetBoardMembersGroupName(web);
|
|
string registeredLandlords = SecurityHelper.GetRegisteredLandlordsGroupName(web);
|
|
var alertsOwner = SecurityHelper.GetAlertsOwnerSafely(web);
|
|
|
|
var ownersReleasesList =
|
|
pmcWeb.GetListByTitleSafely(TaloyhtioPropertyManagersSite.List_LandlordsReleases_Title);
|
|
if (ownersReleasesList != null)
|
|
{
|
|
try
|
|
{
|
|
SecurityHelper.AssignGroupRoleToSecurableObject(pmcWeb, ownersReleasesList,
|
|
SPRoleType.Reader,
|
|
pmcWeb.SiteGroups[landlordsName]);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
this.error("Error occured: {0}", x.Message);
|
|
}
|
|
|
|
try
|
|
{
|
|
SecurityHelper.AssignGroupRoleToSecurableObject(pmcWeb, ownersReleasesList,
|
|
SPRoleType.Reader,
|
|
pmcWeb.SiteGroups[boardMembersName]);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
this.error("Error occured: {0}", x.Message);
|
|
}
|
|
|
|
try
|
|
{
|
|
SecurityHelper.AssignGroupRoleToSecurableObject(pmcWeb, ownersReleasesList,
|
|
SPRoleType.Reader,
|
|
pmcWeb.SiteGroups[registeredLandlords]);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
this.error("Error occured: {0}", x.Message);
|
|
}
|
|
|
|
if (alertsOwner != null)
|
|
{
|
|
SecurityHelper.AssignUserRoleToSecurableObject(pmcWeb, ownersReleasesList,
|
|
SPRoleType.Administrator,
|
|
alertsOwner);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogUtils.LogWarning("List '{0}' not found on '{1}' site",
|
|
TaloyhtioPropertyManagersSite.List_LandlordsReleases_Title, web.Url);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void info(string msg, params object[] args)
|
|
{
|
|
this.notify(LogLevel.Info, msg, args);
|
|
}
|
|
|
|
private void warn(string msg, params object[] args)
|
|
{
|
|
this.notify(LogLevel.Warn, msg, args);
|
|
}
|
|
|
|
private void error(string msg, params object[] args)
|
|
{
|
|
this.notify(LogLevel.Error, msg, args);
|
|
}
|
|
|
|
private void notify(LogLevel level, string msg, params object[] args)
|
|
{
|
|
this.notify(level, string.Format(msg, args));
|
|
}
|
|
|
|
private void notify(LogLevel level, string msg)
|
|
{
|
|
if (this.OnNotify != null)
|
|
{
|
|
this.OnNotify(this, new LogEventArgs { LogLevel = level, Message = msg });
|
|
}
|
|
}
|
|
}
|
|
}
|