private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            foreach (var message in args.Messages)
            {
                message.Seen = true;
                OutageMailMessage outageMessage = _mapper.MapMail(message);
                Console.WriteLine(outageMessage);

                OutageTracingModel tracingModel = _parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    _dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    _publisher.Publish(
                        publication: new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)),
                        publisherName: "ImapIdleEmailClient"
                        );
                }
                catch (Exception)
                {
                    Console.WriteLine("[ImapIdleEmailClient::OnMessageArrived] Sending to PubSub Engine failed.");
                }
            }

            ReregisterIdleHandler();
        }
Пример #2
0
        private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            foreach (var message in args.Messages)
            {
                message.Seen = true;
                OutageMailMessage outageMessage = mapper.MapMail(message);
                Console.WriteLine(outageMessage);

                OutageTracingModel tracingModel = parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"[ImapIdleEmailClient::OnMessageArrived] Sending to PubSub Engine failed. Exception message: {e.Message}");
                }
            }

            ReregisterIdleHandler();
        }
Пример #3
0
 /// <summary>
 ///  Helper function used to fire idle events.
 /// </summary>
 /// <param name="e">The idle event arguments.</param>
 /// <param name="clearOnly">Only clear the action, don't fire the event.</param>
 private void OnIdle(IdleEventArgs e, bool clearOnly)
 {
     if (!clearOnly && Idle != null)
     {
         Idle(this, e);
     }
 }
Пример #4
0
 void Channel_Idle(object sender, IdleEventArgs e)
 {
     if (_channelDoEvents)
     {
         Application.DoEvents();
     }
 }
Пример #5
0
        void Channel_Idle(object sender, IdleEventArgs e)
        {
            // e.bDoEvents = this._doEvents;

            // 2016/1/26
            if (this._doEvents)
            {
                Application.DoEvents();
            }
        }
Пример #6
0
        void biblio_paths_Idle(object sender, IdleEventArgs e)
        {
            this._app_down.Token.ThrowIfCancellationRequested();
#if NO
            if (this.m_bClosed == true || this.Stopped == true)
            {
                throw new InterruptException("中断");
            }
#endif
        }
Пример #7
0
        //EVENT System idle timer - On idle end
        public void SystemIdleTimer1_OnExitIdleState(Object sender, IdleEventArgs e)
        {
            logging.WriteToLog("SystemIdleTimer1_OnExitIdleState triggered!");

            if (activeHour)
            {
                logging.WriteToLog("Active hour and system has come out of idle period of " + idleTime + " seconds. Triggering toast to user!");
                BalloonTip("TEST IDLE!!", "Come out of idle state of " + idleTime, balloonTipTime, true);
                //Need to mark as triggered for that hour and day so hours might need to be their own class
            }
        }
Пример #8
0
 void SampleCarnivore_Idle(object sender, IdleEventArgs e)
 {
     try
     {
         if (CanReproduce)
         {
             BeginReproduction(null);
         }
         if (CanEat && !IsEating)
         {
             if (_targetAnimal != null)
             {
                 if (WithinEatingRange(_targetAnimal))
                 {
                     BeginEating(_targetAnimal);
                     if (IsMoving)
                     {
                         StopMoving();
                     }
                 }
                 else
                 {
                     if (!IsMoving)
                     {
                         BeginMoving(new MovementVector(_targetAnimal.Position, 2));
                     }
                 }
             }
             else
             {
                 if (!ScanForTargetAnimal())
                 {
                     if (!IsMoving)
                     {
                         int randomX = OrganismRandom.Next(0, WorldWidth - 1);
                         int randomY = OrganismRandom.Next(0, WorldHeight - 1);
                         BeginMoving(new MovementVector(new Point(randomX, randomY), 2));
                     }
                 }
             }
         }
         else
         {
             if (IsMoving)
             {
                 StopMoving();
             }
         }
     }
     catch (Exception exc)
     {
         WriteTrace(exc.ToString());
     }
 }
