private void bwDataRequest_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Find out the Index of the bWorker that called this DoWork (could be cleaner, I know)
            int Y;
            int Index  = default;
            var data   = new _queue_data_struct();
            var loopTo = Information.UBound(bwDataRequest);

            for (Y = 0; Y <= loopTo; Y++)
            {
                if (sender.Equals(bwDataRequest[Y]))
                {
                    Index = Y;
                    break;
                }
            }

            if (ManagementNetwork.IsResponseOk(Conversions.ToString(e.Result), "statuscode"))
            {
                data        = new _queue_data_struct();
                data        = queue[queueBWorker[Index]];
                data.status = 0; // re queue the file
                lock (queueLock)
                    queue[queueBWorker[Index]] = data;
                string          errorMsg = ManagementNetwork.GetMessage(Conversions.ToString(e.Result));
                _retry_attempts retry;
                retry.counter         = retryAttempts.counter;
                retry.previousPattern = retryAttempts.previousPattern;
                retry.pattern         = retryAttempts.pattern;
                retry.errorMessage    = retryAttempts.errorMessage;
                retry.errorMessage    = retryAttempts.errorMessage.IndexOf(errorMsg) > -1 ? retryAttempts.errorMessage : retryAttempts.errorMessage + System.Environment.NewLine + errorMsg;
                retry.pattern         = QueuesMultiHash(queue);
                if (retry.previousPattern.Equals(retry.pattern))
                {
                    retry.counter += 1;
                }
                else
                {
                    retry.counter         = 1;
                    retry.previousPattern = retryAttempts.pattern;
                }

                retryAttempts = retry;
                return;
            }

            data        = new _queue_data_struct();
            data        = queue[queueBWorker[Index]];
            data.status = -1; // completed sucessfully status
            lock (queueLock)
                queue[queueBWorker[Index]] = data;
            loadingCounter      += 1;
            CompletionPercentage = (int)(loadingCounter / (double)queue.Count * 100);
            statusMessage        = "Loading data from the cloud ...";
            updateProgress?.Invoke(this, queue[queueBWorker[Index]].misc);
            dataArrived?.Invoke(this, Conversions.ToString(e.Result), queue[queueBWorker[Index]].misc);
        }
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        public Dictionary <string, List <string> > ConvertDataToArray(string key, string[] fields, string response)
        {
            if (ManagementNetwork.GetMessage(response).Equals("1001"))
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(state.currentLang);
                errorMessage = "{'error':true,'message':'" + resources.GetString("errorNoRecordsFound", CultureInfo.CurrentCulture) + "'}";
                return(null);
            }

            try
            {
                var jsonResult = JsonSerializer.Deserialize <Dictionary <string, List <List <Object> > > >(response);
                if (jsonResult.ContainsKey(key))
                {
                    if (!jsonResult[key].ElementAt(0).Count.Equals(fields.Length))
                    {
                        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(state.currentLang);
                        errorMessage = "{'error':true,'message':'" + resources.GetString("JsonFieldsMismatch", CultureInfo.CurrentCulture) + ". table(" + key + "'}";
                        return(null);
                    }
                    else
                    {
                        var results = new Dictionary <string, List <string> >();
                        for (int k = 0, loopTo = fields.Length - 1; k <= loopTo; k++)
                        {
                            var fieldValues = new List <string>();
                            var loopTo1     = Conversions.ToInteger(Operators.SubtractObject(jsonResult[key].Count, 1));
                            for (int i = 0; i <= Conversions.ToInteger(loopTo1); i++)
                            {
                                fieldValues.Add(jsonResult[key].ElementAt(i).ElementAt(k).ToString());
                            }
                            results.Add(fields[k], fieldValues);
                        }

                        return(results);
                    }
                }
                else
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(state.currentLang);
                    errorMessage = "{'error':true,'message':'" + resources.GetString("JsonkeyNotFound", CultureInfo.CurrentCulture) + " (" + key + "'}";
                    return(null);
                }
            }
            catch (Exception ex)
            {
                errorMessage = "{'error':true,'message':'" + ex.ToString() + "'}";
                errorMessage = ex.ToString();
                return(null);
            }
        }
