public void SerializationDoubleRoundtrip()
        {
            var bag = new PropertyBag();
            var t   = new SerializableObject {
                SomeValue = "test1"
            };

            bag.SetValue("foo", t);

            var w   = new StringWriter();
            var ser = new XmlDataSerializer(new DataContext());

            ser.Serialize(w, bag);
            var data = w.ToString();

            SerializableObject.CreationCount = 0;

            bag = ser.Deserialize <PropertyBag> (new StringReader(data));

            // SerializableObject is not instantiated if not queried
            Assert.AreEqual(0, SerializableObject.CreationCount);

            w = new StringWriter();
            ser.Serialize(w, bag);
            data = w.ToString();

            bag = ser.Deserialize <PropertyBag> (new StringReader(data));

            // SerializableObject is not instantiated if not queried
            Assert.AreEqual(0, SerializableObject.CreationCount);

            t = bag.GetValue <SerializableObject> ("foo");
            Assert.NotNull(t);
            Assert.AreEqual("test1", t.SomeValue);
        }
        object ReadWorkspaceItemFile(FilePath fileName, IProgressMonitor monitor)
        {
            XmlTextReader reader = new XmlTextReader(new StreamReader(fileName));

            try
            {
                monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading workspace item: {0}"), fileName), 1);
                reader.MoveToContent();
                XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext);
                ser.SerializationContext.BaseFile        = fileName;
                ser.SerializationContext.ProgressMonitor = monitor;
                WorkspaceItem entry = (WorkspaceItem)ser.Deserialize(reader, typeof(WorkspaceItem));
                entry.ConvertToFormat(MD1ProjectService.FileFormat, false);
                entry.FileName = fileName;
                return(entry);
            }
            catch (Exception ex)
            {
                monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load solution item: {0}"), fileName), ex);
                throw;
            }
            finally
            {
                monitor.EndTask();
                reader.Close();
            }
        }
        public object ReadFile(FilePath file, Type expectedType, IProgressMonitor monitor)
        {
            XmlTextReader reader = new XmlTextReader(new StreamReader(file));

            try {
                monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading project: {0}"), file), 1);

                reader.MoveToContent();

                XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext);
                ser.SerializationContext.BaseFile = file;

                SolutionEntityItem entry = (SolutionEntityItem)ser.Deserialize(reader, typeof(NUnitAssemblyGroupProject));
                entry.FileName = file;
                return(entry);
            }
            catch (Exception ex) {
                monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load project: {0}"), file), ex);
                throw;
            }
            finally {
                monitor.EndTask();
                reader.Close();
            }
        }
Exemple #4
0
        public virtual void LoadUserProperties()
        {
            if (userProperties != null)
            {
                userProperties.Dispose();
            }
            userProperties = null;

            string preferencesFileName = GetPreferencesFileName();

            if (!File.Exists(preferencesFileName))
            {
                return;
            }

            XmlTextReader reader = new XmlTextReader(preferencesFileName);

            try {
                reader.MoveToContent();
                if (reader.LocalName != "Properties")
                {
                    return;
                }

                XmlDataSerializer ser = new XmlDataSerializer(new DataContext());
                ser.SerializationContext.BaseFile = preferencesFileName;
                userProperties = (PropertyBag)ser.Deserialize(reader, typeof(PropertyBag));
            } catch (Exception e) {
                LoggingService.LogError("Exception while loading user solution preferences.", e);
                return;
            } finally {
                reader.Close();
            }
        }
Exemple #5
0
        static CustomExecutionModes GetGlobalCustomExecutionModes()
        {
            if (globalModes == null)
            {
                try
                {
                    XmlDataSerializer ser  = new XmlDataSerializer(GetDataContext());
                    FilePath          file = UserProfile.Current.ConfigDir.Combine("custom-command-modes.xml");
                    if (File.Exists(file))
                    {
                        globalModes = (CustomExecutionModes)ser.Deserialize(file, typeof(CustomExecutionModes));
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.LogError("Could not load global custom execution modes.", ex);
                }

                if (globalModes == null)
                {
                    globalModes = new CustomExecutionModes();
                }
            }
            return(globalModes);
        }
Exemple #6
0
        protected virtual async Task OnLoadUserProperties()
        {
            userProperties.Dispose();
            userProperties = new PropertyBag();

            string preferencesFileName = GetPreferencesFileName();

            await Task.Run(() => {
                if (!File.Exists(preferencesFileName))
                {
                    return;
                }

                using (var streamReader = new StreamReader(preferencesFileName)) {
                    XmlTextReader reader = new XmlTextReader(streamReader);
                    try {
                        reader.MoveToContent();
                        if (reader.LocalName != "Properties")
                        {
                            return;
                        }

                        XmlDataSerializer ser             = new XmlDataSerializer(new DataContext());
                        ser.SerializationContext.BaseFile = preferencesFileName;
                        userProperties = (PropertyBag)ser.Deserialize(reader, typeof(PropertyBag));
                    } catch (Exception e) {
                        LoggingService.LogError("Exception while loading user solution preferences.", e);
                        return;
                    } finally {
                        reader.Close();
                    }
                }
            });
        }
Exemple #7
0
        static AddinAuthoringService()
        {
            if (IdeApp.IsInitialized)
            {
                IdeApp.ProjectOperations.EndBuild += OnEndBuild;
            }

            configFile = Path.Combine(PropertyService.ConfigPath, "AddinAuthoring.config");
            if (File.Exists(configFile))
            {
                try {
                    XmlDataSerializer ser = new XmlDataSerializer(new DataContext());
                    StreamReader      sr  = new StreamReader(configFile);
                    using (sr) {
                        config = (AddinAuthoringServiceConfig)ser.Deserialize(new XmlTextReader(sr), typeof(AddinAuthoringServiceConfig));
                    }
                }
                catch (Exception ex) {
                    LoggingService.LogError("Could not load add-in authoring service configuration", ex);
                }
            }
            if (config == null)
            {
                config = new AddinAuthoringServiceConfig();
            }
        }
Exemple #8
0
        public TargetFramework CreateFramework()
        {
            Stream s;

            if (resource != null)
            {
                s = Addin.GetResource(resource);
            }
            else if (file != null)
            {
                s = File.OpenRead(Addin.GetFilePath(file));
            }
            else
            {
                throw new InvalidOperationException("Framework xml source not specified");
            }

            using (s) {
                XmlTextReader     reader = new XmlTextReader(s);
                XmlDataSerializer ser    = new XmlDataSerializer(new DataContext());
                TargetFramework   fx     = (TargetFramework)ser.Deserialize(reader, typeof(TargetFramework));
                fx.FrameworkNode = this;
                return(fx);
            }
        }
        public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor)
        {
            object readObject = null;

            ProjectExtensionUtil.BeginLoadOperation();
            try {
                string ext = Path.GetExtension(fileName).ToLower();

                if (ext == ".mdp")
                {
                    object project = ReadProjectFile(fileName, monitor);
                    if (project is DotNetProject)
                    {
                        ((DotNetProject)project).SetItemHandler(new MD1DotNetProjectHandler((DotNetProject)project));
                    }
                    readObject = project;
                }
                else if (ext == ".mds")
                {
                    readObject = ReadCombineFile(fileName, monitor);
                }
                else if (ext == ".mdw")
                {
                    readObject = ReadWorkspaceItemFile(fileName, monitor);
                }
                else
                {
                    XmlTextReader reader = new XmlTextReader(new StreamReader(fileName));
                    try {
                        monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading solution item: {0}"), fileName), 1);
                        reader.MoveToContent();
                        XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext);
                        ser.SerializationContext.BaseFile        = fileName;
                        ser.SerializationContext.ProgressMonitor = monitor;
                        SolutionEntityItem entry = (SolutionEntityItem)ser.Deserialize(reader, typeof(SolutionEntityItem));
                        entry.FileName = fileName;
                        MD1ProjectService.InitializeHandler(entry);
                        readObject = entry;
                    }
                    catch (Exception ex) {
                        monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load solution item: {0}"), fileName), ex);
                        throw;
                    }
                    finally {
                        monitor.EndTask();
                        reader.Close();
                    }
                }
            } finally {
                ProjectExtensionUtil.EndLoadOperation();
            }

            IWorkspaceFileObject fo = readObject as IWorkspaceFileObject;

            if (fo != null)
            {
                fo.ConvertToFormat(MD1ProjectService.FileFormat, false);
            }
            return(readObject);
        }
        static void OnWorkspaceItemLoaded(object sender, WorkspaceItemEventArgs e)
        {
            string fileToLoad = GetUserTasksFilename(e.Item);

            userTasks.BeginTaskUpdates();
            try {
                // Load User Tasks from xml file
                if (File.Exists(fileToLoad))
                {
                    XmlDataSerializer serializer = new XmlDataSerializer(new DataContext());
                    List <Task>       ts         = (List <Task>)serializer.Deserialize(fileToLoad, typeof(List <Task>));
                    foreach (Task t in ts)
                    {
                        t.WorkspaceObject = e.Item;
                        userTasks.Add(t);
                    }
                }
            }
            catch (Exception ex) {
                LoggingService.LogWarning("Could not load user tasks: " + fileToLoad, ex);
            }
            finally {
                userTasks.EndTaskUpdates();
            }
        }
