Пример #1
0
        public Link GetLink <TLink>()
        {
            var controllerType = (from lk in _Links where lk.Key == typeof(TLink) select lk.Value).FirstOrDefault();
            var link           = (Link)Activator.CreateInstance(typeof(TLink));

            link.Target = RootRouter.GetUrlForController(controllerType);
            return(link);
        }
Пример #2
0
        /// <summary>
        /// Starts the service, associating it with an <see cref="IServiceHost" /> instance.
        /// </summary>
        /// <param name="serviceHost">The service user interface.</param>
        /// <param name="args">Command line arguments.</param>
        public void Start(IServiceHost serviceHost, string[] args)
        {
            lock (syncLock)
            {
                if (router != null)
                {
                    return;     // Already started
                }
                // Global initialization

                NetTrace.Start();
                Program.Config       = new Config("LillTek.Datacenter.RouterService");
                Program.PerfCounters = null;    // $todo(jeff.lill): new PerfCounterSet(true,Const.RouterServicePerf,Const.RouterServiceName);

                // Service initialization

                this.serviceHost = serviceHost;

                try
                {
                    RootRouter rootRouter;
                    HubRouter  hubRouter;

                    switch (Program.Config.Get("Mode", "HUB").ToUpper())
                    {
                    case "ROOT":

                        SysLog.LogInformation("Router Service v{0}: Starting as ROOT", Helper.GetVersionString());
                        router = rootRouter = new RootRouter();
                        rootRouter.Start();
                        break;

                    case "HUB":
                    default:

                        SysLog.LogInformation("Router Service v{0}: Starting as HUB", Helper.GetVersionString());
                        router = hubRouter = new HubRouter();
                        hubRouter.Start();
                        break;
                    }

                    state = ServiceState.Running;
                }
                catch (Exception e)
                {
                    if (router != null)
                    {
                        router.Stop();
                        router = null;
                    }

                    SysLog.LogException(e);
                    throw;
                }
            }
        }