Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 public TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     if (!HasPermission(new UnqualifiedTopicName(revision.LocalName), TopicPermission.Read))
     {
         return null;
     }
     return ContentProviderChain.TextReaderForTopic(revision);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public override ParsedTopic GetParsedTopic(UnqualifiedTopicRevision topicRevision)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 private bool IsBuiltInTopic(UnqualifiedTopicRevision revision)
 {
     return IsBuiltInTopic(new UnqualifiedTopicName(revision.LocalName));
 }
Ejemplo n.º 7
0
 private DateTime DateTimeFromTopicName(UnqualifiedTopicRevision topic)
 {
     return (DateTime) (_topics[topic]);
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 11
0
 public TextReader TextReaderForTopic(UnqualifiedTopicRevision revision)
 {
     return ContentProviderChain.TextReaderForTopic(revision); 
 }
Ejemplo n.º 12
0
 private string TopicPath(UnqualifiedTopicRevision revision)
 {
     return TopicPath(revision.LocalName, revision.Version);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
                  }
            */
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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; 
        }
Ejemplo n.º 19
0
 public virtual void WriteTopic(UnqualifiedTopicRevision topicRevision, string content)
 {
     _next.WriteTopic(topicRevision, content);
 }
Ejemplo n.º 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); 
        }
Ejemplo n.º 21
0
 public override void WriteTopic(UnqualifiedTopicRevision revision, string content)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 24
0
 private SqlInfoForTopic[] SqlTopicInfosForTopic(UnqualifiedTopicRevision topic)
 {
     return SqlHelper.GetSqlTopicInfosForTopic(Namespace, topic.LocalName, _connectionString);
 }
Ejemplo n.º 25
0
 private bool IsDefinitionTopic(UnqualifiedTopicRevision topicRevision)
 {
     QualifiedTopicName topicName = new QualifiedTopicName(topicRevision.LocalName, Namespace);
     return topicName.Equals(NamespaceManager.DefinitionTopicName);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 29
0
 private static string MakeTopicName(UnqualifiedTopicRevision revision)
 {
     return revision.DottedNameWithVersion;
 }
Ejemplo n.º 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);
        }