Пример #9
0
    void channel_Idle(object sender, IdleEventArgs e)
    {
        bool bConnected = this.Response.IsClientConnected;

        if (bConnected == false)
        {
            LibraryChannel channel = (LibraryChannel)sender;
            channel.Abort();
        }

        // e.bDoEvents = false;
    }
Пример #10
0
 void SampleCarnivore_Idle(object sender, IdleEventArgs e)
 {
     try
     {
         if (CanReproduce)
         {
             BeginReproduction(null);
         }
         if (CanEat && !IsEating)
         {
             if (_targetAnimal != null)
             {
                 if (WithinEatingRange(_targetAnimal))
                 {
                     BeginEating(_targetAnimal);
                     if (IsMoving)
                         StopMoving();
                 }
                 else
                 {
                     if (!IsMoving)
                         BeginMoving(new MovementVector(_targetAnimal.Position, 2));
                 }
             }
             else
             {
                 if (!ScanForTargetAnimal())
                 {
                     if (!IsMoving)
                     {
                         int randomX = OrganismRandom.Next(0, WorldWidth - 1);
                         int randomY = OrganismRandom.Next(0, WorldHeight - 1);
                         BeginMoving(new MovementVector(new Point(randomX, randomY), 2));
                     }
                 }
             }
         }
         else
         {
             if (IsMoving)
                 StopMoving();
         }
     }
     catch (Exception exc)
     {
         WriteTrace(exc.ToString());
     }
 }
        private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            try
            {
                foreach (var message in args.Messages)
                {
                    message.Seen = true;
                    OutageMailMessage outageMessage = mapper.MapMail(message);
                    Logger.LogInformation($"{baseLogString} OnMessageArrived => Message: {outageMessage}");

                    OutageTracingModel tracingModel = parser.Parse(outageMessage);

                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }

                ReregisterIdleHandler();
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} OnMessageArrived => Exception: {e.Message}", e);
            }
        }
Пример #12
0
        private void Inbox_OnNewMessagesArrived(object sender, IdleEventArgs e)
        {
            foreach (var message in e.Messages.OrderByDescending(m => m.Date ?? DateTime.Now))
            {
                var date       = message.Date ?? DateTime.Now;
                var from       = message.From.Address;
                var msgSubject = message.Subject;
                var msgBody    = message.Body.Text;

                var processedMessage = _messageProcessor.Process(date, from, msgSubject, msgBody);

                _meterReadingMessages.Insert(0, processedMessage);

                _appEntitiesRepo.Insert(processedMessage);

                if (!string.IsNullOrEmpty(processedMessage.FlatNumber))
                {
                    _appEntitiesRepo.Upsert(new SenderFlat {
                        Sender = processedMessage.SenderAddress, FlatNumber = processedMessage.FlatNumber
                    });
                }
            }
        }
