Exemple #1
0
        public bool OnConfirmEx(IntPtr title, IntPtr text, DialogButtonFlags flags,
                                IntPtr title0, IntPtr title1, IntPtr title2,
                                IntPtr chkMsg, ref bool chkState, out Int32 retVal)
        {
#if debug
            OnGeneric("OnConfirmEx");
            Console.Error.WriteLine("OnConfirmEx");
#endif
            retVal = -1;

            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.ConfirmEx;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                if (chkMsg != IntPtr.Zero)
                {
                    e.CheckMessage = Marshal.PtrToStringUni(chkMsg);
                }
                e.CheckState = chkState;
                eh(this, e);
                chkState = e.CheckState;
                return(e.BoolReturn);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Actions to take when an alert fires an event.
        /// </summary>
        /// <param name="args"></param>
        private void OnAlertEvent(AlertEventArgs args)
        {
            string message;

            switch (args.EventType)
            {
            case AlertEventType.CloserToTarget:
                message = string.Format("{0}:{1} - {2} - Nearing to price {3}",
                                        args.Instrument.Market,
                                        args.Instrument.Symbol,
                                        args.Price,
                                        args.Alert.PriceTarget);
                break;

            case AlertEventType.TargetReached:
                message = string.Format("{0}:{1} - {2} - Target reached at {3}!",
                                        args.Instrument.Market,
                                        args.Instrument.Symbol,
                                        args.Price,
                                        args.Alert.PriceTarget);
                break;

            default:
                message = "Unknown message type " + args.EventType;
                break;
            }

            AddTextOutput(message);
        }
Exemple #3
0
        public bool OnPrompt(IntPtr title, IntPtr text, ref IntPtr retVal)
        {
#if debug
            OnGeneric("OnPrompt");
            Console.Error.WriteLine("OnPrompt");
#endif
            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.Prompt;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                if (retVal != IntPtr.Zero)
                {
                    e.Text2 = Marshal.PtrToStringUni(retVal);
                }
                eh(this, e);
                retVal = Marshal.StringToHGlobalUni(e.StringReturn);
                return(e.BoolReturn);
            }
            return(false);
        }
Exemple #4
0
        public bool OnSelect(IntPtr title, IntPtr text, uint count, IntPtr list, out int retVal)
        {
#if debug
            OnGeneric("OnSelect");
            Console.Error.WriteLine("OnSelect");
#endif
            retVal = 0;
            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.Select;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                eh(this, e);
                return(e.BoolReturn);
            }
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Broadcast alert
        /// </summary>
        public void BroadcastAlert(AlertMessage msg)
        {
            try
            {
                this.m_tracer.TraceVerbose("Broadcasting alert {0}", msg);

                // Broadcast alert
                // TODO: Fix this, this is bad
                var args = new AlertEventArgs(msg);
                this.Received?.Invoke(this, args);
                if (args.Ignore)
                {
                    return;
                }

                if (msg.Flags == AlertMessageFlags.Transient)
                {
                    ApplicationContext.Current.ShowToast(msg.Subject);
                }
                else
                {
                    this.Save(msg);
                }

                // Committed
                this.Committed?.BeginInvoke(this, args, null, null);
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error broadcasting alert: {0}", e);
            }
        }
Exemple #6
0
 private void Instance_AlertReported(object sender, AlertEventArgs e)
 {
     if (AlertMatches(e))
     {
         HandleUpdate(e.Alert);
     }
 }
Exemple #7
0
        public bool OnPromptPassword(IntPtr title, IntPtr text, IntPtr chkMsg, ref bool chkState, out IntPtr password)
        {
#if debug
            OnGeneric("OnPromptPassword");
            Console.Error.WriteLine("OnPromptPassword");
#endif
            password = IntPtr.Zero;
            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.PromptPassword;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                if (chkMsg != IntPtr.Zero)
                {
                    e.CheckMessage = Marshal.PtrToStringUni(chkMsg);
                }
                e.CheckState = chkState;
                eh(this, e);
                return(e.BoolReturn);
            }
            return(false);
        }
Exemple #8
0
        public void TestAlertEventArgs()
        {
            var args = new AlertEventArgs("Klingons on the starboard bow!");

            Assert.AreEqual("Klingons on the starboard bow!", args.Message);

            Assert.Throws <ArgumentNullException> (() => new AlertEventArgs(null));
        }
 async void Popup_AlertEvent(AlertEventArgs _args)
 {
     alertDialog.AlertEvent -= Popup_AlertEvent;
     if (!_args.IsCancel)
     {
     }
     await Page.Navigation.PopPopupAsync();
 }
