예제 #1
0
        public static void Main(string[] args)
        {
            // Create algorithm setup.
            var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom3       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom4       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());

            algorithmZoom4.SetInput(0, algorithmInitialLand);
            algorithmZoom3.SetInput(0, algorithmZoom4);
            algorithmZoom2.SetInput(0, algorithmZoom3);
            algorithmZoom1.SetInput(0, algorithmZoom2);

            StorageLayer[] storage = null;
            Console.WriteLine("Storing...");
            using (var writer = new StreamWriter("WorldConfig.xml", false))
                StorageAccess.SaveStorage(
                    new StorageLayer[] { StorageAccess.FromRuntime(algorithmZoom1) }, writer);

            Console.WriteLine("Loading...");
            using (var reader = new StreamReader("WorldConfig.xml"))
                storage = StorageAccess.LoadStorage(reader);
            foreach (var l in storage)
            {
                Console.WriteLine(l.Algorithm.GetType().FullName);
            }
        }
예제 #2
0
        private void c_SaveConfigurationButton_Click(object sender, EventArgs e)
        {
            if (this.m_LastSavePath == null)
            {
                this.c_SaveConfigurationAsButton.PerformClick();
            }
            else
            {
                // Convert to storage layers.
                var layers = new List <StorageLayer>();
                foreach (var element in this.c_FlowInterfaceControl.Elements)
                {
                    var algorithmElement = element as AlgorithmFlowElement;
                    if (algorithmElement == null)
                    {
                        continue;
                    }

                    algorithmElement.Layer.EditorX = element.X;
                    algorithmElement.Layer.EditorY = element.Y;

                    layers.Add(algorithmElement.Layer);
                }

                // Save the layers.
                try
                {
                    var memory = new MemoryStream();
                    using (var writer = new StreamWriter(memory))
                    {
                        StorageAccess.SaveStorage(layers.ToArray(), writer);
                        memory.Seek(0, SeekOrigin.Begin);
                        using (var file = new StreamWriter(this.m_LastSavePath, false))
                            memory.CopyTo(file.BaseStream);
                    }

                    MessageBox.Show(this, "Save successful.", "Configuration saved.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Save failure.", ex.Message + "\r\n" + ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }