public GlobalJsonResult <Dictionary <string, string> > GetProjectDeviceStatuses(int projectId) { var projectDevices = dataAccessDispatcher.Dispatch(DeviceActions.GetProjectDevices(projectId)); var statuses = new Dictionary <string, string>(); foreach (var projectDevice in projectDevices) { var name = string.IsNullOrEmpty(projectDevice.Name) ? projectDevice.IpAddress : projectDevice.Name; var status = deviceStatusService.IsOnline(projectDevice) ? ProjectDevicePlaybackStatus.Ready : ProjectDevicePlaybackStatus.NotOnline; statuses.Add(name, status.ToString()); } return(GlobalJsonResult <Dictionary <string, string> > .Success(System.Net.HttpStatusCode.OK, statuses)); }
public void ProcessProjectDeviceVersion(BackgroundJob job) { var projectDeviceVersion = dispatcher.Dispatch(ProjectDeviceActions.GetProjectDeviceVersion(job.ProjectDeviceVersionId)); Guard.This(projectDeviceVersion).AgainstDefaultValue(string.Format("Could not find project device version '{0}'", job.ProjectDeviceVersionId)); var device = dispatcher.Dispatch(DeviceActions.GetProjectDevice(projectDeviceVersion.ProjectDeviceId)); Guard.This(device).AgainstDefaultValue(string.Format("Could not find project device with project device Id '{0}'", projectDeviceVersion.ProjectDeviceId)); Guard.This(device).WithRule(d => deviceStatusService.IsOnline(device), string.Format("Device {0} (with IP Address {1}) is not online", device.Name, device.IpAddress)); var project = dispatcher.Dispatch(ProjectActions.GetProjectFromProjectDevice(projectDeviceVersion.ProjectDeviceId)); Guard.This(project).AgainstDefaultValue(string.Format("Could not find project from project device with id '{0}'", projectDeviceVersion.ProjectDeviceId)); var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(project.Id)); Guard.This(video).AgainstDefaultValue(string.Format("Could not find video for project '{0}'", project.Name)); using (var videoProcessor = videoProcessorInstantiator()) { var videoMetadata = videoProcessor.StartReadingVideo(project.Id, projectDeviceVersion.ProjectDeviceId); var client = piClientFactory.ForDevice(device); // Update video metadata (use project device id instead of video id with client (could have the same video in multiple configurations) var existingVideosOnPi = client.GetAllVideoMetadata(); var existingVideoOnPi = existingVideosOnPi.SingleOrDefault(v => v.Id == projectDeviceVersion.ProjectDeviceId); if (existingVideoOnPi == null) { client.CreateVideoMetadata(new VideoMetadataCreateRequest { Id = projectDeviceVersion.ProjectDeviceId, FileName = video.FilePath, FrameRate = videoMetadata.FrameRate }); } else { client.UpdateVideoMetadata(new VideoMetadataPutRequest { Id = projectDeviceVersion.ProjectDeviceId, FileName = video.FilePath, FrameRate = videoMetadata.FrameRate, }); } // Clear, then send frames to Pi client.ClearFrames(projectDeviceVersion.ProjectDeviceId); int framePosition = 1; while (true) { var read = videoProcessor.ReadNext1000Frames(); client.SendFrames(projectDeviceVersion.ProjectDeviceId, new AppendFramesRequest { AppendFrameRequests = read.Frames .Select(f => new AppendFrameRequest { BinaryData = f, Position = framePosition }) .ToArray() }); dispatcher.Dispatch(BackgroundJobActions.MarkPercentageCompletion(job.Id, read.PercentageComplete)); if (!read.MoreFrames) { break; } framePosition++; } } }