Exemplo n.º 1
0
        public void Clone_RequestForClone_GetCloneObject()
        {
            string expectedToken = "simpleToken";
            string expectedLogin = "******";
            DateTime expectedCreaDate = new DateTime(2018, 4, 22, 2, 7, 0);
            string expectedServerName = "OneDrive";
            SpaceSize expectedSize = new SpaceSize() { TotalSize = 1000, FreeSize = 300, UsedSize = 700 };
            List<string> expectedGroups=new List<string>(){"Group1","Group2"};

            ConnectionStatusEnum expectedStatus = ConnectionStatusEnum.Connected;

            _mockService.SetupGet(account => account.Token).Returns(expectedToken);
            _mockService.SetupGet(account => account.Login).Returns(expectedLogin);
            _mockService.SetupGet(account => account.ServerName).Returns(expectedServerName);
            _mockService.SetupGet(account => account.Status).Returns(expectedStatus);
            _mockService.SetupGet(account => account.Size).Returns(expectedSize);
            _mockService.SetupGet(account => account.Clone()).Returns(_mockService.Object);
            _account.Groups.Add("Group1");
            _account.Groups.Add("Group2");

            var accountClone = _account.Clone();

            CollectionAssert.AreEqual((List<string>)_account.Groups, expectedGroups);
            Assert.AreEqual(accountClone.Token, expectedToken);
            Assert.AreEqual(accountClone.Login, expectedLogin);
            Assert.AreEqual(accountClone.ServerName, expectedServerName);
            Assert.AreEqual(accountClone.Size, expectedSize);
            Assert.AreEqual(accountClone.Status, expectedStatus);
        }
Exemplo n.º 2
0
        public async Task SignIn(string key)
        {
            var authenticationResult = await App.PublicClientApp.AcquireTokenSilentAsync(App.Scopes,
                                                                                         App.PublicClientApp.Users.FirstOrDefault(user => user.DisplayableId == key));

            Token = authenticationResult.AccessToken;
            using (var stream = await GetDataStream("https://graph.microsoft.com/v1.0/me"))
            {
                DeserializedAccount        deserializedAccount = new DeserializedAccount();
                DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedAccount.GetType());
                deserializedAccount = ser.ReadObject(stream) as DeserializedAccount;
                if (deserializedAccount == null)
                {
                    throw new NullReferenceException("Couldn't deserialized the data");
                }
                Login = deserializedAccount.UserPrincipalName;
                Id    = deserializedAccount.Id;
            }
            using (var stream = await GetDataStream("https://graph.microsoft.com/v1.0/me/drive"))
            {
                DeserializedAccount        deserializedAccount = new DeserializedAccount();
                DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedAccount.GetType());
                deserializedAccount = ser.ReadObject(stream) as DeserializedAccount;
                if (deserializedAccount == null)
                {
                    throw new NullReferenceException("Couldn't deserialized the data");
                }
                Size           = new SpaceSize();
                Size.TotalSize = deserializedAccount.Quota.Total;
                Size.UsedSize  = deserializedAccount.Quota.Used;
                Size.FreeSize  = deserializedAccount.Quota.Remaining;
            }

            Status = ConnectionStatusEnum.Connected;
        }
Exemplo n.º 3
0
        /// <summary>
        /// method to check the status of the pinging machines internet connection
        /// </summary>
        /// <returns></returns>
        private static bool HasConnection()
        {
            ConnectionStatusEnum state = 0;

            InternetGetConnectedState(ref state, 0);

            return(((int)ConnectionStatusEnum.INTERNET_CONNECTION_OFFLINE & (int)state) == 0);
        }
