void ISerializer.Save(IPatchGraphManager patchGraphManager, string filename)
        {
            PatchGraph patchGraph = new PatchGraph();

            Patch[] patches = patchGraphManager.GetPatches();
            patchGraph.patches = new SerializedPatch[patches.Length];
            SerializedPatch serializedPatch;
            Patch           patch;
            int             j;

            for (int i = 0; i < patches.Length; i++)
            {
                patch           = patches[i];
                serializedPatch = new SerializedPatch()
                {
                    id         = patch.Id,
                    code       = patch.Code,
                    PosX       = patch.PosX,
                    PosY       = patch.PosY,
                    parameters = new Parameter[patch.Values.Count]
                };
                j = 0;
                foreach (KeyValuePair <string, float> pair in patch.Values)
                {
                    serializedPatch.parameters[j++] = new Parameter()
                    {
                        name  = pair.Key,
                        value = pair.Value
                    };
                }
                patchGraph.patches[i] = serializedPatch;
            }
            patchGraph.connections = patchGraphManager.GetConnections();
            patchGraph.maxId       = ((PatchGraphManager)patchGraphManager).maxId;
            string        xml;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(PatchGraph));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                xmlSerializer.Serialize(memoryStream, patchGraph);
                memoryStream.Position = 0;
                using (StreamReader streamReader = new StreamReader(memoryStream))
                {
                    xml = streamReader.ReadToEnd();
                }
            }
            try
            {
                Tracer.Log("Application.persistentDataPath + Others.SavesFolder + filename" + Application.persistentDataPath + Others.SavesFolder + filename);
                File.WriteAllText(Application.persistentDataPath + Others.SavesFolder + filename, xml, Encoding.UTF8);
            }
            catch (Exception e)
            {
                Tracer.Log(e.Message + e.StackTrace);
            }
        }
 public void Load(string filename)
 {
     processor.Clear(patchGraphManager.GetPatches());
     patchGraphManager.Clear();
     patchCreator.Clear();
     WireDrawer.GetInstance().Clear();
     patchGraphManager = serializer.Load(filename);
     Patch[] patches = patchGraphManager.GetPatches();
     processor.LoadPatches(patches);
     patchCreator.Load(patches);
     Connection[] connections = patchGraphManager.GetConnections();
     processor.LoadConnections(connections);
     WireDrawer.GetInstance().Load(connections);
 }
        public void Init(string[] config)
        {
            MainFactory mainFactory = new MainFactory();

            processorConfig = mainFactory.Create <IProcessorConfig>(config[0], config[1]);
            processorConfig.Init();
            processor         = processorConfig.GetProcessor();
            patchGraphManager = mainFactory.Create <IPatchGraphManager>(config[2], config[3]);
            patchFactory      = mainFactory.Create <IPatchFactory>(config[4], config[5]);
            patchFactory.Init();
            serializer = mainFactory.Create <ISerializer>(config[6], config[7]);
            ((IWaveDrawer)waveDrawer).Init(Others.WavePoints);
            soundData = new float[Others.WavePoints * 2];
        }
Example #4
0
        void ISerializer.Save(IPatchGraphManager patchGraphManager, string filename)
        {
            string json;
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(patchGraphManager.GetType());

            using (MemoryStream memoryStream = new MemoryStream())
            {
                dataContractJsonSerializer.WriteObject(memoryStream, patchGraphManager);
                memoryStream.Position = 0;
                using (StreamReader streamReader = new StreamReader(memoryStream))
                {
                    json = streamReader.ReadToEnd();
                }
            }
            try
            {
                Tracer.Log("Application.persistentDataPath + Others.SavesFolder + filename" + Application.persistentDataPath + Others.SavesFolder + filename);
                File.WriteAllText(Application.persistentDataPath + Others.SavesFolder + filename, json, Encoding.UTF8);
            }
            catch (Exception e)
            {
                Tracer.Log(e.Message + e.StackTrace);
            }
        }