Esempio n. 1
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var sandbox = CreateFullTrustAppDomain();

            frame.SetState(KeySandbox, sandbox);

            // load test assemly into sandbox
            if (sandbox != null && TypeDescriptor.TestAssembly != null)
            {
                sandbox.Load(TypeDescriptor.TestAssembly.GetName());
            }

            SecurityHelper.AddIpListen();

            // retry three times using port scan with three port types.
            int repeat = 3;

            bool result = false;

            for (int i = 1; i <= repeat; ++i)
            {
                if (TrySetupServer(i, sandbox, frame))
                {
                    result = true;
                    break;
                }
            }

            if (result == false)
            {
                throw new Exception(string.Format("Cannot setup host server. See Event log for details"));
            }

            return(true);
        }
Esempio n. 2
0
        protected override void ShutdownServer(RunFrame frame)
        {
            var serverInitiator = frame.GetState(KeyServerInitiator) as KatanaSelfHostServerInitiator;

            if (serverInitiator != null)
            {
                serverInitiator.Dispose();
                frame.SetState(KeyServerInitiator, null);
            }

            var sandbox = frame.GetState(KeySandbox) as AppDomain;

            if (sandbox != null)
            {
                AppDomain.Unload(sandbox);
                frame.SetState(KeySandbox, null);
            }

            var securedServer = frame.GetState(KeyIsSecuredServer) ?? false;

            if ((bool)securedServer)
            {
                var port = frame.GetState(KeyReservedPort) as string;
                TeardownSecureEnvironment(port);
                frame.SetState(KeyIsSecuredServer, null);
            }
        }
Esempio n. 3
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var sandbox = CreateFullTrustAppDomain();

            frame.SetState(KeySandbox, sandbox);

            // load test assemly into sandbox
            if (sandbox != null && TypeDescriptor.TestAssembly != null)
            {
                sandbox.Load(TypeDescriptor.TestAssembly.GetName());
            }

            int  repeat = 10; // a magic number
            bool result = false;

            for (int i = 1; i <= repeat; ++i)
            {
                if (TrySetupServer(i, sandbox, frame))
                {
                    result = true;
                    break;
                }
            }

            if (result == false)
            {
                throw new Exception(string.Format("Cannot setup host server. See Event log for details"));
            }

            return(true);
        }
        public override void Initialize(RunFrame frame)
        {
            /// Create a client strategy which is associated with this host strategy.
            /// Client strategy is rather a component relatively indepdent from
            /// host strategy is because not like host strategy, the client
            /// strategy can be different on test method basis. For example the
            /// security credential could be different. So a HttpClient is created
            /// on basis of eacy test method (in the domain of xunit, is every
            /// TestCommand).
            var clientStrategy = new DefaultClientStrategy
            {
                MessageLog = MessageLog,
                UseProxy   = UseProxy
            };

            frame.SetState(KeyClientStrategy, clientStrategy);
        }
        public override void Initialize(RunFrame frame)
        {
            /// Create a client strategy which is associated with this host strategy.
            /// Client strategy is rather a component relatively indepdent from 
            /// host strategy is because not like host strategy, the client
            /// strategy can be different on test method basis. For example the
            /// security credential could be different. So a HttpClient is created
            /// on basis of eacy test method (in the domain of xunit, is every 
            /// TestCommand).
            var clientStrategy = new DefaultClientStrategy
            {
                MessageLog = MessageLog,
                UseProxy = UseProxy
            };

            frame.SetState(KeyClientStrategy, clientStrategy);
        }
Esempio n. 6
0
        protected override void ShutdownServer(RunFrame frame)
        {
            var context = frame.GetState(KeyWebHostContext) as WebHostContext;

            if (context != null)
            {
                try
                {
                    context.HostOptions.Stop();
                }
                finally
                {
                    ConfigurationTearDown(context);
                    context.HostOptions.Dispose();
                }
            }
            frame.SetState(KeyBaseAddresss, null);
        }
