Пример #1
0
        public override ParsedTopic GetParsedTopic(UnqualifiedTopicRevision revision)
        {
            TextReader textReader = TextReaderForTopic(revision);
            if (textReader == null)
            {
                return null;
            }
            string contents = null;
            try
            {
                contents = textReader.ReadToEnd();
            }
            finally
            {
                textReader.Close();
            }

            ParsedTopic parsedTopic = TopicParser.Parse(contents);

            return parsedTopic;
        }
Пример #2
0
        public override ParsedTopic GetParsedTopic(UnqualifiedTopicRevision revision)
        {
            TextReader textReader = TextReaderForTopic(revision);
            if (textReader == null)
            {
                return null;
            }
            string contents = null;
            try
            {
                contents = textReader.ReadToEnd();
            }
            finally
            {
                textReader.Close();
            }

            ParsedTopic parsedTopic = TopicParser.Parse(contents);

            TopicChange latest = Next.AllChangesForTopicSince(revision.AsUnqualifiedTopicName(), DateTime.MinValue).Latest;
            AddBuiltInProperty(parsedTopic, "_TopicName", revision.LocalName);
            AddBuiltInProperty(parsedTopic, "_TopicFullName", new QualifiedTopicName(revision.LocalName, Namespace).DottedName);
            // Note that even in an non-tip revision, the values of _LastModifiedBy and _CreationTime are of the tip
            // revision. The logic here is that since you must use WikiTalk to access these values, you won't be too
            // surprised that they change on you when someone commits a new revision.
            // Latest can be null in some pathological cases where history information has been deleted.
            AddBuiltInProperty(parsedTopic, "_LastModifiedBy",
                latest == null ? "" : latest.Author);
            AddBuiltInProperty(parsedTopic, "_CreationTime",
                latest == null ? DateTime.MinValue.ToString() : latest.Created.ToString());
            AddBuiltInProperty(parsedTopic, "_ModificationTime",
                latest == null ? DateTime.MinValue.ToString() : latest.Modified.ToString());
            AddBuiltInProperty(parsedTopic, "_Body", contents);
            AddBuiltInProperty(parsedTopic, "_ProcessTextSize", "0");
            AddBuiltInProperty(parsedTopic, "_Wom", "");

            return parsedTopic;
        }
Пример #3
0
 public TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     if (!HasPermission(new UnqualifiedTopicName(revision.LocalName), TopicPermission.Read))
     {
         return null;
     }
     return ContentProviderChain.TextReaderForTopic(revision);
 }
Пример #4
0
        /// <summary>
        /// Write new contents to a topic revision (doesn't write a new version).  
        /// </summary>
        /// <param name="revision">Revision to write</param>
        /// <param name="content">New content</param>
        public override void WriteTopic(UnqualifiedTopicRevision revision, string content)
        {
            string topicName = MakeTopicName(revision);
            bool isArchive = (revision.Version != null) && (revision.Version.Length > 0);

            DateTime lastWriteTime = Federation.TimeProvider.Now;

            _sqlHelper.WriteTopic(Namespace, topicName, lastWriteTime, content, isArchive);
        }
Пример #5
0
 public override ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 private bool IsBuiltInTopic(UnqualifiedTopicRevision revision)
 {
     return IsBuiltInTopic(new UnqualifiedTopicName(revision.LocalName));
 }
Пример #7
0
 private DateTime DateTimeFromTopicName(UnqualifiedTopicRevision topic)
 {
     return (DateTime) (_topics[topic]);
 }
Пример #8
0
        public override TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
        {
            throw new NotImplementedException();

            //if (!TopicExistsLocally(topic))
            //    throw TopicNotFoundException.ForTopic(topic, Namespace);
            //BackingTopic back = GetBackingTopicNamed(topic);
            //if (back != null)
            //    return new StringReader(back.Body);

            //StringBuilder b = new StringBuilder();
            //DateTime dt = DateTimeFromTopicName(topic);
            //b.Append("This page contains information about '''" + dt.ToLongDateString() + "'''.");
            //return new StringReader(b.ToString());
        }
