public async Task PrepareTest()
        {
            serviceProvider = FakeServiceProvider.Create($"{nameof(DeliveryServiceTests)}_{TestContext.TestName}");
            scope           = serviceProvider.CreateScope();
            connections     = scope.ServiceProvider.GetRequiredService <ConnectionsService>();
            packets         = scope.ServiceProvider.GetRequiredService <PacketService>();
            database        = scope.ServiceProvider.GetRequiredService <DatabaseContext>();
            delivery        = scope.ServiceProvider.GetRequiredService <DeliveryService>();

            database.Accounts.Add(new Account {
                AccountId = alice
            });
            database.MailConfirmations.Add(new MailConfirmation {
                AccountId = alice, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10)
            });
            database.Accounts.Add(new Account {
                AccountId = bob
            });
            database.MailConfirmations.Add(new MailConfirmation {
                AccountId = bob, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10)
            });
            database.Accounts.Add(new Account {
                AccountId = charlie
            });
            database.MailConfirmations.Add(new MailConfirmation {
                AccountId = charlie, MailAddress = "*****@*****.**", Token = SkynetRandom.String(10)
            });
            await database.SaveChangesAsync().ConfigureAwait(false);
        }
Example #2
0
        public async Task TestWaitDisconnectEmpty()
        {
            var connections = new ConnectionsService();

            connections.ClientConnected();
            connections.ClientDisconnected();
            await connections.WaitDisconnectAll().ConfigureAwait(false);
        }
Example #3
0
        public SaveConnectionsOnEdit(ConnectionsService connectionsService)
        {
            if (connectionsService == null)
            {
                throw new ArgumentNullException(nameof(connectionsService));
            }

            _connectionsService = connectionsService;
            connectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
        }
Example #4
0
        private MainPageViewModel GetMainPage()
        {
            IConnectionsService connservice    = new ConnectionsService();
            ICommandService     commandservice = new CommandService_NAV2013_R2();

            INavisionObjectsRepository objectsrepository = new NavisionObjectsRepository_2013_R2();
            INavObjectService          objservice        = new NavObjectService(objectsrepository);
            IScriptService             scriptservice     = new ScriptsService();

            return(new MainPageViewModel(connservice, objservice, commandservice, scriptservice));
        }
Example #5
0
        public void ErrorHandlerCalledWhenUnsupportedFileExtensionFound()
        {
            using (FileTestHelpers.DisposableTempFile(out var file, ".blah"))
            {
                var conService        = new ConnectionsService(PuttySessionsManager.Instance);
                var container         = new ContainerInfo();
                var exceptionOccurred = false;

                Import.HeadlessFileImport(new [] { file }, container, conService, s => exceptionOccurred = true);

                Assert.That(exceptionOccurred);
            }
        }
Example #6
0
 public UsersService(
     IUsersRepository usersRepository,
     FilesService imagesService,
     IContactsRepository contactsRepository,
     UnitOfWork unitOfWork,
     BansService bansService,
     ConnectionsService connectionsService)
 {
     this.usersRepository    = usersRepository;
     this.imagesService      = imagesService;
     this.contactsRepository = contactsRepository;
     this.unitOfWork         = unitOfWork;
     this.bansService        = bansService;
     _connectionsService     = connectionsService;
 }
Example #7
0
        public void AnErrorInOneFileDoNotPreventOtherFilesFromProcessing()
        {
            using (FileTestHelpers.DisposableTempFile(out var badFile, ".blah"))
                using (FileTestHelpers.DisposableTempFile(out var rdpFile, ".rdp"))
                {
                    File.AppendAllText(rdpFile, Resources.test_remotedesktopconnection_rdp);
                    var conService     = new ConnectionsService(PuttySessionsManager.Instance);
                    var container      = new ContainerInfo();
                    var exceptionCount = 0;

                    Import.HeadlessFileImport(new[] { badFile, rdpFile }, container, conService, s => exceptionCount++);

                    Assert.That(exceptionCount, Is.EqualTo(1));
                    Assert.That(container.Children, Has.One.Items);
                }
        }
Example #8
0
        public async Task TestWaitDisconnect()
        {
            var connections = new ConnectionsService();

            connections.ClientConnected();
            connections.ClientConnected();
            connections.ClientDisconnected();
            connections.ClientDisconnected();
            connections.ClientConnected();
            bool empty = false;
            var  task  = connections.WaitDisconnectAll().ContinueWith(_ => Assert.IsTrue(empty), TaskScheduler.Default);

            connections.ClientDisconnected();
            empty = true;
            await task.ConfigureAwait(false);
        }
