public CombineReaderV2 (DataSerializer serializer, IProgressMonitor monitor, Type objectType)
		{
			this.serializer = serializer;
			this.objectType = objectType;
			baseFile = serializer.SerializationContext.BaseFile;
			this.monitor = monitor;
		}
		public override DataItem WriteSlnData ()
		{
			DataSerializer ser = new DataSerializer (MSBuildProjectService.DataContext);
			ser.SerializationContext.BaseFile = EntityItem.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';
			DataItem data = (DataItem) ser.Serialize (EntityItem, typeof(CompiledAssemblyProject));
			return data;
		}
		void UpdateEntry ()
		{
			var ser = new DataSerializer (new DataContext ());
			var data = ser.Serialize (this);

			XmlDocument doc = new XmlDocument ();
			var writer = new XmlConfigurationWriter { Namespace = MSBuildProject.Schema };
			var elem = writer.Write (doc, data);

			entry.MSBuildProject.SetMonoDevelopProjectExtension ("Deployment.LinuxDeployData", elem);
		}
		public override void ReadSlnData (DataItem item)
		{
			// Remove the default configuration, since new ones will be loaded
			CompiledAssemblyProject project = (CompiledAssemblyProject) EntityItem;
			project.Configurations.Clear ();
			
			DataSerializer ser = new DataSerializer (MSBuildProjectService.DataContext);
			ser.SerializationContext.BaseFile = EntityItem.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';
			ser.Deserialize (project, item);
		}
		public static void WriteObjectProperties (this IPropertySet pset, object ob, Type typeToScan, bool includeBaseMembers = false)
		{
			DataSerializer ser = new DataSerializer (Services.ProjectService.DataContext);
			var props = Services.ProjectService.DataContext.GetProperties (ser.SerializationContext, ob);
			XmlConfigurationWriter cwriter = null;
			XmlDocument xdoc = null;

			var mso = pset as IMSBuildProjectObject;
			if (mso != null && mso.ParentProject != null)
				ser.SerializationContext.BaseFile = mso.ParentProject.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';
		
			foreach (var prop in props) {
				if (prop.IsExternal)
					continue;
				bool merge = Attribute.IsDefined (prop.Member, typeof(MergeToProjectAttribute));
				if (prop.PropertyType == typeof(FilePath)) {
					var val = (FilePath)prop.GetValue (ob);
					FilePath def = (string)prop.DefaultValue;
					pset.SetValue (prop.Name, val, def, mergeToMainGroup: merge);
				} else if (prop.DataType is PathDataType && prop.PropertyType == typeof(string)) {
					FilePath val = (string)prop.GetValue (ob);
					FilePath def = (string)prop.DefaultValue;
					pset.SetValue (prop.Name, val, def, mergeToMainGroup: merge);
				} else if (prop.PropertyType == typeof(string)) {
					pset.SetValue (prop.Name, (string)prop.GetValue (ob), (string)prop.DefaultValue, merge);
				} else if (prop.DataType.IsSimpleType) {
					pset.SetValue (prop.Name, prop.GetValue (ob), prop.DefaultValue, merge);
				} else if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition () == typeof(Nullable<>)) {
					pset.SetValue (prop.Name, prop.GetValue (ob), prop.DefaultValue, merge);
				} else {
					var val = prop.GetValue (ob);
					if (val != null) {
						if (cwriter == null) {
							cwriter = new XmlConfigurationWriter { Namespace = MSBuildProject.Schema, StoreAllInElements = true };
							xdoc = new XmlDocument ();
						}
						var data = prop.Serialize (ser.SerializationContext, ob, val);
						if (data != null) {
							var elem = cwriter.Write (xdoc, data);
							pset.SetValue (prop.Name, prop.WrapObject ? elem.OuterXml : elem.InnerXml);
						} else
							pset.RemoveProperty (prop.Name);
					} else
						pset.RemoveProperty (prop.Name);
				}
			}
		}
