Ejemplo n.º 1
0
        public static Action FromXML(XmlNode actionNode, EventGenerator eg)
        {
            Action action;
            string name;
            uint   id;

            Persister.StartFromXML(actionNode, out name, out id);
            switch (actionNode.Attributes["type"]?.InnerText)
            {
            case "Analysis":
                AnalysisAction analysisAction = new AnalysisAction(eg, name, id);
                analysisAction.GetAnalysis().SetCommand(actionNode.Attributes["command"]?.InnerText);
                foreach (Instrument inst in (eg.Parent as DetectionSystem).GetInstruments())
                {
                    foreach (Channel ch in inst.GetChannels())
                    {
                        if (ch.Name == actionNode.Attributes["channel"]?.InnerText)
                        {
                            analysisAction.AddChannel(ch);
                        }
                    }
                }
                analysisAction.SetCompiledFileName(actionNode.Attributes["compiled_file"]?.InnerText);
                analysisAction.GetAnalysis().SetResultsFile(actionNode.Attributes["result_file"]?.InnerText);
                switch (actionNode.Attributes["result_parser"]?.InnerText)
                {
                case "FRAM-Pu":
                    analysisAction.GetAnalysis().SetResultParser(new FRAMPlutoniumResultParser());
                    break;

                case "FRAM-U":
                    analysisAction.GetAnalysis().SetResultParser(new FRAMUraniumResultParser());
                    break;

                default:
                    throw new ApplicationException("Corrupted XML node!");
                }
                foreach (XmlNode dataCompilerNode in actionNode.ChildNodes)
                {
                    if (dataCompilerNode.Name != "DataCompiler")
                    {
                        throw new ApplicationException("Corrupted XML node!");
                    }
                    switch (dataCompilerNode.Attributes["type"]?.InnerText)
                    {
                    case "SpectrumCompiler":
                        SpectrumCompiler spectrumCompiler = new SpectrumCompiler("");
                        switch (dataCompilerNode.Attributes["parser"]?.InnerText)
                        {
                        case "CHN":
                            spectrumCompiler.SetSpectrumParser(new CHNParser());
                            break;

                        default:
                            throw new ApplicationException("Corrupted XML node!");
                        }
                        switch (dataCompilerNode.Attributes["writer"]?.InnerText)
                        {
                        case "CHN":
                            spectrumCompiler.SetSpectrumWriter(new CHNWriter());
                            break;

                        default:
                            throw new ApplicationException("Corrupted XML node!");
                        }
                        analysisAction.GetDataCompilers().Add(spectrumCompiler);
                        break;

                    case "FileListCompiler":
                        analysisAction.GetDataCompilers().Add(new FileListCompiler(""));
                        break;

                    default:
                        throw new ApplicationException("Corrupted XML node!");
                    }
                }
                action = analysisAction;
                break;

            case "Command":
                action = new CommandAction(eg, name, id);
                ((CommandAction)action).SetCommand(actionNode.Attributes["command"]?.InnerText);
                break;

            default:
                throw new ApplicationException("Corrupted XML node!");
            }
            return(action);
        }
Ejemplo n.º 2
0
        private void SaveAction(EventGenerator eg, Action action)
        {
            TreeNode        node         = SitesTreeView.SelectedNode;
            DetectionSystem eventWatcher = (DetectionSystem)node.Parent.Tag;
            DetectionSystem sys          = (DetectionSystem)eventWatcher;

            if (action.Name != ActionsComboBox.Text && siteMan.ContainsName(ActionsComboBox.Text))
            {
                MessageBox.Show("All items in the Site Manager require a unique name!");
                return;
            }
            action.Name = ActionNameTextBox.Text;
            switch (ActionTypeComboBox.Text)
            {
            case "Analysis":
                AnalysisAction analysisAction = (AnalysisAction)action;
                analysisAction.GetChannels().Clear();
                foreach (Instrument inst in sys.GetInstruments())
                {
                    foreach (Channel ch in inst.GetChannels())
                    {
                        if (ch.Name == DataCompilerPanel1.ChannelComboBox.Text)
                        {
                            analysisAction.AddChannel(ch);
                            break;
                        }
                    }
                }
                analysisAction.GetDataCompilers().Clear();
                switch (DataCompilerPanel1.DataCompilersComboBox.Text)
                {
                case "Spectrum Compiler":
                    analysisAction.GetDataCompilers().Add(new SpectrumCompiler("", new CHNParser(), new CHNWriter()));
                    break;

                case "File List":
                    analysisAction.GetDataCompilers().Add(new FileListCompiler(""));
                    break;

                default:
                    MessageBox.Show("Invalid data compiler type!");
                    return;
                }
                analysisAction.GetAnalysis().SetCommand(AnalysisCommandTextBox.Text);
                analysisAction.SetCompiledFileName(DataCompilerPanel1.CompiledFileTextBox.Text);
                switch (ResultParserComboBox.Text)
                {
                case "FRAM-Pu":
                    analysisAction.GetAnalysis().SetResultParser(new FRAMPlutoniumResultParser());
                    break;

                case "FRAM-U":
                    analysisAction.GetAnalysis().SetResultParser(new FRAMUraniumResultParser());
                    break;

                default:
                    MessageBox.Show("Invalid result parser type!");
                    return;
                }
                analysisAction.GetAnalysis().SetResultsFile(ResultFileTextBox.Text);
                break;

            case "Command":
                ((CommandAction)action).SetCommand(ActionCommandTextBox.Text);
                break;

            default:
                MessageBox.Show("Invalid action type!");
                return;
            }
        }