/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; string name = Params["name"].Value; long storagemaxlevel = 0; long storagewarninglevel = 0; try { if (Params["storagemaxlevel"].UserTypedIn) { storagemaxlevel = long.Parse(Params["storagemaxlevel"].Value) * 1024 * 1024; // Convert to bytes } if (Params["storagewarninglevel"].UserTypedIn) { storagewarninglevel = long.Parse(Params["storagewarninglevel"].Value) * 1024 * 1024; } } catch { throw new SPException("Please specify levels in terms of whole numbers between 0 and " + (long.MaxValue / 1024) / 1024 + "."); } SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates; if (quotaColl[name] == null) { output = "The template specified does not exist."; return((int)ErrorCodes.GeneralError); } SPQuotaTemplate newTemplate = new SPQuotaTemplate(); newTemplate.Name = name; if (Params["storagemaxlevel"].UserTypedIn) { newTemplate.StorageMaximumLevel = storagemaxlevel; } else { newTemplate.StorageMaximumLevel = quotaColl[name].StorageMaximumLevel; } if (Params["storagewarninglevel"].UserTypedIn) { newTemplate.StorageWarningLevel = storagewarninglevel; } else { newTemplate.StorageWarningLevel = quotaColl[name].StorageWarningLevel; } quotaColl[name] = newTemplate; return((int)ErrorCodes.NoError); }
public QuotaTemplateNode(object parent, SPQuotaTemplate tempate) { this.Tag = tempate; this.SPParent = parent; this.Setup(); int index = Program.Window.Explorer.AddImage(this.ImageUrl()); this.ImageIndex = index; this.SelectedImageIndex = index; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
protected override SPQuota CreateDataObject() { SPQuotaTemplate quota = new SPQuotaTemplate(); quota.Name = Name; SPWebService webService = SPWebService.ContentService; webService.QuotaTemplates.Add(quota); if (Quota != null) { SPQuota clone = Quota.Read(); quota.StorageMaximumLevel = clone.StorageMaximumLevel; quota.StorageWarningLevel = clone.StorageWarningLevel; quota.UserCodeMaximumLevel = clone.UserCodeMaximumLevel; quota.UserCodeWarningLevel = clone.UserCodeWarningLevel; } if (StorageMaximumLevel.HasValue) { if (StorageMaximumLevel.Value > quota.StorageWarningLevel) { quota.StorageMaximumLevel = StorageMaximumLevel.Value; quota.StorageWarningLevel = StorageWarningLevel.Value; } else { quota.StorageWarningLevel = StorageWarningLevel.Value; quota.StorageMaximumLevel = StorageMaximumLevel.Value; } } if (UserCodeMaximumLevel.HasValue) { if (UserCodeMaximumLevel.Value > quota.UserCodeWarningLevel) { quota.UserCodeMaximumLevel = UserCodeMaximumLevel.Value; quota.UserCodeWarningLevel = UserCodeWarningLevel.Value; } else { quota.UserCodeWarningLevel = UserCodeWarningLevel.Value; quota.UserCodeMaximumLevel = UserCodeMaximumLevel.Value; } } webService.Update(); return(quota); }
protected override void UpdateDataObject() { ShouldProcessReason reason; if (!base.ShouldProcess("Set Quotas", null, null, out reason)) { if (reason == ShouldProcessReason.WhatIf) { m_whatIf = true; } } SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = !SyncExistingOnly.IsPresent; if (QuotaTemplate != null) { m_quota = QuotaTemplate.Read(); if (m_quota == null) { throw new SPCmdletException("The specified quota template name could not be found."); } } SPEnumerator enumerator = null; switch (ParameterSetName) { case "SPSite1": case "SPSite2": Sync(Site.Read()); return; case "SPWebApplication1": case "SPWebApplication2": enumerator = new SPEnumerator(WebApplication.Read()); break; default: enumerator = new SPEnumerator(Farm.Read()); break; } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; string scope = Params["scope"].Value.ToLowerInvariant(); SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = Params["setquota"].UserTypedIn; if (Params["quota"].UserTypedIn) { m_quota = m_quotaColl[Params["quota"].Value]; if (m_quota == null) { throw new ArgumentException("The specified quota template name could not be found."); } } SPEnumerator enumerator; if (scope == "farm") { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == "webapplication") { enumerator = new SPEnumerator(SPWebApplication.Lookup(new Uri(Params["url"].Value.TrimEnd('/')))); } else { // scope == "site" using (SPSite site = new SPSite(Params["url"].Value.TrimEnd('/'))) { Sync(site); } return((int)ErrorCodes.NoError); } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); return((int)ErrorCodes.NoError); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; string name = Params["name"].Value; long storagemaxlevel = 0; long storagewarninglevel = 0; try { if (Params["storagemaxlevel"].UserTypedIn) storagemaxlevel = long.Parse(Params["storagemaxlevel"].Value) * 1024 * 1024; // Convert to bytes if (Params["storagewarninglevel"].UserTypedIn) storagewarninglevel = long.Parse(Params["storagewarninglevel"].Value) * 1024 * 1024; } catch { throw new SPException("Please specify levels in terms of whole numbers between 0 and " + (long.MaxValue / 1024) / 1024 + "."); } SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue<SPWebService>(""); SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates; if (quotaColl[name] == null) { output = "The template specified does not exist."; return (int)ErrorCodes.GeneralError; } SPQuotaTemplate newTemplate = new SPQuotaTemplate(); newTemplate.Name = name; if (Params["storagemaxlevel"].UserTypedIn) newTemplate.StorageMaximumLevel = storagemaxlevel; else newTemplate.StorageMaximumLevel = quotaColl[name].StorageMaximumLevel; if (Params["storagewarninglevel"].UserTypedIn) newTemplate.StorageWarningLevel = storagewarninglevel; else newTemplate.StorageWarningLevel = quotaColl[name].StorageWarningLevel; quotaColl[name] = newTemplate; return (int)ErrorCodes.NoError; }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; string scope = Params["scope"].Value.ToLowerInvariant(); SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue<SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = Params["setquota"].UserTypedIn; if (Params["quota"].UserTypedIn) { m_quota = m_quotaColl[Params["quota"].Value]; if (m_quota == null) throw new ArgumentException("The specified quota template name could not be found."); } SPEnumerator enumerator; if (scope == "farm") { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == "webapplication") { enumerator = new SPEnumerator(SPWebApplication.Lookup(new Uri(Params["url"].Value.TrimEnd('/')))); } else { // scope == "site" using (SPSite site = new SPSite(Params["url"].Value.TrimEnd('/'))) { Sync(site); } return (int)ErrorCodes.NoError; } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); return (int)ErrorCodes.NoError; }
/// <summary> /// Syncs the specified site quota with the quota template. /// </summary> /// <param name="site">The site.</param> private void Sync(SPSite site) { SPQuota currentQuota = site.Quota; SPQuotaTemplate currentTemplate = null; foreach (SPQuotaTemplate quota in m_quotaColl) { if (currentQuota.QuotaID == quota.QuotaID) { currentTemplate = quota; break; } } if (currentTemplate == null) { if (!m_setQuota) { Logger.WriteWarning("No quota template has been assigned to site {0}. Use the -setquota parameter to assign a quota.", site.Url); return; } Logger.Write("PROGRESS: Synchronizing {0}", site.Url); Logger.Write("PROGRESS: No quota template assigned to site. Assigning template...", site.Url); site.Quota = m_quota; Logger.Write("PROGRESS: Template \"{0}\" assigned to site.", m_quota.Name); return; } if (m_quota == null || (m_quota != null && currentQuota.QuotaID == m_quota.QuotaID)) { Logger.Write("PROGRESS: Synchronizing {0}", site.Url); Logger.Write("PROGRESS: Currently using template \"{0}\".", currentTemplate.Name); if (site.Quota.InvitedUserMaximumLevel == currentTemplate.InvitedUserMaximumLevel && site.Quota.StorageMaximumLevel == currentTemplate.StorageMaximumLevel && site.Quota.StorageWarningLevel == currentTemplate.StorageWarningLevel && site.Quota.UserCodeMaximumLevel == currentTemplate.UserCodeMaximumLevel && site.Quota.UserCodeWarningLevel == currentTemplate.UserCodeWarningLevel) { Logger.Write("PROGRESS: No changes necessary, quota already synchronized with template."); return; } site.Quota = currentTemplate; Logger.Write("PROGRESS: Storage maximum updated from {0}MB to {1}MB", ((currentQuota.StorageMaximumLevel / 1024) / 1024).ToString(), ((site.Quota.StorageMaximumLevel / 1024) / 1024).ToString()); Logger.Write("PROGRESS: Storage warning updated from {0}MB to {1}MB", ((currentQuota.StorageWarningLevel / 1024) / 1024).ToString(), ((site.Quota.StorageWarningLevel / 1024) / 1024).ToString()); Logger.Write("PROGRESS: User Code Maximum Level updated from {0} to {1}", currentQuota.UserCodeMaximumLevel.ToString(), site.Quota.UserCodeMaximumLevel.ToString()); Logger.Write("PROGRESS: User Code Maximum Level updated from {0} to {1}", currentQuota.UserCodeWarningLevel.ToString(), site.Quota.UserCodeWarningLevel.ToString()); Logger.Write("PROGRESS: Invited user maximum updated from {0} to {1}", currentQuota.InvitedUserMaximumLevel.ToString(), site.Quota.InvitedUserMaximumLevel.ToString()); } }