private void StartUp()
        {
            // default configuration
            EnvId env = IntClient.Target.ClientInfo.ConfigEnv;

            // derived configuration
            _serverPort = OtherSettings.GetValue(WFPropName.Port, EnvHelper.SvcPort(env, SvcId.GridSwitch));
            _nodeId     = OtherSettings.GetValue(WFPropName.NodeId, Guid.NewGuid());
            // create router/worker worksteps
            Routers = GridWorksteps.Create().ToArray();
            Workers = GridWorksteps.Create().ToArray();
            // start discovery endpoint
            string endpoint = ServiceHelper.FormatEndpoint(WcfConst.NetTcp, _serverPort);
            string svcName  = EnvHelper.SvcPrefix(SvcId.GridSwitch);

            _discoServerHost = new CustomServiceHost <IDiscoverV111, DiscoverRecverV111>(
                Logger, new DiscoverRecverV111(this), endpoint,
                svcName, typeof(IDiscoverV111).Name, true);
            IWorkContext context = new WorkContext(Logger, IntClient.Target, HostInstance, ServerInstance);

            // start gridswitch endpoints - routers before workers
            foreach (IWorkstep router in Routers)
            {
                router.Initialise(context);
                router.EnableGrid(GridLevel.Router, _nodeId, _serverPort, null);
            }
            foreach (IWorkstep worker in Workers)
            {
                worker.Initialise(context);
                worker.EnableGrid(GridLevel.Worker, _nodeId, _serverPort, null);
            }
        }
        public WorkflowClient(IWorkContext context, NamedValueSet settings)
        {
            // default configuration
            const SvcId svc    = SvcId.GridSwitch;
            EnvId       env    = EnvHelper.ParseEnvName(BuildConst.BuildEnv);
            Guid        nodeId = Guid.NewGuid();

            // custom configuration
            if (settings != null)
            {
                // environment
                env = (EnvId)settings.GetValue(WFPropName.EnvId, (int)env);
            }
            env = EnvHelper.CheckEnv(env);
            // derived configuration
            string hosts = null;
            int    port  = EnvHelper.SvcPort(env, svc);

            if (settings != null)
            {
                port   = settings.GetValue(WFPropName.Port, port);
                hosts  = settings.GetValue(WFPropName.Hosts, hosts);
                nodeId = settings.GetValue(WFPropName.NodeId, nodeId);
            }
            string svcName = EnvHelper.SvcPrefix(svc);

            string[] serviceAddrs = EnvHelper.GetServiceAddrs(env, svc, false);
            if (hosts != null)
            {
                serviceAddrs = hosts.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            }
            ServiceAddress resolvedServer = V111Helpers.ResolveServer(context.Logger, svcName, new ServiceAddresses(WcfConst.AllProtocols, serviceAddrs, port),
                                                                      new[] { typeof(IDiscoverV111).FullName });
            // initialise worksteps
            List <IWorkstep> worksteps = GridWorksteps.Create();

            foreach (IWorkstep workstep in worksteps)
            {
                workstep.Initialise(context);
                workstep.EnableGrid(GridLevel.Client, nodeId, resolvedServer.Port, resolvedServer.Host);
            }
            Clients = worksteps.ToArray();
        }