예제 #3
0
        private void bwDataRequest_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Find out the Index of the bWorker that called this DoWork (could be cleaner, I know)
            int Y;
            int Index  = default;
            var loopTo = Information.UBound(bwDataRequest);

            for (Y = 0; Y <= loopTo; Y++)
            {
                if (sender.Equals(bwDataRequest[Y]))
                {
                    Index = Y;
                    break;
                }
            }

            string             responseFromServer = Encoding.UTF8.GetString((byte[])e.Result);
            string             decrypted          = "";
            var                encryption         = new AesCipher(state);
            _queue_data_struct data;

            try
            {
                if (IsBase64String(responseFromServer) & !responseFromServer.Equals(""))
                {
                    decrypted = encryption.decrypt(responseFromServer);
                }
                else
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(state.currentLang);
                    decrypted = "{'error':true,'message':'" + resources.GetString("contactingCommServer", CultureInfo.CurrentCulture) + " |" + responseFromServer + "|'}";
                }
            }
            catch (Exception ex)
            {
                decrypted = "{'error':true,'message':'" + ex.Message.ToString().Replace("'", @"\'") + "'}";
            }

            if (!ManagementNetwork.IsResponseOk(decrypted))
            {
                data        = new _queue_data_struct();
                data        = queue[queueBWorker[Index]];
                data.status = 0; // re queue the file
                lock (queueLock)
                    queue[queueBWorker[Index]] = data;
                string          errorMsg = ManagementNetwork.GetMessage(decrypted);
                _retry_attempts retry;
                retry.counter         = retryAttempts.counter;
                retry.previousPattern = retryAttempts.previousPattern;
                retry.pattern         = retryAttempts.pattern;
                retry.errorMessage    = retryAttempts.errorMessage;
                retry.errorMessage    = retryAttempts.errorMessage.IndexOf(errorMsg) > -1 ? retryAttempts.errorMessage : retryAttempts.errorMessage + System.Environment.NewLine + errorMsg;
                retry.pattern         = QueuesMultiHash(queue);
                if (retry.previousPattern.Equals(retry.pattern))
                {
                    retry.counter += 1;
                }
                else
                {
                    retry.counter         = 1;
                    retry.previousPattern = retryAttempts.pattern;
                }

                retryAttempts = retry;
                return;
            }

            data        = new _queue_data_struct();
            data        = queue[queueBWorker[Index]];
            data.status = -1; // completed sucessfully status
            lock (queueLock)
                queue[queueBWorker[Index]] = data;
            loadingCounter      += 1;
            CompletionPercentage = (int)(loadingCounter / (double)queue.Count * 100);
            statusMessage        = "Uploading data to the cloud ...";
            dataArrived?.Invoke(this, decrypted, queue[queueBWorker[Index]].misc);
        }
        private void bwDataRequest_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Find out the Index of the bWorker that called this DoWork (could be cleaner, I know)
            int Y;
            int Index  = default;
            var loopTo = Information.UBound(bwDataRequest);

            for (Y = 0; Y <= loopTo; Y++)
            {
                if (sender.Equals(bwDataRequest[Y]))
                {
                    Index = Y;
                    break;
                }
            }

            var data = new _queue_data_struct();

            if (ManagementNetwork.IsResponseOk(fileExtension[queueBWorker[Index]], "statuscode"))
            {
                data        = queue[queueBWorker[Index]];
                data.status = 0; // re queue the file
                lock (queueLock)
                    queue[queueBWorker[Index]] = data;
                string          errorMsg = "";
                _retry_attempts retry;
                retry.counter         = retryAttempts.counter;
                retry.previousPattern = retryAttempts.previousPattern;
                retry.pattern         = retryAttempts.pattern;
                retry.errorMessage    = retryAttempts.errorMessage;
                errorMsg           = ManagementNetwork.GetMessage(fileExtension[Index]);
                retry.errorMessage = retryAttempts.errorMessage.IndexOf(errorMsg) > -1 ? retryAttempts.errorMessage : retryAttempts.errorMessage + System.Environment.NewLine + errorMsg;
                retry.pattern      = QueuesMultiHash(queue);
                if (retry.previousPattern.Equals(retry.pattern))
                {
                    retry.counter += 1;
                }
                else
                {
                    retry.counter         = 1;
                    retry.previousPattern = retryAttempts.pattern;
                }

                retryAttempts = retry;
                return;
            }
            else if (ManagementNetwork.IsResponseOk(fileExtension[Index]))
            {
                errorMessage = ManagementNetwork.GetMessage(fileExtension[Index]);
            }

            if (!e.Result.Equals(false))
            {
                try
                {
                    fileExtension[queueBWorker[Index]] = queue[queueBWorker[Index]].filenameOrSavePath + fileExtension[queueBWorker[Index]];
                    File.WriteAllBytes(fileExtension[queueBWorker[Index]], (byte[])e.Result);
                }
                catch (Exception ex)
                {
                    _retry_attempts retry;
                    retry.counter         = retryAttempts.counter;
                    retry.previousPattern = retryAttempts.previousPattern;
                    retry.pattern         = retryAttempts.pattern;
                    retry.errorMessage    = retryAttempts.errorMessage;
                    retry.counter         = 100;
                    retry.previousPattern = retry.pattern;
                    retry.errorMessage    = "error saving file";
                    retryAttempts         = retry;
                }
                finally
                {
                }
            }

            data        = new _queue_data_struct();
            data        = queue[queueBWorker[Index]];
            data.status = -1; // completed sucessfully status
            lock (queueLock)
                queue[queueBWorker[Index]] = data;
            loadingCounter      += 1;
            CompletionPercentage = (int)(loadingCounter / (double)queue.Count * 100);
            statusMessage        = "Loading cloud files...";
            dataArrived?.Invoke(this, fileExtension[queueBWorker[Index]], queue[queueBWorker[Index]].misc);
        }