Ejemplo n.º 1
0
        public virtual BOServerTask MapEFToBO(
            ServerTask ef)
        {
            var bo = new BOServerTask();

            bo.SetProperties(
                ef.Id,
                ef.CompletedTime,
                ef.ConcurrencyTag,
                ef.Description,
                ef.DurationSeconds,
                ef.EnvironmentId,
                ef.ErrorMessage,
                ef.HasPendingInterruptions,
                ef.HasWarningsOrErrors,
                ef.JSON,
                ef.Name,
                ef.ProjectId,
                ef.QueueTime,
                ef.ServerNodeId,
                ef.StartTime,
                ef.State,
                ef.TenantId);
            return(bo);
        }
Ejemplo n.º 2
0
        public void MapEFToBO()
        {
            var        mapper = new DALServerTaskMapper();
            ServerTask entity = new ServerTask();

            entity.SetProperties(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", 1, "A", "A", true, true, "A", "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A");

            BOServerTask response = mapper.MapEFToBO(entity);

            response.CompletedTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ConcurrencyTag.Should().Be("A");
            response.Description.Should().Be("A");
            response.DurationSeconds.Should().Be(1);
            response.EnvironmentId.Should().Be("A");
            response.ErrorMessage.Should().Be("A");
            response.HasPendingInterruptions.Should().Be(true);
            response.HasWarningsOrErrors.Should().Be(true);
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.QueueTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ServerNodeId.Should().Be("A");
            response.StartTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.State.Should().Be("A");
            response.TenantId.Should().Be("A");
        }
Ejemplo n.º 3
0
        public virtual ServerTask MapBOToEF(
            BOServerTask bo)
        {
            ServerTask efServerTask = new ServerTask();

            efServerTask.SetProperties(
                bo.CompletedTime,
                bo.ConcurrencyTag,
                bo.Description,
                bo.DurationSeconds,
                bo.EnvironmentId,
                bo.ErrorMessage,
                bo.HasPendingInterruptions,
                bo.HasWarningsOrErrors,
                bo.Id,
                bo.JSON,
                bo.Name,
                bo.ProjectId,
                bo.QueueTime,
                bo.ServerNodeId,
                bo.StartTime,
                bo.State,
                bo.TenantId);
            return(efServerTask);
        }
Ejemplo n.º 4
0
		public void Add(ServerTask serverTask)
		{
			_dispatcher.BeginInvoke((Action)(() =>
			{
				var serverTaskViewModel = new ServerTaskViewModel(serverTask);
				ServerTasks.Add(serverTaskViewModel);
			}));
		}
Ejemplo n.º 5
0
        private void CloseTask(ServerTask task)
        {
            var taskRepo = new ServerTasksRepository(DataBase);

            task.Status = ServerTask.TaskStatus.Completed;
            taskRepo.Update(task);
            logger.Info($"Task Completed successfully!");
        }
Ejemplo n.º 6
0
        public void Dispose()
        {
            if (!CancellationTokenSource.IsCancellationRequested)
            {
                CancellationTokenSource.Cancel();
            }

            ServerTask.Wait();
        }
Ejemplo n.º 7
0
		public void Edit(ServerTask serverTask)
		{
			_dispatcher.BeginInvoke((Action)(() =>
			{
				var serverTaskViewModel = ServerTasks.FirstOrDefault(x => x.ServerTask.UID == serverTask.UID);
				if (serverTaskViewModel != null)
					serverTaskViewModel.ServerTask = serverTask;
			}));
		}
Ejemplo n.º 8
0
        public void Dispose()
        {
            if (!CancellationTokenSource.IsCancellationRequested)
            {
                CancellationTokenSource.Cancel();
            }

            ServerTask.Wait();
            Assert.True(NamedPipeTestUtil.IsPipeFullyClosed(PipeName));
        }
Ejemplo n.º 9
0
        public void MapEFToBOList()
        {
            var        mapper = new DALServerTaskMapper();
            ServerTask entity = new ServerTask();

            entity.SetProperties(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", 1, "A", "A", true, true, "A", "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A");

            List <BOServerTask> response = mapper.MapEFToBO(new List <ServerTask>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
Ejemplo n.º 10
0
 public void ProcessTask(ServerTask task)
 {
     logger.Info($"{this.GetType().Name} started");
     if (MyTaskType() != task.Type)
     {
         throw new Exception("Invalid task for this processor");
     }
     if (RunProcessor(task))
     {
         CloseTask(task);
     }
     else
     {
         logger.Warn($"Something went wrong with:\n{task}");
     }
 }
Ejemplo n.º 11
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IServerTaskRepository>();
            var record = new ServerTask();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new ServerTaskService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLServerTaskMapperMock,
                                                mock.DALMapperMockFactory.DALServerTaskMapperMock);

            ApiServerTaskResponseModel response = await service.Get(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
        // Add a topic, then remove it.
        public async Task AddUserAccountTest()
        {
            CreateUserRequest addUserAccountRequest = new CreateUserRequest(req)
            {
                FirstName               = "Lenin",
                LastName                = "Ravindranath",
                Username                = "******",
                Email                   = "*****@*****.**",
                AccountType             = (int)AccountType.Facebook,
                ThirdPartyAccountHandle = "1234567890",
                ThirdPartyAccessToken   = "AccessToken",
                PasswordHash            = null,
            };

            CreateUserResponse addUserAccountResponse = await ServerTask <CreateUserRequest, CreateUserResponse> .PostRequest(addUserAccountRequest);

            Assert.AreEqual(addUserAccountResponse, ResponseCode.Success);  // *#*#* not sure if this is the right comparison ...
        }
Ejemplo n.º 13
0
        static private CameraGroup FindOrAddCameraGroup(ManagementServer ms, string groupName)
        {
            CameraGroup groupExist = ms.CameraGroupFolder.CameraGroups.Where(x => x.Name == groupName).FirstOrDefault();

            if (groupExist != null)
            {
                return(groupExist);
            }

            CameraGroupFolder folder = ms.CameraGroupFolder;
            ServerTask        task   = folder.AddDeviceGroup(groupName, "group added by tool");

            Console.WriteLine("Camera group add (" + groupName + ") task: " + task.State);
            if (task.State == StateEnum.Success)
            {
                string path = task.Path;
                return(new CameraGroup(EnvironmentManager.Instance.MasterSite.ServerId, path));
            }
            return(null);
        }
Ejemplo n.º 14
0
        protected override bool RunProcessor(ServerTask task)
        {
            var messageRepo = new MessagesRepository(DataBase);
            var accountRepo = new AccountsRepository(DataBase);

            Account targetAccount = accountRepo.GetEntity(task.ObjectId);

            logger.Info($"Target Account NickName {targetAccount.NickName}");
            List <Message> messages = messageRepo.
                                      GetEntitiesByExpression(m => m.From == targetAccount.Id &&
                                                              m.FromName != targetAccount.NickName).
                                      ToList();

            logger.Info($"Retrived {messages.Count} to process");
            foreach (var message in messages)
            {
                logger.Info($"Updating Message {message.Id}");
                message.FromName = targetAccount.NickName;
                messageRepo.Update(message);
            }
            return(true);
        }
Ejemplo n.º 15
0
 protected abstract bool RunProcessor(ServerTask task);
Ejemplo n.º 16
0
		public ServerTaskViewModel(ServerTask serverTask)
		{
			ServerTask = serverTask;
		}
Ejemplo n.º 17
0
        static private bool AddCamera(string parms)
        {
            string[] parameters = parms.Split(',');
            string   ip         = parameters[0];
            string   user       = parameters[1];
            string   pass       = parameters[2];
            string   drivernr   = parameters[3];
            string   hwname     = parameters[4];
            string   cameraName = parameters[5];
            string   rsName     = parameters[6];
            string   groupName  = parameters[7];
            int      drivernum  = int.Parse(drivernr);

            ManagementServer managementServer = new ManagementServer(EnvironmentManager.Instance.MasterSite);
            RecordingServer  recordingServer  = managementServer.RecordingServerFolder.RecordingServers.FirstOrDefault(x => x.Name == rsName);

            if (recordingServer == null)
            {
                Console.WriteLine("Error. Did not find recording server: " + rsName);
                return(false);
            }
            string hardwareDriverPath = recordingServer.HardwareDriverFolder.HardwareDrivers.Where(x => x.Number == drivernum).FirstOrDefault()?.Path;

            if (hardwareDriverPath == null)
            {
                Console.WriteLine("Error. Did not find hardware driver: " + drivernum);
                return(false);
            }
            Console.WriteLine("Will now attempt to add: " + cameraName);
            ServerTask addHardwareServerTask = recordingServer.AddHardware(ip, hardwareDriverPath, user, pass);

            while (addHardwareServerTask.State != StateEnum.Error && addHardwareServerTask.State != StateEnum.Success)
            {
                System.Threading.Thread.Sleep(1000);
                addHardwareServerTask.UpdateState();
            }
            Console.WriteLine("Hardware add task: " + addHardwareServerTask.State);
            if (addHardwareServerTask.State == StateEnum.Error)
            {
                Console.WriteLine("Hardware add error: " + addHardwareServerTask.ErrorText);
                return(false);
            }
            else if (addHardwareServerTask.State == StateEnum.Success)
            {
                string   path     = addHardwareServerTask.Path; // For the added hardware
                Hardware hardware = new Hardware(EnvironmentManager.Instance.MasterSite.ServerId, path);
                hardware.Name    = hwname;
                hardware.Enabled = true;
                hardware.Save();
                Camera camera = hardware.CameraFolder.Cameras.First();
                camera.Name    = cameraName;
                camera.Enabled = true;
                camera.Save();
                // alter other camera properties(?)
                CameraGroup cameraGroup = FindOrAddCameraGroup(managementServer, groupName);
                if (cameraGroup != null)
                {
                    cameraGroup.CameraFolder.AddDeviceGroupMember(camera.Path);                   // make sure the camera is member of one group
                }
            }

            return(true);
        }
Ejemplo n.º 18
0
        public static void RemoveServerTask(ServerTask serverTask)
		{
			Operations.RemoveAll(x => x.ServerTask == serverTask);
            // TODO: Notify
        }
Ejemplo n.º 19
0
		public void EditTask(ServerTask serverTask)
		{
			SyncContext.Post(state =>
			{
				var serverTaskViewModel = ServerTasks.FirstOrDefault(x => x.Task.UID == serverTask.UID);
				if (serverTaskViewModel != null)
					serverTaskViewModel.Task = serverTask;
			}, null);
		}
Ejemplo n.º 20
0
		public void RemoveTask(ServerTask serverTask)
		{
			SyncContext.Post(state =>
			{
				var serverTaskViewModel = ServerTasks.FirstOrDefault(x => x.Task.UID == serverTask.UID);
				if (serverTaskViewModel != null)
					_bindingSourceOperations.Remove(serverTaskViewModel);
			}, null);
		}
Ejemplo n.º 21
0
		public void AddTask(ServerTask serverTask)
		{
			SyncContext.Post(state =>
			{
				var serverTaskModel = new ServerTaskModel(serverTask);
				_bindingSourceOperations.Add(serverTaskModel);
			}, null);
		}
Ejemplo n.º 22
0
        // user1 creates a topic.  user2 likes it.  user3 likes it.
        // get the like feed, and check the user names.  check the like count.
        // clean up - delete the topic.
        public async Task DoLikeFeedTest()
        {
            // step 1, create a topic
            AddTopicRequest addTopicRequest = new AddTopicRequest(user1req)
            {
                TopicCategory     = "Photo",
                TopicFriendlyName = "abcdef",
                TopicTitle        = "Rarest coin",
                TopicText         = "Egyptian coin",
                TopicBlobType     = (int)BlobType1.Image,
                TopicBlobUrl      = "http://coinquest.com/cgi-data/cq_ro/response_380/egypt_10_milliemes_1958.jpg",
                TopicDeepLink     = "coins:abcdef",
                TopicType         = (int)TopicType.New
            };

            AddTopicResponse addResponse = await ServerTask <AddTopicRequest, AddTopicResponse> .PostRequest(addTopicRequest);

            //Assert.AreEqual(addResponse.ResponseCode, ResponseCode.Success);
            // extract topic handle from the response
            this.TopicHandle = addResponse.TopicHandle;
            Console.WriteLine("LikeFeedTest: Added topic");
            await Task.Delay(Constants.ServiceWriteDelay);

            // user2 likes the topic
            AddLikeRequest addLikeRequest = new AddLikeRequest(user2req)
            {
                ContentHandle = this.TopicHandle,
                ContentType   = (int)ContentType1.Topic,
                SequenceId    = Environment.TickCount
            };
            AddLikeResponse addLikeResponse = await ServerTask <AddLikeRequest, AddLikeResponse> .PostRequest(addLikeRequest);

            //Assert.AreEqual(addLikeResponse.ResponseCode, ResponseCode.Success);
            Console.WriteLine("LikeFeedTest: user2 liked topic");
            await Task.Delay(Constants.ServiceWriteDelay);

            // user3 likes the topic
            addLikeRequest = new AddLikeRequest(user3req)
            {
                ContentHandle = this.TopicHandle,
                ContentType   = (int)ContentType1.Topic,
                SequenceId    = Environment.TickCount
            };
            addLikeResponse = await ServerTask <AddLikeRequest, AddLikeResponse> .PostRequest(addLikeRequest);

            //Assert.AreEqual(addLikeResponse.ResponseCode, ResponseCode.Success);
            Console.WriteLine("LikeFeedTest: user3 liked topic");
            await Task.Delay(Constants.ServiceWriteDelay);

            // get the like feed for the topic
            GetLikeFeedRequest getLikesReq = new GetLikeFeedRequest()
            {
                ContentHandle = this.TopicHandle,
                BatchSize     = 10
            };
            GetLikeFeedResponse getLikesResponse = await ServerTask <GetLikeFeedRequest, GetLikeFeedResponse> .PostRequest(getLikesReq);

            //Assert.AreEqual(getLikesResponse.ResponseCode, ResponseCode.Success);
            Console.WriteLine("Likes list:");
            foreach (var user in getLikesResponse.Users)
            {
                Console.WriteLine("User = {0}", user.UserHandle);
            }
        }
Ejemplo n.º 23
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Typ des Tasks herausfinden
            TaskType type = TaskType.Broadcast;

            if (radioBtnBroadcast.Checked)
            {
                type = TaskType.Broadcast;
            }
            else if (radioBtnChatMessage.Checked)
            {
                type = TaskType.ChatMessage;
            }
            else if (radioBtnCommand.Checked)
            {
                type = TaskType.Command;
            }
            else if (radioBtnRestart.Checked)
            {
                type = TaskType.Restart;
            }

            //Zeitintervall des Tasks herausfinden
            Interval interval = Interval.Minutes;
            DateTime time     = new DateTime();

            if (radioBtnInterval.Checked)
            {
                interval = Interval.Minutes;
                time     = new DateTime(1, 1, 1, 0, (int)numericUpDownMinutes.Value, 0, DateTimeKind.Unspecified);
            }
            else if (radioBtnMinuteofHour.Checked)
            {
                interval = Interval.MinuteOfHour;
                time     = dateTimeMinuteOfHour.Value;
            }
            else if (radioBtnTimeOfDay.Checked)
            {
                interval = Interval.TimeOfDay;
                time     = dateTimeTimeOfDay.Value;
            }

            //Id des Tasks festlegen
            int id;

            if (Helper.Instance.loadedServer.Tasks.Count == 0)
            {
                id = 0;
            }
            else
            {
                id = Helper.Instance.loadedServer.Tasks[Helper.Instance.loadedServer.Tasks.Count - 1].Id + 1;
            }

            if (type != TaskType.Restart)
            {
                Task = new ServerTask(id, type, textBoxName.Text, textBoxCommand.Text, interval, time);
            }
            else
            {
                Task = new ServerTask(id, type, textBoxName.Text, interval, time);
                Task.DelaySaveWorld = (int)numericUpDownRestartSavePause.Value;
                Task.UpdateCheck    = checkBoxRestartUpdate.Checked;
            }

            Task.Enabled = true;

            Close();
        }
Ejemplo n.º 24
0
 public AddSchedule()
 {
     InitializeComponent();
     Task = null;
 }
Ejemplo n.º 25
0
		public Operation(ServerTask serverTask)
		{
			ServerTask = serverTask;
		}
Ejemplo n.º 26
0
		public static void AddServerTask(ServerTask serverTask)
		{
			Operations.Add(new Operation(serverTask));
            // TODO: Notify
        }
Ejemplo n.º 27
0
		public void AddTask(ServerTask serverTask)
		{
			Application.Invoke(delegate 
			{
				ServerTasks.Add(serverTask);
				UpdateOperationNode();
			});
		}
Ejemplo n.º 28
0
		public void RemoveTask(ServerTask serverTask)
		{
			Application.Invoke(delegate 
			{
				ServerTasks.Remove(serverTask);
				UpdateOperationNode();
			});
		}
Ejemplo n.º 29
0
 /// <summary>
 /// Wait for the server task to finish.
 /// </summary>
 public void Wait()
 {
     ServerTask.Wait();
 }
        private static bool AddCamera(NewHardwareInfo newHardwareInfo)
        {
            var managementServer = new ManagementServer(EnvironmentManager.Instance.MasterSite);
            var recordingServer  = managementServer.RecordingServerFolder.RecordingServers.FirstOrDefault(x => x.Name == newHardwareInfo.RecorderName);

            if (recordingServer == null)
            {
                Console.WriteLine("Error. Did not find recording server: " + newHardwareInfo.RecorderName);
                return(false);
            }
            string hardwareDriverPath = recordingServer.HardwareDriverFolder.HardwareDrivers.FirstOrDefault(d => d.Number == newHardwareInfo.DriverNumber)?.Path;

            if (hardwareDriverPath == null)
            {
                Console.WriteLine("Error. Did not find hardware driver: " + newHardwareInfo.DriverNumber);
                return(false);
            }
            Console.WriteLine("Will now attempt to add: " + newHardwareInfo.HardwareName);
            ServerTask addHardwareServerTask = recordingServer.AddHardware(newHardwareInfo.Address, hardwareDriverPath, newHardwareInfo.Username, newHardwareInfo.Password ?? string.Empty);
            var        t1 = DateTime.Now;

            while (addHardwareServerTask.State != StateEnum.Error && addHardwareServerTask.State != StateEnum.Success)
            {
                System.Threading.Thread.Sleep(100);
                addHardwareServerTask.UpdateState();
            }
            Console.WriteLine("Hardware add task: " + addHardwareServerTask.State);
            if (addHardwareServerTask.State == StateEnum.Error)
            {
                Console.WriteLine("Hardware add error: " + addHardwareServerTask.ErrorText);
                return(false);
            }

            var hardware =
                new Hardware(EnvironmentManager.Instance.MasterSite.ServerId, addHardwareServerTask.Path)
            {
                Name    = newHardwareInfo.HardwareName,
                Enabled = true
            };

            hardware.Save();

            var cameras = hardware.CameraFolder.Cameras.OrderBy(c => c.Channel).Select(c => (dynamic)c);

            UpdateDevices(cameras, newHardwareInfo.DeviceNamePrefix, "Camera", DeviceEnableStrategy.EnableFirstChannelOnly);
            var microphones = hardware.MicrophoneFolder.Microphones.OrderBy(m => m.Channel).Select(m => (dynamic)m);

            UpdateDevices(microphones, newHardwareInfo.DeviceNamePrefix, "Microphone");
            var speakers = hardware.MicrophoneFolder.Microphones.OrderBy(m => m.Channel).Select(m => (dynamic)m);

            UpdateDevices(speakers, newHardwareInfo.DeviceNamePrefix, "Speaker");
            var inputs = hardware.InputEventFolder.InputEvents.OrderBy(m => m.Channel).Select(m => (dynamic)m);

            UpdateDevices(inputs, newHardwareInfo.DeviceNamePrefix, "Input");
            var outputs = hardware.OutputFolder.Outputs.OrderBy(m => m.Channel).Select(m => (dynamic)m);

            UpdateDevices(outputs, newHardwareInfo.DeviceNamePrefix, "Output");
            var metadata = hardware.MetadataFolder.Metadatas.OrderBy(m => m.Channel).Select(m => (dynamic)m);

            UpdateDevices(metadata, newHardwareInfo.DeviceNamePrefix, "Metadata");

            // alter other camera properties(?)
            var cameraGroup = FindOrAddCameraGroup(managementServer, newHardwareInfo.CameraGroupName);

            foreach (var device in cameras)
            {
                var camera = (Camera)device;
                cameraGroup?.CameraFolder.AddDeviceGroupMember(camera.Path);
            }

            return(true);
        }