コード例 #1
0
 /// <summary>
 /// Static main method
 /// </summary>
 /// <param name="args">Command line argument</param>
 public static void Main(string[] args)
 {
     if (2 <= args.Length && !ExcelOperations.IsNullOrEmptyCredential(args[0], args[1]))
     {
         Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, ConfigurationManager.AppSettings["configSheetName"]);
         string username = args[0].Trim();
         string password = args[1].Trim();
         try
         {
             string targetSite = configVal["CatalogSiteURL"];
             using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, username, password))
             {
                 CreateUpdateProvisionMatterListPermissions(clientContext, configVal);
             }
         }
         catch (Exception exception)
         {
             ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
         }
     }
     else
     {
         ErrorMessage.ShowMessage("Please enter username and password", ErrorMessage.MessageType.Error);
     }
 }
コード例 #2
0
ファイル: CreateTerm.cs プロジェクト: trillian74/mattercenter
        public static void Main(string[] args)
        {
            if (2 <= args.Length)
            {
                string username = args[1], password = args[2];
                bool   action = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture); // Flag to Create or Delete Term store Hierarchy
                if (!ExcelOperations.IsNullOrEmptyCredential(username, password))
                {
                    Console.WriteLine("Reading inputs from Excel...");
                    string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
                    string sheetName = ConfigurationManager.AppSettings["sheetname"];

                    Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
                    listval.Add("Username", username);
                    listval.Add("Password", password);
                    if (args.Length != 0 && !string.IsNullOrWhiteSpace(args[0]))
                    {
                        ReadConfigExcel(listval, action);
                    }
                }
                else
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: Invalid Credentials");
                }
            }
            else
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: Insufficient Parameters");
            }
        }
コード例 #3
0
        /// <summary>
        /// Function to create Site columns in content type hub
        /// </summary>
        /// <param name="revert">Flag to create or remove site columns</param>
        /// <param name="login">Username for authentication</param>
        /// <param name="password">Password for authentication</param>
        internal static void AddSiteColumns(bool revert, string login, string password)
        {
            string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
            string sheetName = ConfigurationManager.AppSettings["sheetname"];

            // Read from Excel
            Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);

            if (listval.Count != 0)
            {
                string targetSite        = listval["ContentTypeHubURL"];                                                                     // Get the URL of site collection
                string contentType       = ConfigurationManager.AppSettings["ContentTypeValue"];                                             // Get Content Type DMS from Excel
                string contentTypegroup  = ConfigurationManager.AppSettings["ContentTypeGroupValue"];                                        // Get Group of Content Type
                bool   isDeployedOnAzure = Convert.ToBoolean(listval["IsDeployedOnAzure"].ToUpperInvariant(), CultureInfo.InvariantCulture); // Get Is Deployed on Azure parameter

                try
                {
                    string        siteColNames = GetConfigDataFromResource("SiteColumn_Config", "SiteColumnNames");
                    List <string> siteColumns  = siteColNames.Split(new char[] { ',' }).ToList();

                    using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password, isDeployedOnAzure))
                    {
                        try
                        {
                            if (revert)
                            {
                                // Revert the creation of Site Columns
                                RevertSiteColumns(clientContext, siteColumns, contentType, contentTypegroup);
                            }
                            else
                            {
                                bool nextStep = CreateSiteColumn(clientContext, siteColumns, contentTypegroup);
                                if (nextStep)
                                {
                                    bool typeCreated = CreateContentType(clientContext, siteColumns, contentType, contentTypegroup);
                                    if (typeCreated)
                                    {
                                        Console.WriteLine(GetConfigDataFromResource("SiteColumn_Config", "MsgContentTypeCreated"));
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                        }
                    }
                }
                catch (Exception exception)
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                }
            }
            else
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: No inputs from Excel file...");
            }
        }
