//Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Humana.HumanaComTenant.Project.HumanaCom"", ""Humana.HumanaComTenant.Project.HumanaCom\Humana.HumanaComTenant.Project.HumanaCom.csproj"", ""{ABB9DB14-D83B-4A2A-BC4B-20A20A8C037D}""
        //EndProject";
        public void Process(SitecoreResourceManagerArgs args)
        {
            string solution = File.ReadAllText(args.SolutionPath);

            foreach (string proj in args.NewOverlayFiles.Where(x => x.EndsWith(".csproj")))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(proj);
                var projGuid     = doc.GetElementsByTagName("ProjectGuid")[0].InnerText;
                var projTypeGuid = doc.GetElementsByTagName("ProjectTypeGuids")[0].InnerText.Split(';').Last();
                int index        = solution.IndexOf("Project(\"") - 1;
                solution = solution.Insert(index,
                                           string.Format(
                                               _solutionProjectTemplate,
                                               projTypeGuid.ToUpper(),
                                               $"{args.Prefix}.{args.Layer}.{args.ProjectName}",
                                               proj.Split(new[] { Path.GetDirectoryName(args.SolutionPath) + '\\' }, StringSplitOptions.None).Last(),
                                               projGuid));
                index    = solution.IndexOf("GlobalSection(ProjectConfigurationPlatforms) = postSolution") + 59;
                solution = solution.Insert(index,
                                           string.Format(_solutionGlobalSectionTemplate, projGuid));
                args.EventLog.Add($"Prepping new project {proj} to be added to the solution {args.SolutionPath}");
            }
            File.WriteAllText(args.SolutionPath, solution);
            args.EventLog.Add($"Adding new projects to solution path {args.SolutionPath}");
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (Path.GetFileName(args.Wrapper.TemplateZip.ToLower()) != _applicableTemplateZip.ToLower())
            {
                return;
            }
            var fileName = ReplaceAllTokens.ReplaceTokens(_fileName, args);
            var template = ReplaceAllTokens.ReplaceTokens(_template, args);

            var path = Directory.EnumerateFiles(args.OverlayTarget, $"*{fileName}*", SearchOption.AllDirectories).FirstOrDefault(x => (Path.GetFileName(x)?.ToLower() ?? string.Empty) == fileName.ToLower());

            if (path == null)
            {
                return;
            }
            var content = File.ReadAllText(path);
            int index   = content.LastIndexOf('}');

            if (index > -1)
            {
                index--;
            }
            index   = content.LastIndexOf('}', index);
            content = content.Insert(index, template);
            File.WriteAllText(path, content);
        }
Exemplo n.º 3
0
        private static string ProcessName(string path, SitecoreResourceManagerArgs args)
        {
            var resolved = ReplaceTokens(path, args, Path.GetFileName(path));

            if (resolved != path)
            {
                try
                {
                    if (Directory.Exists(resolved))
                    {
                        foreach (var child in Directory.EnumerateFileSystemEntries(path))
                        {
                            if (Directory.Exists(child))
                            {
                                Directory.Move(child, resolved + $@"\{Path.GetFileName(child)}");
                            }
                            else
                            {
                                File.Move(child, resolved + $@"\{Path.GetFileName(child)}");
                            }
                        }
                        Directory.Delete(path);
                    }
                    else
                    {
                        Directory.Move(path, resolved);
                    }
                }
                catch (IOException e)
                {
                    throw new IOException($"Problem renaming file {path}.  This is likely due to another project with the same name, remove the old project and try again.", e);
                }
            }
            return(resolved);
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (args.TargetControllerPath.IsNullOrEmpty() || args.ControllerAction.IsNullOrEmpty())
            {
                Log.Debug("Unable to add to existing controller due to the lack of _TARGETCONTROLLERPATH_ and/or _CONTROLLERACTION_");
                return;
            }

            if (!args.TargetControllerPath.EndsWith(".cs"))
            {
                Log.Debug("Unable to add to existing controller due to _TARGETCONTROLLERPATH_ not ending in .cs");
                return;
            }

            string text  = System.IO.File.ReadAllText(args.TargetControllerPath);
            int    index = text.LastIndexOf('}');

            if (index > -1)
            {
                index--;
            }
            index = text.LastIndexOf('}', index);
            string action = ReplaceAllTokens.ReplaceTokens(args.ActionFormat ?? ActionFormat, args, "Controller Code");

            text = text.Insert(index - 1, action);
            Log.Debug($"Adding controller action to controller at {args.TargetControllerPath}");
            System.IO.File.WriteAllText(args.TargetControllerPath, text);
            args.EventLog.Add($"Added code to the existing controller {args.TargetControllerPath}");
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (args.TargetCsProjPath == null)
            {
                return;
            }
            var proj  = File.ReadAllText(args.TargetCsProjPath);
            int index = proj.LastIndexOf("</ItemGroup>", StringComparison.Ordinal) + "</ItemGroup>".Length;

            StringBuilder newItems = new StringBuilder("\n\t<ItemGroup>");

            foreach (var newPath in args.NewOverlayFiles)
            {
                if (newPath.EndsWith(".cs"))
                {
                    newItems.Append($"\n\t\t<Compile Include=\"{newPath.Substring(args.OverlayTarget.Length + 1)}\" />");
                }
                else
                {
                    newItems.Append($"\n\t\t<Content Include=\"{newPath.Substring(args.OverlayTarget.Length + 1)}\" />");
                }
                args.EventLog.Add($"Prepping new file {newPath.Substring(args.OverlayTarget.Length + 1)} to be added to project {args.TargetCsProjPath}");
            }
            newItems.Append("\n\t</ItemGroup>");
            proj = proj.Insert(index, newItems.ToString());
            File.WriteAllText(args.TargetCsProjPath, proj);
            args.EventLog.Add($"Adding new files to {args.TargetCsProjPath}");
        }
Exemplo n.º 6
0
        public void Process(SitecoreResourceManagerArgs args)
        {
            Stack <string> directories         = new Stack <string>(args.NewOverlayDirectories.Reverse());
            List <string>  resolvedDirectories = new List <string>();
            List <string>  resolvedFiles       = new List <string>();

            while (directories.Count > 0)
            {
                var directory          = directories.Pop();
                var processedDirectory = ReplaceTokens(directory.Substring(0, directory.LastIndexOf('\\')), args, directory) + '\\' + Path.GetFileName(directory);
                resolvedDirectories.Add(ProcessName(processedDirectory, args));
                args.EventLog.Add($"Replacing all tokens in folder name {processedDirectory}");
            }
            Stack <string> files = new Stack <string>(args.NewOverlayFiles.Reverse());

            while (files.Count > 0)
            {
                var file          = files.Pop();
                var processedFile = ReplaceTokens(file.Substring(0, file.LastIndexOf('\\')), args, file) + '\\' + Path.GetFileName(file);
                ProcessFile(processedFile, args);
                args.EventLog.Add($"Replacing all tokens in file {processedFile}");
                resolvedFiles.Add(ProcessName(processedFile, args));
                args.EventLog.Add($"Replacing all tokens in file name {processedFile}");
            }

            args.NewOverlayDirectories = resolvedDirectories;
            args.NewOverlayFiles       = resolvedFiles;
        }
Exemplo n.º 7
0
        private static void ProcessFile(string file, SitecoreResourceManagerArgs args)
        {
            var txt = File.ReadAllText(file);

            try
            {
                File.WriteAllText(file, ReplaceTokens(txt, args, Path.GetFileName(file)));
            }catch (IOException e)
            {
                throw new IOException($"Unable to write to {file}", e);
            }
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (args.PlaceholderSettings == null || args.GeneratedRenderingId == null)
            {
                return;
            }
            var placeholderSettings = Factory.GetDatabase("master", false)?.GetItem(args.PlaceholderSettings);

            if (placeholderSettings != null && placeholderSettings.TemplateID.ToString() == PlaceholderSettingsTemplateId && !placeholderSettings["Allowed Controls"].Contains(args.GeneratedRenderingId))
            {
                using (new SecurityDisabler())
                    using (new EditContext(placeholderSettings))
                    {
                        placeholderSettings["Allowed Controls"] = string.IsNullOrWhiteSpace(placeholderSettings["Allowed Controls"]) ? args.GeneratedRenderingId : placeholderSettings["Allowed Controls"] + "|" + args.GeneratedRenderingId;
                    }
                args.EventLog.Add($"Adding new rendering {args.GeneratedRenderingId} to the placeholder settings item {args.PlaceholderSettings}");
            }
        }
Exemplo n.º 9
0
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (args.TemplateFolderTemplateId == null || args.BaseTemplateId == null || args.TemplateName == null)
            {
                return;
            }
            var  folderId     = args.TemplateFolderTemplateId;
            var  templatePath = args.TemplatePath;
            var  db           = Factory.GetDatabase("master", false);
            Item folder       = db.GetItem(templatePath);

            if (folder == null)
            {
                var parts = templatePath.Split('/');
                for (int i = 1; i < parts.Length; i++)
                {
                    folder = db.GetItem(string.Join("/", parts.Take(parts.Length - i)));
                    if (folder != null)
                    {
                        using (new SecurityDisabler())
                        {
                            for (int k = i; k > 0; k--)
                            {
                                folder = folder.Add(parts[parts.Length - k], new TemplateID(new ID(folderId)));
                            }
                        }
                        break;
                    }
                }
            }
            string id       = args.BaseTemplateId ?? _standardTemplateId;
            var    template = folder.Add(args.TemplateName, new TemplateID(new ID(args.BaseTemplateId)));

            using (new SecurityDisabler())
                using (new EditContext(template))
                {
                    template[FieldIDs.Icon] = args.SitecoreIcon;
                }
            args["_GENERATEDTEMPLATEID_"] = template.ID.ToString();
            args.EventLog.Add($"Creating new template {args.GeneratedTemplateId}");
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            string root = args.OverlayTarget;

            if (File.Exists(args.OverlayTarget))
            {
                root = Path.GetDirectoryName(args.OverlayTarget);
            }
            HashSet <string> directories = new HashSet <string>();
            HashSet <string> files       = new HashSet <string>();

            using (var archive = ZipFile.OpenRead(args.Wrapper.TemplateZip))
            {
                foreach (var s in archive.Entries)
                {
                    if (s.FullName.ToLower() == "properties.json")
                    {
                        continue;
                    }
                    var parts = s.FullName.Split('/');
                    for (int i = 1; i <= parts.Length; i++)
                    {
                        if (i == parts.Length && parts[i - 1] != "")
                        {
                            files.Add($@"{root}\{string.Join("/", parts.Take(i)).Replace('/','\\')}".TrimEnd('\\'));
                        }
                        else
                        {
                            directories.Add($@"{root}\{string.Join("/", parts.Take(i)).Replace('/', '\\')}".TrimEnd('\\'));
                        }
                    }
                }
            }
            args.NewOverlayDirectories = new SortedSet <string>(directories, Comparer <string> .Create(Compare));
            args.NewOverlayFiles       = new SortedSet <string>(files, Comparer <string> .Create(Compare));
            ZipFile.ExtractToDirectory(args.Wrapper.TemplateZip, root);
            File.Delete(root + "\\properties.json");
            args.EventLog.Add($"Overlaying template files at root {root}");
        }
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (args.RenderingFolderTemplateId == null || args.RenderingPath == null)
            {
                return;
            }
            var  folderId      = args.RenderingFolderTemplateId;
            var  renderingPath = args.RenderingPath;
            var  db            = Factory.GetDatabase("master", false);
            Item folder        = db.GetItem(renderingPath);

            if (folder == null)
            {
                var parts = renderingPath.Split('/');
                for (int i = 1; i < parts.Length; i++)
                {
                    folder = db.GetItem(string.Join("/", parts.Take(parts.Length - i)));
                    if (folder != null)
                    {
                        using (new SecurityDisabler())
                        {
                            for (int k = i; k > 0; k--)
                            {
                                folder = folder.Add(parts[parts.Length - k], new TemplateID(new ID(folderId)));
                            }
                        }
                        break;
                    }
                }
            }

            if (folder == null)
            {
                Log.Error($"Unable to create rendering folder:{folderId} path:{renderingPath}", this);
                return;
            }
            var rendering = folder.Add(args.RenderingName, new TemplateID(new ID(args.RenderingTemplateId)));

            using (new SecurityDisabler())
            {
                using (new EditContext(rendering)) {
                    if (rendering.TemplateID.ToString() == ControllerRenderingTemplateId)
                    {
                        rendering["Controller"]        = $"{args.ControllerNamespace}, {args.AssemblyName}";
                        rendering["Controller Action"] = args.ControllerAction;
                    }
                    else if (rendering.TemplateID.ToString() == ViewRenderingTemplateId)
                    {
                        rendering["Path"] = args.ViewPath;
                    }
                    rendering["Cacheable"]           = args.CacheOptions.Contains("Cacheable") ? "1" : "";
                    rendering["ClearOnIndexUpdate"]  = args.CacheOptions.Contains("Clear on Index Update") ? "1" : "";
                    rendering["VaryByData"]          = args.CacheOptions.Contains("Vary By Data") ? "1" : "";
                    rendering["VaryByDevice"]        = args.CacheOptions.Contains("Vary By Device") ? "1" : "";
                    rendering["VaryByLogin"]         = args.CacheOptions.Contains("Vary By Login") ? "1" : "";
                    rendering["VaryByParm"]          = args.CacheOptions.Contains("Vary By Parm") ? "1" : "";
                    rendering["VaryByQueryString"]   = args.CacheOptions.Contains("Vary By Query String") ? "1" : "";
                    rendering["VaryByUser"]          = args.CacheOptions.Contains("Vary By User") ? "1" : "";
                    rendering[FieldIDs.Icon]         = args.SitecoreIcon;
                    rendering["Datasource Template"] = args.GeneratedTemplateId;
                    rendering["Datasource Location"] = args.RenderingDatasourceLocation;
                }
            }
            args["_GENERATEDRENDERINGID_"] = rendering.ID.ToString();
            args.EventLog.Add($"Creating new rendering {args.GeneratedRenderingId}");
        }
