Ejemplo n.º 1
0
        public async Task SetLightState(int row, int col, Color color, bool onOff)
        {
            var requestUri = $"http://{_panelBaseAddress}/led";

            using (var request = new HttpRequestMessage(HttpMethod.Put, requestUri))
            {
                var colorString = $"rgba({Convert.ToInt32(color.R * 255)},{Convert.ToInt32(color.G * 255)},{Convert.ToInt32(color.B * 255)},{color.A})";

                if (onOff)
                {
                    request.Content = new StringContent($"{{\"row\":{row},\"column\":{col},\"color\":\"{colorString}\",\"state\":\"{(onOff ? "on" : "off")}\"}}", Encoding.UTF8, "application/json");
                }
                else
                {
                    request.Content = new StringContent($"{{\"row\":{row},\"column\":{col},\"state\":\"{(onOff ? "on" : "off")}\"}}", Encoding.UTF8, "application/json");
                }

                using (var response = await _httpClient.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = $"Light turned {(onOff ? "on" : "off")} to color {colorString} successfully";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                    }
                }
            }

            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
 public void InvokeCheckForDiskSpace(OperationComplete checkForDiskSpaceComplete)
 {
     if (CheckForDiskSpace != null)
     {
         CheckForDiskSpace(checkForDiskSpaceComplete);
     }
 }
Ejemplo n.º 3
0
            private void SendStopComplete()
            {
                OperationStateEventArgs operationStateEventArgs = new OperationStateEventArgs();

                operationStateEventArgs.OperationState = OperationState.StopComplete;
                OperationComplete.SafeInvoke(this, operationStateEventArgs);
            }
Ejemplo n.º 4
0
        public async Task StopLine(int lineNumber, bool reset = false)
        {
            if (!reset && (!_lineRunning.ContainsKey(lineNumber) || !_lineRunning[lineNumber]))
            {
                return;
            }

            var requestUri = $"http://{_panelBaseAddress}/line/{lineNumber}?reset={reset.ToString().ToLower()}";

            using (var request = new HttpRequestMessage(HttpMethod.Delete, requestUri))
            {
                using (var response = await _httpClient.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = "Line stopped set successfully";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                    }

                    _lineRunning[lineNumber] = false;
                }
            }

            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
Ejemplo n.º 5
0
 public override void ApiCredentialsDelete(string provider, OperationComplete apiCredentialsDeleteComplete)
 {
     base.ApiCredentialsDelete(provider);
     ConfigurationSave();
     if (apiCredentialsDeleteComplete != null)
     {
         apiCredentialsDeleteComplete(true);
     }
 }
        public void Handle(OperationComplete message)
        {
            if (message.CorrelationId.Equals(_parentCorrelation))
            {
                Subscriber.Unsubscribe(this);

                Logger?.Invoke($"Operation Complete Id:{message.CorrelationId}");
            }
        }
        private void WorkerThreadMethodStop()
        {
            workerThreadStart.Abort();

            OperationStateEventArgs operationStateEventArgs =
                new OperationStateEventArgs();

            operationStateEventArgs.OperationState = OperationState.StopComplete;
            OperationComplete.SafeInvoke(this, operationStateEventArgs);
        }
        private void WorkerThreadMethodStart()
        {
            Thread.Sleep(SleepTime);
            Done = true;
            OperationStateEventArgs operationStateEventArgs =
                new OperationStateEventArgs();

            operationStateEventArgs.OperationState = OperationState.StartComplete;
            OperationComplete.SafeInvoke(this, operationStateEventArgs);
        }
Ejemplo n.º 9
0
        public async Task <bool> Connect(string panelBaseAddress)
        {
            var requestUri = $"http://{panelBaseAddress}/connect";

            using (var request = new HttpRequestMessage(HttpMethod.Put, requestUri))
            {
                using (var response = await _httpClient.SendAsync(request))
                {
                    IsConnected = false;

                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = "Panel Contacted... waiting for connected status";
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.NotModified)
                    {
                        // Assume panel is already connected
                        LastErrorMessage = "Panel already connected, disconnect + reconnect if not working";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                        OperationComplete?.Invoke(this, EventArgs.Empty);
                        return(false);
                    }
                }
            }

            int retryCount = 0;

            while (retryCount <= 5)
            {
                using (var response = await _httpClient.GetAsync($"http://{panelBaseAddress}/state"))
                {
                    var result = await response.Content.ReadAsStringAsync();

                    var stateResult = Newtonsoft.Json.JsonConvert.DeserializeObject <StateResult>(result);
                    if (stateResult.State > 1)
                    {
                        _panelBaseAddress = panelBaseAddress;
                        LastErrorMessage  = "Success - Connected!";
                        IsConnected       = true;
                        OperationComplete?.Invoke(this, EventArgs.Empty);
                        return(true);
                    }
                }

                await Task.Delay(TimeSpan.FromSeconds(10));
            }

            LastErrorMessage = "Panel controller could not connect to light panel";
            OperationComplete?.Invoke(this, EventArgs.Empty);
            return(false);
        }
