protected void PropageteRequestToWorkers(RestRequest request, Topic topic, Worker worker, Worker coworker)
        {
            var           requestForMaster = request.AddParameter("Cooperator", coworker.Address);
            IRestResponse response;

            if (WorkerQueries.IsWorkerAlive(DBConnection, worker.Id))
            {
                response = PropagateRequest(requestForMaster, worker);
                if (response.ResponseStatus == ResponseStatus.TimedOut ||
                    response.ResponseStatus == ResponseStatus.Error)
                {
                    response = PropagateRequest(request, coworker);
                    TopicsQueries.swapWorkers(DBConnection, topic);
                }
            }
            else
            {
                response = PropagateRequest(request, coworker);
                TopicsQueries.swapWorkers(DBConnection, topic);
            }
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new BadRequestException();
            }
        }
Example #2
0
 public QueuesAndTopics Get(QueuesAndTopicsRequest request)
 {
     if (Encrypt.EncryptToken(request.Time, request.WorkerId, request.Address, request.Token))
     {
         var queues = QueuesQueries.GetWorkerQueues(DBConnection, request.WorkerId);
         var topics = TopicsQueries.GetWorkerTopics(DBConnection, request.WorkerId);
         return(new QueuesAndTopics
         {
             Queues = queues,
             Topics = topics
         });
     }
     throw new BadRequestException();
 }
        protected void processRequest(string topicName, RestRequest request)
        {
            if (!TopicsQueries.TopicExists(DBConnection, topicName))
            {
                throw new TopicNotExistsException();
            }
            else
            {
                var topic    = TopicsQueries.getTopicByName(DBConnection, topicName);
                var worker   = WorkerQueries.GetWorkerById(DBConnection, topic.Worker);
                var coworker = WorkerQueries.GetWorkerById(DBConnection, topic.Cooperator);

                PropageteRequestToWorkers(request, topic, worker, coworker);
            }
        }
Example #4
0
        public void Delete(DeleteTopic request)
        {
            var requestToSend = new RestRequest($"/topics/{request.TopicName}", Method.DELETE);

            if (!TopicsQueries.TopicExists(DBConnection, request.TopicName))
            {
                throw new TopicNotExistsException();
            }
            else
            {
                var topic    = TopicsQueries.getTopicByName(DBConnection, request.TopicName);
                var worker   = WorkerQueries.GetWorkerById(DBConnection, topic.Worker);
                var coworker = WorkerQueries.GetWorkerById(DBConnection, topic.Cooperator);

                TopicsQueries.DeleteTopic(DBConnection, request.TopicName);
                PropageteRequestToWorkers(requestToSend, topic, worker, coworker);
            }
        }
        public Announcement Get(GetAnnouncement request, int subscriberId)
        {
            var requestToSend = new RestRequest($"/topics/{request.TopicName}/announcements", Method.GET);

            requestToSend.AddParameter("SubscriberId", subscriberId);

            if (!TopicsQueries.TopicExists(DBConnection, request.TopicName))
            {
                throw new TopicNotExistsException();
            }
            else
            {
                var topic    = TopicsQueries.getTopicByName(DBConnection, request.TopicName);
                var worker   = WorkerQueries.GetWorkerById(DBConnection, topic.Worker);
                var coworker = WorkerQueries.GetWorkerById(DBConnection, topic.Cooperator);

                return(PropageteRequestToWorkers <Announcement>(requestToSend, topic, worker, coworker));
            }
        }
Example #6
0
        public void Create(CreateTopic request)
        {
            var requestToSend = new RestRequest("topics", Method.POST);

            requestToSend.AddParameter("Name", request.Name);

            if (TopicsQueries.TopicExists(DBConnection, request.Name))
            {
                throw new TopicAlreadyExistsException();
            }
            else
            {
                Worker worker, coworker;
                CalculateTopicWorkers(request.Name, out worker, out coworker);
                var topic = TopicsQueries.CreateTopic(DBConnection, request.Name, worker.Id, coworker.Id);

                PropageteRequestToWorkers(requestToSend, topic, worker, coworker);
            }
        }
 protected override void swapWorkers(ICollection collection)
 {
     TopicsQueries.swapWorkers(DBConnection, (Topic)collection);
 }
Example #8
0
 public IList <String> Get()
 {
     return(TopicsQueries.getTopicsNames(DBConnection));
 }