コード例 #1
0
ファイル: Main.cs プロジェクト: Boomtime/glimmer
        void XBtnLoad_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog();

            if (DialogResult.OK == dlg.ShowDialog())
            {
                try {
                    LogAppend("SequenceJson.Load: ", dlg.FileName);
                    using (var file = dlg.OpenFile()) {
                        mSequenceList[OutputFunc.Custom] = SequenceJson.Load(file);
                        if (OutputFunc.Custom == mFunc)
                        {
                            StartCurrentSequence();
                        }
                    }
                }
                catch (Exception ex) {
                    var msg = string.Format("Error occurred loading JSON. The message was:\r\n{0}", ex.Message);
                    if (ex is JsonException)
                    {
                        msg += string.Format("\r\n\r\nAt:\r\n{0}", (ex as JsonException).JsonPath.FullPath);
                    }
                    LogAppend(Color.White, Color.DarkRed, "Error loading JSON: ", null, msg);
                    MessageBox.Show(msg, "Error loading JSON", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
ファイル: Sequencer.cs プロジェクト: Boomtime/glimmer
        public static ISequence Load(Stream file)
        {
            var sj    = new SequenceJson();
            var jroot = JsonObject.Load(file);

            foreach (var jdev in jroot["Devices"].AsArray())
            {
                sj.AddJsonDevice(jdev.AsObject());
            }
            // controls are optional but must be an array of object if present
            if (jroot.TryGetValue("Controls", out JsonValue jctlarray))
            {
                foreach (var jctl in jctlarray.AsArray())
                {
                    sj.AddJsonControl(jctl.AsObject());
                }
            }
            foreach (var jseq in jroot["Sequences"].AsArray())
            {
                sj.AddJsonSequence(jseq.AsObject());
            }
            return(sj.Program);
        }