Exemple #10
0
        /// <summary>
        /// This method iterates through all known report types and generates alerts for them. It is then up to the
        /// consumer of said alerts as to how the alerts will be handled.
        /// </summary>
        private async Task IterateReportedValues()
        {
            this.Started?.Invoke(this, EventArgs.Empty);
            var token = this._cancellationTokenSource.Token;

            while (!token.IsCancellationRequested)
            {
                using IServiceScope scope = OrbitServiceProvider.Instance.CreateScope();
                var provider = scope.ServiceProvider;

                // Task.WhenAll allows each of these to run concurrently, effectively making this loop run in parallel
                await Task.WhenAll(this.ReportTypes.Select(async reportType =>
                {
                    try
                    {
                        Logger.Debug("Iterating type {reportType}", reportType);
                        Type componentType =
                            this._componentByReportType.GetOrAdd(reportType, ExplicitlyMappedComponent);

                        var component = (IMonitoredComponent)provider.GetRequiredService(componentType);
                        token.ThrowIfCancellationRequested();

                        // TODO: Should we check here that the value is actually new?
                        IModel?report = await component.GetLatestReportAsync(token);

                        if (report == null)
                        {
                            return;
                        }

                        token.ThrowIfCancellationRequested();
                        await this.OnNewValueRead(component, new ValueReadEventArgs(report)).ConfigureAwait(true);

                        if (report is IAlertableModel a)
                        {
                            foreach (var alert in a.GenerateAlerts())
                            {
                                var args = new AlertEventArgs(a, alert);
                                await OnAlertReported(component, args).ConfigureAwait(true);
                            }
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore cancellation errors
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Error in EventMonitor loop");
                    }
                }));

                await Task.Delay(TimeSpan.FromSeconds(SecondsDelay), token).ConfigureAwait(false);
            }

            this.Stopped?.Invoke(this, EventArgs.Empty);
        }
Exemple #11
0
        void OnAlert(object sender, AlertEventArgs e)
        {
            var handler = Alert;

            if (handler != null)
            {
                handler(this, e);
            }
        }
 async void Popup_AlertConfirmationEvent(AlertEventArgs _args)
 {
     alertDialog.AlertEvent -= Popup_AlertConfirmationEvent;
     if (!_args.IsCancel)
     {
         ConfrimationAlert_Result(_args.IsCancel);
     }
     await Page.Navigation.PopPopupAsync();
 }
Exemple #13
0
 private void Engine_AlertRaised(object sender, AlertEventArgs args)
 {
     if (args.DisplayPopup)
     {
         AlertBase alert = args.Alert;
         this._playSound = args.PlaySound;
         this.Alerts.Insert(0, alert);
         this.StartTimer();
     }
 }
Exemple #14
0
 private async void OnAlertEvent(AlertEventArgs args)
 {
     if (string.IsNullOrEmpty(args.Accept))
     {
         await DisplayAlert(args.Title, args.Message, args.Cancel);
     }
     else
     {
         await DisplayAlert(args.Title, args.Message, args.Accept, args.Cancel);
     }
 }
Exemple #15
0
 protected override bool AlertMatches(AlertEventArgs alert)
 {
     try
     {
         bool matches = alert.Query <OxygenGenerator>().Matches(a => a.OxygenLevel);
         if (matches)
         {
             MakePercentage(alert.Alert);
         }
         return(matches);
     }
     catch (Exception e)
     {
         Debug.LogError(e, this);
         return(false);
     }
 }
        public void MainLoop()
        {
            while (true)
            {
                Decision = Refreash();
                if (Trader.CheckTrad(Decision, Ticker.CurrentValue) == ExchangeStatus.buy && firstBuyFlag)
                {
                    firstBuyFlag = false;
                }
                RefreashedEventArgs refreashEA = new RefreashedEventArgs(Ticker.CurrentValue, Ticker.LastValue, Ticker.Status, Decision,
                                                                         Trader.CurrentBitcoinNum, Trader.CurrentCashNum);
                onRefreash(refreashEA);
                if (IsAlert && ((AlertUpper != 0 && Ticker.CurrentValue >= AlertUpper) || (AlertLower != 0 && Ticker.CurrentValue <= AlertLower)))
                {
                    AlertEventArgs alertEA = new AlertEventArgs(Ticker.CurrentValue, AlertUpper, AlertLower);
                    alerted(alertEA);
                }

                Thread.Sleep((int)SleepTime);
            }
        }
Exemple #17
0
    // This is like the last two but for miscellaneous generic alerts that kill a colonist. It just displays
    // the strings that come in for the button and alert text.
    void OnAlertStarted(object sender, AlertEventArgs args)
    {
        alertType = AlertType.Misc;
        int happinessDiff = args.happinessDiff;

        OpenGameOverUI();

        gameOverText.text = args.alertString;

        if (happinessDiff <= 0)
        {
            dayDisplay.text = "Happiness " + happinessDiff;
        }
        else
        {
            dayDisplay.text = "Happiness +" + happinessDiff;
        }

        GameEvents.InvokeHappinessChanged(happinessDiff);
        restartButton.transform.GetChild(0).gameObject.GetComponent <Text>().text = args.buttonString;
    }
Exemple #18
0
        public void OnAlert(IntPtr title, IntPtr text)
        {
#if debug
            OnGeneric("OnAlert");
            Console.Error.WriteLine("OnAlert");
#endif
            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.Alert;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                eh(this, e);
            }
        }
