public JsonResult Export()
        {
            try
            {
                // get the json templates under the root item
                var jsonTemplates = new SitecoreDataManager().GetTemplatesForExport();
                // serialize the templates
                var json = JsonConvert.SerializeObject(jsonTemplates);

                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = true, Data = json
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception ex)
            {
                Log.Error("SitecoreUML Export Exception: An error occurred while exporting templates from Sitecore", ex, this);
                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = false, ErrorMessage = ex.Message
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
        public JsonResult Deploy()
        {
            try
            {
                // read the json from the body of the request
                var jsonBody = new StreamReader(Request.InputStream).ReadToEnd();
                // parse the json
                var templates = JsonConvert.DeserializeObject <List <JsonSitecoreTemplate> >(jsonBody);

                // import the templates
                var manager = new SitecoreDataManager();
                var success = manager.ImportTemplates(templates);

                var response = new JsonResponse()
                {
                    Success = success
                };
                return(new JsonResult()
                {
                    Data = response
                });
            }
            catch (Exception ex)
            {
                Log.Error("SitecoreUML Deploy Exception: An error occurred while deploying templates to Sitecore", ex, this);
                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = false, ErrorMessage = ex.Message
                    }
                });
            }
        }
        public JsonResult Validate()
        {
            try
            {
                // read the json from the body of the request
                var jsonBody = new StreamReader(Request.InputStream).ReadToEnd();
                // parse the json
                var templates = JsonConvert.DeserializeObject <List <JsonSitecoreTemplate> >(jsonBody);

                // validate the templates and get the response
                var response = new SitecoreDataManager().ValidateTemplates(templates);

                // send the response
                return(new JsonResult()
                {
                    Data = JsonConvert.SerializeObject(response)
                });
            }
            catch (Exception ex)
            {
                Log.Error("SitecoreUML ValidateFieldTypes Exception: An error occurred while validating field types", ex, this);
                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = false, ErrorMessage = ex.Message
                    }
                });
            }
        }
Beispiel #4
0
        public JsonResult GetTemplateArchitecture()
        {
            try
            {
                var jsonArchitecture = new SitecoreDataManager().GetTemplateArchitectureForExport();

                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = true, Data = jsonArchitecture
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("SitecoreUML Export Architecture Exception: An error occurred while exporting templates from Sitecore", ex, this);
                return(new JsonResult()
                {
                    Data = new JsonResponse()
                    {
                        Success = false, ErrorMessage = ex.Message
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
Beispiel #5
0
        public override void Execute(CommandContext context)
        {
            var outputFolderPath = SitecoreUMLConfiguration.ExportSaveFolder;
            var outputDirectory  = new DirectoryInfo(outputFolderPath);

            // if the export save folder path doesn't exist then terminate and show an error
            if (!outputDirectory.Exists)
            {
                Log.Error($"SitecoreUML Export Error: Export save folder path could not be found at the configured location: {outputFolderPath}", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert($"SitecoreUML Export Error: Export save folder was not found: {outputFolderPath}");
                return;
            }

            // get the templates for export
            var jsonTemplates = new SitecoreDataManager().GetTemplatesForExport();

            using (var file = File.CreateText($"{outputDirectory.FullName}/{DateTime.Now:yyyyMMddhhmmss}.json"))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(file, jsonTemplates);
            }

            Sitecore.Context.ClientPage.ClientResponse.Alert("Export completed successfully!");
        }
        public override void Execute(CommandContext context)
        {
            var inputFolderPath = SitecoreUMLConfiguration.ImportDropFolder;
            var inputDirectory  = new DirectoryInfo(inputFolderPath);

            // if the import file drop path doesn't exist then terminate and show an error
            if (!inputDirectory.Exists)
            {
                Log.Error($"SitecoreUML Import Error: Drop path could not be found at the configured location: {inputFolderPath}", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert($"SitecoreUML Import Error: Import Drop Folder was not found: {inputFolderPath}");
                return;
            }

            var inputFiles = inputDirectory.EnumerateFiles("*.json").ToArray();

            if (!inputFiles.Any())
            {
                Log.Error("SitecoreUML Import Error: Input files could not be found at the configured location. See the configuration for more.", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert("SitecoreUML Import Error: Import files were not found in the drop folder. See configuration for more.");
                return;
            }

            // deserialize the json
            var importDataSets = GetImportDataSets(inputFiles);

            // if data sets are null or empty report to the log and the client, and then terminate
            if (importDataSets == null)
            {
                Log.Warn("SitecoreUML Import Error: No import data sets were found in the import files. Process terminated.", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert("SitecoreUML Import Error: No import data sets were found in the import files. Process terminated.");
                return;
            }

            // get the root item to add the templates to
            var templateRoot = _database.GetItem(SitecoreUMLConfiguration.Instance.TemplatesRootPath);

            if (templateRoot == null)
            {
                Log.Error($"SitecoreUML Import Error: Template root path does not exist: '{SitecoreUMLConfiguration.Instance.TemplatesRootPath}'.", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert($"SitecoreUML Import Error: Template root path does not exist: '{SitecoreUMLConfiguration.Instance.TemplatesRootPath}'.");
                return;
            }

            // execute the import
            var importManager = new SitecoreDataManager();

            if (!importDataSets.All(set => importManager.ImportTemplates(set, templateRoot)))
            {
                // TODO: add support for rolling back the import and update the logging when complete

                Log.Error("SitecoreUML Import Error: An error occurred while importing the template sets. Process terminated early. Please review your content tree for artifact files.", this);
                Sitecore.Context.ClientPage.ClientResponse.Alert("SitecoreUML Import Error: An error occurred while importing the template sets. Process terminated early. Please review your content tree for artifact files.");
                return;
            }

            // delete or archive the import data
            // TODO: implement delete or archiving functionality

            // refresh the template root so the imported items show
            Sitecore.Context.ClientPage.SendMessage(this, $"item:refreshchildren(id={templateRoot.ID})");
            // show the client a success message
            Sitecore.Context.ClientPage.ClientResponse.Alert("Import completed successfully!");
        }