Example #1
0
        public IDxStoreAccessClient GetClient(string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                target = this.groupCfg.Self;
            }
            Tuple <CachedChannelFactory <IDxStoreAccess>, IDxStoreAccessClient> orAdd = this.FactoryByTarget.GetOrAdd(target, delegate(string server)
            {
                CachedChannelFactory <IDxStoreAccess> cachedChannelFactory = null;
                IDxStoreAccessClient item;
                if (this.groupCfg.Settings.IsUseHttpTransportForClientCommunication)
                {
                    item = new HttpStoreAccessClient(this.groupCfg.Self, HttpClient.TargetInfo.BuildFromNode(server, this.groupCfg), this.groupCfg.Settings.StoreAccessHttpTimeoutInMSec);
                }
                else
                {
                    ServiceEndpoint storeAccessEndpoint = this.groupCfg.GetStoreAccessEndpoint(server, false, false, this.DefaultTimeout);
                    cachedChannelFactory = new CachedChannelFactory <IDxStoreAccess>(storeAccessEndpoint);
                    item = new WcfStoreAccessClient(cachedChannelFactory, (this.DefaultTimeout != null) ? this.DefaultTimeout.Operation : null);
                }
                return(Tuple.Create <CachedChannelFactory <IDxStoreAccess>, IDxStoreAccessClient>(cachedChannelFactory, item));
            });

            return(orAdd.Item2);
        }
        public InstanceSnapshotInfo AcquireSnapshot(string fullKeyName = null, bool isCompress = true, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            return(runner.Execute <InstanceSnapshotInfo>(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, (IDxStoreInstance service) => service.AcquireSnapshot(fullKeyName, isCompress)));
        }
        public InstanceStatusInfo GetStatus(TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            return(runner.Execute <InstanceStatusInfo>(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, (IDxStoreInstance service) => service.GetStatus()));
        }
Example #4
0
 public static void Run <T>(CachedChannelFactory <T> factory, TimeSpan?timeout, Action <T> methodToCall)
 {
     WcfUtils.Run <T, int>(factory, timeout, delegate(T service)
     {
         methodToCall(service);
         return(0);
     });
 }
        public DxStoreAccessReply.GetPropertyNames GetPropertyNames(DxStoreAccessRequest.GetPropertyNames request, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreAccess> runner         = WcfStoreAccessClient.Runner;
            CachedChannelFactory <IDxStoreAccess>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            return(runner.Execute <DxStoreAccessReply.GetPropertyNames>(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, (IDxStoreAccess service) => this.TraceRequests <DxStoreAccessRequest.GetPropertyNames, DxStoreAccessReply.GetPropertyNames>(request, new Func <DxStoreAccessRequest.GetPropertyNames, DxStoreAccessReply.GetPropertyNames>(service.GetPropertyNames))));
        }
        public InstanceGroupConfig GetInstanceConfig(string groupName, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreManager> runner         = DxStoreManagerClient.Runner;
            CachedChannelFactory <IDxStoreManager>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            return(runner.Execute <InstanceGroupConfig>(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, (IDxStoreManager service) => service.GetInstanceConfig(groupName, false)));
        }
Example #7
0
 public void Execute(CachedChannelFactory <TService> factory, TimeSpan?timeout, Action <TService> action)
 {
     this.Execute <int>(factory, timeout, delegate(TService service)
     {
         action(service);
         return(0);
     });
 }
 public void Initialize(CachedChannelFactory <IDxStoreAccess> channelFactory, TimeSpan?operationTimeout)
 {
     this.ChannelFactory   = channelFactory;
     this.OperationTimeout = operationTimeout;
     if (ExTraceGlobals.AccessClientTracer.IsTraceEnabled(TraceType.DebugTrace))
     {
         ExTraceGlobals.AccessClientTracer.TraceDebug <string, string>(0L, "{0} Initialized (timeout: {1})", base.GetType().Name, (operationTimeout != null) ? operationTimeout.ToString() : "<null>");
     }
 }