Exemplo n.º 12
0
        public void Process(SitecoreResourceManagerArgs args)
        {
            if (Path.GetFileName(args.Wrapper.TemplateZip.ToLower()) != _applicableTemplateZip.ToLower())
            {
                return;
            }
            var fileName   = ReplaceAllTokens.ReplaceTokens(_fileName, args);
            var template   = ReplaceAllTokens.ReplaceTokens(_template, args);
            var methodName = ReplaceAllTokens.ReplaceTokens(_methodName, args);

            var path = Directory.EnumerateFiles(args.OverlayTarget, $"*{fileName}*", SearchOption.AllDirectories).FirstOrDefault(x => (Path.GetFileName(x)?.ToLower() ?? string.Empty) == fileName.ToLower());

            if (path == null)
            {
                return;
            }
            var content = File.ReadAllText(path);
            int index   = content.IndexOf(methodName, StringComparison.Ordinal);

            if (index == -1)
            {
                return;
            }
            int brace = content.IndexOf("{", index, StringComparison.Ordinal);
            int semi  = content.IndexOf(";", index, StringComparison.Ordinal);

            while (semi < brace)
            {
                index = content.IndexOf(methodName, index, StringComparison.Ordinal);
                if (index == -1)
                {
                    return;
                }
                brace = content.IndexOf("{", index, StringComparison.Ordinal);
                semi  = content.IndexOf(";", index, StringComparison.Ordinal);
            }

            if (_insertAtEnd)
            {
                int tracker = 0;
                for (; brace < content.Length; brace++)
                {
                    if (content[brace] == '{')
                    {
                        tracker++;
                    }
                    else if (content[brace] == '}')
                    {
                        tracker--;
                    }
                    if (tracker == 0)
                    {
                        break;
                    }
                }
                if (tracker != 0)
                {
                    return;
                }
                brace--;
            }
            content = content.Insert(brace, template);
            File.WriteAllText(path, content);
        }
Exemplo n.º 13
0
        public static string ReplaceTokens(string text, Func <string, bool> containsKey, Func <string, string> getValue, SitecoreResourceManagerArgs args = null, string name = null)
        {
            StringBuilder sb        = new StringBuilder(text);
            bool          token     = false;
            bool          delimiter = false;
            List <char>   tokenName = new List <char>();

            for (int i = text.Length - 1; i >= 0; i--)
            {
                if (text[i] == '_')
                {
                    if (token)
                    {
                        tokenName.Add('_');
                        tokenName.Reverse();
                        string tmp = new string(tokenName.ToArray());
                        if (containsKey(tmp))
                        {
                            sb.Remove(i, tmp.Length);
                            sb.Insert(i, getValue(tmp));
                            args?.EventLog.Add($"Replaced token {tmp} with {getValue(tmp)} at index {i} of {name}");
                        }
                        else
                        {
                            Log.Error($"Unable to locate property {tmp} validate that it is being collected", text);
                        }
                        tokenName.Clear();
                    }
                    token     = !token;
                    delimiter = false;
                }
                else if (token && text[i] == '|')
                {
                    delimiter = !delimiter;
                }
                else if (!char.IsUpper(text[i]) && !delimiter)
                {
                    token = false;
                    tokenName.Clear();
                }
                if (token)
                {
                    tokenName.Add(text[i]);
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 14
0
 public static string ReplaceTokens(string text, SitecoreResourceManagerArgs args, string name = null)
 {
     return(ReplaceTokens(text, args.ContainsKey, x => args[x], args, name));
 }