Пример #9
0
 /// <summary>
 /// Answer a TextReader for the given topic
 /// </summary>
 /// <param name="topic"></param>
 /// <exception cref="TopicNotFoundException">Thrown when the topic doesn't exist</exception>
 /// <returns>TextReader</returns>
 public virtual TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision)
 {
     return _next.TextReaderForTopic(topicRevision);
 }
Пример #10
0
 /// <summary>
 /// Write new contents over the specified version of the topic (doesn't write a new version).
 /// </summary>
 /// <param name="topic">Topic to overwrite.</param>
 /// <param name="version">Version to overwrite.</param>
 /// <param name="content">New content.</param>
 public void WriteTopic(UnqualifiedTopicRevision revision, string content)
 {
     if (revision.Version != null)
     {
         if (!TopicVersionExists(revision))
         {
             throw FlexWikiException.VersionDoesNotExist(new QualifiedTopicName(revision.LocalName, this.Namespace),revision.Version); 
         }
     }
     ContentProviderChain.WriteTopic(revision, content);
 }
Пример #11
0
 public TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     return ContentProviderChain.TextReaderForTopic(revision); 
 }
Пример #12
0
 private string TopicPath(UnqualifiedTopicRevision revision)
 {
     return TopicPath(revision.LocalName, revision.Version);
 }
Пример #13
0
 /// <summary>
 /// Write a new version of the topic (doesn't write a new version).  Generate all needed federation update changes via the supplied generator.
 /// </summary>
 /// <param name="topic">Topic to write</param>
 /// <param name="content">New content</param>
 /// <param name="sink">Object to recieve change info about the topic</param>
 public override void WriteTopic(UnqualifiedTopicRevision topicRevision, string content)
 {
     string root = Root;
     string fullpath = MakePath(root, topicRevision.LocalName, topicRevision.Version);
     FileSystem.WriteFile(fullpath, content);
 }
Пример #14
0
 /// <summary>
 /// Answer a TextReader for the given topic
 /// </summary>
 /// <param name="topic"></param>
 /// <exception cref="TopicNotFoundException">Thrown when the topic doesn't exist</exception>
 /// <returns>TextReader</returns>
 public override TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision)
 {
     string topicFile = TopicPath(topicRevision);
     if (topicFile == null || !FileSystem.FileExists(topicFile))
     {
         return null;
     }
     return new StreamReader(FileSystem.OpenRead(topicFile, FileMode.Open, FileAccess.Read, FileShare.Read));
 }
Пример #15
0
 public void WriteTopicAndNewVersion(UnqualifiedTopicName topic, string content, string author)
 {
     UnqualifiedTopicRevision versionedTopicName = new UnqualifiedTopicRevision(topic,
         TopicRevision.NewVersionStringForUser(author, Federation.TimeProvider.Now));
     UnqualifiedTopicRevision unversionedTopicName = new UnqualifiedTopicRevision(topic);
     ContentProviderChain.WriteTopic(versionedTopicName, content);
     ContentProviderChain.WriteTopic(unversionedTopicName, content);
 }
Пример #16
0
        private void RecordTopicChanges(UnqualifiedTopicRevision topic, bool isNew, string content, string oldText, Hashtable oldProperties)
        {
            throw new NotImplementedException("Reenable if we figure out how to deal with updates.");
            /*
                  try
                  {
                      AbsoluteTopicName absTopic = topic.AsAbsoluteTopicName(Namespace);

                      gen.Push();

                      // Record the topic-level change
                      if (isNew)
                          gen.RecordCreatedTopic(absTopic);
                      else
                          gen.RecordUpdatedTopic(absTopic);

                      //	Now process the imports
                      Hashtable newProperties = NamespaceManager.ExtractExplicitFieldsFromTopicBody(content);
                      if (isNew)
                      {
                          foreach (string pName in newProperties.Keys)
                              gen.RecordPropertyChange(absTopic, pName, FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_Body", FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_TopicName", FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_TopicFullName", FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_LastModifiedBy", FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_CreationTime", FederationUpdate.PropertyChangeType.PropertyAdd);
                          gen.RecordPropertyChange(absTopic, "_ModificationTime", FederationUpdate.PropertyChangeType.PropertyAdd);
                      }
                      else
                      {
                          if (content != oldText)
                          {
                              FillFederationUpdateByComparingPropertyHashes(gen, absTopic, oldProperties, newProperties);
                              gen.RecordPropertyChange(absTopic, "_Body", FederationUpdate.PropertyChangeType.PropertyUpdate);
                          }
                          gen.RecordPropertyChange(absTopic, "_ModificationTime", FederationUpdate.PropertyChangeType.PropertyUpdate);				
                      }
                  }
                  finally
                  {
                      gen.Pop();
                  }
            */
        }
