Пример #1
0
        public void RunAction(DefinedParamsModel options, SecureString passwordSecore)
        {
            // Validate params
            LogHelper.writeBasic("Validate params...");
            ValidationParamsModel resultValidation = ParamsHelper.ValidateParams(options, "import");

            if (resultValidation.valid)
            {
                LogHelper.writeSuccess("The paramaters introduced are valid");

                // Load template from file
                LogHelper.writeBasic("Loading template from file...");
                string directory = "";
                ProvisioningTemplate template = FileHelper.ReadTemplateFromUrl(options.templateName.value, out directory, options.dirPath.value);

                if (template != null)
                {
                    LogHelper.writeSuccess("The template is loaded sucessfully");

                    // Connect with SP
                    LogHelper.writeBasic("Connecting with SharePoint Online...");
                    bool modernAuth = false;
                    bool.TryParse(options.modernAuth.value, out modernAuth);
                    ClientContext context = SPOHelper.Connect(options.urlSite.value, options.username.value, passwordSecore, modernAuth);

                    if (context != null)
                    {
                        LogHelper.writeSuccess("The connection with SPO is established sucessfully");

                        // Import template to SP
                        LogHelper.writeBasic("Import template to SharePoint Online...");
                        bool resultImport = SPOHelper.ImportTemplate(context, template, directory);
                        if (resultImport)
                        {
                            LogHelper.writeSuccess("The proccess of template has finished correctly.");
                        }
                        else
                        {
                            LogHelper.writeError("The template cant be imported to SharePoint, please review the log..");
                        }
                    }
                    else
                    {
                        LogHelper.writeError("There are not connection with SharePoint.");
                    }
                }
                else
                {
                    LogHelper.writeError("There are not template to import to SharePoint.");
                }
            }
            else
            {
                LogHelper.writeError(string.Concat("The paramaters introduced are not valid", string.Join(", ", resultValidation.errors)));
            }
        }
Пример #2
0
        public void RunAction(DefinedParamsModel options, SecureString passwordSecore)
        {
            // Validate params
            LogHelper.writeBasic("Validate params...");
            ValidationParamsModel resultValidation = ParamsHelper.ValidateParams(options, "export");

            if (resultValidation.valid)
            {
                LogHelper.writeSuccess("The paramaters introduced are valid");


                // Connect with SP
                LogHelper.writeBasic("Connecting with SharePoint Online...");
                bool modernAuth = false;
                bool.TryParse(options.modernAuth.value, out modernAuth);
                ClientContext context = SPOHelper.Connect(options.urlSite.value, options.username.value, passwordSecore, modernAuth);

                if (context != null)
                {
                    LogHelper.writeSuccess("The connection with SPO is established sucessfully");

                    // Generate directory
                    string directory = FileHelper.GeneratePathDirectory(options.dirPath.value);

                    // Import template to SP
                    LogHelper.writeBasic("Export template from SharePoint Online...");
                    ProvisioningTemplate templateXML = SPOHelper.ExportTemplate(context, directory);
                    if (templateXML != null)
                    {
                        LogHelper.writeSuccess("The proccess of template has finished correctly.");
                        // Save export data
                        LogHelper.writeBasic("Export template to file system started...");
                        FileHelper.SaveTemplateFromUrl(templateXML, directory, options.templateName.value);
                        LogHelper.writeSuccess("The export of template has finished correctly.");
                    }
                    else
                    {
                        LogHelper.writeError("The template cant be exported to SharePoint, please review the log..");
                    }
                }
                else
                {
                    LogHelper.writeError("There are not connection with SharePoint.");
                }
            }
            else
            {
                LogHelper.writeError(string.Concat("The paramaters introduced are not valid", string.Join(", ", resultValidation.errors)));
            }
        }
Пример #3
0
        // Validate necesary params from app
        public static ValidationParamsModel ValidateParams(DefinedParamsModel options, string typeAction)
        {
            DefinedParamsModel    validationParams = AddValidationType(options, typeAction);
            ValidationParamsModel validation       = new ValidationParamsModel(true, new String[] { });

            // Go over all defined properties in ParamsModel
            foreach (PropertyInfo property in validationParams.GetType().GetProperties())
            {
                string name = property.Name;
                // Get object
                BaseParamModel properties = (BaseParamModel)property.GetValue(options, null);
                // Check if have validations
                if (properties.validations?.Length > 0)
                {
                    string errMsg = ValidateHelper.ValidateField(name, properties.value, properties.validations);
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        validation.valid = false;
                        validation.errors.Append(errMsg);
                    }
                }
            }
            return(validation);
        }