Esempio n. 7
0
        /// <summary>
        /// Assign base address uri to the property marked by <paramref name="NuwaBaseAddressAttribute"/>
        /// assuming that there are not more than 1 property is marked by the attribute
        /// </summary>
        protected void SetBaseAddress(object testClass, RunFrame frame)
        {
            var baseAddress   = frame.GetState(KeyBaseAddresss) as string;
            var testClassType = testClass.GetType();

            /// TODO: 1. check the number of marked property in test class command
            /// TODO: 2. to complain of the property type is not correct
            var baseAddressPrpt = testClassType.GetProperties()
                                  .Where(prop => { return(prop.GetCustomAttributes(typeof(NuwaBaseAddressAttribute), false).Length == 1); })
                                  .FirstOrDefault();

            if (baseAddressPrpt != null && NuwaBaseAddressAttribute.Verify(baseAddressPrpt))
            {
                baseAddressPrpt.SetValue(testClass, baseAddress, null);
            }
            else
            {
                // TODO: warning
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Assign base address uri to the property marked by <paramref name="NuwaBaseAddressAttribute"/>
        /// assuming that there are not more than 1 property is marked by the attribute
        /// </summary>
        protected void SetBaseAddress(object testClass, RunFrame frame)
        {
            var baseAddress = frame.GetState(KeyBaseAddresss) as string;
            var testClassType = testClass.GetType();

            /// TODO: 1. check the number of marked property in test class command
            /// TODO: 2. to complain of the property type is not correct
            var baseAddressPrpt = testClassType.GetProperties()
                .Where(prop => { return prop.GetCustomAttributes(typeof(NuwaBaseAddressAttribute), false).Length == 1; })
                .FirstOrDefault();

            if (baseAddressPrpt != null && NuwaBaseAddressAttribute.Verify(baseAddressPrpt))
            {
                baseAddressPrpt.SetValue(testClass, baseAddress, null);
            }
            else
            {
                // TODO: warning
            }
        }
Esempio n. 9
0
        private void MainTabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (MainTabControl.SelectedItem == BusinessFlowsTab)
            {
                if (BusinessFlowsFrame.Content == null)
                {
                    RepositoryFolder <BusinessFlow> RF = WorkSpace.Instance.SolutionRepository.GetRepositoryItemRootFolder <BusinessFlow>();
                    mBusinessFlowsPage = new BusinessFlowsPage(RF);
                    BusinessFlowsFrame.SetContent(mBusinessFlowsPage);
                }
            }

            if (MainTabControl.SelectedItem == RunTab)
            {
                //Temp - try list sync using SR cache
                if (RunFrame.Content == null)
                {
                    RunFrame.SetContent(new ListsPage());
                }
            }

            //TODO: keep all open pages and cache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! load o

            if (MainTabControl.SelectedItem == ResourcesTab)
            {
                if (ResourcesFrame.Content == null)
                {
                    //ResourcesFrame.SetContent(new ResourcesPage());
                }
            }

            if (MainTabControl.SelectedItem == ConfigurationsTab)
            {
                if (ConfigurationsFrame.Content == null)
                {
                    // ConfigurationsFrame.SetContent(new ConfigurationsPage());
                }
            }
        }
Esempio n. 10
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var context = new WebHostContext()
            {
                TestType   = TypeDescriptor,
                Deployment = new DeploymentDescriptor(TypeDescriptor.TestTypeInfo),
                Frame      = frame
            };

            RetrieveSource(context);
            InitOptions(context);
            ConfigurationInitialize(context);

            if (context.DeploymentOptions != null)
            {
                context.DeploymentOptions.Deploy(context.Source);
            }

            if (context.HostOptions == null)
            {
                throw new NuwaHostSetupException("Host options is not specified.");
            }

            try
            {
                var baseAddress = context.HostOptions.Start().Replace("localhost", Environment.MachineName);
                frame.SetState(KeyBaseAddresss, baseAddress);
                frame.SetState(KeyWebHostContext, context);
            }
            catch (Exception e)
            {
                throw new NuwaHostSetupException("Failed to setup Host.", e);
            }

            return(true);
        }
Esempio n. 11
0
 public virtual void Cleanup(RunFrame frame)
 {
 }
Esempio n. 12
0
 protected abstract void ShutdownServer(RunFrame frame);
Esempio n. 13
0
 public virtual void Cleanup(RunFrame frame)
 {
 }
Esempio n. 14
0
 public override void Cleanup(RunFrame frame)
 {
     ShutdownServer(frame);
 }
Esempio n. 15
0
 protected abstract bool InitializeServer(RunFrame frame);
Esempio n. 16
0
 protected override void ShutdownServer(RunFrame frame)
 {
     var context = frame.GetState(KeyWebHostContext) as WebHostContext;
     if (context != null)
     {
         try
         {
             context.HostOptions.Stop();
         }
         finally
         {
             ConfigurationTearDown(context);
             context.HostOptions.Dispose();
         }
     }
     frame.SetState(KeyBaseAddresss, null);
 }
