public ScreenSaverForm(int scrn,
                               DonePaintingDelegate donePaintingDelegate,
                               ShutDownDelegate shutDownDelegate)
        {
            InitializeComponent();
            screenNumber = scrn;
            Bounds       = Screen.AllScreens[screenNumber].Bounds;
            this.donePaintingDelegate = donePaintingDelegate;
            this.shutDownDelegate     = shutDownDelegate;

            gameOfLife = new GameOfLife(32);

            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // Name explains it.
            SetStyle(ControlStyles.Opaque, true);               // Background is taken care of by DrawImage.
            SetStyle(ControlStyles.UserPaint, true);            // if Allpainting is on, so must this.
            SetStyle(ControlStyles.DoubleBuffer, true);
            UpdateStyles();
        }
Exemple #2
0
        public void ListenToQueue(ReceivedDelegate receivedFunction, ShutDownDelegate shutdownFunction)
        {
            IModel channel = connection.CreateModel();

            channel.BasicQos(0, 1, false);

            channel.QueueDeclare(queue: queueName,
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            EventingBasicConsumer eventingBasicConsumer = new EventingBasicConsumer(channel);

            eventingBasicConsumer.Received += (sender, basicDeliveryEventArgs) =>
            {
                try
                {
                    IBasicProperties basicProperties = basicDeliveryEventArgs.BasicProperties;
                    string           body            = Encoding.UTF8.GetString(basicDeliveryEventArgs.Body.ToArray());

                    if (receivedFunction(body))
                    {
                        channel.BasicAck(basicDeliveryEventArgs.DeliveryTag, false);
                    }
                    else
                    {
                        channel.BasicNack(basicDeliveryEventArgs.DeliveryTag, false, true);
                    }
                }
                catch (Exception)
                {
                    channel.BasicNack(basicDeliveryEventArgs.DeliveryTag, false, true);
                    throw;
                }
            };

            eventingBasicConsumer.Shutdown += (sender, shutdownEventArgs) =>
            {
                shutdownFunction();
            };

            channel.BasicConsume(queueName, false, eventingBasicConsumer);
        }
Exemple #3
0
 /// <summary>
 /// Adds a shutdown delegate to be executed when the console is about to close.
 /// </summary>
 /// <param name="d">The delegate</param>
 public static void AddShutDownDelegate(ShutDownDelegate d)
 {
     // Add delegate to our shutdown delegates
     shutDownDelegates += d;
     // Also add to system shutdown/user logoff delegates
     SystemEvents.SessionEnding += (a, b) => d();
 }
        public void RunTillShutdown()
        {
            donePaintingDel = new DonePaintingDelegate(DonePainting);
            shutDownDel     = new ShutDownDelegate(ShutDown);
            screenCount     = Screen.AllScreens.Length;

            sf = new ScreenSaverForm[screenCount];
            int i = 0;

            for (i = 0; i < screenCount; i++)
            {
                sf[i] = new ScreenSaverForm(i, donePaintingDel, shutDownDel);
                sf[i].Show();
                sf[i].Draw();
            }

            while (screenCount > 0)
            {
                WaitHandle.WaitAny(manualEvents, new TimeSpan(0, 0, 0, 2), false);
                if (shuttingDown == true)
                {
                    CloseAllScreens();
                    continue;
                }

                try {
                    for (i = 0; i < Screen.AllScreens.Length; i++)
                    {
                        switch (sf[i].PaintStatus)
                        {
                        case PaintStates.ShuttingDown:
                            continue;

                        case PaintStates.PaintError:
                            IfPaintDoneResetStatuses(i);
                            Application.DoEvents();
                            sf[i].Draw();
                            break;

                        case PaintStates.OtherPaint:
                            IfPaintDoneResetStatuses(i);
                            break;

                        case PaintStates.NoActivity:
                        case PaintStates.OurPaintPending:
                        case PaintStates.PaintInProgress:
                            break;

                        case PaintStates.PaintSuccessful:
                            IfPaintDoneResetStatuses(i);
                            Application.DoEvents();
                            sf[i].Draw();
                            break;
                        }
                    }
                } catch {
                    Cursor.Show();
                    throw;
                }
            }
        }