コード例 #4
0
        /// <summary>
        /// Main method - Start of the program
        /// </summary>
        /// <param name="args">Input from console</param>
        public static void Main(string[] args)
        {
            bool   revert = false;
            string login, password;

            if (null != args && 2 <= args.Length)
            {
                revert   = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                login    = args[1];
                password = args[2];

                if (!ExcelOperations.IsNullOrEmptyCredential(login, password))
                {
                    Console.WriteLine("Reading inputs from Excel...");
                    string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + ConfigurationManager.AppSettings["filename"];
                    string sheetName = ConfigurationManager.AppSettings["sheetname"];
                    Collection <Collection <string> > groupSheetValues = ExcelOperations.ReadSheet(filePath, ConfigurationManager.AppSettings["groupsheetname"]);
                    string groupName     = Convert.ToString(groupSheetValues[1][0], CultureInfo.InvariantCulture);
                    string errorFilePath = Directory.GetParent(Directory.GetCurrentDirectory()) + ConfigurationManager.AppSettings["errorLogFile"];
                    Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
                    if (listval.Count() > 0)
                    {
                        string targetSite        = listval["CatalogSiteURL"];                                                                        // Get the URL of site collection
                        bool   isDeployedOnAzure = Convert.ToBoolean(listval["IsDeployedOnAzure"].ToUpperInvariant(), CultureInfo.InvariantCulture); // Get Is Deployed on Azure parameter
                        using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password, isDeployedOnAzure))
                        {
                            int listCount = 0;
                            try
                            {
                                listCount = Convert.ToInt32(ConfigurationManager.AppSettings["ListCount"], CultureInfo.InvariantCulture); // Get the total number of lists to be created
                                RevertCreatedList(clientContext, listCount, errorFilePath);
                                RemovePermissionLevelIfExists(clientContext, ConfigurationManager.AppSettings["MatterCenterContributePermission"]);
                                if (!revert)
                                {
                                    CreateSharePointList(clientContext, listCount, groupName); // Create SharePoint List
                                    AddRoleDetails(clientContext);
                                }
                            }
                            catch (Exception exception)
                            {
                                RevertCreatedList(clientContext, listCount, errorFilePath);
                                RemovePermissionLevelIfExists(clientContext, ConfigurationManager.AppSettings["MatterCenterContributePermission"]);
                                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: No inputs found");
                    }
                }
                else
                {
                    Console.WriteLine("Invalid Credentials.");
                }
            }
        }
