Example #1
0
		/// <summary>
		/// Write a topic (and create a historical version)
		/// </summary>
		/// <param name="topic">The topic to write</param>
		/// <param name="content">The content</param>
		void WriteTopicAndNewVersion(LocalTopicName topic, string content, FederationUpdateGenerator gen)
		{
			gen.Push();
			LocalTopicName versionless = new LocalTopicName(topic.Name);

			bool isVersionlessNew = !TopicExistsLocally(versionless);
			bool isVersionedNew = !TopicExistsLocally(topic);

			string oldAuthor = null;
			if (!isVersionlessNew)
				oldAuthor = GetTopicLastAuthor(topic);

			// Write it
			WriteTopic(versionless, content, gen);
			WriteTopic(topic, content, gen);	

			//Generate author property change if needed
			if (!isVersionlessNew)
			{
				//See if the last modified by has changed (not this only happens when writing out the versioned tip file)
				string newLastAuthor = GetTopicLastAuthor(topic);
				if (oldAuthor != newLastAuthor)
				{
					gen.RecordPropertyChange(versionless.AsAbsoluteTopicName(Namespace), "_LastModifiedBy", FederationUpdate.PropertyChangeType.PropertyUpdate);
				}
			}

			gen.Pop();
		}
Example #2
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>
		override protected void WriteTopic(LocalTopicName topic, string content, FederationUpdateGenerator gen)
		{
			string root = Root;
			string fullpath = MakePath(root, topic);
			bool isNew = !(File.Exists(fullpath));

			// Get old topic so we can analyze it for properties to compare with the new one
			string oldText = null;
			Hashtable oldProperties = null;
			if (!isNew)
			{
				using (StreamReader sr = new StreamReader(new FileStream(fullpath, FileMode.Open, FileAccess.Read, FileShare.Read)))
				{
					oldText = sr.ReadToEnd();
				}
				oldProperties = ExtractExplicitFieldsFromTopicBody(oldText);	
			}

			// Change it
			using (StreamWriter sw = new StreamWriter(fullpath))
			{
				sw.Write(content);
			}

			// Quick check to see if we're about to let somebody write the DefinitionTopic for this ContentBase.  
			// If so, we reset our Info object to reread
			string pathToDefinitionTopic = MakePath(Root, DefinitionTopicName.LocalName);
			if (fullpath == pathToDefinitionTopic)
				this.Federation.InvalidateNamespace(Namespace);

			// Record changes
			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 properties
				Hashtable newProperties = 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();
			}
		}
Example #3
0
		private void RecordTopicChanges(LocalTopicName topic, FederationUpdateGenerator gen, bool isNew, string content, string oldText, Hashtable oldProperties)
		{
			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 properties
				Hashtable newProperties = 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();
			}
		}