예제 #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);
            }
        }
예제 #2
0
        private void ExecuteOnChannel(Action <IBaristaServiceApplication> codeBlock)
        {
            var loadBalancerContext = m_loadBalancer.BeginOperation();

            try
            {
                // get a channel to the service app endpoint

                // ReSharper disable SuspiciousTypeConversion.Global
                var channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress);
                // ReSharper restore SuspiciousTypeConversion.Global

                try
                {
                    // execute the code block
                    // ReSharper disable SuspiciousTypeConversion.Global
                    codeBlock((IBaristaServiceApplication)channel);
                    // ReSharper restore SuspiciousTypeConversion.Global
                    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();
            }
        }
        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();
            }
        }
예제 #4
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);
        }
        T Execute <T>(string operationName, Func <IParagoServiceApplication, T> operation) where T : class
        {
            if (Status != SPObjectStatus.Online)
            {
                throw new ParagoServiceException("Parago Service Application Proxy is not online");
            }

            T result = null;

            using (new SPMonitoredScope("ParagoServiceApplicationProxy.Execute:" + operationName))
            {
                SPServiceLoadBalancerContext loadBalancerContext = null;

                using (new SPMonitoredScope("LoadBalancerContext:BeginOperation"))
                    loadBalancerContext = _loadBalancer.BeginOperation();

                try
                {
                    IChannel channel;

                    using (new SPMonitoredScope("GetChannel:" + loadBalancerContext.EndpointAddress))
                        channel = (IChannel)GetChannel(loadBalancerContext.EndpointAddress, ParagoServiceExecuteOptions.AsLoggedOnUser);

                    try
                    {
                        using (new SPMonitoredScope("ExecuteServiceOperation"))
                            result = operation((IParagoServiceApplication)channel);
                    }
                    finally
                    {
                        try
                        {
                            channel.Close();
                        }
                        catch (CommunicationObjectFaultedException)
                        {
                            channel.Abort();
                            throw;
                        }
                        catch (TimeoutException)
                        {
                            channel.Abort();
                            throw;
                        }
                    }
                }
                catch (FaultException <ParagoServiceFault> e)
                {
                    throw new ParagoServiceException(e.Detail);
                }
                catch (Exception)
                {
                    if (loadBalancerContext != null)
                    {
                        loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    }

                    throw;
                }
                finally
                {
                    if (loadBalancerContext != null)
                    {
                        using (new SPMonitoredScope("LoadBalancerContext:EndOperation"))
                            loadBalancerContext.EndOperation();
                    }
                }
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// This is the method that will execute the WCF service operation across the WCF channel.
        /// </summary>
        /// <param name="codeToExecute">A delegate, pointing to the method on the Service Contract interface that you want to run.</param>
        /// <param name="asProcess">Whether to run as the passed-through identity of the user (supported in claims mode), or the app pool account.</param>
        /// <typeparam name="TChannel">The type of channel.</typeparam>
        /// <remarks>
        /// This is a good place to use an SPMonitoredScope so that you can
        /// monitor execution times of your service calls.
        /// This method sets up the load balancer, and calls into the service application.
        /// If an exception occurs  during the load balancer operation, make sure to report it as a failure if it is due to a
        /// communication issue. Otherwise, if it is an exception in your application logic or execution, do not report the failure
        /// to ensure that the server is not taken out of the load balancer.
        /// </remarks>
        protected void ExecuteOnChannel <TChannel>(CodeToExecuteOnChannel <TChannel> codeToExecute, bool asProcess)
        {
            if (codeToExecute == null)
            {
                throw new ArgumentNullException("codeToExecute");
            }

            if (this.Proxy == null)
            {
                throw new EndpointNotFoundException("Could not find an endpoint because the proxy was not found.");
            }

            using (new SPMonitoredScope(string.Format(CultureInfo.InvariantCulture, "{0} - {1}", this.EndPoint, codeToExecute.Method.Name)))
            {
                SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;

                SPServiceLoadBalancer loadBalancer = this.Proxy.LoadBalancer;

                if (loadBalancer == null)
                {
                    diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
                                       "SPServiceLoadBalancerStatus.Failed:  {0}", new object[] { "No Load Balancer was available." });

                    throw new InvalidOperationException("No Load Balancer was available.");
                }


                SPServiceLoadBalancerContext loadBalancerContext = loadBalancer.BeginOperation();
                try
                {
                    using (new SPServiceContextScope(this.currentServiceContext))
                    {
                        ICommunicationObject channel = (ICommunicationObject)this.GetChannel <TChannel>(loadBalancerContext, asProcess);
                        try
                        {
                            codeToExecute((TChannel)channel);
                            channel.Close();
                        }
                        finally
                        {
                            if (channel.State != CommunicationState.Closed)
                            {
                                channel.Abort();
                            }
                        }
                    }
                }
                catch (TimeoutException ex)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;

                    diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
                                       "SPServiceLoadBalancerStatus.Failed:  {0}", new object[] { ex.Message });
                    throw;
                }
                catch (EndpointNotFoundException enfex)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
                                       "SPServiceLoadBalancerStatus.Failed:  {0}", new object[] { enfex.Message });

                    throw;
                }
                catch (ServerTooBusyException stbex)
                {
                    loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
                                       "SPServiceLoadBalancerStatus.Failed:  {0}", new object[] { stbex.Message });

                    throw;
                }
                catch (CommunicationException exception)
                {
                    if (!(exception is FaultException))
                    {
                        loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed;
                    }

                    diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable,
                                       "SPServiceLoadBalancerStatus.Failed:  {0}", new object[] { exception.Message });

                    throw;
                }
                finally
                {
                    loadBalancerContext.EndOperation();
                }
            }
        }