Example #1
0
        public override void Perform(object o, IExplorer explorer)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "*.cmp|*.cmp";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                SquadronHelper.Instance.StartAnimation();

                try
                {
                    ImportExportUtility utility = new ImportExportUtility();

                    if (utility.Import(o as SPWeb, dialog.FileName))
                    {
                        SquadronContext.Info("Imported succesfully!" + Environment.NewLine + Environment.NewLine + "Please ensure home page, list contents, features, sub sites, user permissions in the new site.");
                    }
                }
                finally
                {
                    SquadronHelper.Instance.StopAnimation();
                }
            }
        }
Example #2
0
        public override bool CanMoveNext(int index)
        {
            if (index == PAGE_FILE)
            {
                if ((string.IsNullOrEmpty(FileText.Text))
                    ||
                    !File.Exists(FileText.Text))
                {
                    SquadronContext.Errr("Please enter a valid file!");
                    return(false);
                }
            }

            else if (index == PAGE_FILECONTENT)
            {
                if (!_isFileContentValid)
                {
                    SquadronContext.Errr("Due to error(s) cannot continue further!");
                    return(false);
                }
            }

            else if (index == PAGE_MATCHES)
            {
                return(CanApplyPermissions());
            }

            return(true);
        }
Example #3
0
        public bool ResetToInherit(SPSecurableObject so)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPUtility.ValidateFormDigest();

                try
                {
                    if (so is SPWeb)
                    {
                        ResetWebInheritance(so as SPWeb, true);
                    }

                    else if (so is SPList)
                    {
                        ResetListInheritance(so as SPList, true);
                    }

                    else if (so is SPListItem)
                    {
                        ResetItemInheritance(so as SPListItem, true);
                    }
                }
                catch (Exception ex)
                {
                    SquadronContext.HandleException(ex);
                }
            });

            return(true);
        }
        public void RemoveUserFromWeb(SPWeb web, SPUser user)
        {
            bool old = web.AllowUnsafeUpdates;

            web.AllowUnsafeUpdates = true;
            web.Update();

            try
            {
                web.Users.Remove(user.LoginName);
            }
            catch (Exception ex)
            {
                SquadronContext.HandleException(ex);
            }

            foreach (SPGroup g in web.SiteGroups)
            {
                try
                {
                    g.RemoveUser(user);
                }
                catch (Exception ex)
                {
                    SquadronContext.HandleException(g, ex);
                }
            }

            web.AllowUnsafeUpdates = old;
            web.Update();
        }
Example #5
0
        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.");
            }
        }
Example #6
0
        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();
        }
Example #7
0
        private bool InputsValid()
        {
            if ((_connection1 == null) || (_connection2 == null) || (_connection1.State != ConnectionState.Open) || (_connection2.State != ConnectionState.Open))
            {
                SquadronContext.Info("Please ensure source/destination connections!");
                return(false);
            }

            if (lst1.CheckedIndices.Count == 0)
            {
                SquadronContext.Info("Please select atleast one source table!");
                return(false);
            }

            foreach (string table in lst1.CheckedItems)
            {
                bool found = false;
                foreach (DataRow row in _connection2.GetSchema("Tables").Rows)
                {
                    if (row["TABLE_NAME"].ToString() == table)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    SquadronContext.Info(string.Format("Table {0} do not exists in destination server.  Copy cannot continue!", table));
                    return(false);
                }
            }

            return(true);
        }
        private void ExecuteButton_Click(object sender, EventArgs e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SquadronContext.Url, SquadronContext.GetUserToken()))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        grid.DataSource = null;

                        grid.DataSource = web.Groups.Cast <SPGroup>().ToList();

                        if (CrossSiteCheck.Checked)
                        {
                            grid.DataSource = web.SiteGroups.Cast <SPGroup>().ToList();
                        }

                        ResetGridColumns();
                    }
                }

                if (IncludeUsersCheck.Checked)
                {
                    IncludeUsers();
                }
            });
        }
Example #9
0
        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.");
        }
Example #10
0
        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();
                }
            }
        }
Example #11
0
 private void LogBox_DoubleClick(object sender, EventArgs e)
 {
     if (LogBox.SelectedItem != null)
     {
         SquadronContext.Info(LogBox.SelectedItem.ToString());
     }
 }
