Example #1
0
        // function for thread
        public void ConnectTo()
        {
            // flag to prevent more than one notification per ring
            bool          alerted = false;
            ErrorDelegate erDel   = new ErrorDelegate(ShowURLError);
            AlertDelegate delInst = new AlertDelegate(Alert);

            using (var client = new HttpClient())
            {
                Console.WriteLine("Starting connection.");
                client.Timeout = TimeSpan.FromSeconds(3);
                while (true)
                {
                    try
                    {
                        //Console.WriteLine(serverURL);
                        var response = client.GetAsync(serverURL).Result;

                        if (response.IsSuccessStatusCode)
                        {
                            this.BeginInvoke(erDel, false);
                            if (!successConnection)
                            {
                                successConnection = true;
                                this.BeginInvoke(delInst, "Connected to server.", Form_Alert.enmType.Success);
                                Console.WriteLine("Connected");
                            }
                            var responseContent = response.Content;

                            // by calling .Result you are synchronously reading the result
                            int rung = Int16.Parse(responseContent.ReadAsStringAsync().Result);

                            if (rung == 1 && !alerted)
                            {
                                alerted = true;
                                //AlertDelegate delInst = new AlertDelegate(Alert);
                                this.BeginInvoke(delInst, "Someone is at the door!", Form_Alert.enmType.Rung);
                            }
                            else if (rung == 0 && alerted)
                            {
                                alerted = false;
                            }
                        }
                    }
                    // IF we lose connection to the server
                    catch
                    {
                        this.BeginInvoke(erDel, true);
                        if (successConnection || firstTimeUser)
                        {
                            firstTimeUser = false;
                            Console.WriteLine("Disconnected");
                            //AlertDelegate delInst = new AlertDelegate(Alert);
                            this.BeginInvoke(delInst, "Lost connection to server.", Form_Alert.enmType.Error);
                        }
                        successConnection = false;
                    }
                }
            }
        }
Example #2
0
 public void Alert( string text, float angle, AlertDelegate onClose )
 {
     ArrayList vals = new ArrayList();
     vals.Add(text);
     vals.Add(angle);
     alertCallbacks.Enqueue(onClose);
     Send("alert", vals);
 }
Example #3
0
        public MainForm() : base()
        {
            InitializeComponent();
            Alert          = new AlertDelegate(AlertMethod);
            Exit           = new ExitDelegate(ExitMethod);
            FatalExit      = new FatalExitDelegate(FatalExitMethod);
            Log            = new LogDelegate(LogMethod);
            ReportProgress = new ReportProgressDelegate(ReportProgressMethod);
            Info           = new InfoDelegate(InfoMethod);

            logfile = File.OpenWrite(Path.GetDirectoryName(Application.ExecutablePath) + "\\cuetoogg.log.txt");
        }
Example #4
0
        public SilentForm()
            : base()
        {
            InitializeComponent();
            Alert = new AlertDelegate(AlertMethod);
            Exit = new ExitDelegate(ExitMethod);
            FatalExit = new FatalExitDelegate(FatalExitMethod);
            Log = new LogDelegate(LogMethod);
            ReportProgress = new ReportProgressDelegate(ReportProgressMethod);
            Info = new InfoDelegate(InfoMethod);

            logfile=File.OpenWrite(Path.GetDirectoryName(Application.ExecutablePath)+"\\cuetoogg.log.txt");
        }
Example #5
0
 public void Display(AlertDelegate alertDelegate)
 {
     this.alertDelegate = alertDelegate;
     Debug.Log("setting active");
 }