コード例 #1
0
 private static void DeadTaskTimerElapsed(object o)
 {
     if (TaskDataHandler.GetDeadTaskCount() > 0)
     {
         AgentHub.BroadcastMessage(null);
     }
 }
コード例 #2
0
        public async Task DeviceCameOnline_BannedById()
        {
            var circuitManager    = new Mock <ICircuitManager>();
            var circuitConnection = new Mock <ICircuitConnection>();

            circuitManager.Setup(x => x.Connections).Returns(new[] { circuitConnection.Object });
            circuitConnection.Setup(x => x.User).Returns(_testData.Admin1);
            var appConfig            = new Mock <IApplicationConfig>();
            var viewerHub            = new Mock <IHubContext <ViewerHub> >();
            var expiringTokenService = new Mock <IExpiringTokenService>();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[] { _testData.Device1.ID });

            var hub = new AgentHub(DataService, appConfig.Object, viewerHub.Object, circuitManager.Object, expiringTokenService.Object);

            var hubClients = new Mock <IHubCallerClients>();
            var caller     = new Mock <IClientProxy>();

            hubClients.Setup(x => x.Caller).Returns(caller.Object);
            hub.Clients = hubClients.Object;

            Assert.IsFalse(await hub.DeviceCameOnline(_testData.Device1));
            hubClients.Verify(x => x.Caller, Times.Once);
            caller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Once);
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: zhuzhenping/deepQ-stock
        /// <summary>
        /// Configure Services
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureService()
        {
            var redis   = ConnectionMultiplexer.Connect(Settings.RedisConnectionString);
            var manager = new RedisManager(redis);

            var settings = new JsonSerializerSettings();

            settings.ContractResolver = new SignalRContractResolver();
            var serializer = JsonSerializer.Create(settings);

            GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);

            var agentHub = new AgentHub(manager);

            //Register Hubs
            GlobalHost.DependencyResolver.Register(typeof(AgentHub), () => agentHub);
            GlobalHost.DependencyResolver.Register(typeof(DeepQStockContext), () => new DeepQStockContext());
            GlobalHost.DependencyResolver.Register(typeof(StockExchange), () => new StockExchange(manager));
        }
コード例 #4
0
ファイル: AgentHubTests.cs プロジェクト: zuimei100/Remotely
        public async Task DeviceCameOnline_BannedById()
        {
            var appConfig = new Mock<IApplicationConfig>();
            var browserHub = new Mock<IHubContext<BrowserHub>>();
            var viewerHub = new Mock<IHubContext<ViewerHub>>();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[] { TestData.Device1.ID });

            var hub = new AgentHub(DataService, appConfig.Object, browserHub.Object, viewerHub.Object);

            var hubClients = new Mock<IHubCallerClients>();
            var caller = new Mock<IClientProxy>();
            hubClients.Setup(x => x.Caller).Returns(caller.Object);
            hub.Clients = hubClients.Object;

            Assert.IsFalse(await hub.DeviceCameOnline(TestData.Device1));
            hubClients.Verify(x => x.Caller, Times.Once);
            caller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny<object[]>(), It.IsAny<CancellationToken>()), Times.Once);
        }
コード例 #5
0
        public async Task DeviceCameOnline_NotBanned()
        {
            var appConfig = new Mock <IApplicationConfig>();

            var circuitManager    = new Mock <ICircuitManager>();
            var circuitConnection = new Mock <ICircuitConnection>();

            circuitManager.Setup(x => x.Connections).Returns(new[] { circuitConnection.Object });
            circuitConnection.Setup(x => x.User).Returns(_testData.Admin1);
            var browserHubClients    = new Mock <IHubClients>();
            var expiringTokenService = new Mock <IExpiringTokenService>();

            var viewerHub = new Mock <IHubContext <ViewerHub> >();

            appConfig.Setup(x => x.BannedDevices).Returns(Array.Empty <string>());

            var hub = new AgentHub(DataService, appConfig.Object, viewerHub.Object, circuitManager.Object, expiringTokenService.Object)
            {
                Context = new CallerContext()
            };


            var agentHubClients   = new Mock <IHubCallerClients>();
            var agentHubCaller    = new Mock <IClientProxy>();
            var agentClientsProxy = new Mock <IClientProxy>();

            agentHubClients.Setup(x => x.Caller).Returns(agentHubCaller.Object);
            agentHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(agentClientsProxy.Object);
            hub.Clients = agentHubClients.Object;

            var result = await hub.DeviceCameOnline(_testData.Device1);

            Assert.IsTrue(result);

            agentHubClients.Verify(x => x.Caller, Times.Never);
            agentHubCaller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Never);

            circuitConnection.Verify(x => x.InvokeCircuitEvent(
                                         CircuitEventName.DeviceUpdate,
                                         It.Is <Device>(x => x.ID == _testData.Device1.ID)),
                                     Times.Once);
        }
