示例#1
0
        internal static Simulation GetSimulation(string nameOrID, bool isGuid)
        {
            Simulation sim             = null;
            var        stagedInputList = new SimpleStagedInputFiles();

            using (var db = new ProducerContext())
            {
                Turbine.Data.Entities.Simulation entity = null;

                if (isGuid == true)
                {
                    Guid simulationid = new Guid(nameOrID);
                    entity = db.Simulations.OrderByDescending(q => q.Count).Single(a => a.Id == simulationid);
                }
                else
                {
                    entity = db.Simulations.OrderByDescending(q => q.Count).First(a => a.Name == nameOrID);
                }

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

                    sim = new Simulation
                    {
                        Id          = entity.Id,
                        Name        = entity.Name,
                        Application = entity.ApplicationName,
                    };

                    //sim.StagedInputs = stagedInputList.ToArray<String>();
                    sim.StagedInputs = stagedInputList;
                }
            }
            return(sim);
        }
示例#2
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);
        }