Пример #1
0
        /// <summary>
        /// Reads in all initialisation files and copies them to the output directory for future reference
        /// </summary>
        /// <param name="initialisationFile">The name of the initialization file with information on the simulations to be run</param>
        /// <param name="outputPath">The path to folder in which outputs will be stored</param>
        /// <todo>Need to adjust this file to deal with incorrect inputs, extra columns etc by throwing an error</todo>
        /// <todo>Also need to strip leading spaces</todo>
        public void ReadAndCopyInitialisationFiles(string simulationInitialisationFilename, string definitionsFilename, string outputsFilename, string outputPath)
        {
            // Construct file names
            string SimulationFileString  = "msds:csv?file=input/Model setup/" + simulationInitialisationFilename + "&openMode=readOnly";
            string DefinitionsFileString = "msds:csv?file=input/Model setup/" + definitionsFilename + "&openMode=readOnly";
            string OutputsFileString     = "msds:csv?file=input/Model setup/" + outputsFilename + "&openMode=readOnly";

            // Copy the initialisation files to the output directory
            System.IO.File.Copy("input/Model setup/" + simulationInitialisationFilename, outputPath + simulationInitialisationFilename, true);
            System.IO.File.Copy("input/Model setup/" + definitionsFilename, outputPath + definitionsFilename, true);
            System.IO.File.Copy("input/Model setup/" + outputsFilename, outputPath + outputsFilename, true);

            // Read in the definitions data
            InternalData = DataSet.Open(DefinitionsFileString);

            // Get the names of parameters in the initialization file
            VarParameters = InternalData.Variables[1].GetData();

            // Get the values for the parameters
            VarValues = InternalData.Variables[0].GetData();
#endif

            // Loop over the parameters
            for (int row = 0; row < VarParameters.Length; row++)
            {
                // Switch based on the name of the parameter, and write the value to the appropriate field
                switch (VarParameters.GetValue(row).ToString().ToLower())
                {
                case "mass bin filename":
                    // Set up the mass bins as specified in the initialization file
#if true
                    _ModelMassBins.SetUpMassBins(VarValues.GetValue(row).ToString(), outputPath, inputPath);
#else
                    _ModelMassBins.SetUpMassBins(VarValues.GetValue(row).ToString(), outputPath);
#endif
                    break;
                }
            }

            InternalData.Dispose();

            // Read in the outputs data
            InternalData = DataSet.Open(OutputsFileString);

            // Get the names of parameters in the initialization file
            VarParameters = InternalData.Variables[1].GetData();

            // Get the values for the parameters
            VarValues = InternalData.Variables[0].GetData();

            // Loop over the parameters
            for (int row = 0; row < VarParameters.Length; row++)
            {
                // Switch based on the name of the parameter, and write the value to the appropriate field
                switch (VarParameters.GetValue(row).ToString().ToLower())
                {
                case "track processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackProcesses = true;
                        break;

                    case "no":
                        _TrackProcesses = false;
                        break;
                    }
                    break;

                case "track cross cell processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackCrossCellProcesses = true;
                        break;

                    case "no":
                        _TrackCrossCellProcesses = false;
                        break;
                    }
                    break;

                case "track global processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackGlobalProcesses = true;
                        break;

                    case "no":
                        _TrackGlobalProcesses = false;
                        break;
                    }
                    break;

                case "new cohorts filename":
                    _ProcessTrackingOutputs.Add("NewCohortsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "maturity filename":
                    _ProcessTrackingOutputs.Add("MaturityOutput", VarValues.GetValue(row).ToString());
                    break;

                case "biomasses eaten filename":
                    _ProcessTrackingOutputs.Add("BiomassesEatenOutput", VarValues.GetValue(row).ToString());
                    break;

                case "trophic flows filename":
                    _ProcessTrackingOutputs.Add("TrophicFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "growth filename":
                    _ProcessTrackingOutputs.Add("GrowthOutput", VarValues.GetValue(row).ToString());
                    break;

                case "metabolism filename":
                    _ProcessTrackingOutputs.Add("MetabolismOutput", VarValues.GetValue(row).ToString());
                    break;

                case "npp output filename":
                    _ProcessTrackingOutputs.Add("NPPOutput", VarValues.GetValue(row).ToString());
                    break;

                case "predation flows filename":
                    _ProcessTrackingOutputs.Add("PredationFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "herbivory flows filename":
                    _ProcessTrackingOutputs.Add("HerbivoryFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "mortality filename":
                    _ProcessTrackingOutputs.Add("MortalityOutput", VarValues.GetValue(row).ToString());
                    break;

                case "extinction filename":
                    _ProcessTrackingOutputs.Add("ExtinctionOutput", VarValues.GetValue(row).ToString());
                    break;

                case "output detail":
                    _InitialisationFileStrings.Add("OutputDetail", VarValues.GetValue(row).ToString());
                    break;

                case "live outputs":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _LiveOutputs = true;
                    }
                    else
                    {
                        _LiveOutputs = false;
                    }
                    break;

                case "track marine specifics":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _TrackMarineSpecifics = true;
                    }
                    else
                    {
                        _TrackMarineSpecifics = false;
                    }
                    break;

                case "output metrics":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _OutputMetrics = true;
                    }
                    else
                    {
                        _OutputMetrics = false;
                    }
                    break;

                case "output model state timesteps":

                    if (VarValues.GetValue(row).ToString() != "no")
                    {
                        string[] OutputStateTimesSteps = VarValues.GetValue(row).ToString().Split(new char[] { ';' });
                        foreach (string t in OutputStateTimesSteps)
                        {
                            if (t.Split(new char[] { '-' }).Length > 1)
                            {
                                string[] range = t.Split(new char[] { '-' });
                                for (uint i = Convert.ToUInt32(range[0]); i <= Convert.ToUInt32(range[1]); i++)
                                {
                                    _OutputStateTimestep.Add(i);
                                }
                            }
                            else
                            {
                                _OutputStateTimestep.Add(Convert.ToUInt32(Convert.ToInt32(t)));
                            }
                        }
                    }

                    break;
                }
            }

            InternalData.Dispose();
        }
        void SetVariableValuesFromIDEState(IVariableValueSetter var_value_setter, VSMultiInstanceInfo multi_instance_info)
        {
            VarValues var_values = new VarValues();
            try
            {
                GetVariableValues(var_values);
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            if (var_values.exceptions.Count > 0 && m_Package.IsDebugEnabled())
            {
                DebugOutput.WriteLine("----- Exceptions: GetVariableValues:");
                foreach (Exception ex in var_values.exceptions)
                    DebugOutput.WriteLine("EX: " + ex.ToString());
            }

            AddFilePathVars(var_value_setter, ref var_values.sln_path, SlashPathSeparator, "sln_");
            var_value_setter.SetVariable("sln_open", var_values.sln_path.Length > 0);
            var_value_setter.SetVariable("sln_dirty", var_values.sln_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.doc_path, SlashPathSeparator, "doc_");
            var_value_setter.SetVariable("doc_open", var_values.doc_path.Length > 0);
            var_value_setter.SetVariable("doc_dirty", var_values.doc_dirty ? "*" : "");
            var_value_setter.SetVariable("any_doc_dirty", var_values.any_doc_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.startup_proj_path, SlashPathSeparator, "startup_proj_");
            var_value_setter.SetVariable("startup_proj", var_values.startup_proj);
            var_value_setter.SetVariable("startup_proj_dirty", var_values.startup_proj_dirty ? "*" : "");

            var_value_setter.SetVariable("any_proj_dirty", var_values.any_proj_dirty ? "*" : "");
            var_value_setter.SetVariable("anything_dirty", (var_values.sln_dirty || var_values.any_proj_dirty || var_values.any_doc_dirty) ? "*" : "");

            var_value_setter.SetVariable("wnd_minimized", var_values.wnd_minimized);
            var_value_setter.SetVariable("wnd_foreground", var_values.wnd_foreground);
            var_value_setter.SetVariable("app_active", var_values.app_active);

            bool debugging = false;
            string debug_mode = "";
            switch (var_values.dbgmode)
            {
                case DBGMODE.DBGMODE_Run:
                    debugging = true;
                    debug_mode = "running";
                    break;
                case DBGMODE.DBGMODE_Break:
                    debugging = true;
                    debug_mode = "debugging";
                    break;
            }

            var_value_setter.SetVariable("debugging", debugging);
            var_value_setter.SetVariable("debug_mode", debug_mode);

            var_value_setter.SetVariable("configuration", var_values.configuration);
            var_value_setter.SetVariable("platform", var_values.platform);

            var_value_setter.SetVariable("orig_title", var_values.orig_title);

            var_value_setter.SetVariable("multi_instances", multi_instance_info.multiple_instances);
            var_value_setter.SetVariable("multi_instances_same_ver", multi_instance_info.multiple_instances_same_version);

            var_value_setter.SetVariable("active_wnd_title", var_values.active_wnd_title);
            var_value_setter.SetVariable("active_wnd_class", var_values.active_wnd_class);

            var_value_setter.SetVariable("cmdline", var_values.cmdline);
        }
        void SetVariableValuesFromIDEState(IVariableValueSetter var_value_setter, VSMultiInstanceInfo multi_instance_info)
        {
            VarValues var_values = new VarValues();

            try
            {
                GetVariableValues(var_values);
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            if (var_values.exceptions.Count > 0 && m_Package.IsDebugEnabled())
            {
                DebugOutput.WriteLine("----- Exceptions: GetVariableValues:");
                foreach (Exception ex in var_values.exceptions)
                {
                    DebugOutput.WriteLine("EX: " + ex.ToString());
                }
            }

            AddFilePathVars(var_value_setter, ref var_values.sln_path, SlashPathSeparator, "sln_");
            var_value_setter.SetVariable("sln_open", var_values.sln_path.Length > 0);
            var_value_setter.SetVariable("sln_dirty", var_values.sln_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.doc_path, SlashPathSeparator, "doc_");
            var_value_setter.SetVariable("doc_open", var_values.doc_path.Length > 0);
            var_value_setter.SetVariable("doc_dirty", var_values.doc_dirty ? "*" : "");
            var_value_setter.SetVariable("any_doc_dirty", var_values.any_doc_dirty ? "*" : "");

            AddFilePathVars(var_value_setter, ref var_values.startup_proj_path, SlashPathSeparator, "startup_proj_");
            var_value_setter.SetVariable("startup_proj", var_values.startup_proj);
            var_value_setter.SetVariable("startup_proj_dirty", var_values.startup_proj_dirty ? "*" : "");

            var_value_setter.SetVariable("any_proj_dirty", var_values.any_proj_dirty ? "*" : "");
            var_value_setter.SetVariable("anything_dirty", (var_values.sln_dirty || var_values.any_proj_dirty || var_values.any_doc_dirty) ? "*" : "");

            var_value_setter.SetVariable("wnd_minimized", var_values.wnd_minimized);
            var_value_setter.SetVariable("wnd_foreground", var_values.wnd_foreground);
            var_value_setter.SetVariable("app_active", var_values.app_active);

            bool   debugging  = false;
            string debug_mode = "";

            switch (var_values.dbgmode)
            {
            case DBGMODE.DBGMODE_Run:
                debugging  = true;
                debug_mode = "running";
                break;

            case DBGMODE.DBGMODE_Break:
                debugging  = true;
                debug_mode = "debugging";
                break;
            }

            var_value_setter.SetVariable("debugging", debugging);
            var_value_setter.SetVariable("debug_mode", debug_mode);

            var_value_setter.SetVariable("configuration", var_values.configuration);
            var_value_setter.SetVariable("platform", var_values.platform);

            var_value_setter.SetVariable("orig_title", var_values.orig_title);

            var_value_setter.SetVariable("multi_instances", multi_instance_info.multiple_instances);
            var_value_setter.SetVariable("multi_instances_same_ver", multi_instance_info.multiple_instances_same_version);

            var_value_setter.SetVariable("active_wnd_title", var_values.active_wnd_title);
            var_value_setter.SetVariable("active_wnd_class", var_values.active_wnd_class);

            var_value_setter.SetVariable("cmdline", var_values.cmdline);
        }
        void GetVariableValues(VarValues var_values)
        {
            DTE2 dte = (DTE2)m_Package.GetInterface(typeof(DTE));
            IVsSolution vs_solution = (IVsSolution)m_Package.GetInterface(typeof(IVsSolution));
            string temp_solution_dir, temp_solution_options;
            if (VSConstants.S_OK != vs_solution.GetSolutionInfo(out temp_solution_dir, out var_values.sln_path, out temp_solution_options) || var_values.sln_path == null)
                var_values.sln_path = "";

            IVsDebugger debugger = (IVsDebugger)m_Package.GetInterface(typeof(IVsDebugger));
            DBGMODE[] adbgmode = new DBGMODE[] { DBGMODE.DBGMODE_Design };
            if (VSConstants.S_OK != debugger.GetMode(adbgmode))
                adbgmode[0] = DBGMODE.DBGMODE_Design;
            var_values.dbgmode = adbgmode[0] & ~DBGMODE.DBGMODE_EncMask;

            var_values.sln_dirty = !dte.Solution.Saved;

            try
            {
                SolutionConfiguration2 active_cfg = (SolutionConfiguration2)dte.Solution.SolutionBuild.ActiveConfiguration;
                if (active_cfg != null)
                {
                    var_values.configuration = active_cfg.Name == null ? "" : active_cfg.Name; ;
                    var_values.platform = active_cfg.PlatformName == null ? "" : active_cfg.PlatformName;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Project startup_project = GetStartupProject(dte.Solution);
                if (startup_project != null)
                {
                    var_values.startup_proj = startup_project.Name;
                    var_values.startup_proj_path = startup_project.FullName;
                    var_values.startup_proj_dirty = !startup_project.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Document active_document = dte.ActiveDocument;
                if (active_document != null)
                {
                    var_values.doc_path = active_document.FullName;
                    var_values.doc_dirty = !active_document.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Document doc in dte.Documents)
                {
                    if (!doc.Saved)
                    {
                        var_values.any_doc_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Project proj in dte.Solution.Projects)
                {
                    if (!proj.Saved)
                    {
                        var_values.any_proj_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                var_values.wnd_minimized = m_Package.VSMainWindow.Minimized;
                var_values.wnd_foreground = m_Package.VSMainWindow.IsForegroundWindow();
                var_values.app_active = m_Package.VSMainWindow.IsAppActive;
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            IntPtr active_wnd = GetActiveWindow();
            if (active_wnd != IntPtr.Zero)
            {
                var_values.active_wnd_title = GetWindowText(active_wnd);
                var_values.active_wnd_class = GetWindowClassName(active_wnd);
            }

            var_values.orig_title = m_Package.VSMainWindow.OriginalTitle;

            try
            {
                var_values.cmdline = Marshal.PtrToStringAuto(GetCommandLine());
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }
        }
        void GetVariableValues(VarValues var_values)
        {
            DTE2        dte = (DTE2)m_Package.GetInterface(typeof(DTE));
            IVsSolution vs_solution = (IVsSolution)m_Package.GetInterface(typeof(IVsSolution));
            string      temp_solution_dir, temp_solution_options;

            if (VSConstants.S_OK != vs_solution.GetSolutionInfo(out temp_solution_dir, out var_values.sln_path, out temp_solution_options) || var_values.sln_path == null)
            {
                var_values.sln_path = "";
            }

            IVsDebugger debugger = (IVsDebugger)m_Package.GetInterface(typeof(IVsDebugger));

            DBGMODE[] adbgmode = new DBGMODE[] { DBGMODE.DBGMODE_Design };
            if (VSConstants.S_OK != debugger.GetMode(adbgmode))
            {
                adbgmode[0] = DBGMODE.DBGMODE_Design;
            }
            var_values.dbgmode = adbgmode[0] & ~DBGMODE.DBGMODE_EncMask;

            var_values.sln_dirty = !dte.Solution.Saved;

            try
            {
                SolutionConfiguration2 active_cfg = (SolutionConfiguration2)dte.Solution.SolutionBuild.ActiveConfiguration;
                if (active_cfg != null)
                {
                    var_values.configuration = active_cfg.Name == null ? "" : active_cfg.Name;;
                    var_values.platform      = active_cfg.PlatformName == null ? "" : active_cfg.PlatformName;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Project startup_project = GetStartupProject(dte.Solution);
                if (startup_project != null)
                {
                    var_values.startup_proj       = startup_project.Name;
                    var_values.startup_proj_path  = startup_project.FullName;
                    var_values.startup_proj_dirty = !startup_project.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Document active_document = dte.ActiveDocument;
                if (active_document != null)
                {
                    var_values.doc_path  = active_document.FullName;
                    var_values.doc_dirty = !active_document.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Document doc in dte.Documents)
                {
                    if (!doc.Saved)
                    {
                        var_values.any_doc_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Project proj in dte.Solution.Projects)
                {
                    if (!proj.Saved)
                    {
                        var_values.any_proj_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                var_values.wnd_minimized  = m_Package.VSMainWindow.Minimized;
                var_values.wnd_foreground = m_Package.VSMainWindow.IsForegroundWindow();
                var_values.app_active     = m_Package.VSMainWindow.IsAppActive;
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            IntPtr active_wnd = GetActiveWindow();

            if (active_wnd != IntPtr.Zero)
            {
                var_values.active_wnd_title = GetWindowText(active_wnd);
                var_values.active_wnd_class = GetWindowClassName(active_wnd);
            }

            var_values.orig_title = m_Package.VSMainWindow.OriginalTitle;

            try
            {
                var_values.cmdline = Marshal.PtrToStringAuto(GetCommandLine());
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }
        }