Esempio n. 1
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 data   = new _queue_data_struct();
            var loopTo = Information.UBound(bwDataRequest);

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

            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);
        }
        private void startSendQueue()
        {
            sendToQueue = true;
            while (QueuesToSend(queue) > 0)
            {
                for (int shtIndex = 0, loopTo = threadCount; shtIndex <= loopTo; shtIndex++)
                {
                    for (int i = 0, loopTo1 = queue.Count - 1; i <= loopTo1; i++)
                    {
                        if (!bwDataRequest[shtIndex].IsBusy)
                        {
                            lock (queueLock)
                            {
                                if (queue.ElementAt(i).status.Equals(0))
                                {
                                    var data = new _queue_data_struct();
                                    data.vars               = queue.ElementAt(i).vars;
                                    data.status             = 1;
                                    data.misc               = queue.ElementAt(i).misc;
                                    data.filenameOrSavePath = queue.ElementAt(i).filenameOrSavePath;
                                    queue[i] = data;
                                    queueBWorker[shtIndex]   = i;
                                    dataStatistics[shtIndex] = new _data_statistics();
                                    bwDataRequest[shtIndex].RunWorkerAsync(queue[i]);
                                    System.Threading.Thread.Sleep(50);
                                }
                            }
                        }
                    }
                }
            }

            sendToQueue = false;
        }
        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 void loadQueue(Dictionary <string, string> vars, Dictionary <string, string> misc = null, string filenameOrSavePath = null)
        {
            var queueItem = new _queue_data_struct();

            queueItem.vars               = new Dictionary <string, string>();
            queueItem.misc               = new Dictionary <string, string>();
            queueItem.vars               = vars;
            queueItem.status             = 0;
            queueItem.misc               = misc;
            queueItem.filenameOrSavePath = filenameOrSavePath;
            queue.Add(queueItem);
        }
Esempio n. 5
0
        public void initialize(int _threadCount = 0)
        {
            if (!_threadCount.Equals(0))
            {
                threadCount = _threadCount;
            }

            if (!url.Equals(state.ServerBaseAddr + state.ApiServerAddrPath))
            {
                var queueItem = new _queue_data_struct();
                queueItem.vars = new Dictionary <string, string>();
                queueItem.misc = null;
                queueItem.vars.Add("url", url);
                queueItem.status             = 0;
                queueItem.filenameOrSavePath = "";
                queue.Add(queueItem);
            }
            else
            {
            }

            bwDataRequest = new BackgroundWorker[threadCount + 1];
            queueBWorker  = new int[threadCount + 1];
            for (int shtIndex = 0, loopTo = threadCount; shtIndex <= loopTo; shtIndex++)
            {
                dataStatistics.Add(new _data_statistics());
                bwDataRequest[shtIndex] = new BackgroundWorker();
                bwDataRequest[shtIndex].WorkerReportsProgress      = true;
                bwDataRequest[shtIndex].WorkerSupportsCancellation = true;
                bwDataRequest[shtIndex].DoWork             += bwDataRequest_DoWork;
                bwDataRequest[shtIndex].RunWorkerCompleted += bwDataRequest_RunWorkerCompleted;
            }

            _retry_attempts retry;

            retry.counter         = 0;
            retry.previousPattern = -1;
            retry.pattern         = 0;
            retry.errorMessage    = "";
            retryAttempts         = retry;
        }
Esempio n. 6
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);
        }