public static Response ProcessRequest(Request request, List<Device> devices) { IPTVLib.RequestModel.Response response = new IPTVLib.RequestModel.Response(); response.Successful = false; response.FailReason = "Unable to process request. Bad Data."; //Process Request //Build a request to send on to the relevant devices IPTVLib.RequestModel.Request responseRequest = new IPTVLib.RequestModel.Request(); response.Successful = true; //Switch and do something using the given data switch (request.Action) { case RequestAction.RequestHosts: response = ProcessHostsRequest(request, devices, response, responseRequest); break; case RequestAction.RequestRemotes: response = ProcessRemotesRequest(request, devices, response, responseRequest); break; case RequestAction.RequestDevices: response = ProcessDevicesRequest(request, devices, response, responseRequest); break; default: response = PassThroughRequest(request, devices, responseRequest, response); // By Default just pass the request on to the specified devices -- ones that require extra processing are above break; }//switch //Return the response return response; }
public ActionResult Sample() { Request newRequest = new Request { AccountName = "Lee", Action = RequestAction.RequestId, FriendlyName = "Lee iPhone", CurrentOperationMode = DeviceMode.Remote }; return this.Json(newRequest); }
private static IPTVLib.RequestModel.Response ProcessDevicesRequest(Request request, List<Device> devices, IPTVLib.RequestModel.Response response, IPTVLib.RequestModel.Request responseRequest) { var hosts = devices.Where(d => d.Mode == DeviceMode.Host).ToList(); var remotes = devices.Where(d => d.Mode == DeviceMode.Remote).ToList(); responseRequest.AccountName = request.AccountName; responseRequest.Action = RequestAction.DeviceInfo; responseRequest.DeviceGuid = request.DeviceGuid; responseRequest.FriendlyName = request.FriendlyName; responseRequest.RelatedHostIds = Device.GetDeviceIds(hosts); responseRequest.RelatedRemoteIds = Device.GetDeviceIds(remotes); responseRequest.CurrentOperationMode = request.CurrentOperationMode; response.ActionDevices = devices.Where(d => d.Id.ToString() == request.DeviceGuid).ToList(); response.DataToSend = responseRequest; response.Successful = true; return response; }
private static IPTVLib.RequestModel.Response PassThroughRequest(Request request, List<Device> devices, IPTVLib.RequestModel.Request responseRequest, IPTVLib.RequestModel.Response response) { responseRequest.AccountName = request.AccountName; responseRequest.Action = request.Action; responseRequest.DeviceGuid = request.DeviceGuid; responseRequest.FriendlyName = request.FriendlyName; responseRequest.Message = request.Message; responseRequest.CurrentOperationMode = request.CurrentOperationMode; response.DataToSend = responseRequest; //Find all devices that the alert has been targeted at. var devicesToNotify = new List<string>(); //Ids only if (request.RelatedRemoteIds != null) { foreach (var remote in request.RelatedRemoteIds) devicesToNotify.Add(remote.Key); //devicesToNotify.AddRange(request.RelatedRemoteIds.Select(rri => rri.Key)); }//if if (request.RelatedHostIds != null) { foreach (var remote in request.RelatedHostIds) devicesToNotify.Add(remote.Key); }//if if (request.IncludeAllHosts) { var hosts = devices.Where(d => d.Mode == DeviceMode.Host); devicesToNotify.AddRange(hosts.Select(r => r.Id.ToString())); }//if if (request.IncludeAllRemotes) { var remotes = devices.Where(d => d.Mode == DeviceMode.Remote); devicesToNotify.AddRange(remotes.Select(r => r.Id.ToString())); }//if response.ActionDevices = devices.Where(d => devicesToNotify.Contains(d.Id.ToString())).ToList(); return response; }
public Response() { ActionDevices = new List<Device>(); DataToSend = new Request(); FailReason = string.Empty; }