Beispiel #1
0
 /// <summary>
 /// Answer the formatted text for a given topic, formatted using a given OutputFormat and possibly showing diffs with the previous revision
 /// </summary>
 /// <param name="topic">The topic</param>
 /// <param name="format">What format</param>
 /// <param name="showDiffs">true to show diffs</param>
 /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param>
 /// <returns></returns>
 public static string FormattedTopic(QualifiedTopicRevision topic, OutputFormat format, QualifiedTopicRevision previousVersion, Federation aFederation, LinkMaker lm)
 {
     NamespaceManager relativeToBase = aFederation.NamespaceManagerForNamespace(topic.Namespace);
     return FormattedTopicWithSpecificDiffs(topic, format, previousVersion, aFederation, lm);
 }
Beispiel #2
0
        /// <summary>
        /// Answer the formatted text for a given topic, formatted using a given OutputFormat and possibly showing diffs
        /// with a specified revision
        /// </summary>
        /// <param name="topic">The topic</param>
        /// <param name="format">What format</param>
        /// <param name="showDiffs">true to show diffs</param>
        /// <param name="accumulator">composite cache rule in which to accumulate cache rules (ignored for diffs)</param>
        /// <returns></returns>
        public static string FormattedTopicWithSpecificDiffs(QualifiedTopicRevision topic, OutputFormat format, QualifiedTopicRevision diffWithThisVersion, Federation aFederation, LinkMaker lm)
        {
            // Setup a special link maker that knows what to make the edit links return to
            LinkMaker linker = lm.Clone();
            linker.ReturnToTopicForEditLinks = topic;
            NamespaceManager relativeToBase = aFederation.NamespaceManagerForNamespace(topic.Namespace);

            WikiOutput output = WikiOutput.ForFormat(format, null);
            if (diffWithThisVersion != null)
            {
                ArrayList styledLines = new ArrayList();
                IList leftLines;
                IList rightLines;
                using (TextReader srLeft = relativeToBase.TextReaderForTopic(topic.AsUnqualifiedTopicRevision()))
                {
                    leftLines = MergeBehaviorLines(srLeft.ReadToEnd().Replace("\r", "").Split('\n'));
                }
                using (TextReader srRight = relativeToBase.TextReaderForTopic(diffWithThisVersion.AsUnqualifiedTopicRevision()))
                {
                    rightLines = MergeBehaviorLines(srRight.ReadToEnd().Replace("\r", "").Split('\n'));
                }
                IEnumerable diffs = Diff.Compare(leftLines, rightLines);
                foreach (LineData ld in diffs)
                {
                    LineStyle style = LineStyle.Unchanged;
                    switch (ld.Type)
                    {
                        case LineType.Common:
                            style = LineStyle.Unchanged;
                            break;

                        case LineType.LeftOnly:
                            style = LineStyle.Add;
                            break;

                        case LineType.RightOnly:
                            style = LineStyle.Delete;
                            break;
                    }
                    styledLines.Add(new StyledLine(ld.Text, style));
                }
                Format(topic, styledLines, output, relativeToBase, linker, relativeToBase.ExternalReferences, 0);
            }
            else
            {
                using (TextReader sr = relativeToBase.TextReaderForTopic(topic.AsUnqualifiedTopicRevision()))
                {
                    Format(topic, sr.ReadToEnd(), output, relativeToBase, linker, relativeToBase.ExternalReferences, 0);
                }
            }

            return output.ToString();
        }
 public void UpdateNamespaces(Federation aFed)
 {
     // just kill the old one and reload a new one
     aFed.UnregisterNamespace(aFed.NamespaceManagerForNamespace(Namespace));
     LoadNamespaces(aFed);
 }
        public string ValidateParameter(Federation aFed, string param, string val, bool isCreate)
        {
            if (param == c_namespace)
            {
                if (val == "" || val == null)
                    return "Namespace can not be blank";
                if (isCreate && aFed.NamespaceManagerForNamespace(val) != null)
                    return "Namespace already exists";
                // TODO -- check other constraints (valid chars) for namespaces
            }

            return null;
        }
        private void ValidateDefaultNamespace(Federation aFed)
        {
            ///////////
            ///Make sure the default namespace is configured
            string defaultNamespace = aFed.Configuration.DefaultNamespace;
            if (defaultNamespace == null)
            {
                Result r = new Result("Default namespace not specified", Level.Error);
                r.Writer.Write(@"<p>You have not specified the default namespace for your federation in the federation configuration file (<b>" + HtmlWriter.Escape(ApplicationConfigurationPath) + @"</b>).
            This setting must be present and must name a namespace listed in your configuration file. <p>Here is an example of a valid federation configuration file:");
                r.Writer.Write(ExampleConfig());
                AddResult(r);
                return;
            }

            if (aFed.NamespaceManagerForNamespace(defaultNamespace) == null)
            {
                Result r = new Result("Default namespace not found", Level.Error);
                r.Writer.Write(@"<p>You have specified the default namespace for your federation in the federation configuration file (<b>" + HtmlWriter.Escape(ApplicationConfigurationPath) + @"</b>),
            but the namespace you specified can not be found (either because it's not listed in the configuration file or it's not valid).
            <p>Here is an example of a valid federation configuration file:");
                r.Writer.Write(ExampleConfig());
                AddResult(r);
                return;
            }

            OK("Valid default namespace setting detected: " + HtmlWriter.Escape(defaultNamespace));
        }
 /// <summary>
 /// Validate the parameters for creating the Namespace.
 /// </summary>
 /// <param name="param">Parameters name</param>
 /// <param name="val">Parameter value to validate.</param>
 /// <returns>returns null to indicate success otherwise returns 
 /// the error message to be displayed.</returns>
 public string ValidateParameter(Federation aFed, string param, string val, bool isCreate)
 {
     if (param == ConfigurationParameterNames.Namespace)
     {
         // Would need to be consistent with the namespace
         // names for the FileSystemNameSpaceProvider
         if (val == "" || val == null)
             return "Namespace can not be blank";
         if (isCreate && aFed.NamespaceManagerForNamespace(val) != null)
             return "Namespace already exists";
     }
     else if (param == ConfigurationParameterNames.ConnectionString)
     {
         if (val == "")
             return "ConnectionString can not be null or blank";
     }
     return null;
 }
 public void UpdateNamespaces(Federation aFed)
 {
     // just kill the old ones and reload new ones
     foreach (string each in NamespaceNames)
         aFed.UnregisterNamespace(aFed.NamespaceManagerForNamespace(each));
     LoadNamespaces(aFed);
 }