Esempio n. 17
0
 public override void Initialize(RunFrame frame)
 {
     bool result = InitializeServer(frame);
 }
        protected override void ShutdownServer(RunFrame frame)
        {
            var serverInitiator = frame.GetState(KeyServerInitiator) as KatanaSelfHostServerInitiator;
            if (serverInitiator != null)
            {
                serverInitiator.Dispose();
                frame.SetState(KeyServerInitiator, null);
            }

            var sandbox = frame.GetState(KeySandbox) as AppDomain;
            if (sandbox != null)
            {
                AppDomain.Unload(sandbox);
                frame.SetState(KeySandbox, null);
            }

            var securedServer = frame.GetState(KeyIsSecuredServer) ?? false;
            if ((bool)securedServer)
            {
                var port = frame.GetState(KeyReservedPort) as string;
                TeardownSecureEnvironment(port);
                frame.SetState(KeyIsSecuredServer, null);
            }
        }
Esempio n. 19
0
 public virtual void Initialize(RunFrame frame)
 {
 }
Esempio n. 20
0
        private bool TrySetupServer(int tryIndex, AppDomain sandbox, RunFrame frame)
        {
            string baseAddress;
            string port = _portArranger.Reserve();

            SecurityHelper.AddIpListen();
            SecurityOptionElement securityElem = frame.GetFirstElement <SecurityOptionElement>();

            if (securityElem != null)
            {
                SetupSecureEnvironment(securityElem.Certificate, port);
                baseAddress = string.Format(SecureBaseAddressTemplate, Environment.MachineName, port);
                frame.SetState(KeyIsSecuredServer, true);
            }
            else
            {
                baseAddress = string.Format(NormalBaseAddressTemplate, Environment.MachineName, port);
                frame.SetState(KeyIsSecuredServer, false);
            }

            // looking into the RunFrames and search for TraceElement. if it exists
            // set the tracer's type to the configuration otherwise skip this step
            TraceElement traceElem = frame.GetFirstElement <TraceElement>();
            Type         traceType = null;

            if (traceElem != null)
            {
                traceType = traceElem.TracerType;
            }

            KatanaSelfHostServerInitiator serverInitiator;

            // create initiator in the sandbox
            if (sandbox != null)
            {
                serverInitiator = sandbox.CreateInstanceAndUnwrap(
                    typeof(KatanaSelfHostServerInitiator).Assembly.FullName,
                    typeof(KatanaSelfHostServerInitiator).FullName)
                                  as KatanaSelfHostServerInitiator;
            }
            else
            {
                serverInitiator = new KatanaSelfHostServerInitiator();
            }
            try
            {
                // set up the server
                serverInitiator.Setup(
                    baseAddress,
                    TypeDescriptor.GetDesignatedMethod <NuwaKatanaConfigurationAttribute>(),
                    TypeDescriptor.ConfigureMethod,
                    traceType, GetDefaultRouteTemplate());
            }
            catch (Exception ex)
            {
                EventLog appLog = new System.Diagnostics.EventLog();
                appLog.Source = "Nuwa Katana Self Host Test";
                appLog.WriteEntry(string.Format("try index: {0}\nbase address: {1}\n message: {2}\n stack trace: {3}\n", tryIndex, baseAddress, ex.Message, ex.StackTrace),
                                  EventLogEntryType.Error);

                return(false);
            }

            frame.SetState(KeyReservedPort, port);
            frame.SetState(KeyBaseAddresss, baseAddress);
            frame.SetState(KeyServerInitiator, serverInitiator);
            return(true);
        }
Esempio n. 21
0
 public override void Initialize(RunFrame frame)
 {
     bool result = InitializeServer(frame);
 }
Esempio n. 22
0
 protected abstract void ShutdownServer(RunFrame frame);
Esempio n. 23
0
 protected abstract bool InitializeServer(RunFrame frame);
Esempio n. 24
0
 public override void Cleanup(RunFrame frame)
 {
     ShutdownServer(frame);
 }
