示例#1
0
        /// <summary>
        /// Function to add SharePoint groups at App Catalog
        /// </summary>
        /// <param name="listval">Configuration values from configuration Excel</param>
        /// <param name="groupData">Group details</param>
        private static void AddGroups(Dictionary <string, string> listval, List <DataStorage> groupData)
        {
            try
            {
                // Get the URL of site collection
                string login    = listval["Username"]; // Get the user name
                string password = listval["Password"]; // Get the password

                foreach (DataStorage item in groupData)
                {
                    using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(item.SiteUrl, login, password))
                    {
                        Web             site      = clientContext.Web;
                        GroupCollection collGroup = site.SiteGroups;
                        clientContext.Load(collGroup, groups => groups.Include(properties => properties.Title));
                        clientContext.Load(site.RoleDefinitions);
                        clientContext.ExecuteQuery();

                        //Check if group already exists and create
                        Group currentGrp = CheckAndCreateGroup(collGroup, item, site, clientContext);

                        //Assigning permission to the current group
                        AssignPermission(item, clientContext, site, currentGrp);

                        //Adding users to the current group
                        AddUsersToCurrentGroup(clientContext, site, currentGrp, item);
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                DeleteGroups(listval, groupData);
            }
        }
示例#2
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);
     }
 }
        /// <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
        /// <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
        /// <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 - 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);
     }
 }
示例#8
0
        /// <summary>
        /// Creates terms in term group
        /// </summary>
        /// <param name="listval">Configuration list values from configuration Excel </param>
        /// <param name="TermsData">Terms Data</param>
        public static void CreateTerms(Dictionary <string, string> listval, List <CustomTermGroup> TermsData)
        {
            string targetSite = listval["CatalogSiteURL"]; // Get the URL of site collection
            string login      = listval["Username"];       // Get the user name
            string password   = listval["Password"];       // Get the password

            using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password))
            {
                try
                {
                    CreatePGTerms(TermsData, clientContext);
                }
                catch (Exception exception)
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                }
            }
        }
示例#9
0
        /// <summary>
        /// Creates terms in term group
        /// </summary>
        /// <param name="listval">Configuration list values from configuration Excel </param>
        /// <param name="TermsData">Terms Data</param>
        public static void CreateTerms(Dictionary <string, string> listval, List <CustomTermGroup> TermsData)
        {
            string targetSite        = listval["CatalogSiteURL"];                                                                        // Get the URL of site collection
            string login             = listval["Username"];                                                                              // Get the user name
            string password          = listval["Password"];                                                                              // Get the password
            bool   isDeployedOnAzure = Convert.ToBoolean(listval["IsDeployedOnAzure"].ToUpperInvariant(), CultureInfo.InvariantCulture); // Get Is Deployed on Azure parameter

            using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(targetSite, login, password, isDeployedOnAzure))
            {
                try
                {
                    CreatePGTerms(TermsData, clientContext);
                }
                catch (Exception exception)
                {
                    ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                }
            }
        }
示例#10
0
        /// <summary>
        /// This method is used to delete groups
        /// </summary>
        /// <param name="listval">dictionary object</param>
        /// <param name="groupData">list of data storage objects</param>
        private static void DeleteGroups(Dictionary <string, string> listval, List <DataStorage> groupData)
        {
            try
            {
                // Get the URL of site collection
                string login             = listval["Username"]; // Get the user name
                string password          = listval["Password"]; // Get the password
                bool   isDeployedOnAzure = Convert.ToBoolean(listval["IsDeployedOnAzure"].ToUpperInvariant(), CultureInfo.InvariantCulture);

                foreach (DataStorage item in groupData)
                {
                    using (ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(item.SiteUrl, login, password, isDeployedOnAzure))
                    {
                        //Deleting group if exists
                        Web             site      = clientContext.Web;
                        GroupCollection collGroup = site.SiteGroups;
                        clientContext.Load(collGroup, groups => groups.Include(properties => properties.Title));
                        clientContext.ExecuteQuery();
                        Console.WriteLine("Checking if group " + item.GroupName + " exists");
                        Group currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
                        if (currentGrp != null)
                        {
                            Console.WriteLine("Group " + item.GroupName + " exists. Deleting the group");
                            collGroup.Remove(currentGrp);
                        }
                        site.Update();
                        clientContext.Load(collGroup);
                        clientContext.ExecuteQuery();
                        Console.WriteLine("Successfully deleted group " + item.GroupName);
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
            }
        }
示例#11
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");
            }
        }
示例#12
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);
            }
        }
示例#13
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");
            }
        }
