Esempio n. 1
0
        private async void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(SignInUsername) || string.IsNullOrWhiteSpace(SignInPassword))
                {
                    throw new InvalidOperationException("Please enter your username and password");
                }
                var user = IMService.GetUser(SignInUsername);
                if (user == null)
                {
                    throw new InvalidOperationException("Invalid username, please try again");
                }
                if (user.Password != SignInPassword)
                {
                    throw new InvalidOperationException("Wrong password, please try again");
                }
                await IMService.SetUsernameInDb(SignInUsername);

                RaiseSignInEvent(this, new SignInEventArgs(SignInUsername));
                Close();
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (IMService.GetUsernameFromDb() == null)
     {
         Application.Current.Shutdown();
     }
 }
Esempio n. 3
0
        private async void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(RegisterUsername) || string.IsNullOrWhiteSpace(RegisterPassword) || string.IsNullOrWhiteSpace(ConfirmPassword) ||
                    string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
                {
                    throw new InvalidOperationException("Please fill in all the fields.");
                }
                if (RegisterPassword != ConfirmPassword)
                {
                    throw new InvalidOperationException("Passwords don't match, please try again.");
                }
                IMService.AddUser(new User {
                    Username = RegisterUsername, Password = RegisterPassword, FirstName = FirstName, LastName = LastName
                });
                await IMService.SetUsernameInDb(RegisterUsername);

                RaiseSignInEvent(this, new SignInEventArgs(RegisterUsername));
                Close();
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 4
0
    private string[] GetImsroles(string masterCustomerId, int subCustomerId)
    {
        var timssId = masterCustomerId + "|" + subCustomerId;

        var roleList = new List <string>();

        using (var myim = new IMService {
            Url = _personifyImsUrl
        })
        {
            IMSCustomerRoleGetResult imsCustomerRoleGetResult = myim.IMSCustomerRoleGetByTimssCustomerId(_personifySsoVendorName, _personifySsoVendorPassword, timssId);

            if (imsCustomerRoleGetResult.CustomerRoles == null)
            {
                return new[] { string.Empty }
            }
            ;

            foreach (var roledetail in imsCustomerRoleGetResult.CustomerRoles)
            {
                roleList.Add(roledetail.Value);
            }

            return(roleList.ToArray());
        }
    }
}
Esempio n. 5
0
 private User GetSelectedUser()
 {
     if (SelectedContact == null)
     {
         return(null);
     }
     return(IMService.GetUser(SelectedContact.Username));
 }
Esempio n. 6
0
 public void Login()
 {
     if (IMService.GetUsernameFromDb() == null)
     {
         var signInWindow = new SignInWindow();
         signInWindow.RaiseSignInEvent += SignInButton_RaiseSignInEvent;
         signInWindow.Show();
     }
 }
Esempio n. 7
0
        private void PopulateMessageCollection()
        {
            var messageList = IMService.GetAllMessagesBetweenContacts(LoggedInUser, GetSelectedUser());

            foreach (var message in messageList)
            {
                MessagesCollection.Add(message);
            }
        }
Esempio n. 8
0
        private async void LogoutButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to logout?", "Logout", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                await IMService.EraseUsernameFromDb();

                var signInWindow = new SignInWindow();
                signInWindow.RaiseSignInEvent += SignInButton_RaiseSignInEvent;
                signInWindow.Show();
                Hide();
            }
        }
Esempio n. 9
0
        public void AddContactButton_RaiseContactAddedEvent(object sender, ContactAddedEventArgs e)
        {
            var contact = IMService.GetUser(e.Username);

            if (contact != null)
            {
                IMService.AddContact(LoggedInUser, contact);
                ContactsCollection.Add(contact);
                ContactsDetails.Add(new ContactDetails {
                    Username = contact.Username, FirstName = contact.FirstName, LastName = contact.LastName
                });
            }
        }
Esempio n. 10
0
 private void SendButton_Click(object sender, RoutedEventArgs e)
 {
     if (MessageContent != null && MessageContent != "" && SelectedContact != null)
     {
         var message = new Message {
             Sender = LoggedInUser.Username, Receiver = SelectedContact.Username, TimeSent = DateTime.Now, Content = MessageContent
         };
         IMService.SendMessage(message);
         MessagesCollection.Add(message);
         MessageContent = "";
         SelectedContact.LastMessageContent = message.Content;
         SelectedContact.LastMessageTime    = message.TimeSent;
     }
 }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var user = IMService.GetUser(ContactUsername);

            if (user == null)
            {
                MessageBox.Show("Invalid username. Please try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                RaiseContactAddedEvent(this, new ContactAddedEventArgs(user.Username));
                Close();
                return;
            }
        }
Esempio n. 12
0
        public TowerService()
        {
            tower = new Tower();
            currentPin = 0;

            Console.WriteLine("Build Tower Service started...");
            Console.WriteLine("______________________________");

            messagingService = new IMService(new JabberUser("build_monitor", "password", "jabber.org"));
            messagingService.Processor.Client.OnReadText += new TextHandler(OnReceiveText);
            messagingService.Processor.Client.OnConnect += new AsyncSocketHandler(OnConnect);
            messagingService.Processor.Client.OnMessage += new MessageHandler(onMessage);
            messagingService.Connect();
            while (! messagingService.IsConnected);
            while (true);
        }
