Format for painting tasks
        /// <summary>
        /// Поиск решения.
        /// </summary>
        /// <returns>
        /// Формат ответа клиента.
        /// </returns>
        public AnswerFormat FindSolution()
        {
            TaskFormat workTask = this.currentTask;

            Word workWord = new Word();

            workWord.SetWord(this.currentTask.StartWord);

            AnswerFormat answer = new AnswerFormat();

            while (workTask.NumberOfWordsThatNeedToBeIterated > 0)
            {
                foreach (string convolution in workTask.Convolutions)
                {
                    if (Cryptography.Encryption(workWord.ToString()) == convolution)
                    {
                        ConvolutionSolution convolutionSolution = new ConvolutionSolution(
                            workWord.ToString(), convolution);
                        answer.AddSolution(convolutionSolution);
                        answer.Task = this.currentTask;
                        Console.WriteLine("Найдено решение:" + convolutionSolution);
                    }
                }

                workWord.GoToNextWord();
                workTask.NumberOfWordsThatNeedToBeIterated--;
            }

            return(answer);
        }
예제 #2
0
        public void WorkingTest()
        {
            router.ClearQueues();
            router.MaxTimeForAnswer = new TimeSpan(0, 0, 0, 10);
            ServiceFormat sf = new ServiceFormat();

            router.SendServiceMessage(sf);

            TaskFormat t = new TaskFormat("zveq", 100);

            t.Convolutions.Add(Cryptography.Encryption("zver"));
            t.Convolutions.Add(Cryptography.Encryption("q"));
            t.Convolutions.Add(Cryptography.Encryption("qwerty"));
            t.Convolutions.Add(Cryptography.Encryption("zver31031993"));
            t.StartWord = "q";

            router.SendTask(t);

            TaskFormat task = router.GetTask();

            SearchEngineSolutions fabrica = new SearchEngineSolutions(task);
            AnswerFormat          answer  = fabrica.FindSolution();

            router.SendAnswer(answer);
        }
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="SearchEngineSolutions"/>.
        /// </summary>
        /// <param name="task">
        /// Задание для которого ищется решение.
        /// </param>
        public SearchEngineSolutions(TaskFormat task)
        {
            if (task == null)
            {
                throw new InitializationOfSearchEngineSolutionsWasFailedException();
            }

            this.currentTask = task;
        }
예제 #4
0
        public void ClearingQueueTest()
        {
            TaskFormat t = new TaskFormat("zveq", 100000);

            t.Convolutions.Add(Cryptography.Encryption("zver"));
            t.Convolutions.Add(Cryptography.Encryption("q"));
            t.Convolutions.Add(Cryptography.Encryption("qwerty"));
            t.Convolutions.Add(Cryptography.Encryption("zver31031993"));
            t.StartWord = "q";

            router.SendTask(t);
            router.ClearQueues();
        }
예제 #5
0
        public void CorrectTaskAdding()
        {
            DataBank   dataBank = new DataBank();
            TaskFormat task     = new TaskFormat();

            dataBank.AddTask(task);

            Assert.AreEqual(1, dataBank.TaskCount);
            Assert.AreEqual(0, dataBank.ProgressedTaskCount);

            dataBank.AddTaskToProgressedList(task);

            Assert.AreEqual(1, dataBank.TaskCount);
            Assert.AreEqual(1, dataBank.ProgressedTaskCount);
        }
예제 #6
0
        static TaskFormat Copy(Color?taskColor, TaskFormat original)
        {
            if (taskColor.HasValue)
            {
                return new TaskFormat
                       {
                           Color     = original.Color,
                           Border    = original.Border,
                           BackFill  = new SolidBrush(taskColor.Value),
                           ForeFill  = original.ForeFill,
                           SlackFill = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LightDownwardDiagonal, taskColor.Value, Color.Transparent)
                       }
            }
            ;

            return(original);
        }
예제 #7
0
        /// <summary>
        /// Медот для запуска тестирования производительности.
        /// </summary>
        /// <returns>
        /// Количество операций в секунду.
        /// </returns>
        public long Run()
        {
            Console.WriteLine("Запущено тестирование производительности клиента.");
            Word                  word = new Word(5);
            TaskFormat            tf   = new TaskFormat(word.ToString(), this.PasswordCount);
            SearchEngineSolutions searchEngineSolutions = new SearchEngineSolutions(tf);

            DateTime startTime = DateTime.Now;

            searchEngineSolutions.FindSolution();
            DateTime finishTime = DateTime.Now;

            var result = (this.PasswordCount / ((finishTime - startTime).Milliseconds + 1)) * 100;

            Console.WriteLine("Тестирование производительности клиента окончено.");
            Console.WriteLine(
                "Производительность клиента: " + result.ToString(CultureInfo.InvariantCulture) + " оп/сек");
            return(result);
        }