Esempio n. 25
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var context = new WebHostContext()
            {
                TestType = TypeDescriptor,
                Deployment = new DeploymentDescriptor(TypeDescriptor.TestTypeInfo),
                Frame = frame
            };

            RetrieveSource(context);
            InitOptions(context);
            ConfigurationInitialize(context);

            if (context.DeploymentOptions != null)
            {
                context.DeploymentOptions.Deploy(context.Source);
            }

            if (context.HostOptions == null)
            {
                throw new NuwaHostSetupException("Host options is not specified.");
            }

            try
            {
                var baseAddress = context.HostOptions.Start().Replace("localhost", Environment.MachineName);
                frame.SetState(KeyBaseAddresss, baseAddress);
                frame.SetState(KeyWebHostContext, context);
            }
            catch (Exception e)
            {
                throw new NuwaHostSetupException("Failed to setup Host.", e);
            }

            return true;
        }
        protected override bool InitializeServer(RunFrame frame)
        {
            string baseAddress;
            string port;

            var sandbox = CreateFullTrustAppDomain();
            frame.SetState(KeySandbox, sandbox);

            // load test assemly into sandbox
            if (sandbox != null && TypeDescriptor.TestAssembly != null)
            {
                sandbox.Load(TypeDescriptor.TestAssembly.GetName());
            }

            // setup security strategy and base address
            port = _portArranger.Reserve();
            SecurityHelper.AddIpListen();
            SecurityOptionElement securityElem = frame.GetFirstElement<SecurityOptionElement>();
            if (securityElem != null)
            {
                SetupSecureEnvironment(securityElem.Certificate, port);
                baseAddress = string.Format(SecureBaseAddressTemplate, Environment.MachineName, port);
                frame.SetState(KeyIsSecuredServer, true);
            }
            else
            {
                baseAddress = string.Format(NormalBaseAddressTemplate, Environment.MachineName, port);
                frame.SetState(KeyIsSecuredServer, false);
            }

            // looking into the RunFrames and search for TraceElement. if it exists
            // set the tracer's type to the configuration otherwise skip this step
            TraceElement traceElem = frame.GetFirstElement<TraceElement>();
            Type traceType = null;
            if (traceElem != null)
            {
                traceType = traceElem.TracerType;
            }

            // create initiator in the sandbox
            KatanaSelfHostServerInitiator serverInitiator;
            if (sandbox != null)
            {
                serverInitiator = sandbox.CreateInstanceAndUnwrap(
                    typeof(KatanaSelfHostServerInitiator).Assembly.FullName,
                    typeof(KatanaSelfHostServerInitiator).FullName)
                    as KatanaSelfHostServerInitiator;
            }
            else
            {
                serverInitiator = new KatanaSelfHostServerInitiator();
            }

            // set up the server
            serverInitiator.Setup(
                baseAddress,
                TypeDescriptor.GetDesignatedMethod<NuwaKatanaConfigurationAttribute>(),
                TypeDescriptor.ConfigureMethod,
                traceType, GetDefaultRouteTemplate());

            frame.SetState(KeyReservedPort, port);
            frame.SetState(KeyBaseAddresss, baseAddress);
            frame.SetState(KeyServerInitiator, serverInitiator);

            return true;
        }
Esempio n. 27
0
        protected override bool InitializeServer(RunFrame frame)
        {
            string baseAddress;
            string port;

            AppDomain sandbox = CreateFullTrustAppDomain();

            frame.SetState(KeySandbox, sandbox);

            // load test assemly into sandbox
            if (sandbox != null && TypeDescriptor.TestAssembly != null)
            {
                sandbox.Load(TypeDescriptor.TestAssembly.GetName());
            }

            // setup security strategy and base address
            port = _portArranger.Reserve();
            SecurityOptionElement securityElem = frame.GetFirstElement <SecurityOptionElement>();

            if (securityElem != null)
            {
                SetupSecureEnvironment(securityElem.Certificate, port);
                baseAddress = string.Format(SecureBaseAddressTemplate, port);
                frame.SetState(KeyIsSecuredServer, true);
            }
            else
            {
                baseAddress = string.Format(NormalBaseAddressTemplate, port);
                frame.SetState(KeyIsSecuredServer, false);
            }

            // looking into the RunFrames and search for TraceElement. if it exists
            // set the tracer's type to the configuration otherwise skip this step
            TraceElement traceElem = frame.GetFirstElement <TraceElement>();
            Type         traceType = null;

            if (traceElem != null)
            {
                traceType = traceElem.TracerType;
            }

            // create initiator in the sandbox
            SelfHostServerInitiator serverInitiator;

            if (sandbox != null)
            {
                serverInitiator = sandbox.CreateInstanceAndUnwrap(
                    typeof(SelfHostServerInitiator).Assembly.FullName,
                    typeof(SelfHostServerInitiator).FullName)
                                  as SelfHostServerInitiator;
            }
            else
            {
                serverInitiator = new SelfHostServerInitiator();
            }

            // set up the server
            serverInitiator.Setup(baseAddress, TypeDescriptor.ConfigureMethod, traceType, GetDefaultRouteTemplate());

            frame.SetState(KeyReservedPort, port);
            frame.SetState(KeyBaseAddresss, baseAddress);
            frame.SetState(KeyServerInitiator, serverInitiator);

            return(true);
        }
Esempio n. 28
0
 public virtual void Initialize(RunFrame frame)
 {
 }