Exemple #1
1
        public static void Run(IEnumerable <Tuple <string, string> > files)
        {
            Shared.OpenErrorLog();

            Simulations simulations = new Simulations(null);

            IAT    iat;
            Folder folder = null;

            foreach (var file in files)
            {
                // Cancel the conversion
                if (Shared.Worker.CancellationPending)
                {
                    Shared.CloseErrorLog();
                    return;
                }

                // Read in the IAT
                try
                {
                    iat = new IAT(file.Item1);
                }
                catch (ConversionException)
                {
                    Shared.WriteError(new ErrorData()
                    {
                        FileName = Path.GetFileName(file.Item1),
                        FileType = "IAT",
                        Message  = "The file could not be read",
                        Sheet    = "-",
                        Table    = "-",
                        Severity = "High"
                    });
                    continue;
                }

                if (GroupSims && GroupSheets)
                {
                    folder = new Folder(simulations)
                    {
                        Name = iat.Name
                    }
                }
                ;

                if (file.Item2 != "All")
                {
                    iat.SetSheet(file.Item2);
                    AttachParameterSheet(simulations, iat);

                    // Update the Progress bar
                    Shared.Worker?.ReportProgress(0);
                }
                else
                {
                    // Find all the parameter sheets in the IAT
                    foreach (Sheet sheet in iat.Book.Workbook.Sheets)
                    {
                        // Cancel the conversion
                        if (Shared.Worker.CancellationPending)
                        {
                            Shared.CloseErrorLog();
                            return;
                        }

                        // Ensure a parameter sheet is selected
                        string name = sheet.Name.ToString();
                        if (!name.ToLower().Contains("param"))
                        {
                            continue;
                        }

                        iat.SetSheet(name);

                        if (GroupSims && GroupSheets)
                        {
                            AttachParameterSheet(folder, iat);
                        }
                        else
                        {
                            AttachParameterSheet(simulations, iat);
                        }

                        iat.ClearTables();

                        // Update the Progress bar
                        Shared.Worker?.ReportProgress(0);
                    }
                }

                if (!GroupSims)
                {
                    Shared.WriteApsimX(simulations, iat.Name);
                    simulations = new Simulations(null);
                }
                else if (GroupSheets)
                {
                    simulations.Add(folder);
                }

                iat.Dispose();

                GC.WaitForPendingFinalizers();
            }


            if (GroupSims)
            {
                Shared.WriteApsimX(simulations, "Simulations");
            }
            Shared.CloseErrorLog();
        }
Exemple #2
0
        public static void Run(IEnumerable <string> files)
        {
            Shared.OpenErrorLog();

            Simulations simulations = new Simulations(null);

            foreach (string file in files)
            {
                // Read in the IAT
                IAT    iat    = new IAT(file);
                Folder folder = new Folder(simulations)
                {
                    Name = iat.Name
                };

                // Find all the parameter sheets in the IAT
                List <string> sheets = new List <string>();
                foreach (Sheet sheet in iat.Book.Workbook.Sheets)
                {
                    // Ensure a parameter sheet is selected
                    string name = sheet.Name.ToString();
                    if (!name.ToLower().Contains("param"))
                    {
                        continue;
                    }
                    iat.SetSheet(name);
                }

                // Files will already be written if groupSims is false
                if (!GroupSims)
                {
                    continue;
                }

                // Collect all the IAT files in the same .apsimx file
                if (GroupSheets)
                {
                    simulations.Children.Add(folder);
                }
                // Only gather parameter sets into the same .apsimx file
                else
                {
                    Shared.WriteApsimX(simulations, iat.Name);
                    simulations = new Simulations(null);
                }
            }
            if (GroupSheets)
            {
                Shared.WriteApsimX(simulations, "Simulations");
            }

            Shared.CloseErrorLog();
        }