Example #9
0
        public static R Run <T, R>(CachedChannelFactory <T> factory, TimeSpan?timeout, Func <T, R> methodToCall)
        {
            T t = factory.Factory.CreateChannel();
            R result;

            using (IClientChannel clientChannel = (IClientChannel)((object)t))
            {
                if (timeout != null)
                {
                    clientChannel.OperationTimeout = timeout.Value;
                }
                CommunicationState state = clientChannel.State;
                bool flag = false;
                if (state != CommunicationState.Created)
                {
                    if (state != CommunicationState.Closed)
                    {
                        goto IL_51;
                    }
                }
                try
                {
                    clientChannel.Open();
                    flag = true;
                }
                catch
                {
                    clientChannel.Abort();
                    throw;
                }
IL_51:
                bool flag2 = false;
                try
                {
                    result = methodToCall(t);
                }
                catch (Exception error)
                {
                    if (WcfUtils.IsChannelException(error))
                    {
                        flag2 = true;
                        clientChannel.Abort();
                    }
                    throw;
                }
                finally
                {
                    if (!flag2 && flag)
                    {
                        WcfUtils.CloseChannel(clientChannel);
                    }
                }
            }
            return(result);
        }
        public void TryBecomeLeader(TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreInstance service)
            {
                service.TryBecomeLeader();
            });
        }
        public void Reconfigure(InstanceGroupMemberConfig[] members, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreInstance service)
            {
                service.Reconfigure(members);
            });
        }
        public void NotifyInitiator(Guid commandId, string sender, int instanceNumber, bool isSucceeded, string errorMessage, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreInstance service)
            {
                service.NotifyInitiator(commandId, sender, instanceNumber, isSucceeded, errorMessage);
            });
        }
        public void TriggerRefresh(string reason, bool isForceRefreshCache, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreManager> runner         = DxStoreManagerClient.Runner;
            CachedChannelFactory <IDxStoreManager>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreManager service)
            {
                service.TriggerRefresh(reason, isForceRefreshCache);
            });
        }
        public void StopInstance(string groupName, bool isDisable = true, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreManager> runner         = DxStoreManagerClient.Runner;
            CachedChannelFactory <IDxStoreManager>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreManager service)
            {
                service.StopInstance(groupName, true);
            });
        }
        public void ApplySnapshot(InstanceSnapshotInfo snapshot, bool isForce = false, TimeSpan?timeout = null)
        {
            WcfExceptionTranslator <IDxStoreInstance> runner         = DxStoreInstanceClient.Runner;
            CachedChannelFactory <IDxStoreInstance>   channelFactory = this.ChannelFactory;
            TimeSpan?timeSpan = timeout;

            runner.Execute(channelFactory, (timeSpan != null) ? new TimeSpan?(timeSpan.GetValueOrDefault()) : this.OperationTimeout, delegate(IDxStoreInstance service)
            {
                service.ApplySnapshot(snapshot, isForce);
            });
        }
        public DxStoreManagerClient GetClient(string target)
        {
            if (string.IsNullOrEmpty(target))
            {
                target = this.managerConfig.Self;
            }
            Tuple <CachedChannelFactory <IDxStoreManager>, DxStoreManagerClient> orAdd = this.FactoryByTarget.GetOrAdd(target, delegate(string server)
            {
                ServiceEndpoint endpoint = this.managerConfig.GetEndpoint(server, false, this.DefaultTimeout);
                CachedChannelFactory <IDxStoreManager> cachedChannelFactory = new CachedChannelFactory <IDxStoreManager>(endpoint);
                DxStoreManagerClient item = new DxStoreManagerClient(cachedChannelFactory, (this.DefaultTimeout != null) ? this.DefaultTimeout.Operation : null);
                return(Tuple.Create <CachedChannelFactory <IDxStoreManager>, DxStoreManagerClient>(cachedChannelFactory, item));
            });

            return(orAdd.Item2);
        }
Example #17
0
        public TReturnType Execute <TReturnType>(CachedChannelFactory <TService> factory, TimeSpan?timeout, Func <TService, TReturnType> action)
        {
            TReturnType result;

            try
            {
                result = WcfUtils.Run <TService, TReturnType>(factory, timeout, action);
            }
            catch (Exception ex)
            {
                Exception ex2 = WcfExceptionTranslator <TService> .TranslateException(ex, new Func <Exception, Exception>(this.GenerateTransientException), new Func <Exception, Exception>(this.GeneratePermanentException));

                if (ex2 != null)
                {
                    throw ex2;
                }
                throw;
            }
            return(result);
        }
 public WcfStoreAccessClient(CachedChannelFactory <IDxStoreAccess> channelFactory, TimeSpan?operationTimeout = null)
 {
     this.Initialize(channelFactory, operationTimeout);
 }
 public DxStoreManagerClient(CachedChannelFactory <IDxStoreManager> channelFactory, TimeSpan?operationTimeout = null)
 {
     this.Initialize(channelFactory, operationTimeout);
 }
 public void Initialize(CachedChannelFactory <IDxStoreManager> channelFactory, TimeSpan?operationTimeout = null)
 {
     this.ChannelFactory   = channelFactory;
     this.OperationTimeout = operationTimeout;
 }