Esempio n. 1
0
 public void LoadWebResourceFromASpecificSolution()
 {
     wrManager = new WebResourceManager(Service);
     var sPicker = new SolutionPicker(Service) { StartPosition = FormStartPosition.CenterParent };
     if (sPicker.ShowDialog(this) == DialogResult.OK)
     {
         LoadWebResourcesGeneral(sPicker.SelectedSolution);
     }
 }
        public void LoadWebResourcesGeneral(bool fromSolution)
        {
            Guid solutionId = Guid.Empty;
            List<int> typesToload;

            // If from solution, display the solution picker so that user can
            // select the solution containing the web resources he wants to
            // display
            if (fromSolution)
            {
                var sPicker = new SolutionPicker(Service) { StartPosition = FormStartPosition.CenterParent };
                if (sPicker.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    solutionId = sPicker.SelectedSolution.Id;
                }
                else
                {
                    return;
                }
            }

            // Display web resource types selection dialog
            var dialog = new WebResourceTypeSelectorDialog();
            if (dialog.ShowDialog(ParentForm) == DialogResult.OK)
            {
                typesToload = dialog.TypesToLoad;
            }
            else
            {
                return;
            }

            webresourceTreeView1.Enabled = false;
            webresourceTreeView1.Service = Service;

            WorkAsync(new WorkAsyncInfo("Loading web resources...", e =>
            {
                var args = (Tuple<Guid, List<int>>)e.Argument;

                webresourceTreeView1.LoadWebResourcesFromServer(args.Item1, args.Item2);
            })
            {
                AsyncArgument = new Tuple<Guid, List<int>>(solutionId, typesToload),
                PostWorkCallBack = e =>
                {
                    webresourceTreeView1.DisplayWebResources();

                    webresourceTreeView1.Enabled = true;
                }
            });
        }
