Beispiel #1
0
        public void CanCreateProjectAndGetDeviceVersion()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);

                    var projectDeviceVersion = ProjectDeviceActions.GetLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    projectDeviceVersion = ProjectDeviceActions.GetLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    Assert.NotNull(projectDeviceVersion);
                }
        }
Beispiel #2
0
        public IAssignableDevice GetAssignableDeviceByGuid([CanBeNull] StrGuid?guid)
        {
            if (guid == null)
            {
                return(null);
            }
            var dev = RealDevices.FindByGuid(guid);

            if (dev != null)
            {
                return(dev);
            }
            var devc = DeviceCategories.FindByGuid(guid);

            if (devc != null)
            {
                return(devc);
            }
            var devAc = DeviceActions.FindByGuid(guid);

            if (devAc != null)
            {
                return(devAc);
            }
            var deviceActionGroup = DeviceActionGroups.FindByGuid(guid);

            if (deviceActionGroup != null)
            {
                return(deviceActionGroup);
            }
            return(null);
        }
        public void CanDistinguishBetweenProjectDevicesAndNonProjectDevices()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var anotherProject = new Project {
                        Name = "Test2"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };
                    var anotherDevice = new Device {
                        IpAddress = "192.168.1.2", Name = "MyOtherTestDevice"
                    };

                    project        = ProjectActions.CreateProject(project).Function(conn);
                    anotherProject = ProjectActions.CreateProject(anotherProject).Function(conn);
                    var projectDevice        = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                    var anotherProjectDevice = DeviceActions.AddDeviceToProject(anotherProject.Id, anotherDevice).Function(conn);

                    var devices = DeviceActions.GetProjectDevices(project.Id).Function(conn);

                    Assert.Equal(1, devices.Count());

                    var retrievedDevice = devices.Single();

                    Assert.Equal(device.IpAddress, retrievedDevice.IpAddress);
                    Assert.Equal(device.Name, retrievedDevice.Name);
                }
        }
Beispiel #4
0
        public void CanSetProjectDeviceMappingsTwice()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice        = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                    var projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    var firstMappings = new List <ProjectDeviceVersionMapping>
                    {
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 1,
                            VerticalPosition   = 1,
                            MappingOrder       = 1
                        }
                    };

                    var secondMappings = new List <ProjectDeviceVersionMapping>
                    {
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 1,
                            VerticalPosition   = 1,
                            MappingOrder       = 1,
                        },
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 2,
                            VerticalPosition   = 1,
                            MappingOrder       = 2
                        }
                    };

                    ProjectDeviceActions.SetProjectDeviceMappings(projectDeviceVersion.Id, firstMappings).Function(conn);
                    ProjectDeviceActions.SetProjectDeviceMappings(projectDeviceVersion.Id, secondMappings).Function(conn);

                    var result = ProjectDeviceActions.GetProjectDeviceMappings(projectDeviceVersion.Id).Function(conn);

                    Assert.Equal(2, result.Count());
                }
        }
        public void BypassDevice(int deviceId, int projectId, bool bypass)
        {
            var device = dispatcher.Dispatch(DeviceActions.GetDevice(deviceId));

            Guard.This(device).AgainstDefaultValue(string.Format("Cannot find device with device id '{0}'", deviceId));

            var projectDevice = dispatcher.Dispatch(ProjectDeviceActions.GetProjectDevice(deviceId, projectId));

            Guard.This(projectDevice).AgainstDefaultValue(string.Format("Cannot find project device with device id '{0}' and project id '{1}'", deviceId, projectId));

            dispatcher.Dispatch(ProjectDeviceActions.BypassDevice(projectDevice.Id, bypass));
        }
        public void CanAddDeviceToProject()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                }
        }
