コード例 #1
0
 private void CrmConnection_Load(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(this.LinkerDataPath))
     {
         var data = LinkerData.Get(this.LinkerDataPath);
         if (data != null)
         {
             this.discourl.Text = string.IsNullOrEmpty(data.DiscoveryUrl) ? "" : data.DiscoveryUrl;
         }
     }
 }
コード例 #2
0
 private void CrmConnection_Load(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(this.LinkerDataPath))
     {
         var data = LinkerData.Get(this.LinkerDataPath);
         if (data != null)
         {
             this.discourl.Text = string.IsNullOrEmpty(data.DiscoveryUrl) ? "" : data.DiscoveryUrl.Replace("/XRMServices/2011/Discovery.svc", "");
             this.domain.Text   = data.Domain;
             this.username.Text = data.Username;
             this.password.Text = data.Password;
         }
     }
 }
コード例 #3
0
        internal static void SaveConnectionDetails(string linkerDataPath, string connectionString, string publicUrl)
        {
            try
            {
                var existing = LinkerData.Get(linkerDataPath);

                existing.DiscoveryUrl = connectionString;
                existing.PublicUrl    = publicUrl;

                existing.Save(linkerDataPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Unable to save connection details. Error: {ex.Message}",
                                "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #4
0
        internal static void SaveConnectionDetails(string linkerDataPath, string url, string domain,
                                                   string username, string password, string publicUrl)
        {
            try
            {
                var existing = LinkerData.Get(linkerDataPath);

                existing.DiscoveryUrl = url;
                existing.Domain       = domain;
                existing.Username     = username;
                existing.Password     = password;             // don't worry the password is encrypted :)
                existing.PublicUrl    = publicUrl;

                existing.Save(linkerDataPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Unable to save connection details. Error: {ex.Message}",
                                "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void TryPublishing()
        {
            try
            {
                ToggleControls(false);

                if (Sdk != null)
                {
                    var existing = LinkerData.Get(LinkerDataPath);

                    var isFoundUnmapped = false;

                    if (!Relink && UnmappedFile == null)
                    {
                        var alreadyMappednMatching = SelectedFiles.Where(selectedFile =>
                        {
                            // grab correctly mapped files and publish them
                            return(existing.Mappings
                                   .Any(
                                       a =>
                                       a.SourceFilePath.Equals(selectedFile.FriendlyFilePath,
                                                               StringComparison.InvariantCultureIgnoreCase))
                                   &&
                                   // make sure we don't attempt to publish already published items
                                   !PublishedFiles.Any(
                                       a =>
                                       a.FilePath.Equals(selectedFile.FilePath,
                                                         StringComparison.InvariantCultureIgnoreCase)));
                        }).ToList();

                        UnMappedCount = UnMappedCount ?? SelectedFiles
                                        .Count(selectedFile =>
                        {
                            return(existing.Mappings.Where(
                                       a =>
                                       a.SourceFilePath.Equals(selectedFile.FriendlyFilePath,
                                                               StringComparison.InvariantCultureIgnoreCase))
                                   .Take(1).SingleOrDefault() == null);
                        });

                        if (alreadyMappednMatching.Count > 0)
                        {
                            PublishMappedResources(existing, alreadyMappednMatching);
                        }

                        // now find the unmapped files and mark them as unmapped, when the 'publish/link' button is clicked this unmapped file will be picked up by the same method, see 'if this.unmappedfile != null' check above
                        foreach (var selectedFile in SelectedFiles)
                        {
                            if (isFormClosing)
                            {
                                break;
                            }

                            var matchingItem = existing.Mappings
                                               .Where(
                                a =>
                                a.SourceFilePath.Equals(selectedFile.FriendlyFilePath,
                                                        StringComparison.InvariantCultureIgnoreCase))
                                               .Take(1).SingleOrDefault();

                            if (matchingItem == null)
                            {
                                unmappedLock.WaitOne();

                                if (isFormClosing)
                                {
                                    break;
                                }

                                UnMappedCount--;
                                MarkAsUnmapped(selectedFile);
                                isFoundUnmapped = true;
                            }
                        }
                    }

                    if (UnmappedFile != null && Visible)
                    // this property gets set if relink is set to true, otherwise this gets set by the logic below if there is no mapping
                    {
                        var existing1 = existing;
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            try
                            {
                                PublishUnmappedResource(existing1);
                                existing.Save(LinkerDataPath);
                            }
                            catch (Exception ex)
                            {
                                Status.Update("");
                                Status.Update($"ERROR: {ex.Message}");
                                Controller.Trace("ERROR: {0}", ex.Message);
                                ToggleControl(connect, true);
                                // enable the connect button so the user can try connecting to a different org
                            }
                        }));
                        return;
                    }

                    if (isFoundUnmapped)
                    {
                        existing = LinkerData.Get(LinkerDataPath);
                    }

                    existing.Save(LinkerDataPath);
                    // save the mappings file regardless of the state of the publish since content would've been updated already
                }
                else
                {
                    ToggleControl(connect, true);                     // enable the connect button so the user can try connecting to a different org
                }
            }
            catch (Exception ex)
            {
                Status.Update("");
                Status.Update($"ERROR: {ex.Message}");
                Controller.Trace("ERROR: {0}", ex.Message);
                ToggleControl(connect, true);                 // enable the connect button so the user can try connecting to a different org
            }
        }
コード例 #6
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());
        }