Exemplo n.º 1
0
 public LoadingViewModel(Page page) : base(page)
 {
     BookSyncContactsHelper.ContactLoadExceptionOccured += BookSyncContactsHelper_ContactLoadExceptionOccured;
     BookSyncContactsHelper.ContactsLoadedAndMatchced   += (sender, e) =>
     {
         ContactsLoaded?.Invoke(null, new EventArgs());
     };
 }
        private static void PostMessage()
        {
            var bytes = new byte[10000];
            int i;

            try
            {
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    var message = Encoding.ASCII.GetString(bytes, 0, i);
                    Console.WriteLine(message);

                    var responseType = Parser.GetJsonValue(message, "Action");

                    switch (responseType)
                    {
                    case "Login":
                        var loginResponse = JsonConvert.DeserializeObject <AuthEvent>(message);

                        SendPingAction();
                        OnAuthOver?.Invoke(null, new AuthEventArgs(loginResponse));
                        _timer           = new Timer(5000);
                        _timer.Elapsed  += TimerOnElapsed;
                        _timer.AutoReset = true;
                        _timer.Enabled   = true;
                        break;

                    case "DBGetContactsResponse":
                        var response = JsonConvert.DeserializeObject <GetContactsEventArgs>(message);
                        ContactsLoaded?.Invoke(null, response);
                        break;

                    default:
                        Logger.Log("#Unknown response type: " + message + "\r\n\r\n");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("#Unable to read socket stream\r\n");
                Logger.Log(ex.Message + "\r\n\r\n");
                Disconnected?.Invoke(null, new EventArgs());
            }
        }
 public void Handle(ContactsLoaded message)
 {
     Contacts.AddRange(message.Contacts.Select(contact => new ContactViewModel(contact)));
 }