Esempio n. 1
0
 private InterruptReason HandleInterrupt()
 {
     lock (this)
     {
         var reason = InterruptType;
         InterruptType = InterruptReason.None;
         return(reason);
     }
 }
Esempio n. 2
0
        private void Interrupt(InterruptReason reason)
        {
            if (InternalCancellationTokenSource == null)
            {
                return;
            }

            lock (this)
            {
                InterruptType = reason;
            }

            InternalCancellationTokenSource.Cancel();
        }
 public DotvvmInterruptRequestExecutionException(InterruptReason interruptReason, string customData = null)
     : base($"Request interrupted: {interruptReason} ({customData})")
 {
     InterruptReason = interruptReason;
     CustomData      = customData;
 }
Esempio n. 4
0
 public virtual void OnProcessInterrupt(ILightNodeOptions options, IDictionary <string, object> environment, InterruptReason reason, string detail)
 {
 }
 public virtual void OnProcessInterrupt(ILightNodeOptions options, HttpContext httpContext, InterruptReason reason, string detail)
 {
 }
Esempio n. 6
0
 public DotvvmInterruptRequestExecutionException(InterruptReason interruptReason, string customData = null)
 {
     InterruptReason = interruptReason;
     CustomData      = customData;
 }
 public DotvvmInterruptRequestExecutionException(InterruptReason interruptReason, string customData = null)
 {
     InterruptReason = interruptReason;
     CustomData = customData;
 }
Esempio n. 8
0
        public void Start(CancellationToken externalCancellationToken)
        {
            CancellationToken cancellationToken = ResetCancellationToken(externalCancellationToken);

            uint previousExecutionState = 0;

            try
            {
                previousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS |
                                                                               NativeMethods.ES_DISPLAY_REQUIRED |
                                                                               NativeMethods.ES_SYSTEM_REQUIRED);

                var  history         = new HistoryQueue <FileInfo>(1000);
                int? behindInHistory = null;
                bool userNavigated   = false;

                _directory = new DirectoryInfo(Settings.PictureFolder);
                RefreshFiles();

                var watcher = new FileSystemWatcher(_directory.FullName)
                {
                    IncludeSubdirectories = Settings.Recursive,
                    NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
                };

                watcher.Deleted += FilesDeleted;
                watcher.Renamed += FilesRenamed;
                watcher.Created += FilesCreated;

                watcher.EnableRaisingEvents = true;

                while (true)
                {
                    FileInfo fileInfo;
                    bool     newFile = false;

                    if (behindInHistory.HasValue)
                    {
                        if (behindInHistory.Value >= history.Count)
                        {
                            behindInHistory = history.Count - 1;
                        }

                        if (!userNavigated)
                        {
                            if (--behindInHistory < 0)
                            {
                                behindInHistory = 0;
                            }
                        }

                        fileInfo = history[history.Count - 1 - behindInHistory.Value];

                        if (behindInHistory.Value == 0)
                        {
                            behindInHistory = null;
                        }
                    }

                    else
                    {
                        newFile  = _newFiles.Count > 0;
                        fileInfo = newFile ? _newFiles.Dequeue() : GetRandomFile(_files);
                        history.Enqueue(fileInfo);
                    }

                    Image image;
                    try
                    {
                        image = ReadImage(fileInfo);
                    }
                    catch (Exception e)
                    {
                        using (EventLog eventLog = new EventLog("Application"))
                        {
                            eventLog.Source = "Application";
                            eventLog.WriteEntry(
                                $"flashair -slideshow: Unable to parse file '{fileInfo.FullName}' as image. Exception: {e}",
                                EventLogEntryType.Warning);
                        }

                        image = null; //Continuing to next image
                    }

                    if (image == null)
                    {
                        RefreshFiles(true);
                        continue;
                    }

                    DateTime imageDisplayed = DateTime.Now;
                    FireImageChosen(image, fileInfo.Name);

                    if (newFile && _newFiles.Count == 0) //If last new file, refresh list of files
                    {
                        RefreshFiles();
                    }

                    DateTime maxDisplayUntil = imageDisplayed.AddSeconds(Settings.MaximumDisplaySeconds);
                    DateTime minDisplayUntil = imageDisplayed.AddSeconds(Settings.MinimumDisplaySeconds);
                    bool     interrupted     = false;
                    bool     paused          = false;
                    while (!interrupted && (maxDisplayUntil > DateTime.Now || paused))
                    {
                        if (_newFiles.Count > 0 && minDisplayUntil < DateTime.Now)
                        {
                            break;
                        }

                        int millisecondsToSleep = Math.Min(Settings.ClockIntervalMilliseconds,
                                                           (int)Math.Ceiling((maxDisplayUntil - DateTime.Now).TotalMilliseconds));

                        bool cancelled =
                            cancellationToken.WaitHandle.WaitOne(millisecondsToSleep);

                        userNavigated = false;

                        if (cancelled)
                        {
                            InterruptReason internalInterrupt = HandleInterrupt();
                            switch (internalInterrupt)
                            {
                            case InterruptReason.None:     //The cancellation is external
                                return;

                            case InterruptReason.GoPrevious:
                                if (!behindInHistory.HasValue)
                                {
                                    behindInHistory = 0;
                                }

                                behindInHistory++;
                                userNavigated = true;
                                interrupted   = true;
                                break;

                            case InterruptReason.GoNext:
                                if (behindInHistory.HasValue)
                                {
                                    if (--behindInHistory < 0)
                                    {
                                        behindInHistory = 0;
                                    }

                                    userNavigated = true;
                                }

                                interrupted = true;
                                break;

                            case InterruptReason.PausePlay:
                                paused = !paused;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            cancellationToken = ResetCancellationToken(externalCancellationToken);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                UnhandledExceptionThrown?.Invoke(this, new UnhandledExceptionEventArgs(e, true));

                throw;
            }
            finally
            {
                NativeMethods.SetThreadExecutionState(previousExecutionState);
            }
        }
Esempio n. 9
0
 public void OnProcessInterrupt(ILightNodeOptions options, IDictionary <string, object> environment, InterruptReason reason, string detail)
 {
     MessageBroker.Publish(new InterruptMessage()
     {
         Reason = reason, Detail = detail
     });
 }
 public void OnProcessInterrupt(ILightNodeOptions options, IDictionary<string, object> environment, InterruptReason reason, string detail)
 {
     MessageBroker.Publish(new InterruptMessage() { Reason = reason, Detail = detail });
 }
Esempio n. 11
0
 public virtual void OnProcessInterrupt(ILightNodeOptions options, HttpContext httpContext, InterruptReason reason, string detail)
 {
 }
Esempio n. 12
0
 public virtual void OnProcessInterrupt(ILightNodeOptions options, IDictionary<string, object> environment, InterruptReason reason, string detail)
 {
 }