Ejemplo n.º 1
0
        public void GetSimulationListTest()
        {
            var userName = "******";

            using (var db = new Turbine.DataEF6.ProducerContext())
            {
                var app  = db.Applications.Single(s => s.Name == "ACM");
                var user = db.Users.Single(u => u.Name == userName);
                var sim  = new Turbine.Data.Entities.Simulation
                {
                    Id          = Guid.NewGuid(),
                    Application = app,
                    Create      = DateTime.UtcNow,
                    Name        = "Dummy",
                    Update      = DateTime.UtcNow,
                    User        = user
                };
                db.Simulations.Add(sim);
                db.SaveChanges();
            }

            using (WebClient wc = new WebClient())
            {
                var json = wc.DownloadString("http://localhost:8000/TurbineLite/simulation");
                Console.WriteLine("RESPONSE: {0}", json);
                var simList = JsonConvert.DeserializeObject <SimulationList>(json);
                Assert.IsTrue(simList.Count >= 1);
                var sim = simList.Single(e => e.Name == "Dummy");
                Assert.AreEqual(sim.Name, "Dummy");

                json = wc.DownloadString("http://localhost:8000/TurbineLite/simulation/dummy");
                sim  = JsonConvert.DeserializeObject <Simulation>(json);
                Assert.AreEqual <string>(sim.Name, "Dummy");
                Assert.AreEqual <string>(sim.Application, "ACM");
            }
        }
Ejemplo n.º 2
0
        protected override void OnStart(string[] args)
        {
            Debug.WriteLine("OnStart handler called", "SelfManagedWebApplicationWindowsService");
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "SelfManagedWebApplicationWindowsService");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "ACM"
                    });
                    db.SaveChanges();
                }
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "ACM");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "aspenfile", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application ACM input entries already made", "SelfManagedWebApplicationWindowsService");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "SelfManagedWebApplicationWindowsService");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "AspenPlus"
                    });
                    db.SaveChanges();
                }
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "AspenPlus");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "aspenfile", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application AspenPlus input entries already made", "SelfManagedWebApplicationWindowsService");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "SelfManagedWebApplicationWindowsService");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "GProms"
                    });
                    db.SaveChanges();
                }
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "GProms");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "model", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application GProms input entries already made", "SelfManagedWebApplicationWindowsService");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "SelfManagedWebApplicationWindowsService");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "Excel"
                    });
                    db.SaveChanges();
                }
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "Excel");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "spreadsheet", Id = Guid.NewGuid(), Type = "application/vnd.ms-excel"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application Excel input entries already made", "SelfManagedWebApplicationWindowsService");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }
            try
            {
                string owner = Turbine.Producer.Container.GetAppContext().UserName;
                Debug.WriteLine("OWNER " + owner, "SelfManagedWebApplicationWindowsService");
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "SelfManagedWebApplicationWindowsService");
                    db.Users.Add(new Turbine.Data.Entities.User {
                        Name = owner
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore User entries already made", "SelfManagedWebApplicationWindowsService");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }
            var hosts = new List <ServiceHost>();

            try
            {
                hosts.Add(new WebServiceHost(
                              typeof(Turbine.Lite.Web.Resources.ApplicationResource),
                              new Uri(String.Format("http://{0}/{1}/application", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.SimulationResource),
                        new Uri(String.Format("http://{0}/{1}/simulation", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.SessionResource),
                        new Uri(String.Format("http://{0}/{1}/session", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.JobResource),
                        new Uri(String.Format("http://{0}/{1}/job", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.ConsumerResource),
                        new Uri(String.Format("http://{0}/{1}/consumer", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));

                foreach (var host in hosts)
                {
                    host.Open();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Exception {0}", ex), "SelfManagedWebApplicationWindowsService");
                throw;
            }

            Debug.WriteLine("Service is ready", "SelfManagedWebApplicationWindowsService");
        }
Ejemplo n.º 3
0
        public static void AssemblyInit(TestContext context)
        {
            Console.WriteLine("assembly init");
            CleanUpDatabase();

            // DIJ
            TestProducerContext.name = "Administrator";
            using (var db = new Turbine.DataEF6.ProducerContext())
            {
                db.Users.Add(new Turbine.Data.Entities.User {
                    Name = TestProducerContext.name
                });
                db.SaveChanges();
            }
            // Create the ServiceHost.
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "TurbineLite");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "ACM", Version = "7.3"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "AspenPlus"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "Excel"
                    });
                    db.SaveChanges();
                }

                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var item = db.Applications.Single(s => s.Name == "ACM");
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "configuration",
                        Required = true,
                        Type     = "plain/text"
                    });
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "aspenfile",
                        Required = true,
                        Type     = "application/octet-stream"
                    });
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "any",
                        Required = false,
                        Type     = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application entries already made");
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var item = db.Applications.Single(s => s.Name == "AspenPlus");
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "configuration",
                        Required = true,
                        Type     = "plain/text"
                    });
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "aspenfile",
                        Required = true,
                        Type     = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application entries already made");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Web Application that runs in Console program.
        /// Configuration:
        ///     Need to add URL ACL for URL registration:
        ///     runas /user:Administrator "netsh http add urlacl url=http://localhost:8000/TurbineLite user=lbl\boverhof"
        /// </summary>
        /// <param name="args"></param>
        ///
        static void Main(string[] args)
        {
            // Create the ServiceHost.
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "TurbineLite");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "ACM"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "AspenPlus"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "GProms"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "Excel"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application entries already made");
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "ACM");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "aspenfile", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application ACM input entries already made");
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "AspenPlus");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "aspenfile", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application AspenPlus input entries already made");
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "GProms");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "model", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "any", Id = Guid.NewGuid(), Type = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application GProms input entries already made");
            }
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var app = db.Applications.Single(s => s.Name == "Excel");
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "spreadsheet", Id = Guid.NewGuid(), Type = "application/vnd.ms-excel"
                    });
                    app.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType {
                        Name = "configuration", Id = Guid.NewGuid(), Type = "text/html"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application Excel input entries already made");
            }
            try
            {
                string owner = Turbine.Producer.Container.GetAppContext().UserName;
                Debug.WriteLine("OWNER " + owner);
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "TurbineLite");
                    db.Users.Add(new Turbine.Data.Entities.User {
                        Name = owner
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore User entries already made");
            }
            var hosts = new List <ServiceHost>();

            try
            {
                hosts.Add(new WebServiceHost(
                              typeof(Turbine.Lite.Web.Resources.ApplicationResource),
                              new Uri(String.Format("http://{0}/{1}/application", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.SimulationResource),
                        new Uri(String.Format("http://{0}/{1}/simulation", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.SessionResource),
                        new Uri(String.Format("http://{0}/{1}/session", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.JobResource),
                        new Uri(String.Format("http://{0}/{1}/job", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));
                hosts.Add(
                    new WebServiceHost(
                        typeof(Turbine.Lite.Web.Resources.ConsumerResource),
                        new Uri(String.Format("http://{0}/{1}/consumer", Properties.Settings.Default.netloc, Properties.Settings.Default.webdirectory))
                        ));

                foreach (var host in hosts)
                {
                    host.Open();
                }
                Console.WriteLine("The service is ready");
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();
                foreach (var host in hosts)
                {
                    host.Close();
                }
            }
            finally
            {
                foreach (var host in hosts)
                {
                    ((IDisposable)host).Dispose();
                }
            }

            /*
             * using (WebServiceHost host = new WebServiceHost(typeof(Turbine.Lite.Web.Resources.ApplicationResource), new Uri("http://localhost:8000/TurbineLite/application")))
             * {
             *  //host.AddServiceEndpoint(typeof(Turbine.Lite.Web.Resources.ApplicationResource), new WebHttpBinding(), new Uri("http://localhost:8000/TurbineLite/application"));
             *  host.AddServiceEndpoint(typeof(Turbine.Lite.Web.Resources.SimulationResource), new WebHttpBinding(), new Uri("http://localhost:8000/TurbineLite/simulation"));
             *
             *  // Enable metadata publishing.
             *  //ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
             *  //smb.HttpGetEnabled = true;
             *  //smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
             *  //host.Description.Behaviors.Add(smb);
             *
             *  // Open the ServiceHost to start listening for messages. Since
             *  // no endpoints are explicitly configured, the runtime will create
             *  // one endpoint per base address for each service contract implemented
             *  // by the service.
             *  host.Open();
             *
             *  Console.WriteLine("The service is ready");
             *  Console.WriteLine("Press <Enter> to stop the service.");
             *  Console.ReadLine();
             *
             *  // Close the ServiceHost.
             *  host.Close();
             * }
             * */
        }
        public static void AssemblyInit(TestContext context)
        {
            Console.WriteLine("assembly init");
            CleanUpDatabase();

            // DIJ
            TestProducerContext.name = "Administrator";
            using (var db = new Turbine.DataEF6.ProducerContext())
            {
                db.Users.Add(new Turbine.Data.Entities.User {
                    Name = TestProducerContext.name
                });
                db.SaveChanges();
            }
            // Create the ServiceHost.
            try
            {
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    Debug.WriteLine("Application ProducerContext", "TurbineLite");
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "ACM", Version = "7.3"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "AspenPlus"
                    });
                    db.Applications.Add(new Turbine.Data.Entities.Application {
                        Name = "Excel"
                    });
                    db.SaveChanges();
                }
                using (var db = new Turbine.DataEF6.ProducerContext())
                {
                    var item = db.Applications.Single(s => s.Name == "ACM");
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "configuration",
                        Required = true,
                        Type     = "plain/text"
                    });
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "aspenfile",
                        Required = true,
                        Type     = "plain/text"
                    });
                    item.InputFileTypes.Add(new Turbine.Data.Entities.InputFileType
                    {
                        Id       = Guid.NewGuid(),
                        Name     = "any",
                        Required = true,
                        Type     = "application/octet-stream"
                    });
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                Debug.WriteLine("Ignore Application entries already made");
            }

            hosts.Add(new WebServiceHost(typeof(Turbine.Lite.Web.Resources.ApplicationResource), new Uri("http://localhost:8000/TurbineLite/application")));
            hosts.Add(new WebServiceHost(typeof(Turbine.Lite.Web.Resources.JobResource), new Uri("http://localhost:8000/TurbineLite/job")));
            hosts.Add(new WebServiceHost(typeof(Turbine.Lite.Web.Resources.SessionResource), new Uri("http://localhost:8000/TurbineLite/session")));
            hosts.Add(new WebServiceHost(typeof(Turbine.Lite.Web.Resources.SimulationResource), new Uri("http://localhost:8000/TurbineLite/simulation")));
            foreach (var host in hosts)
            {
                ServiceDebugBehavior stp = host.Description.Behaviors.Find <ServiceDebugBehavior>();
                stp.HttpHelpPageEnabled            = false;
                stp.IncludeExceptionDetailInFaults = true;
                host.Open();
            }
        }