Beispiel #7
0
        public void CanUndoProjectDeviceVersion()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);

                    var projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    var updatedProjectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 99,
                        VerticalPercentage          = 99,
                        NumberOfHorizontalPixels    = 30,
                        NumberOfVerticalPixels      = 30,
                        StartAtHorizontalPercentage = 1,
                        StartAtVerticalPercentage   = 1
                    }).Function(conn);

                    var undoneProjectDeviceVersion = ProjectDeviceActions.UndoLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    var undoEqualsOriginalProjectDeviceVersion = projectDeviceVersion.PropertiesAreEqual(undoneProjectDeviceVersion);

                    Assert.True(undoEqualsOriginalProjectDeviceVersion);
                }
        }
Beispiel #8
0
        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 ProjectDevicePlaybackStatus GetProjectDevicePlaybackStatus(int deviceId, int projectId)
        {
            var device = dispatcher.Dispatch(DeviceActions.GetDevice(deviceId));

            Guard.This(device).AgainstDefaultValue(string.Format("Cannot find device with device id '{0}'", deviceId));

            var projectDevice = dispatcher.Dispatch(ProjectDeviceActions.GetProjectDevice(deviceId, projectId));

            Guard.This(projectDevice).AgainstDefaultValue(string.Format("Cannot find project device with device id '{0}' and project id '{1}'", deviceId, projectId));

            if (projectDevice.IsBypassed)
            {
                return(ProjectDevicePlaybackStatus.Bypassed);
            }

            var deviceClient = clientFactory.ForDevice(device);

            try
            {
                deviceClient.LoadVideo(projectDevice.Id);
                if (!devicePlaybacks.Any(dp => dp.Client.BaseAddress == deviceClient.BaseAddress))
                {
                    devicePlaybacks.Add(new DevicePlayback(projectDevice.Id, deviceClient));
                }

                return(ProjectDevicePlaybackStatus.Ready);
            }
            catch (PiApiClientCommunicationException)
            {
                return(ProjectDevicePlaybackStatus.NotOnline);
            }
            catch (PiApiClientRequestException)
            {
                return(ProjectDevicePlaybackStatus.NotReady);
            }
        }
Beispiel #10
0
        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++;
                }
            }
        }
Beispiel #11
0
        public GlobalJsonResult <EmptyResult> RemoveDeviceFromProject(int deviceId, int projectId)
        {
            dataAccessDispatcher.Dispatch(DeviceActions.RemoveDeviceFromProject(deviceId, projectId));

            return(GlobalJsonResult <ProjectDevice> .Success(System.Net.HttpStatusCode.OK));
        }
Beispiel #12
0
        public GlobalJsonResult <ProjectDevice> AddDeviceToProject(int projectId, Device device)
        {
            var result = dataAccessDispatcher.Dispatch(DeviceActions.AddDeviceToProject(projectId, device));

            return(GlobalJsonResult <ProjectDevice> .Success(System.Net.HttpStatusCode.Created, result));
        }
Beispiel #13
0
        public GlobalJsonResult <IEnumerable <Device> > GetAllPreviouslyDiscoveredDevices()
        {
            var result = dataAccessDispatcher.Dispatch(DeviceActions.GetAllDevices());

            return(GlobalJsonResult <IEnumerable <Device> > .Success(System.Net.HttpStatusCode.OK, result));
        }
Beispiel #14
0
        public GlobalJsonResult <IEnumerable <Device> > GetProjectDevices(int projectId)
        {
            var result = dataAccessDispatcher.Dispatch(DeviceActions.GetProjectDevices(projectId));

            return(GlobalJsonResult <IEnumerable <Device> > .Success(System.Net.HttpStatusCode.OK, result));
        }
Beispiel #15
0
        public GlobalJsonResult <ProjectDevice> AddDiscoveredDeviceToProject(int projectId, [FromBody] DiscoveredDevice device)
        {
            var result = dispatcher.Dispatch(DeviceActions.AddDeviceToProject(projectId, device.Map()));

            return(GlobalJsonResult <ProjectDevice> .Success(HttpStatusCode.OK, result));
        }