Exemplo n.º 1
0
        /// <summary>
        /// Override to make an instance of client per ContractMapping.
        /// The default implementation uses activator
        /// </summary>
        protected virtual TServiceClient DoMakeClientInstance <TServiceClient>(ContractMapping mapping, bool isGlobal, Node node) where TServiceClient : IAgniServiceClient
        {
            var mappingData = isGlobal ? mapping.Global : mapping.Local;

            TServiceClient result;

            try
            {
                if (mappingData.Implementor.GetConstructor(CTOR_SIG_GLUE_ENDPOINT) != null)
                {
                    result = (TServiceClient)Activator.CreateInstance(mappingData.Implementor, node, null); //Glue endpoint signature: node, binding
                }
                else
                {
                    result = (TServiceClient)Activator.CreateInstance(mappingData.Implementor, node);//otherwise must have NODE as a sole parameter
                }
            }
            catch (Exception error)
            {
                if (error is System.Reflection.TargetInvocationException)
                {
                    throw error.InnerException;
                }
                throw new Clients.AgniClientException("Implementor '{0}' must have .ctor(Glue.Node) or .ctor(GlueNode,Glue.Binding). Error: {1}".Args(mappingData.Implementor.FullName, error.ToMessageWithType()));
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override to setup the instance of client after it has been allocated.
        /// The default implementation injects headers, timeoutes, and inspectors for Glue.ClientEndPoints
        /// </summary>
        protected virtual void DoSetupClientInstance(ContractMapping mapping, bool isGlobal, IAgniServiceClient instance, string toHost, string fromHost)
        {
            var mappingData = isGlobal ? mapping.Global : mapping.Local;

            var tms = mappingData.CallTimeoutMs;

            if (tms > 0)
            {
                instance.TimeoutMs = tms;
            }
            instance.ReserveTransport = mappingData.ReserveTransport;


            var gep = instance as ClientEndPoint;

            if (gep != null)
            {
                var icfg = mappingData.Options;
                if (icfg != null)
                {
                    MsgInspectorConfigurator.ConfigureClientInspectors(gep.MsgInspectors, icfg);
                    HeaderConfigurator.ConfigureHeaders(gep.Headers, icfg);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tries to resolve contract type to implementor and tests network service resolvability. Throws in case of error
        /// </summary>
        public void RunTestSetupOf <TServiceClient>(string toHost, string fromHost = null, string svcName = null) where TServiceClient : class, IAgniServiceClient
        {
            Type tcontract = typeof(TServiceClient);

            if (toHost.IsNullOrWhiteSpace())
            {
                throw new Clients.AgniClientException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".TestByContract<{0}>(host==null|empty)".Args(tcontract.Name));
            }

            if (fromHost.IsNullOrWhiteSpace())
            {
                fromHost = AgniSystem.HostName;
            }

            if (fromHost.IsNullOrWhiteSpace())
            {
                throw new Clients.AgniClientException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".TestByContract<{0}>(fromHost==null|empty & AgniSystem is not avail)".Args(tcontract.Name));
            }


            ContractMapping mapping = MapContractToImplementation(tcontract);

            bool isGlobal;
            Node node = ResolveNetworkService(mapping, toHost, fromHost, svcName, out isGlobal);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Makes a client for the call to the specified contract on the specified host
        /// </summary>
        public TServiceClient MakeNew <TServiceClient>(string toHost, string fromHost = null, string svcName = null) where TServiceClient : class, ISkyServiceClient
        {
            Type tcontract = typeof(TServiceClient);

            if (toHost.IsNullOrWhiteSpace())
            {
                throw new Clients.SkyClientException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".GetByContract<{0}>(host==null|empty)".Args(tcontract.Name));
            }

            if (fromHost.IsNullOrWhiteSpace())
            {
                fromHost = App.HostName;
            }

            if (fromHost.IsNullOrWhiteSpace())
            {
                throw new Clients.SkyClientException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".GetByContract<{0}>(fromHost==null|empty & AgnySystem is not avail)".Args(tcontract.Name));
            }


            ContractMapping mapping = MapContractToImplementation(tcontract);

            bool isGlobal;
            Node node = ResolveNetworkService(mapping, toHost, fromHost, svcName, out isGlobal);

            var result = MakeClientInstance <TServiceClient>(mapping, isGlobal, node);

            SetupClientInstance(mapping, isGlobal, result, toHost, fromHost);

            return(result);
        }
Exemplo n.º 5
0
 protected void SetupClientInstance(ContractMapping mapping, bool isGlobal, IAgniServiceClient instance, string toHost, string fromHost)
 {
     try { DoSetupClientInstance(mapping, isGlobal, instance, toHost, fromHost); }
     catch (Exception error)
     {
         throw new Clients.AgniClientException(StringConsts.AGNI_SVC_CLIENT_HUB_SETUP_INSTANCE_ERROR.Args(mapping, error.ToMessageWithType()), error);
     }
 }
Exemplo n.º 6
0
 protected TServiceClient MakeClientInstance <TServiceClient>(ContractMapping mapping, bool isGlobal, Node node) where TServiceClient : IAgniServiceClient
 {
     try { return(DoMakeClientInstance <TServiceClient>(mapping, isGlobal, node)); }
     catch (Exception error)
     {
         throw new Clients.AgniClientException(StringConsts.AGNI_SVC_CLIENT_HUB_MAKE_INSTANCE_ERROR.Args(mapping, error.ToMessageWithType()), error);
     }
 }
Exemplo n.º 7
0
 protected Node ResolveNetworkService(ContractMapping mapping, string toHost, string fromHost, string svcName, out bool isGlobal)
 {
     try { return(DoResolveNetworkService(mapping, toHost, fromHost, svcName, out isGlobal)); }
     catch (Exception error)
     {
         throw new Clients.AgniClientException(StringConsts.AGNI_SVC_CLIENT_HUB_NET_RESOLVE_ERROR.Args(mapping, error.ToMessageWithType()), error);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Override to configure custom memebers.
 /// The default implementation populates the CacheMap registry
 /// </summary>
 protected ServiceClientHub(IConfigSectionNode config)
 {
     ConfigAttribute.Apply(this, config);
     foreach (var nmapping in config.Children.Where(c => c.IsSameName(CONFIG_MAP_SECTION)))
     {
         var mapping = new ContractMapping(nmapping);
         m_CachedMap.Register(mapping);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Override to resolve ContractMapping into physical connection parameters.
        /// The default implementation uses metabase's ResolveNetworkService
        /// </summary>
        protected virtual Node DoResolveNetworkService(ContractMapping mapping, string toHost, string fromHost, string svcName, out bool isGlobal)
        {
            isGlobal = !AgniSystem.Metabase.CatalogReg.ArePathsInSameNOC(fromHost, toHost);

            var mappingData = isGlobal ? mapping.Global : mapping.Local;

            if (svcName.IsNullOrWhiteSpace())
            {
                svcName = mappingData.Service;
            }

            return(AgniSystem.Metabase.ResolveNetworkService(toHost, mappingData.Net, svcName, mappingData.Binding, fromHost));
        }
Exemplo n.º 10
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            ConfigureFormatter(GlobalConfiguration.Configuration);
            ContractMapping.MappingRegistration();

            GlobalInitializer.Initialize();

            _backgroundJobServer = new BackgroundJobServer(
                new BackgroundJobServerOptions()
            {
                Queues     = new string[] { "default", "checker" },
                ServerName = Environment.MachineName
            });
        }
 public static ContractMapping CreateContractMapping(string externalType, string externalId, bool isPrimary, global::System.DateTimeOffset validFrom, global::System.DateTimeOffset validUntil, long customerId, long ID, global::System.Guid tid, string name, long createdById, long modifiedById, global::System.DateTimeOffset created, global::System.DateTimeOffset modified)
 {
     ContractMapping contractMapping = new ContractMapping();
     contractMapping.ExternalType = externalType;
     contractMapping.ExternalId = externalId;
     contractMapping.IsPrimary = isPrimary;
     contractMapping.ValidFrom = validFrom;
     contractMapping.ValidUntil = validUntil;
     contractMapping.CustomerId = customerId;
     contractMapping.Id = ID;
     contractMapping.Tid = tid;
     contractMapping.Name = name;
     contractMapping.CreatedById = createdById;
     contractMapping.ModifiedById = modifiedById;
     contractMapping.Created = created;
     contractMapping.Modified = modified;
     return contractMapping;
 }
 public void AddToContractMappings(ContractMapping contractMapping)
 {
     base.AddObject("ContractMappings", contractMapping);
 }