Пример #17
0
 /// <summary>
 /// Returns the parsed representation of the specified topic. 
 /// </summary>
 /// <param name="topic">The topic for which to return the parsed representation.</param>
 /// <returns>A <see cref="ParsedTopic"/> object containing the parsed representation of the topic.</returns>
 public virtual ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision)
 {
     return _next.GetParsedTopic(topicRevision);
 }
Пример #18
0
        private bool TopicVersionExists(UnqualifiedTopicRevision revision)
        {
            TopicChangeCollection changes = AllChangesForTopic(revision.AsUnqualifiedTopicName());

            if (changes == null)
            {
                return false; 
            }

            foreach (TopicChange change in changes)
            {
                if (change.Version == revision.Version)
                {
                    return true; 
                }
            }

            return false; 
        }
Пример #19
0
 public virtual void WriteTopic(UnqualifiedTopicRevision topicRevision, string content)
 {
     _next.WriteTopic(topicRevision, content);
 }
Пример #20
0
        public DateTime GetTopicCreationTime(UnqualifiedTopicRevision revision)
        {
            TopicChangeCollection changes = AllChangesForTopic(revision.DottedName);

            if (changes == null)
            {
                throw TopicNotFoundException.ForTopic(revision, Namespace); 
            }

            if (revision.Version == null)
            {
                return changes.Latest.Created;
            }
            else
            {
                foreach (TopicChange change in changes)
                {
                    if (change.Version == revision.Version)
                    {
                        return change.Created; 
                    }
                }
            }

            throw TopicNotFoundException.ForTopic(revision, Namespace); 
        }
Пример #21
0
 public override void WriteTopic(UnqualifiedTopicRevision revision, string content)
 {
     throw new NotImplementedException();
 }
Пример #22
0
 /// <summary>
 /// Answer the contents of a given topic.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="version">The version to read, or null for the latest version.</param>
 /// <returns>The contents of the topic or null if it can't be read (e.g., doesn't exist)</returns>
 public string Read(UnqualifiedTopicRevision revision)
 {
     using (TextReader st = TextReaderForTopic(revision))
     {
         if (st == null)
         {
             return null;
         }
         return st.ReadToEnd();
     }
 }
Пример #23
0
 public override TextReader TextReaderForTopic(UnqualifiedTopicRevision topicRevision)
 {
     // We need to special-case the definition topic because otherwise we 
     // cause an infinite loop: this method calls NamespaceManager.HomePage, 
     // which calls TextReaderForTopic on the definition topic to figure out
     // which topic is the home page. 
     if (IsDefinitionTopic(topicRevision))
     {
         return Next.TextReaderForTopic(topicRevision); 
     }
     else if (!IsBuiltInTopic(topicRevision))
     {
         return Next.TextReaderForTopic(topicRevision); 
     }
     else if (topicRevision.Version == null)
     {
         TopicChangeCollection changes = Next.AllChangesForTopicSince(
             topicRevision.AsUnqualifiedTopicName(), DateTime.MinValue);
         if (changes == null || changes.Count == 0)
         {
             string defaultContent = DefaultContentFor(topicRevision.LocalName);
             return new StringReader(defaultContent);
         }
         else
         {
             return Next.TextReaderForTopic(topicRevision);
         }
     }
     else if (topicRevision.Version == TopicRevision.NewVersionStringForUser(c_builtInAuthor, DateTime.MinValue))
     {
         string defaultContent = DefaultContentFor(topicRevision.LocalName);
         return new StringReader(defaultContent);
     }
     else
     {
         return Next.TextReaderForTopic(topicRevision);
     }
 }