Exemple #11
0
 private static AddinConfig GetConfig()
 {
     if (configuration != null)
     {
         return(configuration);
     }
     if (File.Exists(ConfigFile))
     {
         try
         {
             XmlDataSerializer s = new XmlDataSerializer(dataContext);
             using (var reader = File.OpenText(ConfigFile))
             {
                 configuration = (AddinConfig)s.Deserialize(reader, typeof(AddinConfig));
             }
         }
         catch (Exception e)
         {
             ((FilePath)ConfigFile).Delete();
         }
     }
     if (configuration == null)
     {
         configuration = new AddinConfig();
     }
     return(configuration);
 }
Exemple #12
0
        public TargetFramework CreateFramework()
        {
            Stream s;

            if (SystemAssemblyService.UseExpandedFrameworksFile)
            {
                if (resource != null)
                {
                    s = Addin.GetResource(resource);
                }
                else if (file != null)
                {
                    s = File.OpenRead(Addin.GetFilePath(file));
                }
                else
                {
                    throw new InvalidOperationException("Framework xml source not specified");
                }
            }
            else
            {
                string file = System.IO.Path.Combine(SystemAssemblyService.ReferenceFrameworksPath, resource);
                Console.WriteLine("Loading framework file: " + file);
                s = File.OpenRead(file);
            }

            using (s) {
                XmlTextReader     reader = new XmlTextReader(s);
                XmlDataSerializer ser    = new XmlDataSerializer(new DataContext());
                TargetFramework   fx     = (TargetFramework)ser.Deserialize(reader, typeof(TargetFramework));
                fx.FrameworkNode = this;
                return(fx);
            }
        }
Exemple #13
0
        public static ToolboxConfiguration LoadFromFile(string fileName)
        {
            object o;

            using (StreamReader reader = new StreamReader(fileName))
            {
                XmlDataSerializer serializer = new XmlDataSerializer(MonoDevelop.Projects.Services.ProjectService.DataContext);
                o = serializer.Deserialize(reader, typeof(ToolboxConfiguration));
            }
            return((ToolboxConfiguration)o);
        }
Exemple #14
0
    static public Dictionary <A, B> DeserializeDictionary(string filePath)
    {
        Dictionary <A, B> dictionary = new Dictionary <A, B>();
        List <Item>       itemList   = XmlDataSerializer.Deserialize <List <Item> >(filePath);

        foreach (Item item in itemList)
        {
            dictionary.Add(item.Key, item.Value);
        }
        return(dictionary);
    }
        public void SerializeObject(bool serialize, int size)
        {
            var order = new MainDataOne();

            order.Name = "Test";
            var serializerTests = new XmlDataSerializer(serialize);
            var data            = serializerTests.Serialize(order);
            var orderResult     = (IMainData)serializerTests.Deserialize(typeof(MainDataOne), data);

            Assert.AreNotSame(order, orderResult);
            Assert.AreEqual(size, data.Length);
            Assert.AreEqual("Test", orderResult.Name);
        }
 static void LoadRuntimes()
 {
     if (!File.Exists(configFile))
     {
         return;
     }
     try {
         XmlDataSerializer ser = new XmlDataSerializer(new DataContext());
         using (StreamReader sr = new StreamReader(configFile)) {
             customRuntimes = (RuntimeCollection)ser.Deserialize(sr, typeof(RuntimeCollection));
         }
     } catch (Exception ex) {
         LoggingService.LogError("Error while loading mono-runtimes.xml.", ex);
     }
 }
