Example #1
0
        /// <summary>
        /// Aggiornamento stato del canale di pubblicazione
        /// </summary>
        /// <param name="channelRef"></param>
        public static void RefreshChannelState(ChannelRefInfo channelRef)
        {
            //DocsPaUtils.LogsManagement.Debugger.Write("RefreshChannelState - BEGIN");

            try
            {
                if (IsChannelStartedOnRemoteMachine(channelRef))
                {
                    //DocsPaUtils.LogsManagement.Debugger.Write("RefreshChannelState - remote");

                    // Il canale di pubblicazione risulta avviato su un server remoto

                    // Creazione istanza del servizio di pubblicazione remoto
                    using (Publisher.Proxy.PublisherWebService realWs = CreatePublisherInstance(channelRef.PublisherServiceUrl))
                    {
                        Publisher.Proxy.ChannelRefInfo remoteChannel = null;

                        try
                        {
                            // Reperimento dei metadati del canale di pubblicazione
                            remoteChannel = realWs.GetChannel(channelRef.Id);
                        }
                        catch (PublisherException pubEx)
                        {
                            //DocsPaUtils.LogsManagement.Debugger.Write(pubEx);

                            throw pubEx;
                        }
                        catch (Exception ex)
                        {
                            //DocsPaUtils.LogsManagement.Debugger.Write(ex);

                            // Si è verificato un errore nell'esecuzione del servizio di pubblicazione remoto
                            remoteChannel = null;

                            channelRef.State = ChannelStateEnum.UnexpectedStopped;
                        }

                        if (remoteChannel != null)
                        {
                            // Aggiornamento dello stato del canale di pubblicazione
                            if (remoteChannel.State == Proxy.ChannelStateEnum.Started)
                            {
                                channelRef.State = ChannelStateEnum.Started;
                            }
                            else if (remoteChannel.State == Proxy.ChannelStateEnum.Stopped)
                            {
                                channelRef.State = ChannelStateEnum.Stopped;
                            }
                            else if (remoteChannel.State == Proxy.ChannelStateEnum.UnexpectedStopped)
                            {
                                channelRef.State = ChannelStateEnum.UnexpectedStopped;
                            }

                            channelRef.StartExecutionDate  = remoteChannel.StartExecutionDate;
                            channelRef.EndExecutionDate    = remoteChannel.EndExecutionDate;
                            channelRef.MachineName         = remoteChannel.MachineName;
                            channelRef.PublisherServiceUrl = remoteChannel.PublisherServiceUrl;
                        }
                    }
                }
                else
                {
                    StartedChannelTimer timer = GetTimer(channelRef.GetKey());

                    if (timer == null)
                    {
                        if (channelRef.State == ChannelStateEnum.Started &&
                            channelRef.MachineName == ApplicationContext.GetMachineName())
                        {
                            // Se il servizio risulta avviato nella base dati
                            // ma non risulta essere presente nella memoria del server,
                            // significa che è stato fermato in modo non previsto
                            // (es. il server è giù). Pertanto lo stato del servizio viene
                            // impostato a "UnexpectedStopped".
                            channelRef.State = ChannelStateEnum.UnexpectedStopped;
                        }
                    }
                    else
                    {
                        // Il timer è presente: aggiornamento dello stato del canale
                        channelRef.State = ChannelStateEnum.Started;
                        channelRef.StartExecutionDate  = timer.StartExecutionDate;
                        channelRef.EndExecutionDate    = DateTime.MinValue;
                        channelRef.MachineName         = timer.MachineName;
                        channelRef.PublisherServiceUrl = timer.PublisherServiceUrl;
                    }
                }
            }
            catch (Exception ex)
            {
                //DocsPaUtils.LogsManagement.Debugger.Write(ex);
                logger.Error(ex);
                throw new PublisherException(ErrorCodes.UNHANDLED_ERROR, ex.Message);
            }

            //DocsPaUtils.LogsManagement.Debugger.Write("RefreshChannelState - END");
        }
Example #2
0
        /// <summary>
        /// Sospende l'esecuzione di un canale di pubblicazione
        /// </summary>
        /// <param name="channelRef"></param>
        public static void StopChannel(ChannelRefInfo channelRef)
        {
            //DocsPaUtils.LogsManagement.Debugger.Write("StopChannel - INIT");

            // Aggiornamento stato del canale
            RefreshChannelState(channelRef);

            if (channelRef.State == ChannelStateEnum.Started ||
                channelRef.State == ChannelStateEnum.UnexpectedStopped)
            {
                // Il canale di pubblicazione risulta avviato su un server diverso da quello attuale
                if (string.Compare(channelRef.MachineName, ApplicationContext.GetMachineName(), false) != 0)
                {
                    // Si sta tentando di fermare un canale di pubblicazione avviato da un altro computer.
                    // Viene richiamato il servizio di pubblicazione da cui è stato avviato per fermarne correttamente lo stato.
                    using (Publisher.Proxy.PublisherWebService realWs = CreatePublisherInstance(channelRef.PublisherServiceUrl))
                    {
                        try
                        {
                            // Fermo del canale nel server di pubblicazione in cui risulta avviato
                            realWs.StopChannelById(channelRef.Id);
                        }
                        catch (PublisherException pubEx)
                        {
                            throw pubEx;
                        }
                        catch (Exception ex)
                        {
                            //DocsPaUtils.LogsManagement.Debugger.Write(ex);

                            // Si è verificato un errore, il server remoto di pubblicazione non risulta raggiungibile,
                            // pertanto viene forzato lo stato di fermo del servizio sul database
                            using (DocsPaDB.TransactionContext tx = new DocsPaDB.TransactionContext())
                            {
                                channelRef = DataAccess.PublisherDataAdapter.StopService(channelRef);

                                tx.Complete();
                            }

                            //throw new PublisherException(ErrorCodes.STOP_CHANNEL_ON_REMOTE_SERVER_ERROR,
                            //                            string.Format(ErrorDescriptions.STOP_CHANNEL_ON_REMOTE_SERVER_ERROR, ex.ToString()));
                        }
                    }
                }
                else
                {
                    using (DocsPaDB.TransactionContext tx = new DocsPaDB.TransactionContext())
                    {
                        // Impostazione dello stato di fermo del servizio
                        channelRef = DataAccess.PublisherDataAdapter.StopService(channelRef);

                        StopTimer(channelRef);

                        tx.Complete();
                    }
                }
            }
            else
            {
                // L'istanza risulta già fermata
                throw new PublisherException(ErrorCodes.OPERATION_NOT_ALLOWED_PER_SERVICE_STOPPED, ErrorDescriptions.OPERATION_NOT_ALLOWED_PER_SERVICE_STARTED);
            }

            //DocsPaUtils.LogsManagement.Debugger.Write("StopChannel - END");
        }