Beispiel #1
0
 /// <summary>
 /// Invoke method implementation
 /// </summary>
 private T Invoke <T>(string operationName, string uri, ExecuteOptions options, InvokeDelegate <T> operation)
 {
     using (new SPMonitoredScope("Invoke :" + operationName + "_" + uri))
     {
         string ep = FindLoadBalancerEndPoint(uri);
         if (!string.IsNullOrEmpty(ep))
         {
             Uri xu = new Uri(ep);
             IIdentityServiceContract identityapplication = GetChannel(xu, options);
             IClientChannel           clientChannel       = identityapplication as IClientChannel;
             try
             {
                 operation(identityapplication);
                 clientChannel.Close();
             }
             finally
             {
                 if (clientChannel.State != CommunicationState.Closed)
                 {
                     clientChannel.Abort();
                 }
             }
         }
     }
     return(default(T));
 }
Beispiel #2
0
        /// <summary>
        /// ExecuteOnChannel method implementation
        /// </summary>
        private T Execute <T>(string operationName, ExecuteOptions options, ExecuteDelegate <T> operation)
        {
            T      result;
            object obj = null;

            using (new SPMonitoredScope("Execute :" + operationName))
            {
                bool   mustexit     = false;
                string firstaddress = "";
                do
                {
                    SPServiceLoadBalancerContext loadBalancerContext = m_LoadBalancer.BeginOperation();
                    try
                    {
                        if (firstaddress.Equals(loadBalancerContext.EndpointAddress.ToString()))
                        {
                            mustexit = true;
                        }
                        if (!mustexit)
                        {
                            if ((loadBalancerContext.Status == SPServiceLoadBalancerStatus.Succeeded))
                            {
                                if (string.IsNullOrEmpty(firstaddress))
                                {
                                    firstaddress = loadBalancerContext.EndpointAddress.ToString();
                                }

                                IIdentityServiceContract identityapplication = GetChannel(loadBalancerContext.EndpointAddress, options);
                                IClientChannel           clientChannel       = identityapplication as IClientChannel;
                                try
                                {
                                    obj = operation(identityapplication);
                                    clientChannel.Close();
                                    mustexit = true;
                                }
                                catch (TimeoutException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                catch (EndpointNotFoundException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                finally
                                {
                                    if (clientChannel.State != CommunicationState.Closed)
                                    {
                                        clientChannel.Abort();
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        loadBalancerContext.EndOperation();
                    }
                }while (!mustexit);
                result = (T)((object)obj);
            }
            return(result);
        }