Пример #13
0
        // Fired after all other events are fired during a turn
        void IdleEvent(object sender, IdleEventArgs e)
        {
            try
            {
                // Our Creature will reproduce as often as possible so
                // every turn it checks CanReproduce to know when it
                // is capable.  If so we call BeginReproduction with
                // a null Dna parameter to being reproduction.
                if (CanReproduce)
                {
                    BeginReproduction(null);
                }

                // Check to see if we are capable of eating
                // If we are then try to eat or find food,
                // else we'll just stop moving.
                if (CanEat && !IsEating)
                {
                    // If we have a Target Plant we can try
                    // to either eat it, or move towards it.
                    // else we'll move to a random vector
                    // in search of a plant.
                    if (targetPlant != null)
                    {
                        // If we are within range start eating
                        // and stop moving.  Else we'll try
                        // to move towards the plant.
                        if (WithinEatingRange(targetPlant))
                        {
                            BeginEating(targetPlant);
                            if (IsMoving)
                            {
                                StopMoving();
                            }
                        }
                        else
                        {
                            if (!IsMoving)
                            {
                                BeginMoving(new MovementVector(targetPlant.Position, 2));
                            }
                        }
                    }
                    else
                    {
                        // We'll try try to find a target plant
                        // If we don't find one we'll move to
                        // a random vector
                        if (!ScanForTargetPlant())
                        {
                            if (!IsMoving)
                            {
                                int RandomX = OrganismRandom.Next(0, WorldWidth - 1);
                                int RandomY = OrganismRandom.Next(0, WorldHeight - 1);
                                BeginMoving(new MovementVector(new Point(RandomX, RandomY), 2));
                            }
                        }
                    }
                }
                else
                {
                    // Since we are Full or we are already eating
                    // We should stop moving.
                    if (IsMoving)
                    {
                        StopMoving();
                    }
                }
            }
            catch (Exception exc)
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #14
0
 /// <summary>
 ///  Helper function used to fire idle events.
 /// </summary>
 /// <param name="e">The idle event arguments.</param>
 /// <param name="clearOnly">Only clear the action, don't fire the event.</param>
 private void OnIdle(IdleEventArgs e, bool clearOnly)
 {
     if (!clearOnly && Idle != null)
     {
         Idle(this, e);
     }
 }
Пример #15
0
        // Fired after all other events are fired during a turn
        void IdleEvent(object sender, IdleEventArgs e)
        {
            try
            {
                // Our Creature will reproduce as often as possible so
                // every turn it checks CanReproduce to know when it
                // is capable.  If so we call BeginReproduction with
                // a null Dna parameter to being reproduction.
                if (CanReproduce)
                {
                    BeginReproduction(null);
                }

                // If we are already doing something, then we don't
                // need to do something else.  Lets leave the
                // function.
                if (IsAttacking || IsMoving || IsEating)
                {
                    return;
                }

                // Try to find a new target if we need one.
                if (targetAnimal == null)
                {
                    FindNewTarget();
                }

                // If we have a target animal then lets check him out
                if (targetAnimal != null)
                {
                    // If the target is alive, then we need to kill it
                    // else we can immediately eat it.
                    if (targetAnimal.IsAlive)
                    {
                        // If we are within attacking range, then
                        // lets eat the creature.  Else we'll
                        // try to move into range
                        if (WithinAttackingRange(targetAnimal))
                        {
                            BeginAttacking(targetAnimal);
                        }
                        else
                        {
                            MoveToTarget();
                        }
                    }
                    else
                    {
                        // If the creature is dead then we can try to eat it.
                        // If we are within eating range then we'll try to
                        // eat the creature, else we'll move towards it.
                        if (WithinEatingRange(targetAnimal))
                        {
                            if (CanEat)
                            {
                                BeginEating(targetAnimal);
                            }
                        }
                        else
                        {
                            MoveToTarget();
                        }
                    }
                }
                else
                {
                    // If we stop moving we conserve energy.  Sometimes
                    // this works better than running around.
                    StopMoving();
                }
            }
            catch (Exception exc)
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #16
0
 private static void Inbox_OnNewMessagesArrived(object sender, IdleEventArgs e)
 {
     // Show a dialog
     MessageBox.Show($"A new message was downloaded in {e.Folder.Name} folder.");
 }
Пример #17
0
 void channel_Idle(object sender, IdleEventArgs e)
 {
     Application.DoEvents();
 }
Пример #18
0
 void biblio_paths_Idle(object sender, IdleEventArgs e)
 {
     if (this.m_bClosed == true || this.Stopped == true)
     {
         throw new InterruptException("中断");
     }
 }
Пример #19
0
        void channel_Idle(object sender, IdleEventArgs e)
        {
            if (this.m_bClosed == true || this.Stopped == true)
            {
                LibraryChannel channel = (LibraryChannel)sender;
                channel.Abort();
            }

            // e.bDoEvents = false;

            // System.Threading.Thread.Sleep(100);	// 避免CPU资源过度耗费
        }
Пример #20
0
        // Fired after all other events are fired during a turn
        private void IdleEvent(object sender, IdleEventArgs e)
        {
            try
            {
                // Our Creature will reproduce as often as possible so
                // every turn it checks CanReproduce to know when it
                // is capable.  If so we call BeginReproduction with
                // a null Dna parameter to being reproduction.
                if (CanReproduce)
                    BeginReproduction(null);

                // Check to see if we are capable of eating
                // If we are then try to eat or find food,
                // else we'll just stop moving.
                if (CanEat && !IsEating)
                {
                    // If we have a Target Plant we can try
                    // to either eat it, or move towards it.
                    // else we'll move to a random vector
                    // in search of a plant.
                    if (targetPlant != null)
                    {
                        // If we are within range start eating
                        // and stop moving.  Else we'll try
                        // to move towards the plant.
                        if (WithinEatingRange(targetPlant))
                        {
                            BeginEating(targetPlant);
                            if (IsMoving)
                                StopMoving();
                        }
                        else
                        {
                            if (!IsMoving)
                                BeginMoving(new MovementVector(targetPlant.Position, 2));
                        }
                    }
                    else
                    {
                        // We'll try try to find a target plant
                        // If we don't find one we'll move to
                        // a random vector
                        if (!ScanForTargetPlant())
                        {
                            if (!IsMoving)
                            {
                                int RandomX = OrganismRandom.Next(0, WorldWidth - 1);
                                int RandomY = OrganismRandom.Next(0, WorldHeight - 1);
                                BeginMoving(new MovementVector(new Point(RandomX, RandomY), 2));
                            }
                        }
                    }
                }
                else
                {
                    // Since we are Full or we are already eating
                    // We should stop moving.
                    if (IsMoving)
                        StopMoving();
                }
            }
            catch (Exception exc)
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #21
0
        // Fired after all other events are fired during a turn
        void IdleEvent(object sender, IdleEventArgs e) 
        {
            try 
            {
                // Our Creature will reproduce as often as possible so
                // every turn it checks CanReproduce to know when it
                // is capable.  If so we call BeginReproduction with
                // a null Dna parameter to being reproduction.
                if(CanReproduce)
                    BeginReproduction(null);

                // If we are already doing something, then we don't
                // need to do something else.  Lets leave the
                // function.
                if ( IsAttacking || IsMoving || IsEating ) 
                {
                    return;
                }

                // Try to find a new target if we need one.
                if(targetAnimal == null) 
                {
                    FindNewTarget();
                } 

                // If we have a target animal then lets check him out
                if(targetAnimal != null ) 
                {
                    // If the target is alive, then we need to kill it
                    // else we can immediately eat it.
                    if ( targetAnimal.IsAlive ) 
                    {
                        // If we are within attacking range, then
                        // lets eat the creature.  Else we'll
                        // try to move into range
                        if ( WithinAttackingRange(targetAnimal) ) 
                        {
                            BeginAttacking(targetAnimal);
                        } 
                        else 
                        {
                            MoveToTarget();
                        }
                    } 
                    else 
                    {
                        // If the creature is dead then we can try to eat it.
                        // If we are within eating range then we'll try to
                        // eat the creature, else we'll move towards it.
                        if ( WithinEatingRange(targetAnimal) ) 
                        {
                            if (CanEat) 
                            {
                                BeginEating(targetAnimal);
                            } 
                        } 
                        else 
                        {
                            MoveToTarget();
                        }
                    }
                } 
                else 
                {
                    // If we stop moving we conserve energy.  Sometimes
                    // this works better than running around.
                    StopMoving();
                }
            } 
            catch(Exception exc) 
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #22
0
        // Fired after all other events are fired during a turn
        private void MyAnimal_Idle(object sender, IdleEventArgs e)
        {
            try
            {
                // Reproduce as often as possible
                if (CanReproduce)
                {
                    BeginReproduction(null);
                }

                // If we can eat and we have a target plant, eat
                if (CanEat)
                {
                    WriteTrace("Hungry.");
                    if (!IsEating)
                    {
                        WriteTrace("Not eating: Have target plant?");
                        if (targetPlant != null)
                        {
                            WriteTrace("Yes, Have target plant already.");
                            if (WithinEatingRange(targetPlant))
                            {
                                WriteTrace("Within Range, Start eating.");
                                BeginEating(targetPlant);
                                if (IsMoving)
                                {
                                    WriteTrace("Stop while eating.");
                                    StopMoving();
                                }
                            }
                            else
                            {
                                if (!IsMoving)
                                {
                                    WriteTrace("Move to Target Plant");
                                    BeginMoving(new MovementVector(targetPlant.Position, 2));
                                }
                            }
                        }
                        else
                        {
                            WriteTrace("Don't have target plant.");
                            if (!ScanForTargetPlant())
                            {
                                if (!IsMoving)
                                {
                                    WriteTrace("No plant found, so pick a random point and move there");

                                    int RandomX = OrganismRandom.Next(0, WorldWidth - 1);
                                    int RandomY = OrganismRandom.Next(0, WorldHeight - 1);

                                    BeginMoving(new MovementVector(new Point(RandomX, RandomY), 2));
                                }
                                else
                                {
                                    WriteTrace("Moving and Looking...");
                                }
                            }
                        }
                    }
                    else
                    {
                        WriteTrace("Eating.");
                        if (IsMoving)
                        {
                            WriteTrace("Stop moving while eating.");
                            StopMoving();
                        }
                    }
                }
                else
                {
                    WriteTrace("Full: do nothing.");
                    if (IsMoving)
                    {
                        StopMoving();
                    }
                }
            }
            catch (Exception exc)
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #23
0
        void biblio_paths_Idle(object sender, IdleEventArgs e)
        {
            this._app_down.Token.ThrowIfCancellationRequested();
#if NO
            if (this.m_bClosed == true || this.Stopped == true)
            {
                throw new InterruptException("中断");
            }
#endif
        }
Пример #24
0
        // Fired after all other events are fired during a turn
        private void MyAnimal_Idle(object sender, IdleEventArgs e)
        {
            try
            {
                // Reproduce as often as possible
                if (CanReproduce)
                    BeginReproduction(null);

                // If we can eat and we have a target plant, eat
                if (CanEat)
                {
                    WriteTrace("Hungry.");
                    if (!IsEating)
                    {
                        WriteTrace("Not eating: Have target plant?");
                        if (targetPlant != null)
                        {
                            WriteTrace("Yes, Have target plant already.");
                            if (WithinEatingRange(targetPlant))
                            {
                                WriteTrace("Within Range, Start eating.");
                                BeginEating(targetPlant);
                                if (IsMoving)
                                {
                                    WriteTrace("Stop while eating.");
                                    StopMoving();
                                }
                            }
                            else
                            {
                                if (!IsMoving)
                                {
                                    WriteTrace("Move to Target Plant");
                                    BeginMoving(new MovementVector(targetPlant.Position, 2));
                                }
                            }
                        }
                        else
                        {
                            WriteTrace("Don't have target plant.");
                            if (!ScanForTargetPlant())
                                if (!IsMoving)
                                {
                                    WriteTrace("No plant found, so pick a random point and move there");

                                    int RandomX = OrganismRandom.Next(0, WorldWidth - 1);
                                    int RandomY = OrganismRandom.Next(0, WorldHeight - 1);

                                    BeginMoving(new MovementVector(new Point(RandomX, RandomY), 2));
                                }
                                else
                                {
                                    WriteTrace("Moving and Looking...");
                                }
                        }
                    }
                    else
                    {
                        WriteTrace("Eating.");
                        if (IsMoving)
                        {
                            WriteTrace("Stop moving while eating.");
                            StopMoving();
                        }
                    }
                }
                else
                {
                    WriteTrace("Full: do nothing.");
                    if (IsMoving)
                        StopMoving();
                }

                ShouldIMoveForMyFriend();
            }
            catch (Exception exc)
            {
                WriteTrace(exc.ToString());
            }
        }
Пример #25
0
 //EVENT System idle timer - On idle timeout met
 public void SystemIdleTimer1_OnEnterIdleState(Object sender, IdleEventArgs e)
 {
     logging.WriteToLog("SystemIdleTimer1_OnEnterIdleState triggered!");
 }