コード例 #1
0
ファイル: PeersController.cs プロジェクト: darrelmiller/cowpi
        public IActionResult Get(int id)
        {
            var peer = this.peerService.GetPeer(id);

            if (peer == null)
            {
                return(new NotFoundResult());
            }

            var cow = new CooperatingWorker()
            {
                Skills      = peer.Skills,
                TasksUrl    = peer.TasksUrl,
                CapacityUrl = peer.CapacityUrl
            };

            return(new JsonResult(new { cooperatingWorkers = cow }, StatementOfWork.SerializerSettings));
        }
コード例 #2
0
        internal WorkerPeer CreatePeer(CooperatingWorker cow)
        {
            var workerPeer = new WorkerPeer
            {
                Id          = worker.GetNextTaskId(),
                TasksUrl    = cow.TasksUrl,
                CapacityUrl = cow.CapacityUrl
            };


            if (this.worker.Peers.TryAdd(workerPeer.Id, workerPeer))
            {
                return(workerPeer);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: PeersController.cs プロジェクト: darrelmiller/cowpi
        public IActionResult Post()
        {
            CooperatingWorker cow;

            using (var sr = new StreamReader(this.Request.Body))
            {
                try
                {
                    cow = CooperatingWorker.Load(sr);
                }
                catch
                {
                    return(new BadRequestResult());
                }
            }

            var peer = this.peerService.CreatePeer(cow);

            return(new CreatedAtActionResult("get", "peers", new { id = peer.Id }, null));
        }