Esempio n. 3
0
        private void UpdateWebResources(bool publish, IEnumerable<TreeNode> nodes, bool addToSolution = false)
        {
            var solutionUniqueName = string.Empty;
            if (addToSolution)
            {
                var sPicker = new SolutionPicker(Service) { StartPosition = FormStartPosition.CenterParent };

                if (sPicker.ShowDialog(this) == DialogResult.OK)
                {
                    solutionUniqueName = sPicker.SelectedSolution["uniquename"].ToString();
                }
                else
                {
                    return;
                }
            }

            SetWorkingState(true);
            var parameters = new object[] { nodes, publish, solutionUniqueName };

            WorkAsync("Updating web resources...",
                (bw, e) =>
                {
                    var webResourceManager = new WebResourceManager(Service);
                    var idsToPublish = new List<Guid>();
                    var localNodes = (IEnumerable<TreeNode>)((object[])e.Argument)[0];

                    var wrDifferentFromServer = new List<TreeNode>();

                    foreach (TreeNode node in localNodes.Where(n => n.Tag != null))
                    {
                        var wr = (WebResource)node.Tag;
                        Entity serverVersion = null;
                        if (wr.WebResourceEntity != null && wr.WebResourceEntity.Id != Guid.Empty)
                        {
                            serverVersion = webResourceManager.RetrieveWebResource(wr.WebResourceEntity.Id);
                        }

                        if (serverVersion != null && serverVersion.GetAttributeValue<string>("content") != wr.InitialBase64)
                        {
                            wrDifferentFromServer.Add(node);
                        }
                        else
                        {
                            bw.ReportProgress(1, string.Format("Updating {0}...", wr.WebResourceEntity["name"]));

                            wr.WebResourceEntity.Id = webResourceManager.UpdateWebResource(wr.WebResourceEntity);
                            idsToPublish.Add(wr.WebResourceEntity.Id);
                            wr.InitialBase64 = wr.WebResourceEntity.GetAttributeValue<string>("content");
                        }
                    }

                    if (wrDifferentFromServer.Count > 0)
                    {
                        if (
                            CommonDelegates.DisplayMessageBox(null,
                                string.Format(
                                    "The following web resources were updated on the server by someone else:\r\n{0}\r\n\r\nAre you sure you want to update them with your content?",
                                    String.Join("\r\n", wrDifferentFromServer.Select(r => ((WebResource)r.Tag).WebResourceEntity.GetAttributeValue<string>("name")))),
                                "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            foreach (var resource in wrDifferentFromServer)
                            {
                                var wr = (WebResource)resource.Tag;

                                bw.ReportProgress(1, string.Format("Updating {0}...", wr.WebResourceEntity["name"]));

                                wr.WebResourceEntity.Id = webResourceManager.UpdateWebResource(wr.WebResourceEntity);
                                idsToPublish.Add(wr.WebResourceEntity.Id);
                                wr.InitialBase64 = wr.WebResourceEntity.GetAttributeValue<string>("content");
                            }
                        }
                    }

                    // if publish
                    if ((bool)((object[])e.Argument)[1] && wrDifferentFromServer.Count <= localNodes.Count())
                    {
                        bw.ReportProgress(2, "Publishing web resources...");

                        webResourceManager.PublishWebResources(idsToPublish);
                    }

                    if (((object[])e.Argument)[2].ToString().Length > 0 && wrDifferentFromServer.Count < localNodes.Count())
                    {
                        bw.ReportProgress(3, "Adding web resources to solution...");

                        webResourceManager.AddToSolution(idsToPublish, ((object[])e.Argument)[2].ToString());
                    }
                },
                e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, "An error occured: " + e.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (tslResourceName.Text.Contains(" (not published)"))
                    {
                        tslResourceName.Text = tslResourceName.Text.Replace(" (not published)", "");
                        tslResourceName.ForeColor = Color.Black;
                    }

                    SetWorkingState(false);
                },
                e=>SetWorkingMessage(e.UserState.ToString()),
                parameters);
        }
        private void UpdateWebResources(bool publish, IEnumerable<WebResource> webResources, bool addToSolution = false)
        {
            var solutionUniqueName = string.Empty;
            if (addToSolution)
            {
                var sPicker = new SolutionPicker(Service) { StartPosition = FormStartPosition.CenterParent };

                if (sPicker.ShowDialog(this) == DialogResult.OK)
                {
                    solutionUniqueName = sPicker.SelectedSolution["uniquename"].ToString();
                }
                else
                {
                    return;
                }
            }

            SetWorkingState(true);
            var parameters = new object[] { webResources, publish, solutionUniqueName };

            WorkAsync(new WorkAsyncInfo("Updating web resources...",
                 (bw, e) =>
                 {
                     var webResourceManager = new AppCode.WebResourceManager(Service);
                     var resourceToPublish = new List<WebResource>();
                     var resources = ((IEnumerable<WebResource>)((object[])e.Argument)[0]).ToList();

                     var wrDifferentFromServer = new List<WebResource>();

                     foreach (var wr in resources)
                     {
                         Entity serverVersion = null;
                         if (wr.Entity != null && wr.Entity.Id != Guid.Empty)
                         {
                             serverVersion = webResourceManager.RetrieveWebResource(wr.Entity.Id);
                         }

                         if (serverVersion != null && serverVersion.GetAttributeValue<string>("content") != wr.InitialBase64)
                         {
                             wrDifferentFromServer.Add(wr);
                         }
                         else
                         {
                             bw.ReportProgress(1, string.Format("Updating {0}...", wr.Entity.GetAttributeValue<string>("name")));

                             wr.Entity.Id = webResourceManager.UpdateWebResource(wr.Entity);
                             resourceToPublish.Add(wr);
                             wr.InitialBase64 = wr.Entity.GetAttributeValue<string>("content");
                         }
                     }

                     if (wrDifferentFromServer.Count > 0)
                     {
                         if (
                             CommonDelegates.DisplayMessageBox(null,
                                 string.Format(
                                     "The following web resources were updated on the server by someone else:\r\n{0}\r\n\r\nAre you sure you want to update them with your content?",
                                     String.Join("\r\n", wrDifferentFromServer.Select(r => r.Entity.GetAttributeValue<string>("name")))),
                                 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                         {
                             foreach (var resource in wrDifferentFromServer)
                             {
                                 bw.ReportProgress(1, string.Format("Updating {0}...", resource.Entity.GetAttributeValue<string>("name")));

                                 resource.Entity.Id = webResourceManager.UpdateWebResource(resource.Entity);
                                 resourceToPublish.Add(resource);
                                 resource.InitialBase64 = resource.Entity.GetAttributeValue<string>("content");
                             }
                         }
                     }

                     // Process post Update command
                     if (!string.IsNullOrEmpty(Options.Instance.AfterUpdateCommand))
                     {
                         foreach (var webResource in resourceToPublish)
                         {
                             evtManager.ActAfterUpdate(webResource);
                         }
                     }

                     // if publish
                     if ((bool)((object[])e.Argument)[1] && wrDifferentFromServer.Count <= resources.Count())
                     {
                         bw.ReportProgress(2, "Publishing web resources...");

                         webResourceManager.PublishWebResources(resourceToPublish);
                     }

                     // Process post Publish command
                     if (!string.IsNullOrEmpty(Options.Instance.AfterPublishCommand))
                     {
                         foreach (var webResource in resourceToPublish)
                         {
                             evtManager.ActAfterPublish(webResource);
                         }
                     }

                     if (((object[])e.Argument)[2].ToString().Length > 0 && wrDifferentFromServer.Count < resources.Count())
                     {
                         bw.ReportProgress(3, "Adding web resources to solution...");

                         webResourceManager.AddToSolution(resourceToPublish, ((object[])e.Argument)[2].ToString());
                     }
                 })
            {
                AsyncArgument = parameters,
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, Resources.MessageBox_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (tslResourceName.Text.Contains(" (not published)"))
                    {
                        tslResourceName.Text = tslResourceName.Text.Replace(" (not published)", "");
                        tslResourceName.ForeColor = Color.Black;
                    }

                    SetWorkingState(false);
                },
                ProgressChanged = e => SetWorkingMessage(e.UserState.ToString())
            });
        }