Example #9
0
        public Client(IServiceProvider serviceProvider, ConnectionsService connections, PacketService packets, ILogger <Client> logger,
                      PacketStream stream, CancellationToken ct)
        {
            this.serviceProvider = serviceProvider;
            this.connections     = connections;
            this.packets         = packets;
            this.logger          = logger;

            this.stream = stream;
            this.ct     = ct;
            sendQueue   = new JobQueue <Packet, bool>(async(packet, dispose) =>
            {
                try
                {
                    using var buffer = new PacketBuffer();
                    packet.WritePacket(buffer, PacketRole.Server);
                    await stream.WriteAsync(packet.Id, buffer.GetBuffer()).ConfigureAwait(false);
                    logger.LogInformation("Successfully sent packet {0} to session {1}", packet, SessionId.ToString("x8"));
                }
                catch (IOException ex) when(ex.InnerException is SocketException socketEx)
                {
                    await DisposeAsync(waitForHandling: false).ConfigureAwait(false);
                    if (socketEx.SocketErrorCode == SocketError.TimedOut)
                    {
                        logger.LogInformation("Session {0} timed out", SessionId.ToString("x8"));
                    }
                    else
                    {
                        logger.LogInformation("Session {0} lost connection", SessionId.ToString("x8"));
                    }
                }
                catch (Exception ex)
                {
                    await DisposeAsync(waitForHandling: false).ConfigureAwait(false);
                    logger.LogCritical(ex, "Unexpected exception occurred while sending packet {0} to session {1}",
                                       packet.Id.ToString("x2"), SessionId.ToString("x8"));
                }
                finally
                {
                    if (dispose)
                    {
                        (packet as IDisposable)?.Dispose();
                    }
                }
            });
            handler = Listen();
        }
Example #10
0
        public HttpResponseMessage Get(string userId)
        {
            User Data = UserProfileServices.GetFullUserById(userId);


            string currentUser = UserService.GetCurrentUserId();

            ConnectionsService connectionsService = new ConnectionsService();

            Data.Connection = connectionsService.IsConnected(currentUser, userId);

            ItemResponse <User> response = new ItemResponse <User>();

            response.Item = Data;

            return(Request.CreateResponse(response));
        }
Example #11
0
        public void find_connection_info_from_variables_when_theres_providers(IEnumerable<KeyValuePair<string, string>> variables, int expected)
        {
            var provider1 = new Mock<IConnectionCheckerProvider>();
            provider1.Setup(p => p.IsValid(It.IsAny<KeyValuePair<string, string>>())).Returns((KeyValuePair<string, string> pair) => pair.Value == "PROVIDER1");
            provider1.Setup(p => p.GetConnectionInfo(It.IsAny<KeyValuePair<string, string>>())).Returns((KeyValuePair<string, string> pair) => new ConnectionInfo {Name = pair.Key, Value = pair.Value, Provider = ProviderNames.AzureStorage });

            var provider2 = new Mock<IConnectionCheckerProvider>();
            provider2.Setup(p => p.IsValid(It.IsAny<KeyValuePair<string, string>>())).Returns((KeyValuePair<string, string> pair) => pair.Value == "PROVIDER2");
            provider2.Setup(p => p.GetConnectionInfo(It.IsAny<KeyValuePair<string, string>>())).Returns((KeyValuePair<string, string> pair) => new ConnectionInfo { Name = pair.Key, Value = pair.Value, Provider = ProviderNames.MySql });

            var providers = new List<IConnectionCheckerProvider>
            {
                provider1.Object,
                provider2.Object
            };

            var service = new ConnectionsService(providers);

            service.FindConnectionStrings(variables).Should().HaveCount(expected);
        }
Example #12
0
 public static void HeadlessFileImport(
     IEnumerable <string> filePaths,
     ContainerInfo importDestinationContainer,
     ConnectionsService connectionsService,
     Action <string> exceptionAction = null)
 {
     using (connectionsService.BatchedSavingContext())
     {
         foreach (var fileName in filePaths)
         {
             try
             {
                 var importer = BuildConnectionImporterFromFileExtension(fileName);
                 importer.Import(fileName, importDestinationContainer);
             }
             catch (Exception ex)
             {
                 exceptionAction?.Invoke(fileName);
                 Runtime.MessageCollector.AddExceptionMessage($"Error occurred while importing file '{fileName}'.", ex);
             }
         }
     }
 }
Example #13
0
        public void TestReplaceOnDuplicate()
        {
            IClient client1 = new FakeClient {
                AccountId = 1, SessionId = 1
            };
            IClient client2 = new FakeClient {
                AccountId = 1, SessionId = 1
            };
            var connections = new ConnectionsService();

            IClient replaced1 = connections.Add(client1);

            Assert.IsNull(replaced1);

            Assert.IsTrue(connections.TryGet(1, out IClient out1));
            Assert.IsTrue(ReferenceEquals(client1, out1));

            IClient replaced2 = connections.Add(client2);

            Assert.IsTrue(ReferenceEquals(client1, replaced2));

            Assert.IsTrue(connections.TryGet(1, out IClient out2));
            Assert.IsTrue(ReferenceEquals(client2, out2));
        }
 public P04DeleteAccountHandler(ConnectionsService connections)
 {
     this.connections = connections;
 }
Example #15
0
 public async Task check_connection_status_throws_argument_null_exception()
 {
     var service = new ConnectionsService(new List<IConnectionCheckerProvider>());
     ConnectionInfo info = null;
     await Assert.ThrowsAsync<ArgumentNullException>(() => service.CheckConnectionStatus(info));
 }
 public P06CreateSessionHandler(ConnectionsService connections, MessageInjectionService injector)
 {
     this.connections = connections;
     this.injector    = injector;
 }
Example #17
0
 public FileEditingHub(IFileEditStateService files, ConnectionsService connections, IdeContext context)
 {
     _files       = files;
     _connections = connections;
     _context     = context;
 }
 public P08RestoreSessionHandler(ConnectionsService connections)
 {
     this.connections = connections;
 }
 private async Task <Dictionary <long, bool> > CreateSessions(
     DatabaseContext database,
     ConnectionsService connections,
     params (long accountId, long sessionId, bool connected)[] sessions)