Ejemplo n.º 1
0
        public static void SubmitProcessAsync(string content)
        {
            if (!PreferenceManager.WithSendProcessReports)
            {
                return;
            }

            if (content == null)
            {
                return;
            }

            AsyncHelper.FireAndForget(() =>
            {
                try
                {
                    string request = GetRequest("ProcessReporting", content);
                    WebRequestHelper.PostRequest(SERVICE_URL, request);
                }
                catch
                {
                    // Nothing
                }
            });
        }
Ejemplo n.º 2
0
 protected static void OnDeletedFileRenamed(string strOldFilePath, string strNewFilePath)
 {
     if (DeletedFileRenamed != null)
     {
         AsyncHelper.FireAndForget(DeletedFileRenamed, new object[] { strOldFilePath, strNewFilePath });
     }
 }
Ejemplo n.º 3
0
        public static void SubmitExceptionAsync(Exception exception)
        {
            if (!PreferenceManager.WithSendErrorReports)
            {
                return;
            }

            if (exception == null)
            {
                return;
            }

            AsyncHelper.FireAndForget(() =>
            {
                try
                {
                    string request = GetRequest("ErrorReporting", exception.ToString());
                    WebRequestHelper.PostRequest(SERVICE_URL, request);
                }
                catch
                {
                    // Nothing
                }
            });
        }
Ejemplo n.º 4
0
        private async Task DisplayScreenModelAsync(IDisplayLane lane)
        {
            while (true)
            {
                foreach (var person in lane.People.ToList())
                {
                    if (lane.GetType() == typeof(KioskDisplayLane))
                    {
                        if ((DateTime.Now >= person.NextDisplayTime))
                        {
                            Debug.WriteLine($"Displaying {person} for {person.CurrentDisplayCount} in lane {lane.LaneIndex}");
                            await Animate(person, lane);

                            person.CurrentDisplayCount += 1;
                            //TODO: Refactor out RecycleCount
                            if (person.CurrentDisplayCount >= Configuration.KioskDisplayRecycleCount)
                            {
                                lane.People.Remove(person);
                            }
                        }
                        continue;
                    }
                    await Animate(person, lane);

                    var percent = lane.People.IndexOf(person).ToDouble().PercentOf(DefaultTakeCount.ToDouble());
                    if (percent >= 90)
                    {
                        AsyncHelper.FireAndForget(
                            () => lane.UpdateQueueAsync(_currentCount, DefaultTakeCount, WebServerUrl),
                            e =>
                        {
                            Console.WriteLine(@"Error updating name queue for general names");
                            Debug.WriteLine(e);
                        });
                        _currentCount += DefaultTakeCount;
                    }
                    using (Canceller.Token.Register(Thread.CurrentThread.Abort))
                    {
                        //NOTE: This is amount of time before next name displays and begins animation
                        await Task.Delay(TimeSpan.FromSeconds(lane.RotationDelay), Canceller.Token);
                    }
                }

                //TODO: If queue list is not populated continue with existing list. Notifiy issue
                if (!lane.Queue.Any())
                {
                    continue;
                }

                //NOTE: If current queue count less than DefaultTakeCount assume at end of database list and start over at beginning. Need to same position for next runtime.
                if (lane.Queue.Count < DefaultTakeCount)
                {
                    _currentCount = 0;
                }

                lane.People.Clear();
                lane.People.AddRange(lane.Queue);
                lane.Queue.Clear();
            }
        }
