Beispiel #1
0
        public void StartApplicationServices()
        {
            List <Assembly> serverAssemblies = new List <Assembly>();
            var             pathsAssembly    = System.IO.Directory.GetFiles("C:\\ITSolution").Where(a => a.Contains("dll") && a.Contains("Servers"));

            foreach (var asm in pathsAssembly)
            {
                serverAssemblies.Add(Assembly.LoadFrom(asm));
            }

            foreach (var asmServer in serverAssemblies)
            {
                foreach (Type server in asmServer.GetTypes())
                {
                    ItsServerInfo sinfo = new ItsServerInfo(server);
                    try
                    {
                        sinfo.Instance = Activator.CreateInstance(server);
                        RegisterWCFHost(server, sinfo);
                    }
                    catch (Exception ex)
                    {
                        sinfo.Message = ex.Message;
                    }

                    OnlineServers.Add(sinfo);
                }
            }
        }
Beispiel #2
0
        private ServiceHost RegisterWCFHost(Type server, ItsServerInfo sinfo)
        {
            ServiceHost sh = new ServiceHost(server, GetUri(server.FullName));

            AddBehaviors(sh, server);
            //abrindo o host.. deixando o servico pronto para receber requests..
            sh.Open(new TimeSpan(0, 5, 0));
            sinfo.Host     = sh;
            sinfo.Url      = sh.BaseAddresses.FirstOrDefault().AbsoluteUri;
            sinfo.IsOnline = sh.State == CommunicationState.Opened;
            return(sh);
        }
Beispiel #3
0
        public void StartFrameworkServices()
        {
            List <Assembly> serverAssemblies = new List <Assembly>();
            var             pathsAssembly    = System.IO.Directory.GetFiles("C:\\ITSolution\\Framework").Where(a => a.Contains("ITSolution.Framework.Server") && a.EndsWith(".dll"));

            foreach (var asm in pathsAssembly)
            {
                serverAssemblies.Add(Assembly.LoadFrom(asm));
            }

            foreach (var asmServer in serverAssemblies)
            {
                AppDomain.CurrentDomain.Load(asmServer.GetName());
                foreach (Type server in asmServer.GetTypes().Where(t =>
                                                                   !t.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false) &&
                                                                   t.Attributes.HasFlag(TypeAttributes.Public | TypeAttributes.BeforeFieldInit)))
                {
                    ItsServerInfo sinfo = new ItsServerInfo(server);
                    try
                    {
                        sinfo.Instance = Activator.CreateInstance(server);

                        MethodInfo startupMethod = sinfo.Instance.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(ITSolutionStartupAttribute)).Count() > 0).FirstOrDefault();

                        if (startupMethod != null)
                        {
                            startupMethod.Invoke(sinfo.Instance, new object[] { GetUri(server.Name).AbsoluteUri });
                        }

                        RegisterWCFHost(server, sinfo);
                    }
                    catch (Exception ex)
                    {
                        sinfo.Message = ex.Message;
                    }

                    OnlineServers.Add(sinfo);
                }
            }
        }