Exemple #6
0
 public BinaryDataSerializer(DataSerializer serializer)
 {
     this.serializer = serializer;
 }
		/// <summary>
		/// Gets a list of metadata properties which are read and written by this item, so they don't
		/// have to be stored in the generic Metadata dictionary
		/// </summary>
		/// <returns>The known metadata properties.</returns>
		protected virtual IEnumerable<string> GetKnownMetadataProperties ()
		{
			DataSerializer ser = new DataSerializer (Services.ProjectService.DataContext);
			var props = Services.ProjectService.DataContext.GetProperties (ser.SerializationContext, this);
			foreach (var prop in props)
				if (!prop.IsExternal)
					yield return prop.Name;
		}
		public CombineWriterV2 (DataSerializer serializer, IProgressMonitor monitor, Type objectType)
		{
			this.serializer = serializer;
			this.monitor = monitor;
			this.objectType = objectType;
		}
		object ReadProjectFile (FilePath fileName, IProgressMonitor monitor)
		{
			XmlTextReader reader = null;
			try {
				reader = new XmlTextReader (new StreamReader (fileName));
				reader.MoveToContent ();

				string version = reader.GetAttribute ("version");
				if (version == null) version = reader.GetAttribute ("fileversion");
				
				DataSerializer serializer = new DataSerializer (MD1ProjectService.DataContext, fileName);
				IProjectReader projectReader = null;
				
				monitor.BeginTask (GettextCatalog.GetString ("Loading project: {0}", fileName), 1);
				
				if (version == "2.0" || version == "2.1") {
					projectReader = new ProjectReaderV2 (serializer);
					return projectReader.ReadProject (reader);
				}
				else
					throw new MD1UnknownProjectVersion (fileName, version);
			} catch (Exception ex) {
				monitor.ReportError (GettextCatalog.GetString ("Could not load project: {0}", fileName), ex);
				throw;
			} finally {
				monitor.EndTask ();
				if (reader != null)
					reader.Close ();
			}
		}
		internal static void WriteExternalProjectProperties (this MSBuildProject project, object ob, Type typeToScan, bool includeBaseMembers = false)
		{
			DataSerializer ser = new DataSerializer (Services.ProjectService.DataContext);
			var props = Services.ProjectService.DataContext.GetProperties (ser.SerializationContext, ob);

			XmlConfigurationWriter writer = null;
			foreach (var prop in props) {
				if (!prop.IsExternal)
					continue;
				var val = prop.GetValue (ob);
				if (val != null) {
					var data = prop.Serialize (ser.SerializationContext, ob, val);
					if (data != null) {
						data.Name = prop.Name;
						if (writer == null)
							writer = new XmlConfigurationWriter { Namespace = MSBuildProject.Schema };

						XmlDocument doc = new XmlDocument ();
						var elem = writer.Write (doc, data);
						// TODO NPM
						project.SetMonoDevelopProjectExtension (prop.Name, elem);
						continue;
					}
				}
				project.RemoveMonoDevelopProjectExtension (prop.Name);
			}
		}
		public static void ReadObjectProperties (this SlnSection pset, object ob)
		{
			DataSerializer ser = new DataSerializer (solutionDataContext);
			ser.SerializationContext.BaseFile = pset.ParentFile.FileName;
			var data = ReadDataItem (pset);	
			ser.Deserialize (ob, data);
		}
		public static void WriteObjectProperties (this SlnSection pset, object ob)
		{
			DataSerializer ser = new DataSerializer (solutionDataContext);
			ser.SerializationContext.BaseFile = pset.ParentFile.FileName;
			ser.SerializationContext.IncludeDeletedValues = true;
			var data = ser.Serialize (ob, ob.GetType()) as DataItem;
			if (data != null)
				WriteDataItem (pset, data);
		}
		public static void ReadObjectProperties (this IReadOnlyPropertySet pset, object ob, Type typeToScan, bool includeBaseMembers = false)
		{
			DataSerializer ser = new DataSerializer (Services.ProjectService.DataContext);
			var props = Services.ProjectService.DataContext.GetProperties (ser.SerializationContext, ob);

			var mso = pset as IMSBuildProjectObject;
			if (mso != null && mso.ParentProject != null)
				ser.SerializationContext.BaseFile = mso.ParentProject.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';

			foreach (var prop in props) {
				if (prop.IsExternal)
					continue;
				object readVal = null;
				if (prop.PropertyType == typeof(FilePath)) {
					FilePath def = (string)prop.DefaultValue;
					readVal = pset.GetPathValue (prop.Name, def);
				} else if (prop.DataType is PathDataType && prop.PropertyType == typeof(string)) {
					FilePath def = (string)prop.DefaultValue;
					readVal = pset.GetPathValue (prop.Name, def);
					readVal = readVal.ToString ();
				} else if (prop.PropertyType == typeof(string)) {
					readVal = pset.GetValue (prop.Name, (string)prop.DefaultValue);
				} else if (prop.DataType.IsSimpleType) {
					readVal = pset.GetValue (prop.Name, prop.PropertyType, prop.DefaultValue);
				} else if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition () == typeof(Nullable<>)) {
					readVal = pset.GetValue (prop.Name, prop.PropertyType, prop.DefaultValue);
				} else {
					var val = pset.GetValue (prop.Name);
					if (!string.IsNullOrEmpty (val)) {
						try {
							if (!prop.WrapObject)
								val = "<a>" + val + "</a>";
							var data = XmlConfigurationReader.DefaultReader.Read (new XmlTextReader (new StringReader (val)));
							if (prop.HasSetter && prop.DataType.CanCreateInstance) {
								readVal = prop.Deserialize (ser.SerializationContext, ob, data);
							} else if (prop.DataType.CanReuseInstance) {
								// Try to deserialize over the existing instance
								prop.Deserialize (ser.SerializationContext, ob, data, prop.GetValue (ob));
								continue;
							} else {
								throw new InvalidOperationException ("The property '" + prop.Name + "' does not have a setter.");
							}
						} catch (Exception ex) {
							LoggingService.LogError ("Cound not read project property '" + prop.Name + "'", ex);
						}
					} else
						continue;
				}
				prop.SetValue (ob, readVal);
			}
		}
		public ProjectReaderV2 (DataSerializer serializer)
		{
			this.serializer = serializer;
		}
		void WriteSolution (FilePath actualFile, FilePath outFile, Solution solution, IProgressMonitor monitor)
		{
			StreamWriter sw = new StreamWriter (outFile);
			try {
				monitor.BeginTask (GettextCatalog.GetString ("Saving solution: {0}", actualFile), 1);
				XmlTextWriter tw = new XmlTextWriter (sw);
				tw.Formatting = Formatting.Indented;
				DataSerializer serializer = new DataSerializer (MD1ProjectService.DataContext, actualFile);
				CombineWriterV2 combineWriter = new CombineWriterV2 (serializer, monitor, typeof(Solution));
				combineWriter.WriteCombine (tw, solution);
			} catch (Exception ex) {
				monitor.ReportError (GettextCatalog.GetString ("Could not save solution: {0}", actualFile), ex);
				throw;
			} finally {
				monitor.EndTask ();
				sw.Close ();
			}
		}
		object ReadCombineFile (FilePath file, IProgressMonitor monitor)
		{
			XmlTextReader reader = new XmlTextReader (new StreamReader (file));
			reader.MoveToContent ();
			
			string version = reader.GetAttribute ("version");
			if (version == null) version = reader.GetAttribute ("fileversion");
			
			DataSerializer serializer = new DataSerializer (MD1ProjectService.DataContext, file);
			ICombineReader combineReader = null;
			
			if (version == "2.0" || version == "2.1")
				combineReader = new CombineReaderV2 (serializer, monitor, typeof(Solution));
			
			try {
				if (combineReader != null)
					return combineReader.ReadCombine (reader);
				else
					throw new MD1UnknownProjectVersion (file, version);
			} catch (Exception ex) {
				monitor.ReportError (GettextCatalog.GetString ("Could not load solution: {0}", file), ex);
				throw;
			} finally {
				reader.Close ();
			}
		}
		internal static void ReadExternalProjectProperties (this MSBuildProject project, object ob, Type typeToScan, bool includeBaseMembers = false)
		{
			DataSerializer ser = new DataSerializer (Services.ProjectService.DataContext);
			var props = Services.ProjectService.DataContext.GetProperties (ser.SerializationContext, ob);

			foreach (var prop in props) {
				if (!prop.IsExternal)
					continue;
				var sec = project.GetMonoDevelopProjectExtension (prop.Name);
				if (sec != null) {
					var data = XmlConfigurationReader.DefaultReader.Read (sec);
					var val = prop.Deserialize (ser.SerializationContext, ob, data);
					prop.SetValue (ob, val);
				}
			}
		}
Exemple #18
0
		public XmlDataSerializer (DataSerializer serializer)
		{
			this.serializer = serializer;
		}
		public BinaryDataSerializer (DataSerializer serializer)
		{
			this.serializer = serializer;
		}