Ejemplo n.º 1
0
        public static void Run(IEnumerable <string> files)
        {
            Shared.OpenErrorLog();

            foreach (string file in files)
            {
                NABSA nabsa = new NABSA(file);

                Simulations simulations = new Simulations(null)
                {
                    Source = nabsa
                };
                simulations.Add(new Simulation(simulations)
                {
                    Name = nabsa.Name
                });

                Shared.WriteApsimX(simulations, Path.GetFileNameWithoutExtension(file));

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

            Shared.CloseErrorLog();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        public void ReadXml(XmlReader reader)
        {
            XDocument doc = XDocument.Load(reader);

            //Get the list of models
            XElement projectElement = doc.Element("Project");

            //Set the project properties
            CreatedBy = XMLUtilities.readXMLAttribute(projectElement.Attribute("CreatedBy"));
            DateTime?createdDate = DateUtilities.TryParseDate(XMLUtilities.readXMLAttribute(projectElement.Attribute("CreationDate")).Split(new char[] { ' ' })[0], "dd/MM/yyyy");

            CreatedDate    = createdDate == null ? new DateTime(1, 1, 1) : createdDate.Value;
            ContactDetails = XMLUtilities.readXMLAttribute(projectElement.Attribute("ContactDetails"));
            ModifiedBy     = XMLUtilities.readXMLAttribute(projectElement.Attribute("ModifiedBy"));

            Name = projectElement.Element("Name").Value.ToString();

            //Read all of the climate data models
            List <XElement> ClimateDatalements = new List <XElement>(projectElement.Elements("ClimateData").Elements("DataFile"));

            //Read all of the models
            List <XElement> TemplateElements = new List <XElement>(projectElement.Elements().Where(x => x.Name.ToString().Contains("Templates")));
            List <XElement> TypeElements     = new List <XElement>();

            foreach (XElement te in TemplateElements)
            {
                foreach (XElement xe in te.Elements())
                {
                    TypeElements.Add(xe);
                }
            }
            //Read all of the simualtions
            SimulationElements = new List <XElement>();

            foreach (XElement simChild in projectElement.Elements("Simulations").Elements())
            {
                if (simChild.Name.ToString() == "SimulationObject")
                {
                    SimulationElements.Add(simChild);
                }
                else if (simChild.Name.ToString() == "Folder")
                {
                    SimulationElements.AddRange(simChild.Elements("SimulationObject"));
                }
            }

            InputDataModels = new List <InputModel>();

            //Create input models from the xml elements
            foreach (XElement xe in TypeElements)
            {
                InputDataModels.Add(RawInputModelFactory.GenerateRawInputModel(xe));
            }

            //Create the Climate models - these aren't deserialised so don't come out of the factory
            foreach (XElement xe in ClimateDatalements)
            {
                ClimateInputModel cim = new ClimateInputModel();
                cim.FileName = xe.Attribute("href").Value.ToString();
                InputDataModels.Add(cim);
            }

            //Initialise the models
            foreach (InputModel im in InputDataModels)
            {
                im.Init();
            }

            //Create the simualtions
            foreach (XElement xe in SimulationElements)
            {
                Simulations.Add(SimulationFactory.GenerateSimulationXML(this, xe, InputDataModels));
            }

            //Just one for testing
            //Simulations = new List<Simulation>();
            //Simulations.Add(SimulationFactory.GenerateSimulationXML(SimulationElements[0], InputDataModels));

            OutputDataElements = OutputModelController.GetProjectOutputs(this);
        }
Ejemplo n.º 3
0
 public ILifeSimulation AddSimulation(ILifeSimulation simulation)
 {
     Simulations.Add(simulation);
     return(simulation);
 }
Ejemplo n.º 4
0
        internal static Simulations GetSimulations(bool allSimulations)
        {
            var simList = new Simulations();

            Debug.WriteLine("Simulation", "DataMarshall.GetSimulations");
            using (var db = new ProducerContext())
            {
                Debug.WriteLine("Simulation ProducerContext", "TurbineLite");

                if (allSimulations == true)
                {
                    var query = db.Simulations.OrderByDescending(c => c.Create);

                    var provider = System.Security.Cryptography.MD5CryptoServiceProvider.Create();

                    /*byte[] hash = provider.ComputeHash(data);
                     * var comparer = StringComparer.OrdinalIgnoreCase;
                     * var sb = new StringBuilder();
                     * foreach (byte b in hash)
                     *  sb.Append(b.ToString("X2"));
                     * string hval = sb.ToString();*/

                    foreach (var entity in query)
                    {
                        Debug.WriteLine(String.Format("ENTITY {0}: {1}", entity.Name, entity.Id));

                        var stagedInputList = new SimpleStagedInputFiles();

                        foreach (var input in entity.SimulationStagedInputs)
                        {
                            stagedInputList.Add(new SimpleStagedInputFile
                            {
                                Name   = input.Name,
                                Id     = input.Id,
                                MD5Sum = input.Hash
                            });
                        }

                        simList.Add(new Simulation
                        {
                            Id          = entity.Id,
                            Name        = entity.Name,
                            Application = entity.ApplicationName,
                            //StagedInputs = (from i in entity.SimulationStagedInputs select i.Name).ToArray<string>()
                            StagedInputs = stagedInputList
                        });
                    }
                }
                else
                {
                    var query = from c in db.Simulations
                                group c by c.Name into uniqueIds
                                select uniqueIds.OrderByDescending(c => c.Count).FirstOrDefault();


                    foreach (var entity in query)
                    {
                        Debug.WriteLine(String.Format("ENTITY {0}: {1} {2}", entity.Name, entity.Id, entity.Create.ToString()));

                        var stagedInputList = new SimpleStagedInputFiles();

                        foreach (var input in entity.SimulationStagedInputs)
                        {
                            stagedInputList.Add(new SimpleStagedInputFile
                            {
                                Name   = input.Name,
                                Id     = input.Id,
                                MD5Sum = input.Hash
                            });
                        }

                        simList.Add(new Simulation
                        {
                            Id          = entity.Id,
                            Name        = entity.Name,
                            Application = entity.ApplicationName,
                            //StagedInputs = (from i in entity.SimulationStagedInputs select i.Name).ToArray<string>()
                            StagedInputs = stagedInputList
                        });
                    }
                }
            }
            return(simList);
        }
Ejemplo n.º 5
0
        public MainViewModel(IMainModel mainModel, IDataModel dataModel, INavigationService navigationService, IMessageBoxService messageBoxService)
        {
            _mainModel         = mainModel;
            _dataModel         = dataModel;
            _navigationService = navigationService;
            _messageBoxService = messageBoxService;

            Simulations = _mainModel.Simulations
                          .Select(x => new SimulationViewModel(_dataModel, x))
                          .ToObservableCollection();

            ShowSimulationCommand = new RelayCommand <SimulationViewModel>(simulation =>
            {
                _mainModel.SelectedSimulation = simulation.Model;

                _navigationService.NavigateTo("/View/ResultsPage.xaml");
            });

            EditSimulationCommand = new RelayCommand <SimulationViewModel>(simulation =>
            {
                _mainModel.SelectedSimulation = simulation.Model;

                _navigationService.NavigateTo("/View/EditPage.xaml");
            });

            NewSimulationCommand = new RelayCommand(() =>
            {
                _mainModel.SelectedSimulation = null;

                _navigationService.NavigateTo("/View/EditPage.xaml");
            });

            EnableSelectionCommand = new RelayCommand(() =>
            {
                IsSelectionEnabled = true;
            }, () => !IsSimulationsListEmpty);

            DeleteSimulationCommand = new RelayCommand <IList>(items =>
            {
                if (items == null || items.Count == 0)
                {
                    return;
                }

                _messageBoxService.Show("Está prestes a apagar as simulações seleccionadas", "Tem a certeza?", new[] { "eliminar", "cancelar" }, button =>
                {
                    if (button != 0)
                    {
                        return;
                    }

                    var itemsToRemove = items
                                        .Cast <SimulationViewModel>()
                                        .ToArray();

                    foreach (var item in itemsToRemove)
                    {
                        _mainModel.Simulations.Remove(item.Model);

                        Simulations.Remove(item);
                    }

                    _mainModel.Save();

                    IsSimulationsListEmpty = (Simulations.Count == 0);
                });
            });

            ShowAboutCommand = new RelayCommand(() =>
            {
                _navigationService.NavigateTo(new Uri("/View/AboutPage.xaml", UriKind.Relative));
            });

            BackKeyPressCommand = new RelayCommand <CancelEventArgs>(e =>
            {
                if (IsSelectionEnabled)
                {
                    IsSelectionEnabled = false;

                    e.Cancel = true;
                }
            });

            MessengerInstance.Register <SimulationChangedMessage>(this, message =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    var oldSimulation = message.OldSimulation;
                    var newSimulation = message.NewSimulation;

                    if (oldSimulation != null)
                    {
                        var index = _mainModel.Simulations.IndexOf(oldSimulation);

                        _mainModel.Simulations[index] = newSimulation;

                        var simulationViewModel = Simulations.First(x => x.Model == oldSimulation);

                        simulationViewModel.Model = newSimulation;
                    }
                    else
                    {
                        _mainModel.Simulations.Add(newSimulation);

                        Simulations.Add(new SimulationViewModel(_dataModel, newSimulation));
                    }

                    IsSimulationsListEmpty = false;

                    _mainModel.Save();
                });
            });

            IsSimulationsListEmpty = (Simulations.Count == 0);
        }
Ejemplo n.º 6
0
 public void Add(Simulation simulation)
 {
     Simulations.Add(simulation);
     simulation.OnCollision += simulation_OnCollision;
     simulation.OnCompleted += simulation_OnCompleted;
 }