Esempio n. 13
0
 private void DeleteSelectedContact()
 {
     IMService.DeleteContact(LoggedInUser, GetSelectedUser());
     foreach (var contact in ContactsCollection.ToList())
     {
         if (contact.Username == SelectedContact.Username)
         {
             ContactsCollection.Remove(contact);
         }
     }
     foreach (var message in MessagesCollection.ToList())
     {
         MessagesCollection.Remove(message);
     }
     ResetContactsDetails();
 }
Esempio n. 14
0
        //Constructor

        public MainWindow()
        {
            var username = IMService.GetUsernameFromDb();

            if (username != null && IMService.GetUser(username) != null)
            {
                LoggedInUser = IMService.GetUser(username);
                InitProgram();
                var timer = new System.Threading.Timer(state => CheckForNewMessagesAndContacts(), null, DefaultMessageRefreshTime, Timeout.Infinite);
            }
            else
            {
                Hide();
                Login();
            }
        }
Esempio n. 15
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="masterCustomerId"></param>
    /// <param name="subCustomerId"></param>
    /// <returns></returns>
    private string[] GetImsroles(string customerToken)
    {
        using (var myim = new IMService {
            Url = PersonifyImsUrl
        })
        {
            var imsCustomerRoleGetResult = myim.IMSCustomerRoleGet(PersonifyVendorName, PersonifyVendorPassword, customerToken);

            if (imsCustomerRoleGetResult.CustomerRoles == null)
            {
                return new[] { string.Empty }
            }
            ;

            return(imsCustomerRoleGetResult.CustomerRoles.Select(x => x.Value).ToArray());
        }
    }
Esempio n. 16
0
        private void InitProgram()
        {
            InitializeComponent();
            DataContext = this;

            UserList = IMService.LoadUsers();

            var contactList = IMService.GetContacts(LoggedInUser);

            InitContactsCollection(contactList);

            InitContactsDetails();
            if (ContactsDetails != null && ContactsDetails.Count > 0)
            {
                SelectedContact = ContactsDetails.First();
            }
            InitMessagesCollection();
            Show();
        }
Esempio n. 17
0
        private void AddToContactsDetails(User contact)
        {
            var lastMessage = IMService.GetLastMessageFromContact(LoggedInUser, contact);

            if (lastMessage != null)
            {
                ContactsDetails.Add(new ContactDetails
                {
                    Username           = contact.Username,
                    FirstName          = contact.FirstName,
                    LastName           = contact.LastName,
                    LastMessageTime    = lastMessage.TimeSent,
                    LastMessageContent = lastMessage.Content
                });
            }
            else
            {
                ContactsDetails.Add(new ContactDetails {
                    Username = contact.Username, FirstName = contact.FirstName, LastName = contact.LastName
                });
            }
        }
Esempio n. 18
0
 private void CheckForNewMessagesAndContacts()
 {
     if (LoggedInUser != null && SelectedContact != null)
     {
         var messagesList = IMService.GetAllMessagesBetweenContacts(LoggedInUser, GetSelectedUser());
         foreach (var message in messagesList)
         {
             if (MessagesCollection.Count(c => c.Id == message.Id) == 0)
             {
                 MessagesCollection.Add(message);
             }
         }
         var contactsList = IMService.GetContacts(LoggedInUser);
         foreach (var contact in contactsList)
         {
             if (ContactsCollection.Count(c => c.Username == contact.Username) == 0)
             {
                 ContactsCollection.Add(contact);
                 AddToContactsDetails(contact);
             }
         }
     }
 }
Esempio n. 19
0
        public static void Main(string[] args)
        {
            //var cacert = File.ReadAllText(@"C:\GrpcService\key\ca.crt");
            //var servercert = File.ReadAllText(@"C:\GrpcService\key\server.crt");
            //var serverkey = File.ReadAllText(@"C:\GrpcService\key\server.key");
            //var keypair = new KeyCertificatePair(servercert, serverkey);

            //var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, cacert, false);

            Server server = new Server
            {
                Services = { IMService.BindService(new GreeterImpl()) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                //Ports = { new ServerPort("wannian-PC", sslPort, sslCredentials) }
            };

            server.Start();

            Console.WriteLine("Greeter server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Esempio n. 20
0
    // Get Roles for user
    private string[] GetImsroles(string customerToken)
    {
        using (var myim = new IMService {
            Url = _personifyImsUrl
        })
        {
            var roleList = new List <string>();

            var imsCustomerRoleGetResult = myim.IMSCustomerRoleGet(_personifySsoVendorName, _personifySsoVendorPassword, customerToken);

            if (imsCustomerRoleGetResult.CustomerRoles == null)
            {
                return new[] { string.Empty }
            }
            ;

            foreach (var roledetail in imsCustomerRoleGetResult.CustomerRoles)
            {
                roleList.Add(roledetail.Value);
            }

            return(roleList.ToArray());
        }
    }
Esempio n. 21
0
 public void SignInButton_RaiseSignInEvent(object sender, SignInEventArgs e)
 {
     LoggedInUser = IMService.GetUser(e.Username);
     InitProgram();
 }
Esempio n. 22
0
 static void Main(string[] args)
 {
     IMService helloWorldClient = ServiceProxy.Create <IMService>(new Uri("fabric:/MyApplication/Default.MService"));
 }