Ejemplo n.º 5
0
        protected virtual void OnError(OnErrorEventArgs e)
        {
            OnErrorEventHandler[] handlers = null;
            Monitor.Enter(_errorHandlers);
            try
            {
                if (_errorHandlers.Count > 0)
                {
                    handlers = new OnErrorEventHandler[_errorHandlers.Count];
                    _errorHandlers.CopyTo(handlers, 0);
                }
            }
            finally
            {
                Monitor.Exit(_errorHandlers);
            }

            if (handlers != null)
            {
                foreach (OnErrorEventHandler handler in handlers)
                {
                    if (handler != null)
                    {
                        AsyncHelper.FireAndForget(handler, this, e);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private async Task BeginRotaion()
        {
            var width = _canvas.ActualWidth;

            //Kiosk Lanes
            for (var i = 1; i < _numberOfLanes + 1; i++)
            {
                //TODO: Refactor out width
                Lanes.Add(new KioskDisplayLane(laneIndex: i, canvasWidth: width, totalLanes: _numberOfLanes));
            }

            //General Lane
            var model = new GeneralDisplayLane(Configuration.GeneralRotationDelay, width);
            await model.LoadNamesAsync(_currentCount, DefaultTakeCount, WebServerUrl); //TODO: Remove dependecy on webserverurl string

            _currentCount += DefaultTakeCount;
            Lanes.Add(model);

            //Priority Lane
            var priorityLane = new PriorityDisplayLane(Configuration.PriorityRotationDelay, width);
            await priorityLane.LoadNamesAsync(0, DefaultTakeCount, WebServerUrl); //TODO: Remove dependecy on webserverurl string

            Lanes.Add(priorityLane);

            foreach (var lane in Lanes)
            {
                AsyncHelper.FireAndForget(() => DisplayScreenModelAsync(lane), e =>
                {
                    Console.WriteLine($@"Error starting loop for lane {lane.LaneIndex}");
                    Debug.WriteLine(e);
                });
            }
        }
Ejemplo n.º 7
0
        protected virtual void OnDisposed(OnDisposedEventArgs e)
        {
            OnDisposedEventHandler[] handlers = null;
            Monitor.Enter(this);
            try
            {
                if (_handlers != null)
                {
                    handlers = new OnDisposedEventHandler[_handlers.Count];
                    _handlers.CopyTo(handlers, 0);
                    _handlers.Clear();
                }
            }
            finally
            {
                Monitor.Exit(this);
            }

            if (handlers != null)
            {
                foreach (OnDisposedEventHandler handler in handlers)
                {
                    if (handler != null)
                    {
                        AsyncHelper.FireAndForget(handler, this, e);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 protected static void OnFileDeleted(string strFilePath)
 {
     if (FileDeleted != null)
     {
         AsyncHelper.FireAndForget(FileDeleted, new object[] { strFilePath });
     }
 }
Ejemplo n.º 9
0
        public void TestFAF()
        {
            int       delay           = 100;
            Stopwatch s               = new Stopwatch();
            bool      exceptionThrown = false;
            var       waitHandle      = new AutoResetEvent(false);

            s.Start();
            AsyncHelper.FireAndForget(
                () => FAFExample(delay),
                e =>
            {
                exceptionThrown = true;
                waitHandle.Set();
            });
            s.Stop();

            // These lines will be reached immediately
            int EPSILON = 30; // millisecond margin of error

            Assert.Less(s.ElapsedMilliseconds, EPSILON);

            waitHandle.WaitOne(delay * 2 + EPSILON);
            Assert.AreEqual(true, exceptionThrown);
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     if (_healthStreamSub != null)
     {
         AsyncHelper.FireAndForget(async() => await _healthStreamSub.UnsubscribeAsync(), exception =>
         {
             _logger.Error(501, "HeroStreamService :: Error while unsubscribing hero stream", exception);
         });
     }
 }
Ejemplo n.º 11
0
        public MainViewModel()
        {
            #region [ Commands Registering ]

            this.QuitCommand = new DelegateCommand(this.Quit, this.CanExecuteQuit);
            base.RegisterCommand(this.QuitCommand);

            this.CancelCommand = new DelegateCommand(this.Cancel, this.CanExecuteCancel);
            base.RegisterCommand(this.CancelCommand);

            this.ClearLogsCommand = new DelegateCommand(this.ClearLogs, this.CanExecuteClearLogs);
            base.RegisterCommand(this.ClearLogsCommand);

            this.CopyLogsCommand = new DelegateCommand(this.CopyLogs, this.CanExecuteCopyLogs);
            base.RegisterCommand(this.CopyLogsCommand);

            this.ProcessCommand = new DelegateCommand(this.Process, this.CanExecuteProcess);
            base.RegisterCommand(this.ProcessCommand);

            this.GenerateTranslationsCommand = new DelegateCommand(this.GenerateTranslations, this.CanExecuteGenerateTranslations);
            base.RegisterCommand(this.GenerateTranslationsCommand);

            this.GenerateCodeRefsCommand = new DelegateCommand(this.GenerateCodeRefs, this.CanExecuteGenerateCodeRefs);
            base.RegisterCommand(this.GenerateCodeRefsCommand);

            this.ShowExcludedTablesCommand = new DelegateCommand(this.ShowExcludedTables, this.CanExecuteShowExcludedTables);
            base.RegisterCommand(this.ShowExcludedTablesCommand);

            #endregion

            #region [ IHM Initialization ]

            this.SwitchTableSelectionMode = true;

            this.WithSqlProcedureIntegration = true;
            this.WithBusinessIntegration     = true;

            this.SetCompilationModes();

            #endregion

            #region [ Process Initialization ]

            _processor = new Processor();

            _processor.OnProcessMessage     += OnProcessorProcessMessage;
            _processor.OnProcessProgression += OnProcessorProcessProgression;

            #endregion

            AsyncHelper.FireAndForget(() => this.Initialize());

            this.CheckUpdateAsync();
        }
Ejemplo n.º 12
0
        public void Log(string message)
        {
            try
            {
                WebRequest        request = WebRequest.Create(_loggingPartialUrl + _userRef + "/" + message);
                WebResponseGetter getter  = new WebResponseGetter(request.GetResponse);

                AsyncHelper.FireAndForget(getter, null);
            }
            catch
            {
                // suppress all errors
            }
        }
Ejemplo n.º 13
0
        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            await InitConfiguration();
            await InitDisplay();
            await InitAudioSettings();
            await InitConnectionManager();

            if (_debugMode)
            {
                AddLines();
            }

            AsyncHelper.FireAndForget(BeginRotaion);
        }
Ejemplo n.º 14
0
        public void WriteMessage(MessageBase objMessage)
        {
            if (objMessage == null)
            {
                throw new ArgumentNullException("objMessage", "A valid non-null MessageBase is required.");
            }

            bool blnIsMessageTypeAllowed = IsMessageTypeAllowed(objMessage);

            if (blnIsMessageTypeAllowed == true)
            {
                WriteMessageToLogsDelegate objWriteMessageToLogs = new WriteMessageToLogsDelegate(WriteMessageToLogs);
                AsyncHelper.FireAndForget(objWriteMessageToLogs, objMessage);
            }
        }
Ejemplo n.º 15
0
    public static void FireAsync(Delegate del, params object[] args)
    {
        if (del == null)
        {
            return;
        }
        Delegate[] delegates = del.GetInvocationList();
        AsyncFire  asyncFire;

        foreach (Delegate sink in delegates)
        {
            asyncFire = new AsyncFire(InvokeDelegate);
            AsyncHelper.FireAndForget(asyncFire, sink, args);
        }
    }
Ejemplo n.º 16
0
        //The interceptor will log the beginning and end of the method call.
        public void Intercept(IInvocation invocation)
        {
            if (!invocation.Method.Name.StartsWith("Get", System.StringComparison.Ordinal))
            {
                //This happens before the method call
                AsyncHelper.FireAndForget(new AsyncHelper.LogDelegate(LogParameter), "Calling method {0} with parameters {1}", invocation);
            }

            //Actual method call begins
            invocation.Proceed();

            if (!invocation.Method.Name.StartsWith("Get", System.StringComparison.Ordinal))
            {
                AsyncHelper.FireAndForget(new AsyncHelper.LogDelegate(AsyncHelper.PerformLog), "Done: result was {0}.", invocation.ReturnValue);
            }
        }
Ejemplo n.º 17
0
        public void Send(MailMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (!CollectionHelper.IsNullOrEmpty(Recipients))
            {
                EnumerableHelper.ForEach(Recipients, to =>
                {
                    if (!string.IsNullOrEmpty(to))
                    {
                        message.To.Add(to);
                    }
                });
            }

            if (CollectionHelper.IsNullOrEmpty(message.To))
            {
                throw new ArgumentException("No recipient specified");
            }

            if (!CollectionHelper.IsNullOrEmpty(CarbonCopies))
            {
                EnumerableHelper.ForEach(CarbonCopies, cc =>
                {
                    if (!string.IsNullOrEmpty(cc))
                    {
                        message.CC.Add(cc);
                    }
                });
            }

            if (!CollectionHelper.IsNullOrEmpty(BlindCarbonCopies))
            {
                EnumerableHelper.ForEach(BlindCarbonCopies, bcc =>
                {
                    if (!string.IsNullOrEmpty(bcc))
                    {
                        message.Bcc.Add(bcc);
                    }
                });
            }

            AsyncHelper.FireAndForget(SendAsync, message);
        }
Ejemplo n.º 18
0
        protected void OnItemRemovedEvent(object objSender, ItemRemovedEventArgs <TObjectType> objArguments)
        {
            if (Initializing == false)
            {
                ItemRemovedEventHandler <TObjectType> objHandler = ItemRemovedEventAsync;
                if (objHandler != null)
                {
                    AsyncHelper.FireAndForget(objHandler, objSender, objArguments);
                }

                objHandler = ItemRemovedEvent;
                if (objHandler != null)
                {
                    objHandler(objSender, objArguments);
                }
            }
        }
Ejemplo n.º 19
0
 public virtual void Fill(IResultSet <TKey, TValue> results)
 {
     ExceptionHelper.ThrowIfArgumentNull(results, "results");
     Monitor.Enter(_syncLock);
     try
     {
         _updateRequests.Enqueue(results);
         if (!_updateInProgress)
         {
             _updateInProgress = true;
             AsyncHelper.FireAndForget(new ObjectPoolDelegate(ProcessUpdates), null);
         }
     }
     finally
     {
         Monitor.Exit(_syncLock);
     }
 }
Ejemplo n.º 20
0
        private void CheckUpdateAsync()
        {
            if (!PreferenceManager.WithCheckAutomaticUpdates)
            {
                return;
            }

            AsyncHelper.FireAndForget(() =>
            {
                string date, version;
                bool updateReleased = ServiceManager.CheckUpdate(out date, out version);

                if (updateReleased)
                {
                    this.CanBeUpdated  = true;
                    this.UpdateVersion = string.Format("v{0} released!", version);
                }
            });
        }
Ejemplo n.º 21
0
        public static void FireAndForget_SingleArgument()
        {
            // Arrange
            var waitHandle     = new AutoResetEvent(false);
            var threadId       = Thread.CurrentThread.ManagedThreadId;
            var actionThreadId = -1;

            // Act
            AsyncHelper.FireAndForget(arg =>
            {
                Assert.Equal(100, arg);
                actionThreadId = Thread.CurrentThread.ManagedThreadId;
                waitHandle.Set();
            }, 100);
            var result = waitHandle.WaitOne(500);

            // Assert
            Assert.True(result);
            Assert.NotEqual(-1, actionThreadId);
            Assert.NotEqual(threadId, actionThreadId);
        }
Ejemplo n.º 22
0
 public object Invoke(Delegate @delegate, params object[] args)
 {
     AsyncHelper.FireAndForget(@delegate, args);
     return(null);
 }
Ejemplo n.º 23
0
 public static void OnError(string message)
 {
     AsyncHelper.FireAndForget(() => OnErrorAsync(message));
 }
Ejemplo n.º 24
0
 public static void DownloadGravatar_Begin(string gravatarID, int size, string targetFolderPath)
 {
     AsyncHelper.FireAndForget(delegate {
         DownloadGravatar(gravatarID, size, targetFolderPath);
     });
 }