コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ApplicationId,BreweryId")] CollaborationRequest collaborationRequest)
        {
            if (id != collaborationRequest.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(collaborationRequest);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CollaborationRequestExists(collaborationRequest.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationId"] = new SelectList(_context.ApplicationUser, "Id", "Id", collaborationRequest.SenderId);
            ViewData["BreweryId"]     = new SelectList(_context.Brewery, "Id", "Id", collaborationRequest.ReceiverId);
            return(View(collaborationRequest));
        }
コード例 #2
0
        internal void AddSubscriber(CollaborationRequest collaborationRequest, Subscriber subscriber)
        {
            var subscriberList = subscribers.GetOrAdd(collaborationRequest, request => new ConcurrentBag <Subscriber>());

            subscriberList.Add(subscriber);
            SubscriptionRequested?.Invoke(this, subscriber);
        }
コード例 #3
0
 internal void HandleStopCollaboration(CollaborationRequest collaborationRequest)
 {
     StopCollaborationRequested?.Invoke(this, collaborationRequest);
     lock (collaborationRequestLock)
     {
         currentCollaborationRequest = null;
     }
 }
コード例 #4
0
 private static void OnCollaborationRequestAccepted(object sender, CollaborationRequest request)
 {
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine($"A collaboration request arrived from {request.SenderName} ({request.SenderAddress}) for file {request.Filename}, starting work now...");
     Console.ResetColor();
     //TODO: this call should be made only if this application actually wants to collaborate
     //In this example, let's collaborate only if we're not working on a file ourselves
     workCancellationTokenSource = new CancellationTokenSource();
     PerformWorkOnFile(request.Filename, workCancellationTokenSource.Token);
 }
コード例 #5
0
ファイル: AgentSelector.cs プロジェクト: Sharpen6/IMAP
        internal void AddCollabConstraints(Constant targetAgent, Action collabAction, Constant senderAgent)
        {
            CollaborationRequest cr = new CollaborationRequest();

            cr.CollaborationRequired = collabAction;
            cr.Sender   = senderAgent;
            cr.Receiver = targetAgent;

            CollborationRequests.Add(cr);
        }
コード例 #6
0
 private bool SwitchCollaborationRequest(CollaborationRequest request)
 {
     lock (collaborationRequestLock)
     {
         if (currentCollaborationRequest != null)
         {
             return(false);
         }
         currentCollaborationRequest = request;
         return(true);
     }
 }
コード例 #7
0
        private void NotifySubscribersTheyShouldStopCollaborating(CollaborationRequest collaborationRequest)
        {
            bool couldRemove = subscribers.TryRemove(collaborationRequest, out ConcurrentBag <Subscriber> subscribersList);

            if (!couldRemove)
            {
                return;
            }
            foreach (var subscriber in subscribersList)
            {
                NotifySubscriberToStopCollaborating(collaborationRequest, subscriber);
                SubscriberNotifiedToStopCollaborating?.Invoke(this, subscriber);
            }
        }
コード例 #8
0
        public IActionResult Create(int id)
        {
            List <BeerStyle> li = new List <BeerStyle>();

            li = _context.BeerStyle.ToList();
            ViewBag.listofitems = li;

            CollaborationRequest currentRequest = _context.CollaborationRequest.Where(cr => cr.Id == id).FirstOrDefault();

            ViewModels.CollabBeersViewModel collabBeersViewModel = new ViewModels.CollabBeersViewModel
            {
                BeerStyles           = li,
                CollaborationRequest = currentRequest
            };

            return(View(collabBeersViewModel));
        }
コード例 #9
0
        private void NotifySubscriberToStopCollaborating(CollaborationRequest request, Subscriber subscriber)
        {
            //Create a WCF client by indicating A-B-C: Address, Binding, Contract
            //Address
            var serviceAddress = GetCollaborationServiceAddress(subscriber.Address, unicastPort);
            //Binding
            NetTcpBinding tcpBinding = new NetTcpBinding();

            tcpBinding.Security.Mode = SecurityMode.None;
            tcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
            //Create the ChannelFactory by indicating the Contract (i.e. the service interface)
            ChannelFactory <ISubscriptionService> factory = new ChannelFactory <ISubscriptionService>(tcpBinding, new EndpointAddress(serviceAddress));

            //Open the channel and send the request
            ISubscriptionService proxy = factory.CreateChannel();

            proxy.StopCollaborating(request);
            factory.Close();
        }
コード例 #10
0
        public void StopCollaboration()
        {
            CollaborationRequest collaborationRequest;

            lock (collaborationRequestLock)
            {
                collaborationRequest        = currentCollaborationRequest;
                currentCollaborationRequest = null;
            }
            if (collaborationRequest == null)
            {
                return;
            }
            var localAddress = networkAddress.GetLocalAddress();

            if (collaborationRequest.SenderAddress.Equals(localAddress))
            {
                NotifySubscribersTheyShouldStopCollaborating(collaborationRequest);
            }
        }
コード例 #11
0
        // GET: CollaborationRequests/Delete/5
        public async Task <IActionResult> Delete(int?id, CollaborationRequest collaborationRequest)
        {
            if (id == null)
            {
                return(NotFound());
            }
            CollaborationRequest collabReq = _context.CollaborationRequest.Where(i => i.Id == id).SingleOrDefault();

            collabReq = await _context.CollaborationRequest
                        .Include(c => c.SenderId)
                        .Include(c => c.ReceiverId)
                        .FirstOrDefaultAsync(m => m.Id == id);

            if (collaborationRequest == null)
            {
                return(NotFound());
            }

            return(View(collaborationRequest));
        }
コード例 #12
0
        internal void HandleCollaborationRequest(CollaborationRequest request)
        {
            var localAddress = networkAddress.GetLocalAddress();

            if (request.SenderAddress.Equals(localAddress))
            {
                //It originated from myself, just discard it
                //When broadcasting, the sender also receives its own message
                return;
            }

            if (SwitchCollaborationRequest(request))
            {
                SubscribeCollaborator(request);
                CollaborationRequestAccepted?.Invoke(this, request);
            }
            else
            {
                CollaborationRequestDeclined?.Invoke(this, request);
            }
        }
コード例 #13
0
        //// POST: CollaborationRequests/Create
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        //// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public async Task<IActionResult> Create([Bind("Id,ApplicationId,BreweryId")] CollaborationRequest collaborationRequest)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        _context.Add(collaborationRequest);
        //        await _context.SaveChangesAsync();
        //        return RedirectToAction(nameof(Index));
        //    }
        //    ViewData["ApplicationId"] = new SelectList(_context.ApplicationUser, "Id", "Id", collaborationRequest.ApplicationId);
        //    ViewData["BreweryId"] = new SelectList(_context.Brewery, "Id", "Id", collaborationRequest.BreweryId);
        //    return View(collaborationRequest);
        //}

        public IActionResult SendCollaborationRequest(int id)
        {
            //instatiate a follow
            CollaborationRequest collaborationRequest = new CollaborationRequest();
            //set applicationid as fk
            string  userId          = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            Brewery loggedInBrewery = _context.Brewery.Where(i => i.ApplicationId == userId).SingleOrDefault();

            collaborationRequest.SenderId   = loggedInBrewery.Id;
            collaborationRequest.SenderName = loggedInBrewery.Name;
            Brewery receivingBrewery = _context.Brewery.Where(i => i.Id == id).SingleOrDefault();

            //set breweryid as fk
            collaborationRequest.ReceiverId   = id;
            collaborationRequest.ReceiverName = receivingBrewery.Name;
            //add to table
            _context.Add(collaborationRequest);
            //save changes
            _context.SaveChanges();
            //return to same view (redirect to index action)
            return(RedirectToAction("Index", "Breweries"));
        }
コード例 #14
0
 // PUT: api/CollaborationRequests/5
 public void Put(Guid id, [FromBody] CollaborationRequest value)
 {
     db.Entry(value).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
コード例 #15
0
 public void StopCollaborating(CollaborationRequest collaborationRequest)
 {
     collaborationRequest.SenderAddress = GetClientIp();
     client.HandleStopCollaboration(collaborationRequest);
 }
コード例 #16
0
 private static void OnStopCollaborationRequested(object sender, CollaborationRequest request)
 {
     Console.WriteLine($"We were asked to stop our collaboration on file {request.Filename}, stopping work now...");
     workCancellationTokenSource?.Cancel();
     WriteInstructions();
 }
コード例 #17
0
 private static void OnCollaborationRequestDeclined(object sender, CollaborationRequest request)
 {
     Console.WriteLine($"A collaboration request arrived from {request.SenderName} ({request.SenderAddress}), but it was declined since we're already busy");
 }
コード例 #18
0
 // POST: api/CollaborationRequests
 public void Post([FromBody] CollaborationRequest value)
 {
     db.CollaborationRequests.Add(value);
     db.SaveChanges();
 }
コード例 #19
0
 public void SubscribeCollaborator(CollaborationRequest request, Subscriber subscriber)
 {
     request.SenderAddress = subscriber.Address = GetClientIp();
     client.AddSubscriber(request, subscriber);
 }
コード例 #20
0
 public void BroadcastCollaborationRequest(CollaborationRequest request)
 {
     request.SenderAddress = GetClientIp();
     client.HandleCollaborationRequest(request);
 }