Exemple #1
0
        private void SaveFile(string saveFileName)
        {
            var serializer = new MISPLIB.SerializationContext();
            var builder    = new StringBuilder();

            serializer.Serialize(GlobalScope, builder);

            var dirName = System.IO.Path.GetDirectoryName(saveFileName);

            if (!String.IsNullOrEmpty(dirName))
            {
                System.IO.Directory.CreateDirectory(dirName);
            }

            System.IO.File.WriteAllText(saveFileName, builder.ToString());
            OpenFilePath = saveFileName;
            this.Title   = OpenFilePath;
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            TextBox_TextChanged(null, null);
            String OpenFilePath = null;

            InputBox.Focus();

            this.Title = "New Environment";

            MISPLIB.Core.InitiateCore(s =>
            {
                OutputBox.AppendText(s);
                OutputBox.ScrollToEnd();
            });

            MISPLIB.Core.AddCoreFunction("recall function", (args, c) =>
            {
                MISPLIB.Core.EmissionID = Guid.NewGuid();
                var builder             = new StringBuilder();
                args[0].Emit(builder);
                InputBox.Text = builder.ToString();
                return(args[0]);
            });

            MISPLIB.Core.AddCoreFunction("@", (args, c) =>
            {
                return(GlobalScope);
            });

            MISPLIB.Core.AddCoreFunction("save file", (args, c) =>
            {
                if (args[0].Type != MISPLIB.AtomType.String)
                {
                    throw new MISPLIB.EvaluationError("Expected string as first argument to save.");
                }
                var saveFileName = (args[0] as MISPLIB.StringAtom).Value;

                var serializer = new MISPLIB.SerializationContext();
                var builder    = new StringBuilder();
                serializer.Serialize(GlobalScope, builder);

                var dirName = System.IO.Path.GetDirectoryName(saveFileName);
                if (!String.IsNullOrEmpty(dirName))
                {
                    System.IO.Directory.CreateDirectory(dirName);
                }

                System.IO.File.WriteAllText(saveFileName, builder.ToString());
                OpenFilePath = saveFileName;
                this.Title   = OpenFilePath;
                return(new MISPLIB.StringAtom {
                    Value = OpenFilePath
                });
            });

            MISPLIB.Core.AddCoreFunction("load file", (args, c) =>
            {
                if (args[0].Type != MISPLIB.AtomType.String)
                {
                    throw new MISPLIB.EvaluationError("Expected path as first argument to load.");
                }

                var text   = System.IO.File.ReadAllText((args[0] as MISPLIB.StringAtom).Value);
                var parsed = MISPLIB.Core.Parse(new MISPLIB.StringIterator(text));
                var result = MISPLIB.Core.Evaluate(parsed, GlobalScope);
                if (result.Type != MISPLIB.AtomType.Record)
                {
                    throw new MISPLIB.EvaluationError("Loading of file did not produce record.");
                }
                OpenFilePath = (args[0] as MISPLIB.StringAtom).Value;
                this.Title   = OpenFilePath;
                GlobalScope  = result as MISPLIB.RecordAtom;
                return(GlobalScope);
            });

            OutputBox.Document.Blocks.Add(OutputRoot);

            var buildVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var run          = new Run("MISP 3.0 Build " + buildVersion + "\n")
            {
                Foreground = Brushes.Red
            };

            OutputRoot.Inlines.Add(run);
        }