Example #1
0
        /// <summary>
        /// Get all time zone informations
        /// </summary>
        /// <returns></returns>
        private static TimeZoneCollection GetTimeZones()
        {
            lock (_SyncRoot)
            {
                if (_Zones != null)
                {
                    return(_Zones);
                }

                //open key where all time zones are located in the registry

                RegistryKey timeZoneKeys = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones");

                //create a new hashtable which will store the name

                //of the timezone and the associate time zone information struct

                _Zones = new TimeZoneCollection();

                //iterate through each time zone in the registry and add it to the hash table

                foreach (string zonekey in timeZoneKeys.GetSubKeyNames())
                {
                    //get current time zone key

                    RegistryKey individualZone = timeZoneKeys.OpenSubKey(zonekey);

                    //create new TZI struct and populate it with values from key

                    TimeZoneInformation TZI = new TimeZoneInformation();

                    TZI.standardName = individualZone.GetValue("Std").ToString();

                    string displayName = individualZone.GetValue("Display").ToString();

                    TZI.daylightName = individualZone.GetValue("Dlt").ToString();

                    //read binary TZI data, convert to byte array

                    byte[] b = (byte[])individualZone.GetValue("TZI");

                    TZI.bias         = BitConverter.ToInt32(b, 0);
                    TZI.standardBias = BitConverter.ToInt32(b, 4);
                    TZI.daylightBias = BitConverter.ToInt32(b, 8);

                    TZI.standardDate = new SYSTEMTIME(b, 12);
                    TZI.daylightDate = new SYSTEMTIME(b, 28);

                    //Marshal.PtrToStructure(

                    //add the name and TZI struct to hash table

                    _Zones.Add(displayName, TZI);
                }

                return(_Zones);
            }
        }
Example #2
0
        /// <summary>
        /// Get the Time zone by display name
        /// </summary>
        /// <param name="displayName">part of display name</param>
        /// <param name="wholeDisplayName">whole display name</param>
        /// <returns>time zone</returns>
        public static TimeZoneInformation GetTimeZone(string displayName, out string wholeDisplayName)
        {
            TimeZoneCollection tzc = TimeZone.GetTimeZones();

            foreach (string key in tzc.Keys)
            {
                if (key.IndexOf(displayName, 0, StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    wholeDisplayName = key;
                    return(tzc[key]);
                }
            }

            throw new Exception(string.Format("Can't find the display name : {0}", displayName));
        }
Example #3
0
        /// <summary>
        /// Get current time zone display name
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentTimeZoneDisplayName()
        {
            TimeZoneInformation tzi;

            GetTimeZoneInformation(out tzi);
            TimeZoneCollection tzc = TimeZone.GetTimeZones();

            foreach (string displayName in tzc.Keys)
            {
                TimeZoneInformation tz = tzc[displayName];
                if (tz.standardName.Equals(tzi.standardName, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(displayName);
                }
            }

            throw new Exception(string.Format("Can't find the display name of {0}", tzi.standardName));
        }
Example #4
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");
            var siteURL     = Environment.GetEnvironmentVariable("siteURL");
            var spTimeZones = new List <SPTimeZone>();
            var result      = await Task.Run(async() => {
                using (var ctx = new ClientContext(siteURL))
                {
                    var user     = Environment.GetEnvironmentVariable("spAdminUser");
                    var psw      = Environment.GetEnvironmentVariable("password");
                    var passWord = new SecureString();
                    foreach (char c in psw.ToCharArray())
                    {
                        passWord.AppendChar(c);
                    }
                    ctx.Credentials        = new SharePointOnlineCredentials(user, passWord);
                    Web web                = ctx.Web;
                    TimeZoneCollection tzc = ctx.Web.RegionalSettings.TimeZones;
                    ctx.Load(tzc);
                    await ctx.ExecuteQueryAsync();

                    var timeZones = tzc.ToList();

                    foreach (var item in timeZones)
                    {
                        var spTimeZone = new SPTimeZone
                        {
                            Id          = item.Id,
                            Description = item.Description
                        };
                        spTimeZones.Add(spTimeZone);
                    }

                    log.Info("Time Zones Collected");
                    return(spTimeZones);
                }
            });

            return(req.CreateResponse(HttpStatusCode.OK, result));
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // define initial script, needed to render the chrome control
            string script = @"
            function chromeLoaded() {
                $('body').show();
            }

            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'
                };

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);
                chromeNavigation.setVisible(true);
            }";

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);

            // Set some default values
            //lblBasePath.Text = Request["SPHostUrl"].Substring(0, 8 + Request["SPHostUrl"].Substring(8).IndexOf("/")) + "/sites/";
            if (Request["RequestorSite"] != null)
            {
                lblBasePath.Text = Request["RequestorSite"] + "/";
            }
            else
            {
                lblBasePath.Text = Request["SPHostUrl"] + "/";
            }
            //templateSiteLink.Text = ConfigurationManager.AppSettings["TemplateSiteUrl"];
            //templateSiteLink.NavigateUrl = ConfigurationManager.AppSettings["TemplateSiteUrl"];

            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (ClientContext ctx = spContext.CreateUserClientContextForSPHost())
            {
                // Get time zones from server side
                RegionalSettings   reg   = ctx.Web.RegionalSettings;
                TimeZoneCollection zones = ctx.Web.RegionalSettings.TimeZones;
                ctx.Load(reg);
                ctx.Load(zones);
                ctx.ExecuteQuery();
            }

            // Set default values for the controls
            if (!Page.IsPostBack)
            {
                //RecordedPanel.Visible = false;
                //RequestPanel.Visible = true;
                processViews.ActiveViewIndex = 0;
                processViews.SetActiveView(RequestView);
                // Set template options - could also come from Azure or from some other solution, now hard coded.
                ddlTemplate.Items.Add(new System.Web.UI.WebControls.ListItem("Community", "CommunityTemplate.xml:COMMUNITY#0"));

                ddlTemplate.SelectedIndex = 0;
            }
        }
