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())
            });
        }