Exemple #19
0
        public bool OnConfirm(IntPtr title, IntPtr text)
        {
#if debug
            OnGeneric("OnConfirm");
            Console.Error.WriteLine("OnConfirm");
#endif
            AlertEventHandler eh = (AlertEventHandler)(owner.Events[WebBrowser.AlertEvent]);
            if (eh != null)
            {
                AlertEventArgs e = new AlertEventArgs();
                e.Type = DialogType.Confirm;
                if (title != IntPtr.Zero)
                {
                    e.Title = Marshal.PtrToStringUni(title);
                }
                if (text != IntPtr.Zero)
                {
                    e.Text = Marshal.PtrToStringUni(text);
                }
                eh(this, e);
                return(e.BoolReturn);
            }
            return(false);
        }
Exemple #20
0
 // If the big alert box is on the screen don't click the day.
 void OnAlertStarted(object sender, AlertEventArgs args)
 {
     advanceDayButton.interactable = false;
 }
Exemple #21
0
		void OnEngineAlert (object sender, AlertEventArgs e)
		{
			OnAlert (e);
		}
Exemple #22
0
 //If an alert is given I don't want you to click stuff, that would be weird.
 void OnAlertStarted(object sender, AlertEventArgs args)
 {
     inMenu = true;
 }
Exemple #23
0
 public Matcher(AlertEventArgs args)
 {
     this._args = args;
 }
Exemple #24
0
        void OnAlert(object sender, AlertEventArgs e)
        {
            var handler = Alert;

            if (handler != null)
                handler (this, e);
        }
 private void alert_OnAlert(object sender, AlertEventArgs e)
 {
     _FireAlert = true;
 }
 public void alerted(AlertEventArgs e)
 {
     alert?.Invoke(this, e);
 }
Exemple #27
0
 /// <summary>
 ///   Use this to query <see cref="AlertEventArgs"/> using Expressions for readability.
 /// </summary>
 public static Matcher <TModel> Query <TModel>(this AlertEventArgs args) where TModel : class, IAlertableModel => new Matcher <TModel>(args);
Exemple #28
0
 private void Client_Alert(object sender, AlertEventArgs e)
 {
     NewLogMessage?.Invoke(this, $"{DateTime.Now}: {e.Message}");
 }
Exemple #29
0
 private Task OnAlertReported(object sender, AlertEventArgs args)
 {
     return(this.RunInCorrectSynchronizationContext(() => this.AlertReported?.Invoke(sender, args)));
 }
Exemple #30
0
        void CameraWindow_AlertHandler(object sender, AlertEventArgs eventArgs)
        {
            if (Camera.Plugin != null)
            {
                var a = (String) Camera.Plugin.GetType().GetMethod("ProcessAlert").Invoke(Camera.Plugin, new object[] { eventArgs.Description });
                if (!String.IsNullOrEmpty(a))
                {
                    string[] actions = a.ToLower().Split(',');
                    foreach (var action in actions)
                    {
                        if (!String.IsNullOrEmpty(action))
                        {
                            switch (action)
                            {
                                case "alarm":
                                    CameraAlarm(eventArgs.Description, EventArgs.Empty);
                                    break;
                                case "flash":
                                    FlashCounter = 10;
                                    break;
                            }
                            if (action.StartsWith("border:") && action.Length>7)
                            {
                                string col = action.Substring(7);
                                try
                                {
                                    _customColor = Color.FromArgb(Convert.ToInt32(col));
                                    Custom = true;
                                }
                                catch (Exception e)
                                {
                                    Log.Error("",e);//MainForm.LogExceptionToFile(e);
                                }

                            }
                        }
                    }
                }
            }
        }
Exemple #31
0
 static void ResetAlert(AlertEventArgs args)
 {
     nextAlert = nextAlert.AddDays(1);
 }
Exemple #32
0
 void communicator_OnAlert(object source, AlertEventArgs e)
 {
     //Предупреждние
 }
Exemple #33
0
 protected abstract bool AlertMatches(AlertEventArgs alert);