private void EnsureUsers() { foreach (string user in UsersText.Lines) { if (string.IsNullOrEmpty(user)) { continue; } foreach (int i in WebList.CheckedIndices) { SPWeb web = WebList.Items[i] as SPWeb; try { web.EnsureUser(user.Trim()); SquadronContext.WriteMessage("Success: " + web.ToString() + " " + user); } catch (Exception ex) { SquadronContext.WriteMessage("Failure: " + web.ToString() + " " + user + " " + ex.ToString()); } } } SquadronContext.Info("Operation Completed.. Please check the log for details."); }
private void ShowResultToGrid() { grid.DataSource = null; grid.DataSource = Result; grid.Columns["UsersInGroup"].Visible = ShowUsersInGroup.Checked; grid.Columns["InheritUrl"].Visible = IncludeInheritUrlChecked.Checked; if (grid.Columns.Contains("InternalObject")) { grid.Columns["InternalObject"].Visible = false; } if (_discardedCount > 0) { SquadronContext.WriteMessage("Discarded " + _discardedCount.ToString() + " result(s) based on condition specified!"); } if (_errorsOccurred) { SquadronContext.Errr("Some of the permission items thrown exeptions. Please check the log for details!"); } Helper.Instance.DisableSort(grid); }
private void ExecuteButton_Click(object sender, EventArgs e) { _hasErrors = false; SquadronContext.WriteMessage("Started.."); SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite site = new SPSite(SquadronContext.Url); DataTable table = RefreshUserProfiles(site); RefreshMySiteInfo(); if (table != null) { SquadronContext.WriteMessage(table.Rows.Count.ToString() + " rows found"); } SquadronContext.WriteMessage("Completed."); }); if (_hasErrors) { SquadronContext.Errr("Errors occurred!"); } }
private void PerformDelete() { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SquadronContext.Url)) { using (SPWeb web = site.OpenWeb()) { foreach (string title in NameList.CheckedItems) { SPList list = web.Lists[title]; try { list.Delete(); SquadronContext.WriteMessage(title + " DELETE done."); } catch (Exception ex) { SquadronContext.WriteMessage("DELETE Exception for " + title + " " + ex.ToString()); } } } } }); SquadronContext.WriteMessage("Performed DELETE operations."); RefreshList(); }
public override void Perform(object o, IExplorer explorer) { SquadronContext.WriteMessage("Export operation started.."); try { SPWeb source = (o as SPWeb); if (GetParent()) { if (CreateDestinationWeb(source)) { SquadronHelper.Instance.StartAnimation(); if (ExportWeb(source)) { if (ImportWeb(_destWeb)) { DeleteFolder(); Success(); explorer.RefreshData(); } } } } } finally { SquadronHelper.Instance.StopAnimation(); SquadronContext.WriteMessage("Export operation completed."); } }
public override void Perform(object o, IExplorer explorer) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "*.cmp|*.cmp"; if (dialog.ShowDialog() == DialogResult.OK) { SquadronHelper.Instance.StartAnimation(); SquadronContext.WriteMessage("Starting Export to file(s): " + dialog.FileName); try { ImportExportUtility utility = new ImportExportUtility(); if (utility.Export(o as SPWeb, dialog.FileName)) { string message = "Exported succesfully!" + Environment.NewLine + Environment.NewLine + "Following are the files:" + Environment.NewLine; foreach (string file in Directory.GetFiles(Helper.Instance.ExtractFolder(dialog.FileName), Helper.Instance.ExtractFileName(dialog.FileName).Replace(".cmp", "*.cmp"))) { message += file + Environment.NewLine; } SquadronContext.Info(message); } } finally { SquadronHelper.Instance.StopAnimation(); } } }
private void PerformEmpty() { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SquadronContext.Url)) { using (SPWeb web = site.OpenWeb()) { foreach (int ix in NameList.CheckedIndices) { string title = _listTitles[ix]; SPList list = web.Lists[title]; int count = list.Items.Count; for (int x = list.Items.Count - 1; x >= 0; x--) { list.Items[x].Delete(); } SquadronContext.WriteMessage(title + " EMPTY performed by deleting " + count.ToString() + " items"); } } } }); SquadronContext.WriteMessage("Performed Empty operations."); }
private void CommandControl_Load(object sender, EventArgs e) { _Program = Environment.GetEnvironmentVariable("windir") + "\\System32\\cmd.exe"; if (!File.Exists(_Program)) { SquadronContext.WriteMessage("Unable to find cmd.exe at: " + _Program); } }
private void ExecuteButton_Click(object sender, EventArgs e) { SquadronHelper.Instance.StartAnimation(); List <AverageResultEntity> averageList = new List <AverageResultEntity>(); int count = (int)CountText.Value; _testCount = 0; int rc = 0; SquadronContext.ClearMessages(); var urls = GetUrls(); SquadronContext.WriteMessage("Starting Testing: " + urls.Count().ToString() + " URL(s) found.."); bool firstTestDone = false; try { foreach (string url in urls) { if (!firstTestDone) { CheckResponse(url); // First test firstTestDone = true; } _testList.Clear(); for (int i = 1; i <= count; i++) { CheckResponseAddEntity(new ThreadParam() { Url = url, Index = i }); } averageList.Add(GetAverageResultEntity(_testList, url, count)); grid.DataSource = null; grid.DataSource = averageList; if (rc++ > 10) { Application.DoEvents(); } } grid.DataSource = null; grid.DataSource = averageList; } finally { SquadronHelper.Instance.StopAnimation(); ShowAverageResultSummary("Simple Test", averageList); } }
private void ExecuteButton_Click(object sender, EventArgs e) { SquadronContext.WriteMessage("Using " + SquadronContext.DomainName + " ..."); _result = _adHelper.GetAll(SquadronContext.DomainName, true, true, true).ToList(); CheckHighlight(); grid.DataSource = _result; Helper.Instance.ResizeRowsToFit(grid); pgrid.Visible = true; }
private void ShowResultToGrid() { grid.DataSource = null; grid.DataSource = _result; grid.Columns["UsersInGroup"].Visible = ShowUsersInGroup.Checked; if (_discardedCount > 0) { SquadronContext.WriteMessage("Discarded " + _discardedCount.ToString() + " based on condition specified!"); } }
protected override bool InternalExecute() { SPSecurity.RunWithElevatedPrivileges(delegate() { SPFarm farm = SPFarm.Local; foreach (SPServer server in farm.Servers) { SquadronContext.WriteMessage(server.Name + " " + server.Role + " " + server.TypeName); } }); return(DisplayResult(DetailsList.Count == 0)); }
public void SafePerform(object o, IExplorer explorer) { try { Perform(o, explorer); SquadronContext.WriteMessage(this.Text + " operation completed!"); } catch (Exception ex) { SquadronContext.Errr(ex.ToString()); } }
private void CalculateButton_Click(object sender, EventArgs e) { SquadronContext.WriteMessage("Started.."); if (AreInputsValid()) { DataTable table = (grid.DataSource as DataTable); if (!table.Columns.Contains("MySite Url")) { table.Columns.Add("MySite Url", typeof(string)); } if (!table.Columns.Contains("Status")) { table.Columns.Add("Status", typeof(string)); } if (SizeCheck.Checked) { if (!table.Columns.Contains("Size")) { table.Columns.Add("Size", typeof(string)); } } if (LastModifiedDateCheck.Checked) { if (!table.Columns.Contains("Last Modified Date")) { table.Columns.Add("Last Modified Date", typeof(string)); } } Helper.Instance.RefreshGridData(grid); for (int i = 1; i <= 3; i++) // Guarantee Loop { foreach (DataRow row in table.Rows) { if (string.IsNullOrEmpty(row["Status"].ToString()) || row["Status"].ToString().StartsWith("Exception")) { DoWork(row); } } } } SquadronContext.WriteMessage("Completed."); }
private void DoAction(List <SPListItemVersion> selectedList, bool delete) { string message = "Operation completed successfully!" + Environment.NewLine + selectedList.Count.ToString() + " version(s) "; if (delete) { message += " Deleted!"; } else { message += " Recycled!"; } bool hasErrors = false; int count = selectedList.Count; while (count > 0) { try { var v = selectedList[count - 1]; if (delete) { v.Delete(); } else { v.Recycle(); } selectedList.RemoveAt(count - 1); } catch (Exception ex) { SquadronContext.WriteMessage(ex.ToString()); hasErrors = true; } count--; } if (!hasErrors) { _versions.Clear(); grid.DataSource = _versions; SquadronContext.Info(message); } }
private void ExecuteAllButton_Click(object sender, EventArgs e) { foreach (ActionControl.Action action in actionControl.GetCheckedActions()) { try { action.Execute(); SquadronContext.WriteMessage("Action: " + action.Name + " completed"); } catch (Exception ex) { SquadronContext.WriteMessage("Action: " + action.Name + " Error: " + ex.ToString()); } } }
private void FindVersions() { SPSecurity.RunWithElevatedPrivileges(delegate() { _versions.Clear(); int count = Helper.Instance.Int(CountText.Text); foreach (SPList list in GetLists()) { foreach (SPListItem item in list.Items) { VersionGridItem gridItem = new VersionGridItem() { Item = item, ListTitle = list.Title, ItemTitle = _utility.GetSimpleDisplayName(item) }; foreach (SPListItemVersion v in item.Versions) { if (!v.IsCurrentVersion) { if ((DateTime.Now - v.Created).TotalDays > count) { gridItem.VersionItems.Add(new VersionItem() { Item = v }); } } } gridItem.VersionCount = gridItem.VersionItems.Count; if (gridItem.VersionItems.Count > 0) { _versions.Add(gridItem); } } } grid.DataSource = _versions.ToList(); }); if (_versions.Count == 0) { SquadronContext.WriteMessage("No item(s) found matching criteria!"); } }
private void ExportToHTMLButton_Click(object sender, EventArgs e) { if (ResultPanel.Controls.OfType <GridPanel>().Count() > 0) { string html = GetHTMLReport(); string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + "Squadron_Documentation_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + ".html"; File.WriteAllText(path, html); Process.Start(path); } else { SquadronContext.WriteMessage("No result(s) to show."); } }
public DataTable GetDataTableFromCSVFile() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "*.csv|*.csv"; DataTable table = null; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] lines = File.ReadAllLines(dialog.FileName); if (lines.Count() > 0) { table = new DataTable(); foreach (string c in lines[0].Split(',')) { table.Columns.Add(c, typeof(string)); } for (int i = 1; i < lines.Count(); i++) { DataRow row = table.NewRow(); int ix = 0; foreach (string c in lines[i].Split(',')) { if (ix >= table.Columns.Count) { table.Columns.Add("New Column " + Guid.NewGuid().ToString(), typeof(string)); SquadronContext.WriteMessage("Invalid column generated! (data value contains ',')"); } row[ix] = c; ix++; } table.Rows.Add(row); } } } return(table); }
private void CalculateButton_Click(object sender, EventArgs e) { SquadronContext.WriteMessage("Started.."); SPSecurity.RunWithElevatedPrivileges(delegate() { _list.Clear(); using (SPSite siteCollection = new SPSite(SquadronContext.Url)) { if (DocLibCheck.Checked) { var r1 = siteCollection.StorageManagementInformation( SPSite.StorageManagementInformationType.DocumentLibrary, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 1000000 ); AddToList(r1); } if (ListCheck.Checked) { var r2 = siteCollection.StorageManagementInformation( SPSite.StorageManagementInformationType.List, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 1000000 ); AddToList(r2); } ShowTotal(); grid.DataSource = _list; } }); GC.Collect(); SquadronContext.WriteMessage("Completed."); }
private void CheckResponseAddEntity(object o) { string url = string.Empty; int i = 0; if (o != null) { url = (o as ThreadParam).Url; i = (o as ThreadParam).Index; } TestResultEntity entity = new TestResultEntity(); entity.TestName = "Request " + i.ToString(); DateTime startTime = DateTime.Now; try { CheckResponse(url); } catch (Exception ex) { entity.Exception = ex; SquadronContext.WriteMessage(ex.ToString()); } TimeSpan span = DateTime.Now - startTime; if (entity.Success) { entity.ResponseTime = span.TotalSeconds; } else { entity.TestName += " (Exception)"; } lock (this) { _testList.Add(entity); } }
private void PerformButton_Click(object sender, EventArgs e) { SquadronContext.WriteMessage("Started.."); SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite site = new SPSite(SquadronContext.Url); UserProfileManager manager = null; try { manager = new UserProfileManager(SPServiceContext.GetContext(site)); } catch (Exception ex) { SquadronContext.Errr("Unable to create UserProfileManager object!" + Environment.NewLine + "Please ensure Central Administration > User Profile Service Application > Permissions are set!"); SquadronContext.HandleException(ex); return; } DataTable table = new DataTable(); foreach (Property p in manager.Properties) { table.Columns.Add(p.Name, typeof(string)); } foreach (UserProfile profile in manager) { DataRow row = table.NewRow(); foreach (Property property in manager.Properties) { row[property.Name] = profile[property.Name].Value; } table.Rows.Add(row); } grid.DataSource = table; SquadronContext.WriteMessage(table.Rows.Count.ToString() + " rows found"); SquadronContext.WriteMessage("Completed."); }); }
private void StartCopying() { pbr.Maximum = lst1.CheckedItems.Count; pbr.Value = 0; foreach (string table in lst1.CheckedItems) { if (!DoTableExists(table)) { CreateTable(table); } SetIdentityInsertOn(table); Copy(table); pbr.Value++; } SquadronContext.WriteMessage("Operation completed"); }
public override void Perform(object o, IExplorer explorer) { if (ConfirmDelete(o)) { SquadronHelper.Instance.StartAnimation(); try { if (o is SPSite) { (o as SPSite).Delete(); } else if (o is SPWeb) { foreach (SPWeb web in _utility.GetWebsRecursively(o as SPWeb).Reverse()) { try { web.Delete(); } catch { } } (o as SPWeb).Delete(); } else if (o is SPList) { (o as SPList).Delete(); } explorer.DeleteSelectedNode(); SquadronContext.WriteMessage("Delete operation completed!"); } finally { SquadronHelper.Instance.StopAnimation(); } } }
private void StartCopying() { var copyItemControls = copyControl1.GetCopyControls(); pbr1.Value = 0; pbr1.Maximum = copyItemControls.Count(); foreach (CopyItemControl control in copyItemControls) { SPList sourceList = _sourceWeb.Lists[control.SourceListName]; SPList destList = GetDestinationList(_sourceWeb, _destinationWeb, control.SourceListName, control.DestinationListName); pbr2.Maximum = sourceList.Items.Count; CopyItems(sourceList, destList); pbr1.Value++; SquadronContext.WriteMessage("Copied " + sourceList.Items.Count.ToString() + " item(s) to " + control.DestinationListName); } SquadronContext.WriteMessage("Completed!"); }
private void ExecuteButton_Click(object sender, EventArgs e) { if (OptionsList.CheckedIndices.Count > 0) { SquadronHelper.Instance.StartAnimation(); try { // Clear ClearControls(); // Farm Section if (IsChecked(Option_CoreInfo)) { Refresh_CoreInfo(); } if (IsChecked(Option_FarmServers)) { Refresh_FarmServers(); } if (IsChecked(Option_Services)) { Refresh_Services(); } if (IsChecked(Option_ServiceApplications)) { Refresh_ServiceApplications(); } if (IsChecked(Option_ContentDatabases)) { Refresh_ContentDatabases(); } if (IsChecked(Option_FarmSolutions)) { Refresh_FarmSolutions(); } if (IsChecked(Option_UserSolutions)) { Refresh_UserSolutions(); } if (IsChecked(Option_ManagedPaths)) { Refresh_ManagedPaths(); } // Application Section if (IsChecked(Option_WebApplications)) { Refresh_WebApplications(); } if (IsChecked(Option_SiteCollections)) { Refresh_SiteCollections(); } if (IsChecked(Option_Sites)) { Refresh_Sites(); } if (IsChecked(Option_Lists)) { Refresh_Lists(); } if (IsChecked(Option_Items)) { Refresh_Items(); } } finally { SquadronHelper.Instance.StopAnimation(); SquadronContext.WriteMessage(this.Text + " operation completed!"); } } else { SquadronContext.Warn("Please select atleast one item!"); } }
private DataTable RefreshUserProfiles(SPSite site) { UserProfileManager manager = null; try { manager = new UserProfileManager(SPServiceContext.GetContext(site)); } catch (NullReferenceException nex) { SquadronContext.Errr("User Profile Error!" + Environment.NewLine + "Please ensure User Profile Service application is Provisioned & Permissions are set correctly."); return(null); } catch (UserProfileApplicationNotAvailableException uex) { SquadronContext.Errr("User Profile Error!" + Environment.NewLine + "Please configure User Profile Service Application & Ensure Permissions are set correctly."); return(null); } catch { throw; } DataTable table = new DataTable(); foreach (Property p in manager.Properties) { table.Columns.Add(p.Name, typeof(string)); } foreach (UserProfile profile in manager) { DataRow row = table.NewRow(); foreach (Property property in manager.Properties) { row[property.Name] = profile[property.Name].Value; } bool canAdd = true; if (!FilterColumn.Text.Contains("(")) { try { canAdd = (profile[FilterColumn.Text].Value != null) && profile[FilterColumn.Text].Value.ToString().Contains(FilterValue.Text); } catch (Exception ex) { _hasErrors = true; SquadronContext.WriteMessage("Error: " + ex.ToString()); canAdd = false; } } if (canAdd) { table.Rows.Add(row); } } grid.DataSource = table; return(table); }
private void Delete() { var checkedItems = new List <NameEntity>(); foreach (NameEntity o in ItemsList.CheckedItems) { checkedItems.Add(o); } int errorCount = 0; SPSecurity.RunWithElevatedPrivileges(delegate() { foreach (NameEntity ne in checkedItems) { SPSecurableObject spso = ne.SecurableObject.InternalObject as SPSecurableObject; ne.Deleted = false; try { if (string.IsNullOrEmpty(ne.ContainerSPGroup)) { spso.RoleAssignments.Remove(ne.Principal); } else { RemoveUserFromSharePointGroup(ne, spso); } ne.Deleted = true; } catch (Exception ex) { SquadronContext.WriteMessage(ex.ToString()); errorCount++; ne.Deleted = false; } // Remove from Groups if (ne.Principal is SPGroup) { if (spso is SPWeb) { try { if (string.IsNullOrEmpty(ne.ContainerSPGroup)) { bool old = (spso as SPWeb).AllowUnsafeUpdates; (spso as SPWeb).AllowUnsafeUpdates = true; (spso as SPWeb).Update(); (spso as SPWeb).SiteGroups.Remove(ne.Principal.Name); (spso as SPWeb).AllowUnsafeUpdates = old; (spso as SPWeb).Update(); } ne.Deleted = true; } catch (Exception ex) { SquadronContext.HandleException(spso, ex); errorCount++; ne.Deleted = false; } } } if (ne.Deleted) { ItemsList.Items.Remove(ne); } } }); // Display if (errorCount > 0) { SquadronContext.Info("Error(s) occured. Please see the master log for details!"); } }