コード例 #5
0
ファイル: UploadFile.cs プロジェクト: yabroffs/mattercenter
        /// <summary>
        /// Program Entry Point
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void Main(string[] args)
        {
            try
            {
                if (5 <= args.Length)
                {
                    bool uploadAssets = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                    if (!ExcelOperations.IsNullOrEmptyCredential(args[1], args[2]))  // Validate Username and Password and azure website url
                    {
                        Console.WriteLine("Reading inputs from Excel...");
                        string parentPath = Convert.ToString(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, CultureInfo.InvariantCulture);
                        Console.WriteLine(parentPath);
                        string filePath = parentPath + "\\" + ConfigurationManager.AppSettings["filename"];
                        Console.WriteLine(filePath);
                        string sheetName = ConfigurationManager.AppSettings["configsheetname"];
                        Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
                        string login                    = args[1]; // Get the user name
                        string password                 = args[2]; // Get the password
                        string azureWebsiteUrl          = args[3];
                        string appInsightsId            = args[4];
                        string catalogURL               = listval["CatalogSiteURL"];
                        string matterCenterAssetsFolder = ConfigurationManager.AppSettings["AssetsFolder"];
                        parentPath = Convert.ToString(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, CultureInfo.InvariantCulture);

                        using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(catalogURL, login, password))
                        {
                            List siteAssets;
                            ListItemCollection matterCenterFolder;
                            FolderCollection   listFolders;
                            matterCenterFolder = CheckFolderExists(matterCenterAssetsFolder, clientContext, out siteAssets, out matterCenterFolder, out listFolders);

                            if (0 < matterCenterFolder.Count)
                            {
                                Console.WriteLine("\n " + matterCenterAssetsFolder + " already present... Deleting...");
                                matterCenterFolder[0].DeleteObject();
                                clientContext.ExecuteQuery();
                                Console.WriteLine("Successfully deleted " + matterCenterAssetsFolder + " from SharePoint.");
                            }

                            if (uploadAssets)
                            {
                                UploadFilesToFolder(matterCenterAssetsFolder, clientContext, siteAssets,
                                                    listFolders, listval, azureWebsiteUrl, appInsightsId);
                            }
                        }
                    }
                }
                else
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: Insufficient Parameters");
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: yabroffs/mattercenter
        /// <summary>
        /// Storing Credentials For SharePoint
        /// </summary>
        /// <param name="login">Login detail</param>
        /// <param name="password">Pass word</param>
        /// <returns>Client context object</returns>
        public static ClientContext GetClientContext(string login, string password)
        {
            string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
            string sheetName = ConfigurationManager.AppSettings["sheetname"];
            // Read from Excel
            Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
            string catalogSiteURL = listval["TenantURL"];

            return(ConfigureSharePointContext.ConfigureClientContext(catalogSiteURL, login, password));
        }
コード例 #7
0
        /// <summary>
        /// Main Method to initiate the execution
        /// </summary>
        /// <param name="args">Command line argument</param>
        public static void Main(string[] args)
        {
            try
            {
                if (null != args && 2 <= args.Length)
                {
                    bool createData = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                    if (!ExcelOperations.IsNullOrEmptyCredential(args[1], args[2]))
                    {
                        //// Read Configuration sheet and Sample data sheet from Excel
                        string filePath        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
                        string sheetName       = ConfigurationManager.AppSettings["sheetname"];
                        string configSheetName = ConfigurationManager.AppSettings["configsheetname"];
                        Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, configSheetName);
                        configVal.Add("Username", args[1].Trim());
                        configVal.Add("Password", args[2].Trim());
                        Collection <Collection <string> > dataValue = ExcelOperations.ReadSheet(filePath, sheetName);
                        List <DataStorage> matterDetails            = MatterProvisionHelper.FetchMatterData(dataValue);
                        ClientTermSets     clientDetails            = TermStoreOperations.GetClientDetails(configVal);

                        if (createData)
                        {
                            CreateData(matterDetails, clientDetails, configVal);
                        }
                        else
                        {
                            RevertData(matterDetails, clientDetails, configVal);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Username and Password");
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect command line argument was supplied. Kindly provide correct command line argument.");
                }
                Console.WriteLine("\n\n---Execution completed---");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
            catch (Exception exception)
            {
                Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                Console.WriteLine("Error log will found at {0}", errorFilePath);
                Console.WriteLine("\n\n---Execution completed---");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
コード例 #8
0
 /// <summary>
 /// Main method - Start of the program
 /// </summary>
 /// <param name="args">Command line arguments</param>
 public static void Main(string[] args)
 {
     if (2 == args.Length && !ExcelOperations.IsNullOrEmptyCredential(args[0], args[1]))
     {
         Console.Title = "Update List Permission";
         ErrorMessage.ShowMessage(ConfigurationManager.AppSettings["ExcelMessage"], ErrorMessage.MessageType.Success);
         try
         {
             string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
             string sheetName = ConfigurationManager.AppSettings["SheetName"];
             Collection <Collection <string> > groupSheetValues = ExcelOperations.ReadSheet(filePath, ConfigurationManager.AppSettings["GroupSheetName"]);
             string groupName = Convert.ToString(groupSheetValues[1][0], CultureInfo.InvariantCulture);
             string username  = args[0].Trim();
             string password  = args[1].Trim();
             Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
             if (listval.Count() > 0)
             {
                 // Get Is Deployed on Azure parameter
                 bool isDeployedOnAzure = Convert.ToBoolean(listval["IsDeployedOnAzure"].ToUpperInvariant(), CultureInfo.InvariantCulture);
                 // Get the Client Context
                 using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(listval["CatalogSiteURL"], username, password, isDeployedOnAzure))
                 {
                     try
                     {
                         UpdateListPermissions(groupName, clientContext);
                         ErrorMessage.ShowMessage(ConfigurationManager.AppSettings["ListSuccess"], ErrorMessage.MessageType.Success);
                     }
                     catch (Exception exception)
                     {
                         ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                         ErrorMessage.ShowMessage(string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["ListFailure"], errorFilePath), ErrorMessage.MessageType.Error);
                     }
                 }
             }
             else
             {
                 ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: No inputs found");
             }
         }
         catch (Exception exception)
         {
             ErrorLogger.LogErrorToTextFile(errorFilePath, string.Concat(exception.Message, "\n", exception.StackTrace));
         }
     }
     else
     {
         ErrorMessage.ShowMessage(ConfigurationManager.AppSettings["Invalidcredential"], ErrorMessage.MessageType.Error);
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: yabroffs/mattercenter
        /// <summary>
        /// This method is the entry point for the application
        /// </summary>
        /// <param name="args">input from console</param>
        public static void Main(string[] args)
        {
            string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
            string sheetName = ConfigurationManager.AppSettings["configsheetname"];

            if (null != args && 3 <= args.Length)
            {
                string login = args[1], password = args[2];
                if (!ExcelOperations.IsNullOrEmptyCredential(login, password))
                {
                    Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
                    listval.Add("Username", login);
                    listval.Add("Password", password);
                    Collection <Collection <string> > groupSheetValues = ExcelOperations.ReadSheet(filePath, ConfigurationManager.AppSettings["groupsheetname"]);
                    List <DataStorage> groupData = ReadGroupConfig(groupSheetValues, listval);
                    if (args.Length != 0 && !string.IsNullOrWhiteSpace(args[0]))
                    {
                        if (Convert.ToBoolean(args[0], CultureInfo.InvariantCulture))
                        {
                            AddGroups(listval, groupData);
                        }
                        else
                        {
                            DeleteGroups(listval, groupData);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Invalid Credentials.");
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Exception Details: Invalid Credentials.");
                }
            }
            else
            {
                Console.WriteLine("Insufficient Parameters.");
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Exception Details: Insufficient Parameters.");
            }
        }
コード例 #10
0
        /// <summary>
        /// This method is the entry point for this application
        /// </summary>
        /// <param name="args">input from console</param>
        private static void Main(string[] args)
        {
            string configSheet = ConfigurationManager.AppSettings["configsheetname"];
            string filePath    = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
            Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, configSheet);

            if (2 <= args.Length)
            {
                string login = args[1], password = args[2];
                bool   createSiteCollections = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                configVal.Add("Username", login);
                if (!ExcelOperations.IsNullOrEmptyCredential(login, password))
                {
                    try
                    {
                        Collection <Collection <string> > clientVal = ExcelOperations.ReadSheet(filePath, ConfigurationManager.AppSettings["clientsheetname"]);
                        bool   isDeployedOnAzure = Convert.ToBoolean(configVal["IsDeployedOnAzure"], CultureInfo.InvariantCulture);
                        string targetSite        = configVal["TenantAdminURL"];
                        string tenantSite        = configVal["TenantURL"];

                        using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password, isDeployedOnAzure))
                        {
                            using (SecureString securePassword = new SecureString())
                            {
                                foreach (char letter in password)
                                {
                                    securePassword.AppendChar(letter);
                                }
                                SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

                                // Activate feature on tenant site collection
                                ActivateFeature(tenantSite, onlineCredentials);
                                for (int count = 1; count < clientVal.Count; count++)
                                {
                                    string clientName   = clientVal[count][0];
                                    string clientUrl    = clientVal[count][2];
                                    string siteOwners   = clientVal[count][3];
                                    string siteVisitors = clientVal[count][4];
                                    if (createSiteCollections)
                                    {
                                        CreateSiteCollections(clientContext, configVal, clientUrl, clientName);
                                        CreateRestrictedGroup(clientUrl, onlineCredentials);

                                        //// Check if the user list for the group is empty
                                        if (!string.IsNullOrEmpty(siteOwners))
                                        {
                                            AssignPermissions(clientUrl, onlineCredentials, ConfigurationManager.AppSettings["Owners Group"], siteOwners);
                                        }

                                        //// Check if the user list for the group is empty
                                        if (!string.IsNullOrEmpty(siteVisitors))
                                        {
                                            AssignPermissions(clientUrl, onlineCredentials, ConfigurationManager.AppSettings["Visitors Group"], siteVisitors);
                                        }

                                        ActivateFeature(clientUrl, onlineCredentials);
                                    }
                                    else
                                    {
                                        DeleteSiteCollection(clientContext, clientUrl);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorLogger.DisplayErrorMessage(exception.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Command-line parameters are missing. Provide {0} Action(true/false) {1} Username and {2} Password");
            }
        }
コード例 #11
0
        /// <summary>
        /// Main method - Start of the program
        /// </summary>
        /// <param name="args"> argument as parameter </param>
        public static void Main(string[] args)
        {
            if (2 <= args.Length && !ExcelOperations.IsNullOrEmptyCredential(args[0], args[1]))
            {
                try
                {
                    // Read login credentials from excel
                    string filePath  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
                    string sheetName = ConfigurationManager.AppSettings["SheetName"];
                    Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);
                    bool   isDeployedOnAzure            = Convert.ToBoolean(listval["IsDeployedOnAzure"], CultureInfo.InvariantCulture);
                    string username = args[0].Trim();
                    string password = args[1].Trim();

                    // Read client context for Tenant URL
                    using (ClientContext userClientContext = ConfigureSharePointContext.ConfigureClientContext(listval["CatalogSiteURL"], username, password, isDeployedOnAzure))
                    {
                        // Reading SharePoint properties
                        string groupName         = ConfigurationManager.AppSettings["PracticeGroupName"]; // Get Practice Group Name
                        string termSetName       = ConfigurationManager.AppSettings["TermSetName"];       // Get Term Set Name
                        string clientIdProperty  = ConfigurationManager.AppSettings["ClientIDProperty"];  // Get Client ID
                        string clientUrlProperty = ConfigurationManager.AppSettings["ClientUrlProperty"]; // Get Client Url
                        string clientUrl         = null;                                                  // Store Client URL
                        string selectedField     = null;

                        // Reading client term sets
                        ClientTermSets clientTermSets = TermStoreOperations.GetClientDetails(userClientContext, groupName, termSetName, clientIdProperty, clientUrlProperty);

                        // Iterating over clients in term store to get client URL and update lists
                        foreach (Client client in clientTermSets.ClientTerms)
                        {
                            try
                            {
                                clientUrl = client.ClientUrl;
                                if (!string.IsNullOrEmpty(clientUrl))
                                {
                                    ClientContext  clientContext = ConfigureSharePointContext.ConfigureClientContext(clientUrl, username, password, isDeployedOnAzure);
                                    List           list          = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["ListName"]);
                                    ViewCollection viewFields    = list.Views;
                                    View           targetView    = viewFields.GetByTitle(ConfigurationManager.AppSettings["ViewName"]);
                                    clientContext.Load(targetView.ViewFields);
                                    clientContext.ExecuteQuery();

                                    // Update fields to list only if title field is not present already
                                    selectedField = UpdateFields(selectedField, client, clientContext, list, targetView);
                                }

                                ErrorMessage.ShowMessage(client.ClientName + " site collection view updated with field", ErrorMessage.MessageType.Success);
                            }
                            catch (Exception exception)
                            {
                                ErrorMessage.ShowMessage(exception.Message + client.ClientName, ErrorMessage.MessageType.Error);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    ErrorMessage.ShowMessage(exception.Message, ErrorMessage.MessageType.Error);
                }
            }
            else
            {
                ErrorMessage.ShowMessage("Please enter the Username and Password", ErrorMessage.MessageType.Error);
            }
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: yabroffs/mattercenter
        /// <summary>
        /// This method is the entry point for the application
        /// </summary>
        /// <param name="args">input from console</param>
        public static void Main(string[] args)
        {
            if (null != args && 2 <= args.Length)
            {
                string login = args[1].Trim(), password = args[2].Trim();
                bool   createType = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                if (!ExcelOperations.IsNullOrEmptyCredential(login, password))
                {
                    string filePath                     = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
                    string sheetName                    = ConfigurationManager.AppSettings["configsheetname"];
                    string termStoreSheetname           = ConfigurationManager.AppSettings["termstoreSheetname"];
                    Dictionary <string, string> listval = ExcelOperations.ReadFromExcel(filePath, sheetName);

                    // Read from Excel
                    Collection <Collection <string> > termStoreVal = ExcelOperations.ReadSheet(filePath, termStoreSheetname);
                    List <string> contentTypeVal        = new List <string>();
                    List <string> documentTemplateList  = new List <string>();
                    int           contentTypeIndex      = termStoreVal[0].IndexOf(ConfigurationManager.AppSettings["contentTypeColumnName"]);
                    int           documentTemplateIndex = termStoreVal[0].IndexOf(ConfigurationManager.AppSettings["documentTemplateColumnName"]);

                    for (int count = 1; count < termStoreVal.Count; count++)
                    {
                        if (!contentTypeVal.Contains(termStoreVal[count][contentTypeIndex]))
                        {
                            contentTypeVal.Add(termStoreVal[count][contentTypeIndex]);
                        }
                        documentTemplateList = documentTemplateList.Union(termStoreVal[count][documentTemplateIndex].Split(';')).ToList();
                    }
                    contentTypeVal = contentTypeVal.Union(documentTemplateList).ToList();

                    try
                    {
                        if (0 != listval.Count)
                        {
                            string        targetSite    = listval["ContentTypeHubURL"]; // Get the URL of site collection
                            ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password);

                            for (int count = 0; count < contentTypeVal.Count; count++)
                            {
                                string parentContentType = ConfigurationManager.AppSettings["ContentTypeValue"];
                                string contentType       = contentTypeVal[count];                                     // Get Content Type DMS from Excel
                                string contentTypeGroup  = ConfigurationManager.AppSettings["ContentTypeGroupValue"]; // Get Group of Content Type
                                if (createType)
                                {
                                    CreateContentType(clientContext, contentType, parentContentType, contentTypeGroup);
                                }
                                else
                                {
                                    DeleteContentType(clientContext, contentType);
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                    }
                }
                else
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: Invalid Credentials");
                }
            }
            else
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: Insufficient Parameters");
            }
        }
コード例 #13
0
        /// <summary>
        /// Function to update permissions on send mail list
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="configVal">Configuration values from configuration excel</param>
        internal static void CreateUpdateProvisionMatterListPermissions(ClientContext clientContext, Dictionary <string, string> configVal)
        {
            Dictionary <string, string> groupValues = ExcelOperations.ReadFromExcel(filePath, ConfigurationManager.AppSettings["groupSheetName"]);

            Console.Write("Creating Provision Matter List...");
            List provisionMatterList;
            //This is a dummy list that is getting created to check whether the current login user can create matter or not
            //Otherwise this list has no significance
            string listName = ConfigurationManager.AppSettings["listName"];
            Web    web      = clientContext.Web;

            ListCollection listcoll = web.Lists;

            clientContext.Load(listcoll, lists => lists.Include(list => list.Title)); //Refresh the collection
            clientContext.ExecuteQuery();
            provisionMatterList = listcoll.Cast <List>().FirstOrDefault(list => list.Title == listName);

            if (null == provisionMatterList)
            {
                ListCreationInformation listCreationInfo = new ListCreationInformation();
                listCreationInfo.Title        = listName;
                listCreationInfo.TemplateType = (int)ListTemplateType.Announcements;
                provisionMatterList           = web.Lists.Add(listCreationInfo);
                clientContext.Load(provisionMatterList);
                clientContext.ExecuteQuery();
            }

            clientContext.Load(listcoll, lists => lists.Include(list => list.Title, list => list.HasUniqueRoleAssignments)); //Refresh the collection
            clientContext.ExecuteQuery();
            provisionMatterList = listcoll.Cast <List>().FirstOrDefault(list => list.Title == listName);



            //Update list permissions
            if (provisionMatterList.HasUniqueRoleAssignments)
            {
                provisionMatterList.ResetRoleInheritance();
            }

            provisionMatterList.BreakRoleInheritance(false, true);
            clientContext.Load(provisionMatterList);
            clientContext.ExecuteQuery();

            RoleAssignmentCollection roleAssignment = provisionMatterList.RoleAssignments;
            List <string>            groupNames     = groupValues.Keys.ToList();

            if (3 <= groupNames.Count)
            {
                Group          provisionGroup = web.SiteGroups.GetByName(groupNames[2]);
                RoleDefinition contributeRole = web.RoleDefinitions.GetByName(ConfigurationManager.AppSettings["roleType"]);
                clientContext.Load(roleAssignment);
                clientContext.Load(provisionGroup);
                clientContext.Load(contributeRole);
                clientContext.ExecuteQuery();

                RoleDefinitionBindingCollection collRdb = new Microsoft.SharePoint.Client.RoleDefinitionBindingCollection(clientContext);
                collRdb.Add(contributeRole);
                roleAssignment.Add(provisionGroup, collRdb);
                clientContext.ExecuteQuery();
            }
        }
コード例 #14
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Arguments from the command line</param>
        public static void Main(string[] args)
        {
            int argLength = null != args ? args.Length : 0;

            /*
             * Scenarios
             * 3 = false, Username and Password : Delete All pages
             * 3 = true, username and password : create all pages
             * 4 = false, <Page Name>, username, password  :  Delete specific page as mentioned in parameter
             * 4 = true, <Page Name>, username, password  :  Create specific page as mentioned in parameter
             * */

            if (null != args && 4 <= argLength)
            {
                bool isSpecificPageRequest = (4 < argLength) ? true : false;
                bool isCreatePageRequest   = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);

                if (isSpecificPageRequest)
                {
                    string pageName    = args[1];
                    string configSheet = ConfigurationManager.AppSettings["configsheetname"];
                    string filePath    = string.Concat(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, Constants.Backslash, ConfigurationManager.AppSettings["filename"]);
                    Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, configSheet);

                    if (!ExcelOperations.IsNullOrEmptyCredential(args[1], args[2]))
                    {
                        configVal.Add("Username", args[1]);
                        configVal.Add("Password", args[2]);
                        configVal.Add("UISiteURL", args[3]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Credentials. No inputs found");
                        return;
                    }
                    // Create specific page
                    if (isCreatePageRequest)
                    {
                        switch (pageName.ToUpperInvariant())
                        {
                        case Constants.MatterCenterHome:
                        {
                            CreateProvisionPages(configVal, ConfigurationManager.AppSettings["urlConstant"], ConfigurationManager.AppSettings["sourcefilenametemplate"], ConfigurationManager.AppSettings["webDashboardUrl"], MatterCenterPage.MatterCenterHome);         //Call for provisioning matter center home page
                            break;
                        }

                        case Constants.Settings:
                        {
                            CreateProvisionPages(configVal, ConfigurationManager.AppSettings["SettingsPageUrlConstant"], ConfigurationManager.AppSettings["SettingsHelperFileName"], ConfigurationManager.AppSettings["settingsUrl"], MatterCenterPage.Settings);                //Call for provisioning settings page
                            break;
                        }

                        case Constants.DocumentDetails:
                        {
                            CreateProvisionPages(configVal, string.Empty, ConfigurationManager.AppSettings["DocumentLandingFileName"], string.Empty, MatterCenterPage.DocumentDetails);               //Call for provisioning document landing page
                            break;
                        }

                        default:
                        {
                            Console.WriteLine(Constants.InvalidParameterFileName);
                            break;
                        }
                        }
                    }
                    else
                    {
                        // Delete specific page
                        switch (pageName.ToUpperInvariant())
                        {
                        case Constants.MatterCenterHome:
                        {
                            DeleteSitePages(configVal, MatterCenterPage.MatterCenterHome);         //Call for deleting matter center home page
                            break;
                        }

                        case Constants.Settings:
                        {
                            DeleteSitePages(configVal, MatterCenterPage.Settings);          //Call for deleting settings page
                            break;
                        }

                        case Constants.DocumentDetails:
                        {
                            DeleteSitePages(configVal, MatterCenterPage.DocumentDetails);           //Call for deleting document details page
                            break;
                        }

                        default:
                        {
                            Console.WriteLine(Constants.InvalidParameterFileName);
                            break;
                        }
                        }
                    }
                }
                else
                {
                    string configSheet = ConfigurationManager.AppSettings["configsheetname"];
                    string filePath    = string.Concat(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, Constants.Backslash, ConfigurationManager.AppSettings["filename"]);
                    Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, configSheet);

                    if (!ExcelOperations.IsNullOrEmptyCredential(args[1], args[2]))
                    {
                        configVal.Add("Username", args[1]);
                        configVal.Add("Password", args[2]);
                        configVal.Add("UISiteURL", args[3]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid credentials. No inputs found");
                        return;
                    }
                    // Create all pages
                    if (isCreatePageRequest)
                    {
                        CreateProvisionPages(configVal, ConfigurationManager.AppSettings["urlConstant"], ConfigurationManager.AppSettings["sourcefilenametemplate"], ConfigurationManager.AppSettings["webDashboardUrl"], MatterCenterPage.MatterCenterHome); //Call for provisioning matter center home page
                        CreateProvisionPages(configVal, ConfigurationManager.AppSettings["SettingsPageUrlConstant"], ConfigurationManager.AppSettings["SettingsHelperFileName"], ConfigurationManager.AppSettings["settingsUrl"], MatterCenterPage.Settings); //Call for provisioning settings page
                        CreateProvisionPages(configVal, string.Empty, ConfigurationManager.AppSettings["DocumentLandingFileName"], string.Empty, MatterCenterPage.DocumentDetails);                                                                           //Call for provisioning document landing page
                    }
                    else
                    {
                        //  Delete all pages
                        DeleteSitePages(configVal, MatterCenterPage.MatterCenterHome); //Call for deleting matter center home page
                        DeleteSitePages(configVal, MatterCenterPage.Settings);         //Call for deleting settings page
                        DeleteSitePages(configVal, MatterCenterPage.DocumentDetails);  //Call for deleting document details page
                    }
                }
            }
            else
            {
                Console.Write(Constants.InvalidParameter);
            }
        }
コード例 #15
0
        /// <summary>
        /// Function to update permissions on send mail list
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="configVal">Configuration values from configuration excel</param>
        internal static void UpdateSendMailListPermissions(ClientContext clientContext, Dictionary <string, string> configVal)
        {
            Dictionary <string, string> groupValues = ExcelOperations.ReadFromExcel(filePath, ConfigurationManager.AppSettings["groupSheetName"]);

            Console.Write("Updating permissions for Send Mail list");

            string listName = ConfigurationManager.AppSettings["listName"];
            Web    web      = clientContext.Web;

            clientContext.Load(web);
            clientContext.ExecuteQuery();

            ListCollection listcoll = web.Lists;

            //Attempt to get the list
            List sendList;
            int  attempts = 0;

            do
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(30000);
                clientContext.Load(listcoll, lists => lists.Include(list => list.Title, list => list.HasUniqueRoleAssignments)); //Refresh the collection
                clientContext.ExecuteQuery();
                sendList  = listcoll.Cast <List>().FirstOrDefault(list => list.Title == listName);
                attempts += 1;
            }while (null == sendList && 20 > attempts);
            Console.WriteLine(string.Empty);

            if (null != sendList)
            {
                //Update list permissions
                if (sendList.HasUniqueRoleAssignments)
                {
                    sendList.ResetRoleInheritance();
                }

                sendList.BreakRoleInheritance(false, true);
                clientContext.Load(sendList);
                clientContext.ExecuteQuery();

                RoleAssignmentCollection roleAssignment = sendList.RoleAssignments;
                List <string>            groupNames     = groupValues.Keys.ToList();
                if (3 <= groupNames.Count)
                {
                    Group          provisionGroup = web.SiteGroups.GetByName(groupNames[2]);
                    RoleDefinition contributeRole = web.RoleDefinitions.GetByName(ConfigurationManager.AppSettings["roleType"]);
                    clientContext.Load(roleAssignment);
                    clientContext.Load(provisionGroup);
                    clientContext.Load(contributeRole);
                    clientContext.ExecuteQuery();

                    RoleDefinitionBindingCollection collRdb = new Microsoft.SharePoint.Client.RoleDefinitionBindingCollection(clientContext);
                    collRdb.Add(contributeRole);
                    roleAssignment.Add(provisionGroup, collRdb);
                    clientContext.ExecuteQuery();
                }
            }
            else
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: SendMail list was not created successfully at " + configVal["CatalogSiteURL"] + "/" + ConfigurationManager.AppSettings["ProvisionMatterAppName"]);
            }
        }