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