/// <summary> /// /// </summary> /// <param name="channelRef"></param> private static void StopTimer(ChannelRefInfo channelRef) { if (_dictionary.ContainsKey(channelRef.GetKey())) { StartedChannelTimer timer = _dictionary[channelRef.GetKey()]; if (timer != null) { timer.Timer.ClearJobs(); timer.Timer.Stop(); timer.Timer.Dispose(); lock (_dictionary) _dictionary.Remove(channelRef.GetKey()); } } }
/// <summary> /// /// </summary> /// <param name="channelRef"></param> private static void StartTimer(ChannelRefInfo channelRef) { // Creazione timer Schedule.ScheduleTimer timer = new Schedule.ScheduleTimer(); timer.Error += new Schedule.ExceptionEventHandler(OnScheduleError); if (channelRef.ExecutionConfiguration.IntervalType != JobExecutionConfigurations.IntervalTypesEnum.Block) { long ticks; long.TryParse(channelRef.ExecutionConfiguration.ExecutionTicks, out ticks); Schedule.ScheduledTime interval = new Schedule.ScheduledTime( (Schedule.EventTimeBase)Enum.Parse(typeof(Schedule.EventTimeBase), channelRef.ExecutionConfiguration.IntervalType.ToString(), true), TimeSpan.FromTicks(ticks)); timer.AddJob(interval, new Schedule.ScheduledEventHandler(Publish), channelRef); } else { string[] spans = channelRef.ExecutionConfiguration.ExecutionTicks.Split('|'); string strIntervalBase = string.Empty; string strStartTime = string.Empty; string strStopTime = string.Empty; if (spans.Length > 0) { strIntervalBase = spans[0]; } if (spans.Length > 1) { strStartTime = spans[1]; } if (spans.Length > 2) { strStopTime = spans[2]; } long intervalBase; long.TryParse(strIntervalBase, out intervalBase); long startTime; long.TryParse(strStartTime, out startTime); long stopTime; long.TryParse(strStopTime, out stopTime); Schedule.BlockWrapper interval = new Schedule.BlockWrapper( new Schedule.SimpleInterval(DateTime.Parse("01/01/2000"), TimeSpan.FromTicks(intervalBase)), "Daily", new DateTime(startTime).ToString(), new DateTime(stopTime).ToString()); timer.AddJob(interval, new Schedule.ScheduledEventHandler(Publish), channelRef); } // Avvio timer timer.Start(); // Creazione entry StartedChannelTimer entry = new StartedChannelTimer { Timer = timer, StartExecutionDate = channelRef.StartExecutionDate, MachineName = channelRef.MachineName, PublisherServiceUrl = channelRef.PublisherServiceUrl }; lock (_dictionary) _dictionary.Add(channelRef.GetKey(), entry); }
/// <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"); }