Exemple #17
0
 public IList <ItemToolboxNode> LoadItemsIsolated(TargetRuntime runtime, Type loaderType, string filename)
 {
     if (!typeof(IExternalToolboxLoader).IsAssignableFrom(loaderType))
     {
         throw new InvalidOperationException("Type '" + loaderType + "' does not implement 'IExternalToolboxLoader'");
     }
     try {
         ExternalItemLoader loader = CreateExternalLoader <ExternalItemLoader> (runtime);
         string             s      = loader.LoadItems(loaderType.Assembly.FullName, loaderType.FullName, filename);
         XmlDataSerializer  ser    = new XmlDataSerializer(MonoDevelop.Projects.Services.ProjectService.DataContext);
         ToolboxList        list   = (ToolboxList)ser.Deserialize(new StringReader(s), typeof(ToolboxList));
         return(list);
     } catch {
         return(new List <ItemToolboxNode> ());
     }
 }
Exemple #18
0
        internal static Repository InternalGetRepositoryReference(string path, string id)
        {
            string file = InternalGetRepositoryPath(path, id);

            if (file == null)
            {
                return(null);
            }

            XmlDataSerializer ser    = new XmlDataSerializer(dataContext);
            XmlTextReader     reader = new XmlTextReader(new StreamReader(file));

            try {
                return((Repository)ser.Deserialize(reader, typeof(Repository)));
            } finally {
                reader.Close();
            }
        }
        public void XmlDataSerializer_DeserializeXmlData_Success()
        {
            // Arrange
            var data =
                @"<?xml version=""1.0"" encoding=""utf-16""?><MockCountry xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><Alpha2Code>mt</Alpha2Code></MockCountry>";

            var mockCountry = new MockCountry()
            {
                Alpha2Code = "mt"
            };

            // Act
            var country = _sut.Deserialize(data);

            // Assert
            Assert.NotNull(country);
            Assert.Equal(mockCountry.Alpha2Code, country.Alpha2Code);
        }
