Пример #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);
            }
        }
Пример #2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (IMService.GetUsernameFromDb() == null)
     {
         Application.Current.Shutdown();
     }
 }
Пример #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);
            }
        }
Пример #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());
        }
    }
}
Пример #5
0
 private User GetSelectedUser()
 {
     if (SelectedContact == null)
     {
         return(null);
     }
     return(IMService.GetUser(SelectedContact.Username));
 }
Пример #6
0
 public void Login()
 {
     if (IMService.GetUsernameFromDb() == null)
     {
         var signInWindow = new SignInWindow();
         signInWindow.RaiseSignInEvent += SignInButton_RaiseSignInEvent;
         signInWindow.Show();
     }
 }
Пример #7
0
        private void PopulateMessageCollection()
        {
            var messageList = IMService.GetAllMessagesBetweenContacts(LoggedInUser, GetSelectedUser());

            foreach (var message in messageList)
            {
                MessagesCollection.Add(message);
            }
        }
Пример #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();
            }
        }
Пример #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
                });
            }
        }
Пример #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;
     }
 }
Пример #11
0
        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;
            }
        }
Пример #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);
        }
Пример #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();
 }
Пример #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();
            }
        }
Пример #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());
        }
    }
Пример #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();
        }
Пример #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
                });
            }
        }
Пример #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);
             }
         }
     }
 }
Пример #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();
        }
Пример #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());
        }
    }
Пример #21
0
 public void SignInButton_RaiseSignInEvent(object sender, SignInEventArgs e)
 {
     LoggedInUser = IMService.GetUser(e.Username);
     InitProgram();
 }
Пример #22
0
 static void Main(string[] args)
 {
     IMService helloWorldClient = ServiceProxy.Create <IMService>(new Uri("fabric:/MyApplication/Default.MService"));
 }