Exemplo n.º 4
0
        protected virtual void ConnectionStatusChange(ConnectionStatusEnum e)
        {
            _connectionStatus = e;
            EventHandler <ConnectionStatusEnum> handler = OnConnectionStatusChange;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemplo n.º 5
0
        private static bool HasConnection()
        {
            //instance of our ConnectionStatusEnum
            ConnectionStatusEnum state = 0;

            //call the API
            InternetGetConnectedState(ref state, 0);

            //check the status
            if (((int)ConnectionStatusEnum.InternetConnectionOffline & (int)state) != 0)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// method to check the status of the pinging machines internet connection
        /// </summary>
        /// <returns></returns>
        private static bool HasConnection()
        {
            //instance of our ConnectionStatusEnum
            ConnectionStatusEnum state = 0;

            //call the API
            InternetGetConnectedState(ref state, 0);

            //check the status, if not offline and the returned state
            //isnt 0 then we have a connection
            if (((int)ConnectionStatusEnum.INTERNET_CONNECTION_OFFLINE & (int)state) != 0)
            {
                //return true, we have a connection
                return(false);
            }
            //return false, no connection available
            return(true);
        }
Exemplo n.º 7
0
        private static bool HasConnection() // Test the connection to the host before ping
        {
            //instance of our ConnectionStatusEnum
            ConnectionStatusEnum state = 0;

            //call the API
            InternetGetConnectedState(ref state, 0);

            //check the status, if not offline and the returned state
            //isnt 0 then we have a connection
            if (((int)ConnectionStatusEnum.InternetConnectionOffline & (int)state) != 0)
            {
                //return true, we have a connection
                return(false);
            }
            //return false, no connection available
            return(true);
        }
Exemplo n.º 8
0
 public async Task Update()
 {
     using (var stream = await GetDataStream("https://graph.microsoft.com/v1.0/me/drive"))
     {
         DeserializedAccount        deserializedAccount = new DeserializedAccount();
         DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedAccount.GetType());
         deserializedAccount = ser.ReadObject(stream) as DeserializedAccount;
         if (deserializedAccount == null)
         {
             throw new NullReferenceException("Couldn't deserialized the data");
         }
         Size           = new SpaceSize();
         Size.TotalSize = deserializedAccount.Quota.Total;
         Size.UsedSize  = deserializedAccount.Quota.Used;
         Size.FreeSize  = deserializedAccount.Quota.Remaining;
     }
     Status = ConnectionStatusEnum.Connected;
 }
        public static dynamic GetTSObject(ConnectionStatusEnum dynEnum)
        {
            var tsType = TSActivator.CreateInstance("Tekla.Structures.ConnectionStatusEnum").GetType();

            switch (dynEnum)
            {
            case ConnectionStatusEnum.STATUS_UNKNOWN:
                return(System.Enum.Parse(tsType, "STATUS_UNKNOWN"));

            case ConnectionStatusEnum.STATUS_OK:
                return(System.Enum.Parse(tsType, "STATUS_OK"));

            case ConnectionStatusEnum.STATUS_WARNING:
                return(System.Enum.Parse(tsType, "STATUS_WARNING"));

            case ConnectionStatusEnum.STATUS_ERROR:
                return(System.Enum.Parse(tsType, "STATUS_ERROR"));

            default:
                throw new DynamicAPIException(dynEnum.ToString() + "- enum value is not implemented");
            }
        }
Exemplo n.º 10
0
        public void BindingParameters_ChangeFileStorageAccount_GetChangeInAccount()
        {
            string expectedToken = "simpleToken";
            string expectedLogin = "******";
            DateTime expectedCreaDate = new DateTime(2018, 4, 22, 2, 7, 0);
            string expectedServerName = "OneDrive";
            SpaceSize expectedSize = new SpaceSize() { TotalSize = 1000, FreeSize = 300, UsedSize = 700 };
            ConnectionStatusEnum expectedStatus = ConnectionStatusEnum.Connected;

            _mockService.SetupGet(account => account.Token).Returns(expectedToken);
            _mockService.SetupGet(account => account.Login).Returns(expectedLogin);
            _mockService.SetupGet(account => account.ServerName).Returns(expectedServerName);
            _mockService.SetupGet(account => account.Status).Returns(expectedStatus);
            _mockService.SetupGet(account => account.Size).Returns(expectedSize);

            Assert.AreEqual(_account.Token, expectedToken);
            Assert.AreEqual(_account.Login, expectedLogin);
            Assert.AreEqual(_account.ServerName, expectedServerName);
            Assert.AreEqual(_account.Size, expectedSize);
            Assert.AreEqual(_account.Status, expectedStatus);

        }
Exemplo n.º 11
0
 static extern bool InternetGetConnectedState(ref ConnectionStatusEnum flags, int dw);
Exemplo n.º 12
0
 static extern bool InternetGetConnectedState(ref ConnectionStatusEnum flags, int dw);
Exemplo n.º 13
0
        internal static void OnConnectionStatusChanged(ulong serverConnectionHandlerID, ConnectionStatusEnum newStatus, uint errorNumber)
        {
            if (newStatus == ConnectionStatusEnum.STATUS_DISCONNECTED)
            {
                Connections.TryRemove(serverConnectionHandlerID, out var unused);
                return;
            }
            var con = GetConnection(serverConnectionHandlerID);

            con.Status = newStatus;
            switch (newStatus)
            {
            case ConnectionStatusEnum.STATUS_DISCONNECTED:
                break;

            case ConnectionStatusEnum.STATUS_CONNECTING:
                break;

            case ConnectionStatusEnum.STATUS_CONNECTED:
                break;

            case ConnectionStatusEnum.STATUS_CONNECTION_ESTABLISHING:
                break;

            case ConnectionStatusEnum.STATUS_CONNECTION_ESTABLISHED:
            {
                con.Update();
                con.DelayedCall(1000, (c) => c.Init());
            }
            break;

            default:
                break;
            }
            Log($"Server {serverConnectionHandlerID} {newStatus} {con.GUID}");
        }
Exemplo n.º 14
0
        private async Task MainTask(CancellationToken ct)
        {
            const string funcName = nameof(MainTask);

            while (!ct.IsCancellationRequested)
            {
                // Accept the new tcp connection
                try
                {
                    // ConnectAsync() throws ObjectDisposedException (derived from InvalidOperationException) when canceled.
                    // This is done by calling _tcpClient.Close().
                    // CancellationToken is registered on upper level function to call _tcpClient.Close() on cancel.
                    _tcpClient = new TcpClient();
                    await _tcpClient.ConnectAsync(_hostIp, _hostPort);

                    // Reset these values for the new connection
                    _sendMessageFailedSignal = new SemaphoreSlim(0, 1);
                    _receiveMessageSignal    = new SemaphoreSlim(0, 1);

                    Log.InfoEx(funcName, $"[{_logName}] Connected to {_tcpClient.Client.RemoteEndPoint}", false);

                    // Throw InvalidOperationException when disconnected and trying to get stream.
                    _tcpStream = _tcpClient.GetStream();

                    ConnectionStatus = ConnectionStatusEnum.Connected;
                }
                catch (Exception e) when(e is SocketException || e is InvalidOperationException)
                {
                    ConnectionStatus = ConnectionStatusEnum.Disconnected;
                    _tcpClient?.Close();

                    // Cancellation is done by throwing SocketException.
                    // Check CancellationToken.
                    ct.ThrowIfCancellationRequested();

                    Log.DebugEx(funcName, e.ToString(), false);
                    await Task.Delay(10000, ct);

                    continue;
                }

                try
                {
                    var localCts = new CancellationTokenSource();

                    using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(ct, localCts.Token))
                    {
                        var receiveTask       = ReceiveMessages(linkedCts.Token);
                        var sendFailTask      = _sendMessageFailedSignal.WaitAsync(linkedCts.Token);
                        var messageTooOldTask = MessageTooOld(linkedCts.Token);
                        await Task.WhenAny(receiveTask, sendFailTask, messageTooOldTask);

                        ct.ThrowIfCancellationRequested();
                        localCts.Cancel();
                    }
                }
                finally
                {
                    ConnectionStatus = ConnectionStatusEnum.Disconnected;
                    _tcpStream.Dispose();
                    _tcpClient.Close();
                    Log.DebugEx(funcName, $"[{_logName}] Connection lost", false);

                    if (!_messageQueue.IsEmpty || _messageInQueue.CurrentCount > 0)
                    {
                        _messageQueue   = new ConcurrentQueue <string>();
                        _messageInQueue = new SemaphoreSlim(0);
                    }
                }
            }
        }
Exemplo n.º 15
0
 private void _coreComClient_OnConnectionStatusChange(object sender, ConnectionStatusEnum e)
 {
     ConnectionStatus = e;
 }
 public ConnectionStatusChangedArgs(ConnectionStatusEnum prev, ConnectionStatusEnum actual) : base()
 {
     Prev   = prev;
     Actual = actual;
 }