示例#1
0
        private IOrganizationService BeginGetCrmConnection(string url, string domain, string username, string password)
        {
            IOrganizationService sdk = null;

            try
            {
                string publicUrl = "";
                sdk            = QuickConnection.Connect(url, domain, username, password, out publicUrl);
                this.PublicUrl = publicUrl;

                Controller.SaveConnectionDetails(this.LinkerDataPath, url, domain, username, password, publicUrl);
            }
            catch (Exception ex)
            {
                UpdateStatus(string.Format("Connection failed: {0}", ex.Message));
            }

            return(sdk);
        }
        private IOrganizationService BeginGetCrmConnection(string connectionString)
        {
            IOrganizationService sdk = null;

            try
            {
                string publicUrl = "";
                sdk            = QuickConnection.Connect(connectionString, out publicUrl);
                this.PublicUrl = publicUrl;

                Controller.SaveConnectionDetails(this.LinkerDataPath, connectionString, publicUrl);
            }
            catch (Exception ex)
            {
                UpdateStatus(string.Format("Connection failed: {0}", ex.Message));
            }

            return(sdk);
        }
示例#3
0
        internal void TryLinkOrPublish(string linkerDataPath, List <SelectedFile> selectedFiles, bool relinking)
        {
            var linked = LinkerData.Get(linkerDataPath);

            var message = relinking ? "Initializing re-link on: {0}" : "Initializing link/publish on: {0}";

            Trace(message, linked.PublicUrl);

            var wrp =
                new WebResourcePublisher
            {
                Relink         = relinking,
                Controller     = this,
                LinkerDataPath = linkerDataPath,
                SelectedFiles  = selectedFiles
            };

            // setting this will cause the wrp to mark the 1st file in selectedfiles to be relinked

            Task.Factory.StartNew(
                () =>
            {
                Trace("Connecting...");
                Status.Update("Connecting ... ", false);

                var publicUrl            = "";
                IOrganizationService sdk = null;

                try
                {
                    sdk = QuickConnection.Connect(linked.DiscoveryUrl, out publicUrl);
                    Status.Update("done!");
                }
                catch (Exception ex)
                {
                    Status.Update("");
                    Status.Update($"Connection failed: {ex.Message}");
                    Trace("Connection failed: {0}", ex.Message);
                }

                return(new object[] { sdk, publicUrl });
            })
            .ContinueWith(
                state =>
            {
                try
                {
                    if (state?.Result?.FirstOrDefault() == null)
                    {
                        Status.Update("");
                        Status.Update("ERROR: couldn't connect to CRM.");
                        Trace("ERROR: couldn't connect to CRM.");

                        wrp.Relink = false;
                        wrp.ShowConnectionWindow = true;
                        wrp.Initialize();

                        return;
                    }

                    var result = state.Result;

                    var sdk                  = (IOrganizationService)result[0];
                    wrp.Sdk                  = sdk;
                    wrp.PublicUrl            = result[1].ToString();
                    wrp.ShowConnectionWindow = wrp.Sdk == null;

                    wrp.Initialize();
                    wrp.TryPublishing();
                }
                catch (Exception ex)
                {
                    Status.Update("");
                    Status.Update($"ERROR: {ex.Message}");
                    Trace("ERROR: {0}", ex.Message);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }