Exemplo n.º 1
0
        private void MarkDeprecate(String baseFolder, FrameworkEntity e, TextWriter writer)
        {
            String file = e.GetPath(baseFolder, DocumentType.Model);

            if (file == null || !File.Exists(file))
            {
                return;
            }

            this.Log(Level.Verbose, String.Format("Checking {0}...", e.name));

            Action <TypedEntity> markFunctions  = (t) => Mark <FunctionEntity>(t.Functions);
            Action <ClassEntity> markMethods    = (c) => Mark <MethodEntity>(c.Methods);
            Action <ClassEntity> markProperties = (c) => Mark <PropertyEntity>(c.Properties);

            switch (e.type)
            {
            case FrameworkEntityType.T:
                LoadAndMark <TypedEntity> (e.name, file, writer, markFunctions);
                break;

            case FrameworkEntityType.C:
                LoadAndMark <ClassEntity> (e.name, file, writer, markFunctions, markMethods, markProperties);
                break;

            case FrameworkEntityType.P:
                LoadAndMark <ProtocolEntity> (e.name, file, writer, markFunctions, markMethods, markProperties);
                break;

            default:
                throw new NotSupportedException("Unsupported type: " + e.type);
            }
        }
Exemplo n.º 2
0
        protected void Patch(String baseFolder, FrameworkEntity entity, IEnumerable <PatchReplace> replacements)
        {
            String path = entity.GetPath(baseFolder, this.Type);

            if (path == null)
            {
                return;
            }

            IList <String> paths = new List <String>();

            switch (this.Type)
            {
            case DocumentType.Generated:
                paths.Add(path + ".cs");
                paths.Add(path + ".Class.cs");
                paths.Add(path + ".Constants.cs");
                paths.Add(path + ".Constructors.cs");
                paths.Add(path + ".Protocol.cs");
                paths.Add(path + ".Protocols.cs");
                break;

            default:
                paths.Add(path);
                break;
            }

            this.Patch(paths, entity, replacements);
        }
        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));
            }
        }
Exemplo n.º 4
0
        protected T FindAndLoad <T>(String baseFolder, IList <FrameworkEntity> entities, FrameworkEntityType type, String name, bool useCache = true) where T : BaseEntity
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            // Try the cache first
            String     key    = type + ":" + name;
            BaseEntity result = null;

            if (useCache && !cache.TryGetValue(key, out result))
            {
                //this.Log (Level.Verbose, "Cache miss for '" + type + "' and name '" + name + "'");

                var             candidates = entities.Where(e => e.type == type && e.name == name).ToList();
                FrameworkEntity candidate  = candidates.FirstOrDefault();

                // Print a warning if multiple
                if (candidates.Count > 1)
                {
                    this.Log(Level.Warning, "Found several entities with the type '" + type + "' and name '" + name + "'");
                }

                if (candidate != null)
                {
                    String file = candidate.GetPath(baseFolder, DocumentType.Model);
                    result = BaseEntity.LoadFrom <T> (file);
                }
            }
            else
            {
                //this.Log (Level.Verbose, "Cache hit for '" + type + "' and name '" + name + "'");
            }

            // Add to MRU
            if (useCache && result != null)
            {
                cache.Add(key, result);
            }

            return(result as T);
        }
Exemplo n.º 5
0
        protected void Change(String baseFolder, FrameworkEntity e, IEnumerable <String> changes, TextWriter writer)
        {
            String file = e.GetPath(baseFolder, DocumentType.Model);

            if (file == null || !File.Exists(file))
            {
                return;
            }

            this.Log(Level.Verbose, String.Format("Patching '{0}'...", e.name));

            switch (e.type)
            {
            case FrameworkEntityType.T:
                LoadAndChange <TypedEntity> (e.name, file, changes, writer);
                break;

            case FrameworkEntityType.C:
                LoadAndChange <ClassEntity> (e.name, file, changes, writer);
                break;

            case FrameworkEntityType.P:
                LoadAndChange <ProtocolEntity> (e.name, file, changes, writer);
                break;

            case FrameworkEntityType.S:
                LoadAndChange <StructureEntity> (e.name, file, changes, writer);
                break;

            case FrameworkEntityType.E:
                LoadAndChange <EnumerationEntity> (e.name, file, changes, writer);
                break;

            default:
                throw new NotSupportedException("Unsupported type: " + e.type);
            }
        }