예제 #8
0
        // ReSharper restore FunctionNeverReturns

        /// <summary>
        /// Прослушивание подтверждений взятия заданий.
        /// </summary>
        private void ConfirmationListner()
        {
            while (true)
            {
                // блок, проверяющий, какие задания были взяты
                var taskGetting = this.taskManagerRouter.TaskTaken();

                if (taskGetting == null)
                {
                    continue;
                }

                TaskFormat tf = this.dispatchingData.TaskList.Find(format => format.ToString() == taskGetting.ToString());
                this.dispatchingData.RemoveTask(tf);
                this.dispatchingData.AddTaskToProgressedList(tf);

                this.AddNewTasks();
            }

            // ReSharper disable FunctionNeverReturns
        }
예제 #9
0
        public void GettingConfirmationTest()
        {
            router.ClearQueues();
            router.MaxTimeForAnswer = new TimeSpan(0, 0, 0, 1);

            TaskFormat task = new TaskFormat("123", 1000);

            task.AddConvolution("123");
            router.SendTask(task);

            router.GetTask();

            var confirm = router.TaskTaken();

            Assert.AreEqual(confirm.NumberOfWordsThatNeedToBeIterated, task.NumberOfWordsThatNeedToBeIterated);
            Assert.AreEqual(confirm.StartWord, task.StartWord);
            for (int i = 0; i < confirm.Convolutions.Count; i++)
            {
                Assert.AreEqual(confirm.Convolutions[i], task.Convolutions[i]);
            }
        }
        public void SearchEngineSolutionsInitializatedCorrectly()
        {
            TaskFormat task = new TaskFormat();

            task.Convolutions.Add(Cryptography.Encryption("zzzzzz"));

            SearchEngineSolutions searchEngineSolutions = new SearchEngineSolutions(task);
            AnswerFormat          answerFormat          = searchEngineSolutions.FindSolution();

            Assert.AreEqual(answerFormat.Solution.Length, 0);

            task.NumberOfWordsThatNeedToBeIterated = 100;
            task.Convolutions.Add(
                Cryptography.Encryption(Alphabet.GetSymbol(99).ToString(CultureInfo.InvariantCulture)));
            searchEngineSolutions = new SearchEngineSolutions(task);
            answerFormat          = searchEngineSolutions.FindSolution();
            Assert.AreEqual(answerFormat.Solution.Length, 1);

            Assert.Throws <InitializationOfSearchEngineSolutionsWasFailedException>(
                () => searchEngineSolutions = new SearchEngineSolutions(null));
        }
예제 #11
0
        /// <summary>
        /// Добавить новое задание в очередь на исполнение.
        /// </summary>
        private void AddNewTasks()
        {
            while (this.dispatchingData.TaskCount < DefaultDispatchingSettings.MinCountTaskInQueue)
            {
                TaskFormat task = new TaskFormat(
                    this.workWord.ToString(),
                    DefaultDispatchingSettings.DefaultNumberOfWordsThatNeedToBeIterated)
                {
                    Convolutions =
                        this
                        .dispatchingData
                        .Convolutions
                };

                this.taskManagerRouter.SendTask(task);

                this.dispatchingData.AddTask(task);

                this.workWord.GoToWordAfterCurrent(
                    DefaultDispatchingSettings.DefaultNumberOfWordsThatNeedToBeIterated);
            }
        }
예제 #12
0
        // ReSharper restore FunctionNeverReturns

        /// <summary>
        /// Проверка выполнения заданий.
        /// </summary>
        private void TaskChecker()
        {
            while (true)
            {
                // блок проверки выполнения взятых заданий
                TaskFormat buf = null;

                if (this.dispatchingData.ProgressedTaskList.Count == 0)
                {
                    Thread.Sleep(DefaultDispatchingSettings.MaxTimeForTask);
                }
                else
                {
                    var sleepTimeSpan = (DateTime.Now - this.dispatchingData.ProgressedTaskList.First().Value)
                                        + DefaultDispatchingSettings.MaxTimeForTask;
                    Thread.Sleep(sleepTimeSpan);
                }

                foreach (KeyValuePair <TaskFormat, DateTime> keyValuePair in this.dispatchingData.ProgressedTaskList)
                {
                    if (DateTime.Now - keyValuePair.Value >= DefaultDispatchingSettings.MaxTimeForTask)
                    {
                        this.taskManagerRouter.SendTask(keyValuePair.Key);

                        this.dispatchingData.AddTask(keyValuePair.Key);
                        buf = keyValuePair.Key;
                        break;
                    }
                }

                if (buf != null)
                {
                    this.dispatchingData.RemoveTaskFromProgressedList(buf);
                }
            }

            // ReSharper disable FunctionNeverReturns
        }
