111 lines
3.5 KiB
C#
111 lines
3.5 KiB
C#
using Microsoft.SharePoint;
|
|
using Microsoft.SharePoint.Publishing;
|
|
using Microsoft.SharePoint.Utilities;
|
|
using Microsoft.SharePoint.WebPartPages;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Web.UI.WebControls.WebParts;
|
|
using WebPart = System.Web.UI.WebControls.WebParts.WebPart;
|
|
using System.Xml;
|
|
using Taloyhtio.CondoUpdate.Common;
|
|
|
|
namespace CondoUpdate.ActivateAsumisenTietopankki2019
|
|
{
|
|
public class UpdaterImpl : ICondoUpdater
|
|
{
|
|
private const string LIST_TITLE = "Lisäpalvelut";
|
|
private const string ASUMISEN_PLUGIN_TITLE = "Asumisen tietopankki";
|
|
private const string ASUMISEN_PAGE_OLD = "asumisentietopankki.aspx";
|
|
private const string ASUMISEN_PAGE_NEW = "_layouts/15/taloyhtio/Tietopankki.aspx";
|
|
private const string FIELD_URL = "Url";
|
|
private readonly Guid TIETOPANKKI_2019_FEATURE_PMC = Guid.Parse("6892b8f4-fdd0-4971-a10b-ca9ce8e1d749");
|
|
private readonly Guid TIETOPANKKI_2019_FEATURE_CONDO = Guid.Parse("8dafa63d-5f12-47dd-9967-de2e01e8d97e");
|
|
private const string TIETOPANKKI_2019_FEATURE_TITLE = "AsumisenTietopankki2019";
|
|
|
|
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)
|
|
{
|
|
try
|
|
{
|
|
using (var site = new SPSite(url))
|
|
{
|
|
using (var web = site.OpenWeb())
|
|
{
|
|
if (!web.Exists)
|
|
{
|
|
this.error("Web '{0}' does not exist", web.Url);
|
|
return;
|
|
}
|
|
|
|
if (!web.Features.Any(f => f.DefinitionId.Equals(TIETOPANKKI_2019_FEATURE_CONDO)))
|
|
{
|
|
web.Features.Add(TIETOPANKKI_2019_FEATURE_CONDO, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.error("Error occured when update '{0}' site:\n{1}\n{2}", url, ex.Message, ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
#region notifier
|
|
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 });
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|