public void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // we had errors, and we got a post-back result of no, don't overwrite
            if (args.Result == "no" || args.Result == "undefined")
            {
                args.SaveAnimation = false;
                args.AbortPipeline();
                return;
            }

            // we had errors, and we got a post-back result of yes, allow overwrite
            if (args.IsPostBack)
            {
                return;
            }

            string error = GetErrorValue(args);

            // no errors detected, we're good
            if (string.IsNullOrEmpty(error))
            {
                return;
            }

            Sitecore.Web.UI.Sheer.SheerResponse.Confirm(error);
            args.WaitForPostBack();
        }
		public void Process(SaveArgs args)
		{
			Assert.ArgumentNotNull(args, "args");

			if (!args.HasSheerUI)
			{
				return;
			}

			// we had errors, and we got a post-back result of no, don't overwrite
			if (args.Result == "no" || args.Result == "undefined")
			{
				args.SaveAnimation = false;
				args.AbortPipeline();
				return;
			}

			// we had errors, and we got a post-back result of yes, allow overwrite
			if (args.IsPostBack) return;

			string error = GetDialogText(args);

			// no errors detected, we're good
			if (string.IsNullOrEmpty(error)) return;
			
			SheerResponse.Confirm(error);
			args.WaitForPostBack();
		}
        public void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // we had errors, and we got a post-back result of no, don't overwrite
            if (args.Result == "no" || args.Result == "undefined")
            {
                args.SaveAnimation = false;
                args.AbortPipeline();
                return;
            }

            // we had errors, and we got a post-back result of yes, allow overwrite
            if (args.IsPostBack) return;

            string error = GetErrorValue(args);

            // no errors detected, we're good
            if (string.IsNullOrEmpty(error)) return;

            // occasionally if you serialize an item "too fast" after changing it, the ShadowWriter's async operations
            // will be in process or have not yet begun to update the serialized item.
            // in these circumstances, we wish to treat a "conflict" or exception as a possible false positive, wait a bit for the ShadowWriter,
            // and try again. If it fails 4x in a row, 500ms apart, it's considered an unrecoverable conflict and we show the error.
            const int retries = 4;
            for (int retryCount = 0; retryCount < retries; retryCount++)
            {
                Thread.Sleep(500);
                error = GetErrorValue(args);
                if (string.IsNullOrEmpty(error)) return;
            }

            Sitecore.Web.UI.Sheer.SheerResponse.Confirm(error);
            args.WaitForPostBack();
        }