コード例 #6
0
ファイル: AgentHubTests.cs プロジェクト: remote3993/remotely
        public async Task DeviceCameOnline_NotBanned()
        {
            var appConfig = new Mock <IApplicationConfig>();

            var browserHub          = new Mock <IHubContext <BrowserHub> >();
            var browserHubClients   = new Mock <IHubClients>();
            var browserClientsProxy = new Mock <IClientProxy>();

            browserHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(browserClientsProxy.Object);
            browserHub.Setup(x => x.Clients).Returns(browserHubClients.Object);

            var viewerHub = new Mock <IHubContext <ViewerHub> >();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[0]);

            var hub = new AgentHub(DataService, appConfig.Object, browserHub.Object, viewerHub.Object);

            hub.Context = new CallerContext();
            //hub.Context.Items.Add("Device", TestData.Device1);

            var agentHubClients   = new Mock <IHubCallerClients>();
            var agentHubCaller    = new Mock <IClientProxy>();
            var agentClientsProxy = new Mock <IClientProxy>();

            agentHubClients.Setup(x => x.Caller).Returns(agentHubCaller.Object);
            agentHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(agentClientsProxy.Object);
            hub.Clients = agentHubClients.Object;

            Assert.IsTrue(await hub.DeviceCameOnline(TestData.Device1));
            agentHubClients.Verify(x => x.Caller, Times.Never);
            agentHubCaller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Never);

            browserClientsProxy.Verify(x => x.SendCoreAsync("DeviceCameOnline",
                                                            It.Is <object[]>(x => x[0] == TestData.Device1),
                                                            It.IsAny <CancellationToken>()),
                                       Times.Once);
        }
コード例 #7
0
        public RegisterTaskResult RegisterTask(RegisterTaskRequest taskRequest)
        {
            Application app = null;

            try
            {
                // load the corresponding application to make sure the appid is valid
                app = ApplicationHandler.GetApplication(taskRequest.AppId);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex, "Error loading app for id " + taskRequest.AppId, EventId.TaskManagement.General);
            }

            // If we do not know the appid, we must not register the task. Client applications
            // must observe this response and try to re-register the application, before
            // trying to register the task again (this can happen if the TaskManagement Web
            // was unreachable when the client application tried to register the appid before).
            if (app == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, RegisterTaskRequest.ERROR_UNKNOWN_APPID));
            }

            RegisterTaskResult result = null;

            try
            {
                // calculate hash with the default algrithm if not given
                var hash = taskRequest.Hash == 0
                    ? ComputeTaskHash(taskRequest.Type + taskRequest.AppId + taskRequest.Tag + taskRequest.TaskData)
                    : taskRequest.Hash;

                result = TaskDataHandler.RegisterTask(
                    taskRequest.Type,
                    taskRequest.Title,
                    taskRequest.Priority,
                    taskRequest.AppId,
                    taskRequest.Tag,
                    taskRequest.FinalizeUrl,
                    hash,
                    taskRequest.TaskData,
                    taskRequest.MachineName);
            }
            catch (Exception ex)
            {
                // the client app needs to be notified
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            try
            {
                // notify agents
                AgentHub.BroadcastMessage(result.Task);

                // notify monitor clients
                TaskMonitorHub.OnTaskEvent(SnTaskEvent.CreateRegisteredEvent(
                                               result.Task.Id, result.Task.Title, string.Empty, result.Task.AppId,
                                               result.Task.Tag, null, result.Task.Type, result.Task.Order,
                                               result.Task.Hash, result.Task.TaskData));
            }
            catch (Exception ex)
            {
                // The task has been created successfully, this error is only about
                // notification, so client applications should not be notified.
                SnLog.WriteException(ex, "Error during agent or monitor notification after a task was registered.", EventId.TaskManagement.Communication);
            }

            return(result);
        }