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