Пример #24
0
 private SqlInfoForTopic[] SqlTopicInfosForTopic(UnqualifiedTopicRevision topic)
 {
     return SqlHelper.GetSqlTopicInfosForTopic(Namespace, topic.LocalName, _connectionString);
 }
Пример #25
0
 private bool IsDefinitionTopic(UnqualifiedTopicRevision topicRevision)
 {
     QualifiedTopicName topicName = new QualifiedTopicName(topicRevision.LocalName, Namespace);
     return topicName.Equals(NamespaceManager.DefinitionTopicName);
 }
Пример #26
0
 /// <summary>
 /// Answer a TextReader for the given topic
 /// </summary>
 /// <param name="topic"></param>
 /// <exception cref="TopicNotFoundException">Thrown when the topic doesn't exist</exception>
 /// <returns>TextReader</returns>
 public override TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     string topicName = MakeTopicName(revision);
     if (topicName == null || !SqlHelper.TopicExists(Namespace, topicName, _connectionString))
     {
         throw TopicNotFoundException.ForTopic(revision, Namespace);
     }
     return new StringReader(SqlHelper.GetTopicBody(Namespace, topicName, _connectionString));
 }
Пример #27
0
 /// <summary>
 /// Answer a TextReader for the given topic
 /// </summary>
 /// <param name="topic"></param>
 /// <exception cref="TopicNotFoundException">Thrown when the topic doesn't exist</exception>
 /// <returns>TextReader</returns>
 public override TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     string topicName = MakeTopicName(revision);
     if (topicName == null || !_sqlHelper.TopicExists(Namespace, topicName))
     {
         return null;
     }
     return new StringReader(_sqlHelper.GetTopicBody(Namespace, topicName));
 }
Пример #28
0
        /// <summary>
        /// Write a new version of the topic (doesn't write a new version).  Generate all needed federation update changes via the supplied generator.
        /// </summary>
        /// <param name="topic">Topic to write</param>
        /// <param name="content">New content</param>
        /// <param name="gen">Object to recieve change info about the topic</param>
        public override void WriteTopic(UnqualifiedTopicRevision revision, string content)
        {
            string topicName = MakeTopicName(revision);
            bool isNew = !(SqlHelper.TopicExists(Namespace, topicName, _connectionString));

            // Get old topic so we can analyze it for imports to compare with the new one
            string oldText = null;
            Hashtable oldProperties = null;
            if (!isNew)
            {
                oldText = SqlHelper.GetTopicBody(Namespace, topicName, _connectionString);
                // TODO: Deal with how this API has changed
                //oldProperties = NamespaceManager.ExtractExplicitFieldsFromTopicBody(oldText);
                throw new NotImplementedException(); 
            }

            string nameWithVersion = revision.DottedNameWithVersion; 
            SqlHelper.WriteTopic(Namespace, topicName, LastWriteTime(nameWithVersion), _connectionString, content, ((revision.Version != null && revision.Version.Length > 0) ? true : false));

            // Record changes
            RecordTopicChanges(revision, isNew, content, oldText, oldProperties);
        }
Пример #29
0
 private static string MakeTopicName(UnqualifiedTopicRevision revision)
 {
     return revision.DottedNameWithVersion;
 }
Пример #30
0
        public void SetWomCache(UnqualifiedTopicRevision revision, string wom)
        {
            if (!HasPermission(new UnqualifiedTopicName(revision.LocalName), TopicPermission.Read))
            {
                return;
            }
            ParsedTopic parsedTopic = ContentProviderChain.GetParsedTopic(revision);

            if (parsedTopic == null)
            {
                return;
            }
            TopicPropertyValue topicPropertyValue = new TopicPropertyValue(wom);
            parsedTopic.Properties["_Wom"].Values.Clear();
            parsedTopic.Properties["_Wom"].Values.Add(topicPropertyValue);
        }