Пример #1
0
        public static ISimulationProducerContract Get(string name)
        {
            using (TurbineModelContainer container = new TurbineModelContainer())
            {
                Simulation obj = container.Simulations
                                 .OrderByDescending(q => q.Create).First(s => s.Name == name);
            }
            ProducerSimulationContract sc = new ProducerSimulationContract();

            sc.name = name;
            return(sc);
        }
Пример #2
0
        public static ISimulationProducerContract Create(string simulationName, string applicationName)
        {
            string owner = Container.GetAppContext().UserName;

            using (TurbineModelContainer container = new TurbineModelContainer())
            {
                User       user = container.Users.Single <User>(s => s.Name == owner);
                Simulation obj  = container.Simulations.OrderByDescending(q => q.Create)
                                  .FirstOrDefault(s => s.Name == simulationName);
                if (obj != null)
                {
                    throw new InvalidStateChangeException(String.Format(
                                                              "Simulation with Name '{0}' already exists", simulationName));
                }

                Application app = container.Applications.SingleOrDefault <Application>(s => s.Name == applicationName);
                if (app == null)
                {
                    throw new ArgumentException(String.Format(
                                                    "Application '{0}' does not exist", applicationName));
                }

                var sim = new Simulation()
                {
                    Name        = simulationName,
                    Id          = Guid.NewGuid(),
                    User        = user,
                    Application = app,
                    Create      = DateTime.UtcNow,
                    Update      = DateTime.UtcNow
                };

                foreach (var input in app.InputFileTypes)
                {
                    if ("any".Equals(input.Name))
                    {
                        continue;
                    }
                    sim.SimulationStagedInputs.Add(new SimulationStagedInput()
                    {
                        Id = Guid.NewGuid(), Name = input.Name, InputFileType = input, Hash = null, Simulation = sim
                    });
                }
                container.Simulations.AddObject(sim);
                container.SaveChanges();
            }
            ProducerSimulationContract sc = new ProducerSimulationContract();

            sc.name = simulationName;
            return(sc);
        }