98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Web.UI.WebControls.WebParts;
|
|
using System.Xml;
|
|
using Microsoft.SharePoint;
|
|
using Microsoft.SharePoint.Publishing;
|
|
using Microsoft.SharePoint.Utilities;
|
|
using Microsoft.SharePoint.WebPartPages;
|
|
using Taloyhtio.CondoAutomation.Resources;
|
|
using Taloyhtio.CondoAutomation.Utils;
|
|
using Taloyhtio.CondoUpdate.Common;
|
|
using WebPart = System.Web.UI.WebControls.WebParts.WebPart;
|
|
|
|
namespace CondoUpdate.WarmaMigration.RetargetWebParts
|
|
{
|
|
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(SPUrlUtility.CombineUrl(url, ""), TaloyhtioPropertyManagersSite.List_TenantsReleases_Title, "69db0a59-a5d2-4c44-804b-80ed97ea8a7a");
|
|
this.updateImpl(SPUrlUtility.CombineUrl(url, "Osakkaille"), TaloyhtioPropertyManagersSite.List_LandlordsReleases_Title, "5e81ab96-1807-4c7a-a27d-3e44afe26c0c");
|
|
this.updateImpl(SPUrlUtility.CombineUrl(url, "Hallitukselle"), TaloyhtioPropertyManagersSite.List_BoardMembersReleases_Title, "6172775d-d0a1-4f5c-b652-2b3c5cfd7a37");
|
|
}
|
|
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, string listTitle, string oldListId)
|
|
{
|
|
using (var site = new SPSite(url))
|
|
{
|
|
using (var web = site.OpenWeb())
|
|
{
|
|
if (!web.Exists)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Thread.CurrentThread.CurrentUICulture = new CultureInfo((int)web.Language);
|
|
|
|
if (!PublishingWeb.IsPublishingWeb(web))
|
|
{
|
|
return;
|
|
}
|
|
var pweb = PublishingWeb.GetPublishingWeb(web);
|
|
WebPartsHelper.SetupDataFormWebPartOnStartPage(pweb, listTitle, oldListId, "/uudenkaupunginisannoitsijakeskus");
|
|
WebPartsHelper.SetupWebPartsOnNewsPage(pweb, "Uutinen", listTitle, oldListId, "/uudenkaupunginisannoitsijakeskus");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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 });
|
|
}
|
|
}
|
|
}
|
|
}
|