Example #12
0
        private void Reset()
        {
            SquadronContext.StartMonitoringExceptions();

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    int count = 0;
                    foreach (int i in ItemsList.CheckedIndices)
                    {
                        if (_permissionUtility.ResetToInherit(_selectedList[i].InternalObject as SPSecurableObject))
                        {
                            count++;
                        }
                    }

                    if (count < ItemsList.CheckedIndices.Count)
                    {
                        SquadronContext.Warn("Reset operation of some item(s) invoked errors. Please refresh & retry.");
                    }
                }
                catch (Exception ex)
                {
                    SquadronContext.HandleException(ex);
                }
                finally
                {
                    SquadronContext.StopMonitoringExceptions();
                    FooterPanel.Text = "Operation completed!";
                }
            });
        }
Example #13
0
        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 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);
        }
Example #15
0
        private void ApplyPermissionForWeb(PermissionEntity pentity, SPWeb web)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPUtility.ValidateFormDigest();

                    using (SPSite elevatedSite = new SPSite(web.Site.ID))
                    {
                        using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
                        {
                            if (pentity.PermissionType == "Inherit")
                            {
                                if (!elevatedWeb.IsRootWeb)
                                {
                                    elevatedWeb.ResetRoleInheritance();
                                }
                            }

                            else if (pentity.PermissionType == "Unique")
                            {
                                if (!elevatedWeb.IsRootWeb)
                                {
                                    elevatedWeb.BreakRoleInheritance(false);
                                }

                                ClearPermissions(elevatedWeb);
                                DeleteAllGroupsAndUsers(elevatedWeb);

                                foreach (RoleEntity rentity in pentity.Roles)
                                {
                                    if (rentity.Type == RoleTypeEnum.SharePointGroup)
                                    {
                                        DeleteGroup(elevatedWeb, rentity.AssignmentName);
                                        CreateGroup(elevatedWeb, rentity.AssignmentName, rentity.Owner);
                                        AddUsersToGroup(elevatedWeb, rentity.AssignmentName, rentity.Users);

                                        AssignPermissionLevels(elevatedWeb, rentity.AssignmentName, rentity.PermissionLevels);
                                    }


                                    else if ((rentity.Type == RoleTypeEnum.DomainGroup) ||
                                             (rentity.Type == RoleTypeEnum.User))
                                    {
                                        AssignPermissionLevelsToNonSharePointGroup(elevatedWeb, rentity.AssignmentName, rentity.PermissionLevels);
                                    }
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                SquadronContext.HandleException(ex);
            }
        }
        public IList <object> RefreshSharePointObjects(IList <object> objects)
        {
            SquadronHelper.Instance.StartAnimation();

            IList <object> result = new List <object>();

            _internalList = new List <object>();

            try
            {
                foreach (object o in objects)
                {
                    try
                    {
                        if (o is SPWebApplication)
                        {
                            result.Add(GetNewWebApplication(o as SPWebApplication));
                        }

                        else if (o is SPSite)
                        {
                            result.Add(GetNewSite(o as SPSite));
                        }

                        else if (o is SPWeb)
                        {
                            result.Add(GetNewWeb(o as SPWeb));
                        }

                        else if (o is SPList)
                        {
                            result.Add(GetNewList(o as SPList));
                        }

                        else if (o is SPListItem)
                        {
                            result.Add(GetNewListItem(o as SPListItem));
                        }

                        else
                        {
                            throw new ApplicationException("Invalid type!");
                        }
                    }
                    catch (Exception ex)
                    {
                        SquadronContext.HandleException(o, ex);
                    }
                }
            }
            finally
            {
                SquadronHelper.Instance.StopAnimation();
            }

            return(result);
        }
Example #17
0
        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);
            }
        }
Example #18
0
        private bool AreInputsValid()
        {
            if ((SelectedColumns.CheckedItems.Count == 0) && (AddinList.SelectedIndex != 0) && !IsListBoxSelected())
            {
                SquadronContext.Info("Please check atleast one column!");
                return(false);
            }

            return(true);
        }
