Example #1
0
 /// <summary>
 /// Read configuration values from Excel and create term store hierarchy
 /// </summary>
 /// <param name="listval">Configuration values from configuration Excel</param>
 /// <param name="action">Flag to create or delete hierarchy</param>
 public static void ReadConfigExcel(Dictionary <string, string> listval, bool action)
 {
     try
     {
         string filePath        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
         string termSheetName   = ConfigurationManager.AppSettings["termconfig"];
         string clientSheetName = ConfigurationManager.AppSettings["clientconfig"];
         if (System.IO.File.Exists(filePath))
         {
             Collection <Collection <string> > termSheetValues   = ExcelOperations.ReadSheet(filePath, termSheetName);
             Collection <Collection <string> > clientSheetValues = ExcelOperations.ReadSheet(filePath, clientSheetName);
             List <DataStorage> termList   = ReadTermData(termSheetValues, "Practice_Group").ToList();
             List <DataStorage> clientList = ReadTermData(clientSheetValues, "Client").ToList();
             if (action)
             {
                 CreateTermStructure(listval, termList);
                 CreateClientStructure(listval, clientList, action);
             }
             else
             {
                 CreateClientStructure(listval, clientList, action);
             }
         }
         else
         {
             ErrorLogger.LogErrorToTextFile(errorFilePath, "Couldn't find file: " + filePath);
         }
     }
     catch (Exception exception)
     {
         ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
     }
 }
        /// <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.");
                }
            }
        }
Example #3
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();
            }
        }
Example #4
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);
     }
 }
Example #5
0
        /// <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.");
            }
        }
Example #6
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");
            }
        }
Example #7
0
        /// <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");
            }
        }