source: trunk/CrypPlugins/WorkspaceManager/Model/ModelPersistance.cs @ 1740

Last change on this file since 1740 was 1740, checked in by kopal, 12 years ago

Created first Version of XMLSerializer for the loading/saving of workspaceManager files

File size: 3.4 KB
Line 
1/*                             
2   Copyright 2010 Nils Kopal, Viktor M.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.IO;
22using System.Xml.Serialization;
23using System.Runtime.Serialization.Formatters.Binary;
24using System.Reflection;
25using Cryptool.PluginBase;
26using XMLSerialization;
27
28namespace WorkspaceManager.Model
29{
30    /// <summary>
31    /// Class with static methods for loading and saving of WorkspaceModels
32    /// </summary>
33    public class ModelPersistance
34    {
35        /// <summary>
36        /// Deserializes a model from the given file with the given filename
37        /// </summary>
38        /// <param name="filename"></param>
39        /// <returns></returns>
40        public static WorkspaceModel loadModel(string filename, WorkspaceManager workspaceManagerEditor)
41        {
42            WorkspaceModel workspacemodel = (WorkspaceModel)XMLSerialization.XMLSerialization.Deserialize(filename);   
43            workspacemodel.WorkspaceManagerEditor = workspaceManagerEditor;
44
45            foreach (PluginModel pluginModel in workspacemodel.AllPluginModels)
46            {
47                pluginModel.Plugin.OnGuiLogNotificationOccured += workspaceManagerEditor.GuiLogNotificationOccured;
48                pluginModel.Plugin.OnPluginProgressChanged += pluginModel.PluginProgressChanged;
49                pluginModel.Plugin.OnPluginStatusChanged += pluginModel.PluginStatusChanged;
50            }
51               
52            foreach (ConnectorModel connectorModel in workspacemodel.AllConnectorModels)
53            {
54                if(connectorModel.Outgoing == true){
55                    connectorModel.PluginModel.Plugin.PropertyChanged += connectorModel.PropertyChangedOnPlugin;
56                }
57
58                if (connectorModel.IsDynamic == true)
59                {
60                    DynamicPropertyInfoAttribute dynamicPropertyInfoAttribute = connectorModel.PluginModel.Plugin.GetDynamicPropertyInfo();
61                    EventInfo eventinfo = connectorModel.PluginModel.PluginType.GetEvent(dynamicPropertyInfoAttribute.UpdateDynamicPropertiesEvent);
62                    eventinfo.AddEventHandler(connectorModel.PluginModel.Plugin, new DynamicPropertiesChanged(connectorModel.PropertyTypeChangedOnPlugin));
63                }
64            }
65            return workspacemodel;         
66        }
67
68        /// <summary>
69        /// Serializes the given model to a file with the given filename
70        /// </summary>
71        /// <param name="workspaceModel"></param>
72        /// <param name="filename"></param>
73        /// <returns></returns>
74        public static void saveModel(WorkspaceModel workspaceModel, string filename)
75        {
76           XMLSerialization.XMLSerialization.Serialize(workspaceModel, filename);
77        }
78    }
79}
Note: See TracBrowser for help on using the repository browser.