protected void PatchDiscussion(String baseFolder, DocSet docSet, Framework f, FrameworkEntity entity)
        {
            String path = entity.GetPath (baseFolder, this.Type);
            if (path == null || !File.Exists(path)) {
                return;
            }

            String contents = File.ReadAllText (path);
            bool modified = false;

            // Search for discussion parts
            int index = 0;
            int beginning = 0;
            int ending = 0;
            while ((beginning = contents.IndexOf(DISCUSSION_BEGIN, index)) != -1) {
                ending = contents.IndexOf (DISCUSSION_END, beginning);
                String content = contents.Substring (beginning, ending + DISCUSSION_END.Length - beginning);
                String replacement = content;

                // Count opening and closing paragraphs
                int opening = DISCUSSION_OPENING_REGEX.Matches (replacement).Count;
                int closing = DISCUSSION_CLOSING_REGEX.Matches (replacement).Count;

                if (opening < closing) {
                    throw new NotSupportedException ();
                }
                if (opening > closing) {
                    replacement = replacement.Replace ("<!-- begin discussion -->", String.Empty);
                    replacement = replacement.Replace ("<!-- end discussion -->", String.Empty);
                    for (int i = closing; i < opening; i++) {
                        replacement += "</p>";
                    }
                    replacement = "<!-- begin discussion -->" + replacement;
                    replacement = replacement + "<!-- end discussion -->";

                    contents = contents.Replace (content, replacement);
                    modified |= true;
                }

                index = beginning + replacement.Length;
            }

            if (modified) {
                this.Log (Level.Info, String.Format ("Patching {0} for '{1}'...", this.Type, entity.name));
                File.WriteAllText (path, contents);
            } else {
                this.Log (Level.Debug, String.Format ("Skipping {0} for '{1}'...", this.Type, entity.name));
            }
        }
Example #2
0
        public String GetPath(String baseFolder, DocumentType documentType)
        {
            if (this.Framework == null)
            {
                throw new ArgumentException("Entity should be part of a framework");
            }

            String    path      = null;
            Framework framework = this.Framework;
            DocSet    docSet    = framework.DocSet;

            switch (documentType)
            {
            case DocumentType.DocSet:
                if (docSet != null && this.File != null)
                {
                    path = Path.Combine(docSet.AbsolutePath, this.File);
                }
                break;

            case DocumentType.Generated:
                path = Path.Combine(baseFolder, documentType.ToString(), framework.assembly, framework.name + "_" + this.type.ToString(), this.name);
                Directory.CreateDirectory(Path.GetDirectoryName(path));
                break;

            default:
                if (docSet != null)
                {
                    path = Path.Combine(baseFolder, docSet.Name, framework.name, documentType.ToString(), this.type.ToString(), this.name);
                }
                else
                {
                    path = Path.Combine(baseFolder, framework.name, documentType.ToString(), this.type.ToString(), this.name);
                }
                Directory.CreateDirectory(Path.GetDirectoryName(path));
                break;
            }

            String extension = extensions[documentType];

            if (!String.IsNullOrEmpty(extension))
            {
                path += extension;
            }

            return(path);
        }
Example #3
0
        public String GetPath(String baseFolder, DocumentType documentType)
        {
            String path   = null;
            DocSet docSet = this.DocSet;

            switch (documentType)
            {
            case DocumentType.Generated:
                path = Path.Combine(baseFolder, documentType.ToString(), this.assembly);
                Directory.CreateDirectory(Path.GetDirectoryName(path));
                break;

            default:
                break;
            }

            return(path);
        }