Example #6
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            string siteURL = req.GetQueryNameValuePairs()
                             .FirstOrDefault(q => string.Compare(q.Key, "siteURL", true) == 0)
                             .Value;

            string timeZoneToSet = req.GetQueryNameValuePairs()
                                   .FirstOrDefault(q => string.Compare(q.Key, "timeZone", true) == 0)
                                   .Value;

            // Get request body
            dynamic data = await req.Content.ReadAsAsync <object>();

            if (siteURL == null)
            {
                siteURL = data?.siteURL;
                if (siteURL == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass the siteURL in the request body"));
                }
            }
            if (timeZoneToSet == null)
            {
                timeZoneToSet = data?.timeZone;
                if (timeZoneToSet == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass the timeZone in the request body"));
                }
            }

            // Get access to source site
            using (var ctx = new ClientContext(siteURL))
            {
                var User = Environment.GetEnvironmentVariable("spAdminUser");
                var Psw  = Environment.GetEnvironmentVariable("password");
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in Psw.ToCharArray())
                {
                    passWord.AppendChar(c);
                }
                ctx.Credentials = new SharePointOnlineCredentials(User, passWord);

                // Actual code for operations
                Web web = ctx.Web;
                Microsoft.SharePoint.Client.TimeZone tz = ctx.Web.RegionalSettings.TimeZone;
                TimeZoneCollection tzc = ctx.Web.RegionalSettings.TimeZones;
                ctx.Load(tz);
                ctx.Load(tzc);
                //ctx.Load(web);
                ctx.ExecuteQuery();

                var timeZone  = tz;
                var timeZones = tzc.Where(x => x.Description == timeZoneToSet).FirstOrDefault();

                ctx.Web.RegionalSettings.TimeZone = timeZones;
                ctx.Web.Update();
                ctx.ExecuteQuery();
                log.Info("New regional settings set {0}", ctx.Web.RegionalSettings.TimeZone.Description);
            }

            return(req.CreateResponse(HttpStatusCode.OK, "The Time Zone is correctly configured"));
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // define initial script, needed to render the chrome control
            string script = @"
            function chromeLoaded() {
                $('body').show();
            }

            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'
                };

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);
                chromeNavigation.setVisible(true);
            }";

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);

            // Set some default values
            lblBasePath.Text             = Request["SPHostUrl"].Substring(0, 8 + Request["SPHostUrl"].Substring(8).IndexOf("/")) + "/sites/";
            templateSiteLink.Text        = ConfigurationManager.AppSettings["TemplateSiteUrl"];
            templateSiteLink.NavigateUrl = ConfigurationManager.AppSettings["TemplateSiteUrl"];

            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (ClientContext ctx = spContext.CreateUserClientContextForSPHost())
            {
                // Get time zones from server side
                RegionalSettings   reg   = ctx.Web.RegionalSettings;
                TimeZoneCollection zones = ctx.Web.RegionalSettings.TimeZones;
                ctx.Load(reg);
                ctx.Load(zones);
                ctx.ExecuteQuery();

                foreach (var item in zones)
                {
                    timeZone.Items.Add(new System.Web.UI.WebControls.ListItem(item.Description, item.Id.ToString()));
                }

                // Add wanted languages for creation list
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1033).DisplayName, "1033"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1035).DisplayName, "1035"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1036).DisplayName, "1036"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1053).DisplayName, "1053"));
            }

            // Set default values for the controls
            if (!Page.IsPostBack)
            {
                // Set template options - could also come from Azure or from some other solution, now hard coded.
                listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Team", "ContosoTemplate-01.xml"));
                listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Simplistic", "ContosoTemplate-02.xml"));
                listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Oslo Team", "ContosoTemplate-03.xml"));
                listTemplates.SelectedIndex = 0;

                txtUrl.Text              = DateTime.Now.Ticks.ToString();
                txtStorage.Text          = "100";
                timeZone.SelectedValue   = "10";
                listTemplates.Enabled    = false;
                templateSiteLink.Enabled = true;
            }
        }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // define initial script, needed to render the chrome control
            string script = @"
            function chromeLoaded() {
                $('body').show();
            }

            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'
                };

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);
                chromeNavigation.setVisible(true);
            }";

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);


            listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Team", "STS#0"));
            listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Organization", "STS#0"));
            listTemplates.Items.Add(new System.Web.UI.WebControls.ListItem("Group", "STS#0"));
            listTemplates.SelectedIndex = 0;

            lblBasePath.Text = Request["SPHostUrl"].Substring(0, 8 + Request["SPHostUrl"].Substring(8).IndexOf("/")) + "/sites/";

            txtStorage.Text = "100";

            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (ClientContext ctx = spContext.CreateUserClientContextForSPHost())
            {
                // Get time zones from server side
                RegionalSettings   reg   = ctx.Web.RegionalSettings;
                TimeZoneCollection zones = ctx.Web.RegionalSettings.TimeZones;
                ctx.Load(reg);
                ctx.Load(zones);
                ctx.ExecuteQuery();

                foreach (var item in zones)
                {
                    timeZone.Items.Add(new System.Web.UI.WebControls.ListItem(item.Description, item.Id.ToString()));
                }

                // Add wanted languages for creation list
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1033).DisplayName, "1033"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1035).DisplayName, "1035"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1036).DisplayName, "1036"));
                language.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(1053).DisplayName, "1053"));

                if (!Page.IsPostBack)
                {
                    txtUrl.Text            = Guid.NewGuid().ToString().Replace("-", "");
                    timeZone.SelectedValue = "10";
                }
            }
        }