示例#1
0
        public APITests()
        {
            var builder = new ContainerBuilder();
            builder.RegisterModule(new IoC.Module());
            var container = builder.Build();
            this.service = container.Resolve<IEasyNoteService>();

            service.Login(
               new UserInfo
               {
                   Email = "*****@*****.**",
                   Password = "******"
               });
        }
示例#2
0
        public MainWindow()
        {
            InitializeComponent();
            var container = InitializeIoC();

            this.service = container.Resolve <IEasyNoteService>();

            this.SetWindowName("new");
            fileContent.TextChanged += fileContent_TextChanged;

            bool loginSuccess = false;

            while (!loginSuccess)
            {
                var loginDialog = new LoginDialog();
                if (loginDialog.ShowDialog() == true)
                {
                    try
                    {
                        var logonInfo = service.Login(Globals.Credentials);
                        signalr = new EasyNoteHubService();

                        signalr.connection.On <string>("FileGotLocked", message => {
                            if (Globals.CurrentlyOpenedFile != null && Globals.CurrentlyOpenedFile.Id == int.Parse(message))
                            {
                                if (!TextChanged)
                                {
                                    Globals.CurrentlyOpenedFile.IsLocked = true;
                                    Globals.IsReadOnly = true;
                                    this.Dispatcher.Invoke(() =>
                                    {
                                        fileContent.IsReadOnly = true;
                                    });
                                }
                            }
                        });

                        signalr.connection.On <string>("FileGotUnlocked", message => {
                            if (Globals.CurrentlyOpenedFile != null && Globals.CurrentlyOpenedFile.Id == int.Parse(message))
                            {
                                Globals.CurrentlyOpenedFile.IsLocked = false;
                                Globals.IsReadOnly = false;
                                this.Dispatcher.Invoke(() =>
                                {
                                    fileContent.IsReadOnly = false;
                                });
                            }
                        });

                        signalr.connection.On <string, string>("UnlockFileRequested", (fileId, requestor) => {
                            if (Globals.CurrentlyOpenedFile != null && Globals.CurrentlyOpenedFile.Id == int.Parse(fileId) &&
                                !(requestor.ToString() == Globals.Credentials.Email || requestor.ToString() == Globals.Credentials.UserName))
                            {
                                this.Dispatcher.Invoke(() =>
                                {
                                    var choice = MessageBox.Show($"{requestor} wants to unlock this file, do You allow?", "Unlocking request",
                                                                 MessageBoxButton.YesNo,
                                                                 MessageBoxImage.Question);

                                    switch (choice)
                                    {
                                    case MessageBoxResult.Yes:
                                        signalr.UnlockFile(fileId);
                                        break;

                                    case MessageBoxResult.No:
                                        signalr.ForbidUnlockingFile(fileId, Globals.Credentials.UserName);
                                        break;

                                    default: break;
                                    }
                                });
                            }
                        });

                        signalr.connection.On <string, string>("UnlockingFileForbidden", (fileId, forbidder) => {
                            if (Globals.CurrentlyOpenedFile != null && Globals.CurrentlyOpenedFile.Id == int.Parse(fileId))
                            {
                                this.Dispatcher.Invoke(() =>
                                {
                                    MessageBox.Show($"{forbidder} did not allow to unlock this file.", "Unlocking forbidden",
                                                    MessageBoxButton.OK,
                                                    MessageBoxImage.Information);
                                });
                            }
                        });

                        signalr.connection.On("FilesListChanged", () => {
                            MessageBox.Show("File list got updated!");
                        });

                        signalr.Connect().ContinueWith(a => { MessageBox.Show(a.Result.ToString()); });
                        loginSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        loginSuccess = false;
                        MessageBox.Show(ex.Message);
                    }
                }
                loginDialog.Close();
            }
        }