Example #19
0
        private bool Valid()
        {
            if (SourcePermissions.GetSelectedPermissions().Count == 0)
            {
                SquadronContext.Warn("Please select atleast one permission to copy!");
                return(false);
            }

            return(true);
        }
Example #20
0
        private bool InputsValid()
        {
            if (!File.Exists(FileText.Text))
            {
                SquadronContext.Warn("File do not exists!");
                return(false);
            }

            return(true);
        }
        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);
            }
        }
Example #22
0
        private bool Valid()
        {
            bool result = ItemsList.CheckedIndices.Count > 0;

            if (!result)
            {
                SquadronContext.Warn("Please check atleast one item!" + Environment.NewLine + Environment.NewLine + "(You can right click & check/uncheck items)");
            }

            return(result);
        }
Example #23
0
        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;
        }
Example #24
0
        private void ApplyPermissionForListItem(PermissionEntity pentity, SPListItem item)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPUtility.ValidateFormDigest();

                    using (SPSite elevatedSite = new SPSite(item.ParentList.ParentWeb.Site.ID))
                    {
                        using (SPWeb elevatedWeb = elevatedSite.OpenWeb(item.ParentList.ParentWeb.ID))
                        {
                            elevatedWeb.AllowUnsafeUpdates = true;

                            SPList elevatedList         = elevatedWeb.Lists[item.ParentList.Title];
                            SPListItem elevatedListItem = elevatedList.GetItemById(item.ID);
                            if (pentity.PermissionType == "Inherit")
                            {
                                elevatedListItem.ResetRoleInheritance();
                            }

                            else if (pentity.PermissionType == "Unique")
                            {
                                elevatedListItem.BreakRoleInheritance(false);

                                ClearPermissions(elevatedListItem);

                                foreach (RoleEntity rentity in pentity.Roles)
                                {
                                    if (rentity.Type == RoleTypeEnum.SharePointGroup)
                                    {
                                        // Do not delete as parents may use it, DeleteGroup(list.ParentWeb, rentity.AssignmentName);
                                        CreateGroup(elevatedListItem.ParentList.ParentWeb, rentity.AssignmentName, rentity.Owner);
                                        AddUsersToGroup(elevatedListItem.ParentList.ParentWeb, rentity.AssignmentName, rentity.Users);

                                        AssignPermissionLevels(elevatedListItem, rentity.AssignmentName, rentity.PermissionLevels);
                                    }

                                    else if ((rentity.Type == RoleTypeEnum.DomainGroup) ||
                                             (rentity.Type == RoleTypeEnum.User))
                                    {
                                        AssignPermissionLevelsToNonSharePointGroup(elevatedListItem, rentity.AssignmentName, rentity.PermissionLevels);
                                    }
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                SquadronContext.HandleException(ex);
            }
        }
Example #25
0
        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!");
            }
        }
Example #26
0
        private IList <SPUser> GetUsers()
        {
            IList <SPUser> list = new List <SPUser>();

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(_url));

                    foreach (SPSite site in webApplication.Sites)
                    {
                        foreach (SPWeb web in site.AllWebs)
                        {
                            foreach (SPUser user in web.AllUsers)
                            {
                                bool found = false;

                                if (string.IsNullOrEmpty(NameText.Text))
                                {
                                    found = true;
                                    AddUser(list, user);
                                }

                                else if (!string.IsNullOrEmpty(user.LoginName))
                                {
                                    if (user.LoginName.ToLower().Contains(NameText.Text.ToLower()))
                                    {
                                        found = true;
                                        AddUser(list, user);
                                    }

                                    if (!found)
                                    {
                                        if (user.Name.ToLower().Contains(NameText.Text.ToLower()))
                                        {
                                            found = true;
                                            AddUser(list, user);
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                SquadronContext.HandleException(ex);
            }

            return(list);
        }
Example #27
0
        private void Copy()
        {
            var permissions = SourcePermissions.GetSelectedPermissions();

            _permissionUtility.SetPermissions(DestUserText.Text, permissions);

            FooterPanel.Text = "Copy operation completed!";

            if (_permissionUtility.SkippedPermissions)
            {
                SquadronContext.Warn(FooterPanel.Text + Environment.NewLine + Environment.NewLine + "('Limited Access' permissions were skipped!)");
            }
        }