예제 #13
0
        private void CALENDAR_Load(object sender, EventArgs e)
        {
            CONNECTION.open_connection();
            ProjectManager _mManager = new ProjectManager();

            using (MySqlDataAdapter da = new MySqlDataAdapter("SELECT room.room_name,room.current_status,guest.first_name,guest.last_name,reservation.arrival_date,reservation.depature_Date,room_packages.package_name FROM reservation,recerved_rooms,room_packages,room,guest WHERE reservation.reservation_id = recerved_rooms.reservation_no AND recerved_rooms.room_id = room.room_id AND room.room_package_id = room_packages.room_package_id AND guest.guest_id = reservation.guest_id AND reservation.depature_Date >= CURDATE()", CONNECTION.CON))
            {
                DataTable getRooms = new DataTable();
                da.Fill(getRooms);
                if (getRooms.Rows.Count > 0)
                {
                    int      a     = 0;
                    MyTask[] rooms = new MyTask[getRooms.Rows.Count];
                    foreach (DataRow dr in getRooms.Rows)
                    {
                        double duration, start;
                        rooms[a]           = new MyTask(_mManager);
                        rooms[a].TaskColor = getRoomColor(dr["current_status"].ToString());
                        rooms[a].Name      = "Room " + dr["room_name"].ToString();

                        if (Convert.ToDateTime(dr["arrival_date"].ToString()).Date < DateTime.Now.Date)
                        {
                            duration = (Convert.ToDateTime(dr["depature_Date"].ToString()).Date - DateTime.Today.Date).TotalDays;
                            start    = 0;
                        }
                        else
                        {
                            duration = (Convert.ToDateTime(dr["depature_Date"].ToString()).Date - Convert.ToDateTime(dr["arrival_date"].ToString()).Date).TotalDays;
                            start    = (Convert.ToDateTime(dr["arrival_date"].ToString()).Date - DateTime.Today.Date).TotalDays;
                        }

                        _mManager.Add(rooms[a]);
                        _mManager.SetStart(rooms[a], (int)start);
                        _mManager.SetDuration(rooms[a], (int)duration);
                        gnattChartRoom.PaintHeader += (s, ee) =>
                        {
                            var headerFormat = new HeaderFormat();
                            headerFormat = ee.Format;
                            headerFormat.GradientLight = Color.Silver;
                            headerFormat.GradientDark  = Color.Gray;
                            ee.Format = headerFormat;
                        };
                        gnattChartRoom.PaintTask += (s, ee) =>
                        {
                            MyTask ptask = ee.Task as MyTask;
                            if (ptask != null)
                            {
                                var format = new TaskFormat();
                                format          = ee.Format;
                                format.BackFill = new SolidBrush(ptask.TaskColor);
                                format.Border   = new Pen(new SolidBrush(ptask.TaskColor));
                                ee.Format       = format;
                            }
                        };
                        gnattChartRoom.SetToolTip(rooms[a], dr["first_name"].ToString() + " " + dr["last_name"].ToString() + "\nRoom " + dr["room_name"].ToString() + "\n" + dr["current_status"].ToString());
                        a++;
                    }

                    gnattChartRoom.Init(_mManager);
                    gnattChartRoom.CreateTaskDelegate = delegate() { return(new MyTask(_mManager)); };
                }
            }
        }
예제 #14
0
 // need to create a paint event for each task for custom painting
 /// <summary>
 /// Initialize a new instance of TaskPaintEventArgs with the editable default font and task paint format
 /// </summary>
 public TaskPaintEventArgs(Graphics graphics, Rectangle clipRect, Chart chart, Task task, int row, bool critical, Font font, TaskFormat format)
     : base(graphics, clipRect, chart)
 {
     this.Task = task;
         this.Row = row;
         this.Font = font;
         this.Format = format;
         this.IsCritical = critical;
 }
 /// <summary>
 /// Метод добавления задания в список текущих заданий.
 /// </summary>
 /// <param name="taskFormat">
 /// Задание для добавления.
 /// </param>
 public void AddTask(TaskFormat taskFormat)
 {
     this.TaskList.Add(taskFormat);
 }
 /// <summary>
 /// Метод добавления задания в список обрабатываемых заданий.
 /// </summary>
 /// <param name="taskFormat">
 /// Задание для добавления.
 /// </param>
 public void AddTaskToProgressedList(TaskFormat taskFormat)
 {
     this.ProgressedTaskList.Add(taskFormat, DateTime.Now);
 }
 /// <summary>
 /// Метод удаления задания из списка текущих заданий.
 /// </summary>
 /// <param name="taskFormat">
 /// Задание для удаления.
 /// </param>
 public void RemoveTask(TaskFormat taskFormat)
 {
     this.TaskList.Remove(taskFormat);
 }
 /// <summary>
 /// Метод удаления задания из списка обрабатываемых заданий.
 /// </summary>
 /// <param name="taskFormat">
 /// Задание для удаления.
 /// </param>
 public void RemoveTaskFromProgressedList(TaskFormat taskFormat)
 {
     this.ProgressedTaskList.Remove(taskFormat);
 }
 public void SetUp()
 {
     this.task = new TaskFormat("qweqwe", 100);
 }