Ejemplo n.º 10
0
 public Downloader(string url, string filename, string messageUrl,
                   ProgressChange progressCallback, ConnectionFailed failedCallback,
                   OperationComplete completeCallback, MessageDownloaded msgDone)
 {
     _Url               = url;
     _Filename          = filename;
     _MsgUrl            = messageUrl;
     _ProgressCallback  = progressCallback;
     _FailedCallback    = failedCallback;
     _CompleteCallback  = completeCallback;
     _MessageDownloaded = msgDone;
 }
Ejemplo n.º 11
0
        public async Task Disconnect()
        {
            var requestUri = $"http://{_panelBaseAddress}/connect";

            using (var request = new HttpRequestMessage(HttpMethod.Delete, requestUri))
            {
                using (var response = await _httpClient.SendAsync(request))
                {
                    IsConnected = false;

                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = "Panel Contacted... waiting for disconnected status";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                        OperationComplete?.Invoke(this, EventArgs.Empty);
                        return;
                    }
                }
            }

            int retryCount = 0;

            while (retryCount <= 5)
            {
                using (var response = await _httpClient.GetAsync($"http://{_panelBaseAddress}/state"))
                {
                    var result = await response.Content.ReadAsStringAsync();

                    var stateResult = Newtonsoft.Json.JsonConvert.DeserializeObject <StateResult>(result);
                    if (stateResult.State <= 1)
                    {
                        LastErrorMessage  = "Success - Disconnected";
                        IsConnected       = false;
                        _panelBaseAddress = null;
                        OperationComplete?.Invoke(this, EventArgs.Empty);
                        return;
                    }
                }

                await Task.Delay(TimeSpan.FromSeconds(10));
            }

            LastErrorMessage = "Panel controller could not disconnect from light panel";
            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
Ejemplo n.º 12
0
        public async Task StartLine(int lineNumber, string command)
        {
            var isRunning = false;

            if (String.IsNullOrWhiteSpace(command) && _lineRunning.TryGetValue(lineNumber, out isRunning))
            {
                if (isRunning)
                {
                    return;
                }
            }

            var requestUri = $"http://{_panelBaseAddress}/line/{lineNumber}";

            using (var request = new HttpRequestMessage(HttpMethod.Post, requestUri))
            {
                if (!String.IsNullOrWhiteSpace(command))
                {
                    request.Content = new StringContent(command, Encoding.UTF8, "application/json");
                }

                using (var response = await _httpClient.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = "Line started set successfully";
                        isRunning        = true;
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                    }

                    if (_lineRunning.ContainsKey(lineNumber))
                    {
                        _lineRunning[lineNumber] = isRunning;
                    }
                    else
                    {
                        _lineRunning.Add(lineNumber, isRunning);
                    }
                }
            }

            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
Ejemplo n.º 13
0
        public override void AccountStartSession(string applicationName, OperationComplete accountStartSessionComplete)
        {
            _configurationFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), applicationName);

            UserStorageInitialiseLocal();

            ConfigurationLoadLocal();

            FavouritesLoadLocal();

            HistoryLoadLocal();

            if (accountStartSessionComplete != null)
            {
                accountStartSessionComplete(true);
            }
        }
