Exemplo n.º 1
0
        public MainWindow(WcfContactsStorage storage)
        {
            InitializeComponent();

            Style labelStyle   = DetailsGrid.FindResource("LabelStyle") as Style;
            Style textBoxStyle = DetailsGrid.FindResource("TextBoxStyle") as Style;

            foreach (Contact.FieldKind fieldKind in Enum.GetValues(typeof(Contact.FieldKind)))
            {
                if (fieldKind != Contact.FieldKind.FullName)
                {
                    fieldKinds.Add(fieldKind);
                }
            }

            int i = -1;

            foreach (Contact.FieldKind fieldKind in fieldKinds)
            {
                i++;

                DetailsGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });

                var label = new Label {
                    Content = Contact.GetFieldKindName(fieldKind) + ":",
                    Style   = labelStyle
                };
                label.SetValue(Grid.RowProperty, i);

                var textBox = new TextBox {
                    Style = textBoxStyle
                };
                textBox.SetValue(Grid.RowProperty, i);
                textBox.IsReadOnly = true;

                DetailsGrid.Children.Add(label);
                DetailsGrid.Children.Add(textBox);
                contactFields.Add(textBox);
            }
            i++;
            DetailsGrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            ButtonsPanel.SetValue(Grid.RowProperty, i);

            this.storage = storage;
            StartContactsUpdaterAsync();
            Title = $"{TITLE} - Connected to {storage.ConnectedToURI}";
        }
Exemplo n.º 2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Lock();

            Log($"Establishing connection to {UriTextBox.Text}");
            string endpoint       = UriTextBox.Text;
            var    connectionTask = new Task <WcfContactsStorage>(() => {
                return(new WcfContactsStorage(false, endpoint));
            });

            connectionTask.Start();

            try {
                Storage = await connectionTask;
            }
            catch (AggregateException notFlattenedAe) {
                AggregateException ae = notFlattenedAe.Flatten();
                Log("Could not connect to server!");
                Log($"Technical details: {ae.InnerExceptions[ae.InnerExceptions.Count - 1].Message}");
                Storage = null;
                await UnlockAsync(true);

                return;
            }

            if (Storage.IsGreetingSuccessful)
            {
                var mainWindow = new MainWindow(Storage);
                mainWindow.Show();
                Close();
            }
            else
            {
                Log("Could not connect to server: greeting wasn't successful (wrong or bad server?)");
                Storage = null;
                await UnlockAsync(true);
            }
        }