Example #1
0
        /// <summary>
        /// ExecuteOnChannel method implementation
        /// </summary>
        private void ExecuteOnChannel(string operationName, ExecuteOptions options, CodeToRunOnChannel codeBlock)
        {
            using (new SPMonitoredScope("ExecuteOnChannel:" + 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();
                                }

                                IChannel channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress, options);
                                try
                                {
                                    codeBlock((IIdentityServiceContract)channel);
                                    channel.Close();
                                    mustexit = true;
                                }
                                catch (TimeoutException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                catch (EndpointNotFoundException)
                                {
                                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                                }
                                finally
                                {
                                    if (channel.State != CommunicationState.Closed)
                                    {
                                        channel.Abort();
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        loadBalancerContext.EndOperation();
                    }
                }while (!mustexit);
            }
        }
        private void ExecuteOnChannel(string operationName, CodeToRunOnChannel codeBlock)
        {
            SPServiceLoadBalancerContext loadBalancerContext = _loadBalancer.BeginOperation();

            try
            {
                // get a channel to the service app endpoint
                IChannel channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress);
                try
                {
                    // execute the code block
                    codeBlock((IDayNamerContract)channel);
                    channel.Close();
                }
                catch (TimeoutException)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    throw;
                }
                catch (EndpointNotFoundException)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    throw;
                }
                finally
                {
                    if (channel.State != CommunicationState.Closed)
                    {
                        channel.Abort();
                    }
                }
            }
            finally
            {
                loadBalancerContext.EndOperation();
            }
        }
Example #3
0
 /// <summary>
 /// ExecuteOnChannel method implementation
 /// </summary>
 private void ExecuteOnSpecificChannel(string operationName, string uri, ExecuteOptions options, CodeToRunOnChannel codeBlock)
 {
     using (new SPMonitoredScope("ExecuteSpecificChannel:" + operationName))
     {
         try
         {
             string ep = FindLoadBalancerEndPoint(uri);
             if (!string.IsNullOrEmpty(ep))
             {
                 Uri      xu      = new Uri(ep);
                 IChannel channel = (IChannel)GetChannel(xu, options);
                 try
                 {
                     codeBlock((IIdentityServiceContract)channel);
                     channel.Close();
                 }
                 finally
                 {
                     if (channel.State != CommunicationState.Closed)
                     {
                         channel.Abort();
                     }
                 }
             }
         }
         finally
         {
         }
     }
 }