Taylohtio/CustomNavigationProvider/CustomNavigationCondoMarker/Program.cs

61 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Taloyhtio.CustomNavigationCommon;
namespace Taloyhtio.CustomNavigationCondoMarker
{
class Program
{
private const string UNMARK = "unmark";
static void Main(string[] args)
{
if (args.Length != 1 && args.Length != 2)
{
Console.WriteLine(string.Format("Usage: Taloyhtio.CustomNavigationCondoMarker.exe <CondoSiteUrl> [{0}]", UNMARK));
Console.WriteLine("Example: Taloyhtio.CustomNavigationCondoMarker.exe http://taloyhtio.mobimus.com/demo2/ristijaakko");
return;
}
string url = args[0];
using (var site = new SPSite(url))
{
using (var web = site.OpenWeb())
{
bool result = isCondoMark(args);
if (result)
{
Console.WriteLine(string.Format("Trying to mark web site '{0}' as Condo site...", url));
WebPropertyHelper.Set(web, Constants.IS_CONDO_PROPERTY_KEY, result.ToString());
web.Update();
Console.WriteLine(string.Format("Web site '{0}' successfully marked as Condo site", url));
}
else
{
Console.WriteLine(string.Format("Trying to remove Condo mark from web site '{0}'...", url));
// it doesn't work on Properties - only on AllProperties
WebPropertyHelper.Set(web, Constants.IS_CONDO_PROPERTY_KEY, result.ToString());
web.Update();
Console.WriteLine(string.Format("Condo mark successfully removed from web site '{0}'", url));
}
}
}
}
private static bool isCondoMark(string[] args)
{
if (args.Length != 2)
{
return true;
}
return args[1] != UNMARK;
}
}
}