Ejemplo n.º 1
0
        private void UpdateButtonsDiscoveryOrganization()
        {
            if (lstVwOrganizations.SelectedItems.Count == 1)
            {
                OrganizationDetailViewItem detail = lstVwOrganizations.SelectedItems[0] as OrganizationDetailViewItem;

                if (detail != null)
                {
                    OpenConnectionFormForOrganizationDetail(detail);
                }
            }
        }
        private void bntCreateConnectionFromOrganization_Click(object sender, RoutedEventArgs e)
        {
            if (!IsControlsEnabled)
            {
                return;
            }

            if (sender is Button button)
            {
                OrganizationDetailViewItem detail = GetItemFromRoutedDataContext <OrganizationDetailViewItem>(e);

                if (detail != null)
                {
                    OpenConnectionFormForOrganizationDetail(detail);
                }
            }
        }
Ejemplo n.º 3
0
        private void OpenConnectionFormForOrganizationDetail(OrganizationDetailViewItem detail)
        {
            ConnectionData connectionData = new ConnectionData()
            {
                ConnectionId = Guid.NewGuid(),

                ConnectionConfiguration = _crmConfig,

                DiscoveryUrl    = detail.DiscoveryUri.ToString(),
                OrganizationUrl = detail.OrganizationServiceEndpoint,
                PublicUrl       = detail.WebApplicationEndpoint,
                UniqueOrgName   = detail.UniqueName,

                User = detail.User,

                OrganizationId      = detail.OrganizationId,
                FriendlyName        = detail.FriendlyName,
                OrganizationVersion = detail.OrganizationVersion,
                OrganizationState   = detail.State.ToString(),
                UrlName             = detail.UrlName,
            };

            var form = new WindowCrmConnectionCard(_iWriteToOutput, connectionData, _crmConfig.Users);

            if (form.ShowDialog().GetValueOrDefault())
            {
                this.Dispatcher.Invoke(() =>
                {
                    connectionData.Save();
                    connectionData.ConnectionConfiguration = this._crmConfig;
                    connectionData.LoadIntellisenseAsync();
                    connectionData.StartWatchFile();
                    this._crmConfig.Connections.Add(connectionData);
                });
            }

            UpdateCurrentConnectionInfo();

            this._crmConfig.Save();
        }
Ejemplo n.º 4
0
        private async void CmBDiscoveryServiceUrl_KeyDown(object sender, KeyEventArgs e)
        {
            if (!IsControlsEnabled)
            {
                return;
            }

            if (e.Key != Key.Enter)
            {
                return;
            }

            string discoveryServiceUrl = cmBDiscoveryServiceUrl.Text?.Trim();

            if (string.IsNullOrEmpty(discoveryServiceUrl))
            {
                return;
            }

            if (!discoveryServiceUrl.EndsWith(Properties.MessageBoxStrings.DefaultDiscoveryServiceUrlSuffix, StringComparison.InvariantCultureIgnoreCase))
            {
                discoveryServiceUrl = discoveryServiceUrl.TrimEnd('/') + Properties.MessageBoxStrings.DefaultDiscoveryServiceUrlSuffix;
            }

            if (!Uri.TryCreate(discoveryServiceUrl, UriKind.Absolute, out Uri discoveryServiceUri))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.WindowStatusStrings.DiscoveryServiceCouldNotBeReceived);
                _iWriteToOutput.ActivateOutputWindow(null, this);
                return;
            }

            ToggleControls(null, false, Properties.WindowStatusStrings.DiscoveringOrganizations);

            try
            {
                this._itemsSource.Clear();

                var serviceManagement = await CreateManagementAsync(discoveryServiceUri);

                if (serviceManagement == null)
                {
                    ToggleControls(null, true, Properties.WindowStatusStrings.DiscoveryServiceConfigurationCouldNotBeReceived);
                    _iWriteToOutput.ActivateOutputWindow(null, this);
                    return;
                }

                var user = cmBDiscoveryServiceUser.SelectedItem as ConnectionUserData;

                var discoveryService = QuickConnection.CreateDiscoveryService(serviceManagement, user?.Username, user?.Password);

                if (discoveryService == null)
                {
                    ToggleControls(null, true, Properties.WindowStatusStrings.DiscoveryServiceCouldNotBeReceived);
                    _iWriteToOutput.ActivateOutputWindow(null, this);
                    return;
                }

                var repository = new DiscoveryServiceRepository(discoveryService);

                var orgs = await repository.DiscoverOrganizationsAsync();

                this._itemsSource.Clear();

                foreach (var org in orgs.OrderBy(o => o.UniqueName).ThenBy(o => o.OrganizationId))
                {
                    var viewItem = new OrganizationDetailViewItem(discoveryServiceUri, user, org);

                    this._itemsSource.Add(viewItem);
                }

                ToggleControls(null, true, Properties.WindowStatusStrings.DiscoveringOrganizationsCompleted);
            }
            catch (Exception ex)
            {
                ToggleControls(null, true, Properties.WindowStatusStrings.DiscoveringOrganizationsFailed);
                _iWriteToOutput.WriteErrorToOutput(null, ex);
            }
        }