Ejemplo n.º 14
0
        private async Task <DataModel> GetModelFromFileAsync(string text)
        {
            try
            {
                OperationStarted?.Invoke("Reading model data...", new EventArgs());

                var model = DataModel.FromJsonFile(text);
                return(await Task.FromResult(model));
            }
            catch (Exception exc)
            {
                throw new Exception($"Error reading model data: {exc.Message}", exc);
            }
            finally
            {
                OperationComplete?.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 15
0
 private async Task <DataModel> GetAssemblyModelAsync(string text)
 {
     try
     {
         // help from https://docs.microsoft.com/en-us/dotnet/framework/deployment/best-practices-for-assembly-loading
         OperationStarted?.Invoke("Analyzing assembly...", new EventArgs());
         var assembly = Assembly.LoadFrom(text);
         var result   = new AssemblyModelBuilder().GetDataModel(assembly);
         return(await Task.FromResult(result));
     }
     catch (Exception exc)
     {
         throw new Exception($"Error analyzing assembly: {exc.Message}");
     }
     finally
     {
         OperationComplete?.Invoke(this, new EventArgs());
     }
 }
Ejemplo n.º 16
0
 private async Task <DataModel> GetConnectionModelAsync(string text)
 {
     try
     {
         OperationStarted?.Invoke("Analyzing database...", new EventArgs());
         using (var cn = GetConnection(text))
         {
             return(await new SqlServerModelBuilder().GetDataModelAsync(cn));
         }
     }
     catch (Exception exc)
     {
         throw new Exception($"Error analyzing database: {exc.Message}", exc);
     }
     finally
     {
         OperationComplete?.Invoke(this, new EventArgs());
     }
 }
Ejemplo n.º 17
0
        private async Task ExecuteInner(EventArgs e, string statusBarMessage, bool commit, string successMessage = null)
        {
            try
            {
                OperationStarted?.Invoke(statusBarMessage, e);

                using (var cn = GetConnection.Invoke(tbDest.Text))
                {
                    await SqlDialect.ExecuteAsync(cn, tbScriptOutput.Text, commit);

                    if (commit)
                    {
                        ScriptExecuted?.Invoke(this, new EventArgs());
                        if (_manualEdits)
                        {
                            MessageBox.Show("Changes applied successfully.", "Script Executed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

                    if (!string.IsNullOrEmpty(successMessage))
                    {
                        MessageBox.Show(successMessage, "SQL Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (!_manualEdits && commit)
                    {
                        await GenerateScriptAsync();
                    }
                }
            }
            catch (Exception exc)
            {
                if (MessageBox.Show(exc.Message + "\r\n\r\nClick OK to create test case.", "Script Error", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    frmSaveTestCase.PromptSaveZipFile(false, exc.Message, _sourceModel, _destModel, _diff);
                }
            }
            finally
            {
                OperationComplete?.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 18
0
        public async Task TurnPanelOff()
        {
            var requestUri = $"http://{_panelBaseAddress}/leds";

            using (var request = new HttpRequestMessage(HttpMethod.Delete, requestUri))
            {
                using (var response = await _httpClient.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = $"Panel turned off successfully";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                    }

                    _lineRunning.Keys.ToList().ForEach(k => _lineRunning[k] = false);
                }
            }

            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
Ejemplo n.º 19
0
        public async Task SetTempo(int newTempo)
        {
            var requestUri = $"http://{_panelBaseAddress}/tempo";

            using (var request = new HttpRequestMessage(HttpMethod.Put, requestUri))
            {
                request.Content = new StringContent($"{{\"bpm\":{newTempo}}}", Encoding.UTF8, "application/json");

                using (var response = await _httpClient.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LastErrorMessage = "Tempo set successfully";
                    }
                    else
                    {
                        LastErrorMessage = $"Failed to contact panel: {response.ReasonPhrase}";
                    }
                }
            }

            OperationComplete?.Invoke(this, EventArgs.Empty);
            return;
        }
Ejemplo n.º 20
0
        public override void AccountStartSession(string applicationName, OperationComplete accountStartSessionComplete)
        {
            _configurationFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), applicationName);

            UserStorageInitialiseLocal();

            ConfigurationLoadLocal();

            FavouritesLoadLocal();

            HistoryLoadLocal();

            if (accountStartSessionComplete != null)
            {
                accountStartSessionComplete(true);
            }
        }
Ejemplo n.º 21
0
 public override void ApiCredentialsDelete(string provider, OperationComplete apiCredentialsDeleteComplete)
 {
     base.ApiCredentialsDelete(provider);
     ConfigurationSave();
     if (apiCredentialsDeleteComplete != null)
     {
         apiCredentialsDeleteComplete(true);
     }
 }
Ejemplo n.º 22
0
 private void OnOperationComplete(OperationEventArgs args)
 {
     OperationComplete?.Invoke(this, args);
 }
Ejemplo n.º 23
0
        public override void ApiCredentialsSet(string provider, string apiCredentials1, string apiCredentials2, string apiCredentials3, string apiCredentials4, OperationComplete apiCredentialsSetComplete)
        {
            ApiCredential apic = new ApiCredential();

            apic.Provider = provider;
            apic.ApiCredentials1 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials1);
            apic.ApiCredentials2 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials2);
            apic.ApiCredentials3 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials3);
            apic.ApiCredentials4 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials4);

            base.ApiCredentialsAdd(apic);

            ConfigurationSave();

            if (apiCredentialsSetComplete != null)
            {
                apiCredentialsSetComplete(true);
            }
        }
 public abstract void ApiCredentialsDelete(string provider, OperationComplete apiCredentialsDeleteComplete);
 public abstract void ApiCredentialsSet(string provider, string apiCredentials1, string apiCredentials2, string apiCredentials3, string apiCredentials4, OperationComplete apiCredentialsSetComplete);
 public abstract void AccountStartSession(string applicationName, OperationComplete accountStartSessionComplete);
Ejemplo n.º 27
0
        public override void ApiCredentialsSet(string provider, string apiCredentials1, string apiCredentials2, string apiCredentials3, string apiCredentials4, OperationComplete apiCredentialsSetComplete)
        {
            ApiCredential apic = new ApiCredential();

            apic.Provider        = provider;
            apic.ApiCredentials1 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials1);
            apic.ApiCredentials2 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials2);
            apic.ApiCredentials3 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials3);
            apic.ApiCredentials4 = Obany.Cryptography.SecureEncryption.EncryptData(apiCredentials4);

            base.ApiCredentialsAdd(apic);

            ConfigurationSave();

            if (apiCredentialsSetComplete != null)
            {
                apiCredentialsSetComplete(true);
            }
        }