示例#14
0
        /// <summary>
        /// Delete matter center home page, settings page and document details page
        /// </summary>
        /// <param name="configVal">Values in Config sheet</param>
        /// <param name="pageType">Page to be deleted</param>
        internal static void DeleteSitePages(Dictionary <string, string> configVal, MatterCenterPage pageType)
        {
            try
            {
                string        login = configVal["Username"];    // Get the user name
                string        password = configVal["Password"]; // Get the password
                List <string> files = new List <string>();
                string        tenantUrl = configVal["TenantURL"];
                string        tenantDashboardFileName, oldWebdashboard, catalogSiteURL, FileName = string.Empty;
                ClientContext siteClientContext = ConfigureSharePointContext.ConfigureClientContext(tenantUrl, login, password);
                switch (Convert.ToString(pageType, CultureInfo.InvariantCulture).ToUpperInvariant())
                {
                case Constants.MatterCenterHome:
                {
                    tenantDashboardFileName = tenantUrl + ConfigurationManager.AppSettings["spWebDashboardPage"];
                    oldWebdashboard         = ConfigurationManager.AppSettings["oldWebdashboardPage"];
                    FileName = tenantDashboardFileName.Substring(tenantDashboardFileName.LastIndexOf('/') + 1);
                    files.Add(oldWebdashboard);
                    Console.WriteLine(string.Concat(Constants.DeletePageSuccessMessage, tenantUrl));
                    break;
                }

                case Constants.Settings:
                {
                    FileName = ConfigurationManager.AppSettings["SettingsPageName"];
                    Console.WriteLine(string.Concat(Constants.DeletePageSuccessMessage, tenantUrl));
                    break;
                }

                case Constants.DocumentDetails:
                {
                    catalogSiteURL    = configVal["CatalogSiteURL"];
                    siteClientContext = ConfigureSharePointContext.ConfigureClientContext(catalogSiteURL, login, password);
                    FileName          = ConfigurationManager.AppSettings["DocumentLandingPageName"];
                    Console.WriteLine(string.Concat(Constants.DeletePageSuccessMessage + catalogSiteURL));
                    break;
                }
                }
                files.Add(FileName);
                DeletePages(siteClientContext, files);

                if (string.Equals(Constants.Settings, Convert.ToString(pageType, CultureInfo.InvariantCulture).ToUpperInvariant()))
                {
                    string groupName         = ConfigurationManager.AppSettings["PracticeGroupName"],
                           termSetName       = ConfigurationManager.AppSettings["TermSetName"],
                           clientIdProperty  = ConfigurationManager.AppSettings["ClientIDProperty"],
                           clientUrlProperty = ConfigurationManager.AppSettings["ClientUrlProperty"];
                    try
                    {
                        ClientTermSets clients = TermStoreOperations.GetClientDetails(siteClientContext, groupName, termSetName, clientIdProperty, clientUrlProperty);
                        foreach (Client client in clients.ClientTerms)
                        {
                            try
                            {
                                string        clientUrl     = client.ClientUrl;
                                ClientContext clientContext = ConfigureSharePointContext.ConfigureClientContext(clientUrl, login, password);
                                Console.WriteLine(string.Concat(Constants.DeletePageSuccessMessage, clientUrl));
                                DeletePages(clientContext, files);
                                DeleteList(clientContext);
                            }
                            catch (Exception exception)
                            {
                                ErrorLogger.DisplayErrorMessage(string.Format(CultureInfo.InvariantCulture, Constants.ProvisioningPageExceptionMessage, exception.Message, exception.StackTrace));
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorLogger.DisplayErrorMessage(string.Format(CultureInfo.InvariantCulture, Constants.ProvisioningPageExceptionMessage, exception.Message, exception.StackTrace));
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.DisplayErrorMessage(string.Format(CultureInfo.InvariantCulture, Constants.ProvisioningPageExceptionMessage, exception.Message, exception.StackTrace));
            }
        }
示例#15
0
        /// <summary>
        /// To create Provision matter pages
        /// </summary>
        /// <param name="configVal">values in the config sheet</param>
        /// <param name="urlConstantName">To get constant name of page</param>
        /// <param name="sourceFileTemplate">To get source file path</param>
        /// <param name="pageUrlName">To get page Url name</param>
        /// <param name="pageType">Page to be deleted</param>
        internal static void CreateProvisionPages(Dictionary <string, string> configVal, string urlConstantName, string sourceFileTemplate, string pageUrlName, MatterCenterPage pageType)
        {
            try
            {
                string        login                  = configVal["Username"]; // Get the user name
                string        password               = configVal["Password"]; // Get the password
                string        tenantUrl              = configVal["TenantURL"];
                List <string> files                  = new List <string>();
                string        FileName               = string.Empty;
                string        pageFileName           = string.Empty;
                string        pageContent            = string.Empty;
                string        catalogSiteURL         = configVal["CatalogSiteURL"]; // Get the URL for catalog site collection
                string        catalogSiteConstant    = ConfigurationManager.AppSettings["catalogSiteConstant"];
                string        tenantSettingsFileName = string.Empty;
                string        destinationFileName    = string.Empty;
                ClientContext ClientContext          = ConfigureSharePointContext.ConfigureClientContext(tenantUrl, login, password);

                string pageUrlConstant        = urlConstantName;
                string sourceFileTemplatePath = string.Concat(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, Constants.Backslash, ConfigurationManager.AppSettings["staticContentFolder"], Constants.Backslash, ConfigurationManager.AppSettings["htmlFolder"], Constants.Backslash, sourceFileTemplate);
                string pageUrl = configVal["UISiteURL"];
                // Read the content of helper file
                pageContent = System.IO.File.ReadAllText(sourceFileTemplatePath);
                // Set the Catalog site collection URL in the content of webdashboard helper page
                pageContent = pageContent.Replace(catalogSiteConstant, new Uri(catalogSiteURL).AbsolutePath);

                FileName = string.Concat(tenantUrl, ConfigurationManager.AppSettings["spWebDashboardPage"]);
                bool value = false;
                // App web part content
                switch (Convert.ToString(pageType, CultureInfo.InvariantCulture).ToUpperInvariant())
                {
                case Constants.MatterCenterHome:
                {
                    pageContent  = pageContent.Trim();
                    pageContent  = pageContent.Replace(pageUrlConstant, pageUrl);
                    pageFileName = FileName.Substring(FileName.LastIndexOf('/') + 1);
                    Console.WriteLine(string.Concat(Constants.DeletePageMessage, tenantUrl));
                    destinationFileName = FileName;
                    break;
                }

                case Constants.Settings:
                {
                    pageContent            = pageContent.Replace(pageUrlConstant, pageUrl);
                    tenantSettingsFileName = string.Concat(tenantUrl, ConfigurationManager.AppSettings["spSettingsPage"]);
                    pageFileName           = ConfigurationManager.AppSettings["SettingsPageName"];
                    Console.WriteLine(string.Concat(Constants.DeletePageMessage, tenantUrl));
                    destinationFileName = tenantSettingsFileName;
                    value = true;
                    break;
                }

                case Constants.DocumentDetails:
                {
                    pageFileName  = ConfigurationManager.AppSettings["DocumentLandingPageName"];
                    ClientContext = ConfigureSharePointContext.ConfigureClientContext(catalogSiteURL, login, password);
                    FileName      = string.Concat(catalogSiteURL, ConfigurationManager.AppSettings["spDocumentLanding"]);
                    Console.WriteLine(string.Concat(Constants.DeletePageSuccessMessage, catalogSiteURL));
                    destinationFileName = pageFileName;
                    break;
                }
                }

                files.Add(pageFileName);
                DeletePages(ClientContext, files);
                Folder DestinationFolder = CreateHelperPage(ClientContext, FileName);
                CreateMatterCenterPage(ClientContext, DestinationFolder, destinationFileName, pageContent, value);

                if (string.Equals(Constants.Settings, Convert.ToString(pageType, CultureInfo.InvariantCulture).ToUpperInvariant()))
                {
                    string groupName         = ConfigurationManager.AppSettings["PracticeGroupName"],
                           termSetName       = ConfigurationManager.AppSettings["TermSetName"],
                           clientIdProperty  = ConfigurationManager.AppSettings["ClientIDProperty"],
                           clientUrlProperty = ConfigurationManager.AppSettings["ClientUrlProperty"];
                    ClientTermSets clients   = TermStoreOperations.GetClientDetails(ClientContext, groupName, termSetName, clientIdProperty, clientUrlProperty); // Read client details from term store
                    // As Client level web dashboard will not be created, commenting code for provisioning client web dashboard page
                    foreach (Client client in clients.ClientTerms)
                    {
                        try
                        {
                            string clientUrl = client.ClientUrl;
                            // string fileName = clientUrl + ConfigurationManager.AppSettings["spWebDashboardPage"];
                            string        settingsFileName = string.Concat(clientUrl, ConfigurationManager.AppSettings["spSettingsPage"]);
                            ClientContext clientContext    = ConfigureSharePointContext.ConfigureClientContext(clientUrl, login, password);
                            // Deleting client web dashboard pages
                            Console.WriteLine(string.Concat(Constants.DeletePageMessage, clientUrl));
                            DeletePages(clientContext, files);
                            // Create helper file for site collections
                            // Folder destinationFolder = CreateHelperPage(clientContext, fileName);
                            Folder destinationFolder = CreateHelperPage(clientContext, settingsFileName);

                            // Upload web dashboard page
                            // CreateMatterCenterPage(clientContext, destinationFolder, fileName, helperFileContent, false);

                            // Upload settings page
                            CreateMatterCenterPage(clientContext, destinationFolder, settingsFileName, pageContent, true);
                            // Create list
                            CreateList(clientContext);
                        }
                        catch (Exception exception)
                        {
                            ErrorLogger.DisplayErrorMessage(string.Format(CultureInfo.InvariantCulture, Constants.ProvisioningPageExceptionMessage, exception.Message, exception.StackTrace));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.DisplayErrorMessage(string.Format(CultureInfo.InvariantCulture, Constants.ProvisioningPageExceptionMessage, exception.Message, exception.StackTrace));
            }
        }