Exemple #20
0
        internal static Repository InternalGetRepositoryReference(string path, string id)
        {
            string file = Path.Combine(path, id) + ".mdvcs";

            if (!File.Exists(file))
            {
                return(null);
            }

            XmlDataSerializer ser    = new XmlDataSerializer(dataContext);
            XmlTextReader     reader = new XmlTextReader(new StreamReader(file));

            try {
                return((Repository)ser.Deserialize(reader, typeof(Repository)));
            } finally {
                reader.Close();
            }
        }
        internal static ComponentIndex Load()
        {
            if (!File.Exists(ToolboxIndexFile))
            {
                return(new ComponentIndex());
            }

            XmlDataSerializer ser = new XmlDataSerializer(IdeApp.Services.ProjectService.DataContext);

            try {
                using (StreamReader sr = new StreamReader(ToolboxIndexFile)) {
                    return((ComponentIndex)ser.Deserialize(sr, typeof(ComponentIndex)));
                }
            }
            catch (Exception ex) {
                // Ignore exceptions
                LoggingService.LogError(ex.ToString());
                return(new ComponentIndex());
            }
        }
 static VersionControlConfiguration GetConfiguration()
 {
     if (configuration == null)
     {
         if (File.Exists(ConfigFile))
         {
             try {
                 XmlDataSerializer ser = new XmlDataSerializer(dataContext);
                 using (var reader = File.OpenText(ConfigFile))
                     configuration = (VersionControlConfiguration)ser.Deserialize(reader, typeof(VersionControlConfiguration));
             } catch {
                 ((FilePath)ConfigFile).Delete();
             }
         }
         if (configuration == null)
         {
             configuration = new VersionControlConfiguration();
         }
     }
     return(configuration);
 }
        void LoadViews()
        {
            try {
                XmlDataSerializer ser  = new XmlDataSerializer(new DataContext());
                FilePath          file = ConfigFile;
                if (System.IO.File.Exists(file))
                {
                    views = (List <ChartView>)ser.Deserialize(file, typeof(List <ChartView>));
                    UpdateViews();
                    return;
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error while loading monitor-views.xml", ex);
            }
            views = new List <ChartView> ();
            ChartView v = new ChartView();

            v.Name = "Default";
            views.Add(v);
            UpdateViews();
        }
 static VersionControlConfiguration GetConfiguration()
 {
     if (configuration == null)
     {
         if (File.Exists(ConfigFile))
         {
             XmlDataSerializer ser    = new XmlDataSerializer(dataContext);
             XmlTextReader     reader = new XmlTextReader(new StreamReader(ConfigFile));
             try {
                 configuration = (VersionControlConfiguration)ser.Deserialize(reader, typeof(VersionControlConfiguration));
             } finally {
                 reader.Close();
             }
         }
         if (configuration == null)
         {
             configuration = new VersionControlConfiguration();
         }
     }
     return(configuration);
 }
Exemple #25
0
        WorkspaceItem ReadWorkspaceItemFile(FilePath fileName, ProgressMonitor monitor)
        {
            XmlTextReader reader = new XmlTextReader(new StreamReader(fileName));

            try {
                monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading workspace item: {0}"), fileName), 1);
                reader.MoveToContent();
                XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext);
                ser.SerializationContext.BaseFile        = fileName;
                ser.SerializationContext.ProgressMonitor = monitor;
                WorkspaceItem entry = (WorkspaceItem)ser.Deserialize(reader, typeof(WorkspaceItem));
                entry.FileName = fileName;
                return(entry);
            } catch (Exception ex) {
                string msg = string.Format(GettextCatalog.GetString("Could not load workspace item: {0}"), fileName);
                LoggingService.LogError(msg, ex);
                throw new UserException(msg, ErrorHelper.GetErrorMessage(ex));
            } finally {
                monitor.EndTask();
                reader.Close();
            }
        }
        public virtual void LoadUserProperties()
        {
            if (this.userProperties != null)
            {
                this.userProperties.Dispose();
            }
            this.userProperties = (PropertyBag)null;
            string preferencesFileName = this.GetPreferencesFileName();

            if (!File.Exists(preferencesFileName))
            {
                return;
            }
            XmlTextReader xmlTextReader = new XmlTextReader(preferencesFileName);

            try
            {
                int content = (int)xmlTextReader.MoveToContent();
                if (xmlTextReader.LocalName != "Properties")
                {
                    return;
                }
                XmlDataSerializer ser = new XmlDataSerializer(new DataContext());
                this.DataContextIncludeType(ser);
                ser.SerializationContext.BaseFile = preferencesFileName;
                this.userProperties = (PropertyBag)ser.Deserialize((XmlReader)xmlTextReader, typeof(PropertyBag));
            }
            catch (Exception ex)
            {
                LoggingService.LogError("Exception while loading user solution preferences.", ex);
            }
            finally
            {
                xmlTextReader.Close();
            }
        }
        public static LinuxDeployData GetLinuxDeployData(Project entry)
        {
            LinuxDeployData data = (LinuxDeployData)entry.ExtendedProperties ["Deployment.LinuxDeployData"];

            if (data != null)
            {
                return(data);
            }

            var elem = entry.MSBuildProject.GetMonoDevelopProjectExtension("Deployment.LinuxDeployData");

            if (elem != null)
            {
                XmlDataSerializer ser = new XmlDataSerializer(new DataContext());
                data = (LinuxDeployData)ser.Deserialize(new XmlNodeReader(elem), typeof(LinuxDeployData));
            }
            else
            {
                data = CreateDefault(entry);
            }
            data.entry = entry;
            entry.ExtendedProperties ["Deployment.LinuxDeployData"] = data;
            return(data);
        }
        public static TObj Deserialize <TObj>(string rootElementName, string xmlObject, XmlSerializerSettings settings)
        {
            XmlDataSerializer serializer = new XmlDataSerializer(settings);

            return((TObj)serializer.Deserialize(typeof(TObj), rootElementName, xmlObject));
        }
        public static TObj Deserialize <TObj>(XmlReader reader)
        {
            XmlDataSerializer serializer = new XmlDataSerializer();

            return((TObj)serializer.Deserialize(typeof(TObj), reader));
        }
        public static TObj Deserialize <TObj>(string rootElementName, XmlReader reader, XmlSerializerSettings settings)
        {
            XmlDataSerializer serializer = new XmlDataSerializer(settings);

            return((TObj)serializer.Deserialize(typeof(TObj), rootElementName, reader));
        }