예제 #1
0
        public static int CheckImagesQuality(List <ImageItem> imageItems, Action <ControllerTaskResultMessage> actionToCallAfterComplete)
        {
            if (imageItems is null)
            {
                throw new ArgumentNullException(nameof(imageItems));
            }

            if (actionToCallAfterComplete is null)
            {
                throw new ArgumentNullException(nameof(actionToCallAfterComplete));
            }

            var message = new ControllerTaskRequestMessage()
            {
                taskid = TaskIdCntr++,
                type   = (int)TaskType.Quality
            };

            message.images.AddRange(imageItems.
                                    Select(i =>
            {
                return(new List <string>()
                {
                    i.DatabaseId.ToString(), i.FilePath
                });
            }).ToList());

            RunTask(message, actionToCallAfterComplete);

            return(message.taskid);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uiThreadDispatcher"></param>
        /// <param name="databaseFilePath"></param>
        /// <exception cref="BackendControllerInitializationException">
        /// Throws BackendControllerInitializationException if the controller fails to
        /// set provided databaseFilePath
        /// </exception>
        public static async Task Initialize(CoreDispatcher uiThreadDispatcher, string databaseFilePath)
        {
            if (string.IsNullOrEmpty(databaseFilePath))
            {
                throw new ArgumentException("message", nameof(databaseFilePath));
            }

            if (!databaseFilePath.Any() || !Path.HasExtension(databaseFilePath))
            {
                throw new ArgumentException("Invalid parameter: databaseFilePath should contain a valid path.");
            }

            OutgoingQueueName         = "front";
            IncomingQueueName         = "back";
            LauncherOutgoingQueueName = "launcher";

            Communicator        = RabbitMQCommunicationService.Instance;
            _uiThreadDispatcher = uiThreadDispatcher ?? throw new ArgumentNullException(nameof(uiThreadDispatcher));
            Communicator.Initialize(uiThreadDispatcher);

            try
            {
                Communicator.DeclareOutgoingQueue(LauncherOutgoingQueueName);
            }
            catch (QueueAlreadyExistsException) { }
            try
            {
                Communicator.DeclareOutgoingQueue(OutgoingQueueName);
            }
            catch (QueueAlreadyExistsException) { }
            try
            {
                Communicator.DeclareIncomingQueue(IncomingQueueName);
            }
            catch (QueueAlreadyExistsException) { }

            Communicator.MessageReceived += MessageReceiver;

            var helloMessage = new ControllerTaskRequestMessage()
            {
                taskid = TaskIdCntr++,
                type   = (int)TaskType.Initialize
            };

            RunTask(helloMessage, PathSendCompleteHandler);
            await Task.Delay(500);

            if (!Initialized)
            {
                throw new BackendControllerInitializationException();
            }
        }
        public void ToJsonTest()
        {
            ControllerTaskRequestMessage msg = new ControllerTaskRequestMessage()
            {
                taskid = 1,
                type   = 2
            };

            msg.images.Add(new List <string>()
            {
                "1", "image/1"
            });
            msg.images.Add(new List <string>()
            {
                "2", "image/2"
            });

            string result   = msg.ToJson();
            string expected = "{\"taskid\":1,\"type\":2,\"images\":[[\"1\",\"image/1\"],[\"2\",\"image/2\"]]}";

            Assert.AreEqual(expected, result);
        }
        public void FromJsonTest()
        {
            string json = "{\"taskid\":1,\"type\":2,\"images\":[[\"1\",\"image/1\"],[\"2\",\"image/2\"]]}";
            ControllerTaskRequestMessage expected = new ControllerTaskRequestMessage()
            {
                taskid = 1,
                type   = 2
            };

            expected.images.Add(new List <string>()
            {
                "1", "image/1"
            });
            expected.images.Add(new List <string>()
            {
                "2", "image/2"
            });

            var result = ControllerTaskRequestMessage.FromJson(json);

            Assert.AreEqual(expected.taskid, result.taskid);
            Assert.AreEqual(expected.type, result.type);
            Assert.IsTrue(expected.images.SequenceEqual(result.images));
        }
예제 #5
0
        public static int CompareImages(List <ImageItem> comparedImageItems, Action <ControllerTaskResultMessage> actionToCallAfterComplete)
        {
            if (comparedImageItems is null)
            {
                throw new ArgumentNullException(nameof(comparedImageItems));
            }

            if (actionToCallAfterComplete is null)
            {
                throw new ArgumentNullException(nameof(actionToCallAfterComplete));
            }

            if (comparedImageItems.Count < 2)
            {
                throw new ArgumentOutOfRangeException("comparedImagesIds list count should be at least 2");
            }

            var message = new ControllerTaskRequestMessage()
            {
                taskid = TaskIdCntr++,
                type   = (int)TaskType.Compare
            };

            message.images.AddRange(comparedImageItems.
                                    Select(i =>
            {
                return(new List <string>()
                {
                    i.DatabaseId.ToString(), i.FilePath
                });
            }).ToList());

            RunTask(message, actionToCallAfterComplete);

            return(message.taskid);
        }
예제 #6
0
 private static void RunTask(ControllerTaskRequestMessage message, Action <ControllerTaskResultMessage> actionToCallAfterComplete)
 {
     Tasks.Add(message.taskid, message);
     TaskCompleteActions.Add(message.taskid, actionToCallAfterComplete);
     Communicator.Send(OutgoingQueueName, message.ToJson());
 }