Exemplo n.º 4
0
        public virtual void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.IsPostBack)
            {
                if (args.Result == "no")
                {
                    args.AbortPipeline();
                }

                args.IsPostBack = false;

                return;
            }

            if (args.Items == null)
            {
                return;
            }

            foreach (var saveItem in args.Items)
            {
                if (!string.IsNullOrEmpty(saveItem.Revision))
                {
                    Item existingItem = Client.ContentDatabase.GetItem(saveItem.ID, saveItem.Language, saveItem.Version);
                    if (existingItem == null)
                    {
                        continue;
                    }

                    // added: ignore transparent synced items, whose revisions are randomly generated
                    if (existingItem.Statistics.UpdatedBy.Equals(UnicornDataProvider.TransparentSyncUpdatedByValue, StringComparison.Ordinal))
                    {
                        continue;
                    }

                    string cleanedExistingRevision = existingItem[FieldIDs.Revision].Replace("-", string.Empty);
                    string cleanedNewRevision      = saveItem.Revision.Replace("-", string.Empty);
                    if (cleanedExistingRevision.Equals(cleanedNewRevision, StringComparison.InvariantCultureIgnoreCase) || EditorConstants.IgnoreRevision.Equals(cleanedNewRevision, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    if (!args.HasSheerUI)
                    {
                        break;
                    }

                    SheerResponse.Confirm("One or more items have been changed.\n\nDo you want to overwrite these changes?");

                    args.WaitForPostBack();

                    break;
                }
            }
        }
        public void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // we had errors, and we got a post-back result of no, don't overwrite
            if (args.Result == "no" || args.Result == "undefined")
            {
                args.SaveAnimation = false;
                args.AbortPipeline();
                return;
            }

            // we had errors, and we got a post-back result of yes, allow overwrite
            if (args.IsPostBack) return;

            var results = new Dictionary<Item, IList<FieldDesynchronization>>();

            foreach (var item in args.Items)
            {
                Item existingItem = Client.ContentDatabase.GetItem(item.ID);
                SyncItem serializedVersion = ReadSerializedVersion(existingItem);

                // not having an existing serialized version means no possibility of conflict here
                if (serializedVersion == null) continue;

                var fieldIssues = GetFieldSyncStatus(existingItem, serializedVersion);

                if (fieldIssues.Count == 0) continue;

                results.Add(existingItem, fieldIssues);
            }

            // no problems
            if (results.Count == 0) return;

            var sb = new StringBuilder();
            sb.Append("CRITICAL:\n");
            sb.Append("Item state conflicted with existing serialized value. Chances are you need to sync your database with the filesystem. The following fields had problems:\n");
            foreach (var item in results)
            {
                sb.AppendFormat("\n{0}: {1}", item.Key.DisplayName, string.Join(", ", item.Value.Select(x => x.FieldName)));
            }

            sb.Append("\n\nDo you want to overwrite anyway? You may cause someone else to lose committed work by doing this.");

            Sitecore.Web.UI.Sheer.SheerResponse.Confirm(sb.ToString());
            args.WaitForPostBack();
        }
        public void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // we had errors, and we got a post-back result of no, don't overwrite
            if (args.Result == "no" || args.Result == "undefined")
            {
                args.SaveAnimation = false;
                args.AbortPipeline();
                return;
            }

            // we had errors, and we got a post-back result of yes, allow overwrite
            if (args.IsPostBack)
            {
                return;
            }

            string error = GetErrorValue(args);

            // no errors detected, we're good
            if (string.IsNullOrEmpty(error))
            {
                return;
            }

            // occasionally if you serialize an item "too fast" after changing it, the ShadowWriter's async operations
            // will be in process or have not yet begun to update the serialized item.
            // in these circumstances, we wish to treat a "conflict" or exception as a possible false positive, wait a bit for the ShadowWriter,
            // and try again. If it fails 4x in a row, 500ms apart, it's considered an unrecoverable conflict and we show the error.
            const int retries = 4;

            for (int retryCount = 0; retryCount < retries; retryCount++)
            {
                Thread.Sleep(500);
                error = GetErrorValue(args);
                if (string.IsNullOrEmpty(error))
                {
                    return;
                }
            }

            Sitecore.Web.UI.Sheer.SheerResponse.Confirm(error);
            args.WaitForPostBack();
        }
        public virtual void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.IsPostBack)
            {
                if (args.Result == "no")
                    args.AbortPipeline();

                args.IsPostBack = false;

                return;
            }

            if (args.Items == null)
                return;

            foreach (var saveItem in args.Items)
            {
                if (!string.IsNullOrEmpty(saveItem.Revision))
                {
                    Item existingItem = Client.ContentDatabase.GetItem(saveItem.ID, saveItem.Language, saveItem.Version);
                    if (existingItem == null) continue;

                    // added: ignore transparent synced items, whose revisions are randomly generated
                    if (existingItem.Statistics.UpdatedBy.Equals(UnicornDataProvider.TransparentSyncUpdatedByValue, StringComparison.Ordinal)) continue;

                    string cleanedExistingRevision = existingItem[FieldIDs.Revision].Replace("-", string.Empty);
                    string cleanedNewRevision = saveItem.Revision.Replace("-", string.Empty);
                    if (cleanedExistingRevision.Equals(cleanedNewRevision, StringComparison.InvariantCultureIgnoreCase) || EditorConstants.IgnoreRevision.Equals(cleanedNewRevision, StringComparison.InvariantCultureIgnoreCase))
                        continue;

                    if (!args.HasSheerUI)
                        break;

                    SheerResponse.Confirm("One or more items have been changed.\n\nDo you want to overwrite these changes?");

                    args.WaitForPostBack();

                    break;
                }
            }
        }