Esempio n. 1
0
        // TODO: Put strings into the resources.
        //
        public Cloneable Clone(ICloneContext cloneCtx)
        {
            var result = (Cloneable)MemberwiseClone();

            if (cloneCtx != null && cloneCtx.SetCloneOrigin)
            {
                throw new NotSupportedException($"Setting clone origin is not supported for this object.{Environment.NewLine}\tObject:{this.FmtStr().GNLI2()}").SetErrorCode(code: GeneralErrorCodes.Operation.NotSupported);
            }
            PopulateClone(cloneCtx, result);
            return(result);
        }
        public override async Task MutateOnClone(JObject content, ICloneContext context)
        {
            var mutatedContentItems = await _embeddedContentItemsGraphSyncer.MutateOnClone((JArray?)content[ContainerName], context);

            var mutatedContentItemsJArray = JArray.FromObject(mutatedContentItems);

            content[ContainerName] = mutatedContentItemsJArray;

            // we could return the mutated contentitems from this method and the derived class could use Alter with the appropriate part
            // context.ContentItem.Alter<FlowPart>(p => p.Widgets = mutatedContentItems.ToList());
        }
Esempio n. 3
0
        public override Task MutateOnClone(JObject content, ICloneContext context)
        {
            string title = (string?)content[nameof(TitlePart.Title)] ?? string.Empty;

            var newTitle = _titlePartCloneGenerator.Generate(title);

            context.ContentItem.DisplayText  = newTitle;
            content[nameof(TitlePart.Title)] = newTitle;

            return(Task.CompletedTask);
        }
Esempio n. 4
0
        public object Clone(ICloneContext context, object src)
        {
            var target = FormatterServices.GetUninitializedObject(_type);

            foreach (var cloneField in _cloneFields)
            {
                var value = cloneField.Get(src);
                if (cloneField.Deep)
                {
                    value = context.Clone(value);
                }
                cloneField.Set(target, value);
            }

            return(target);
        }
Esempio n. 5
0
        public CloneableDisposable Clone(ICloneContext cloneCtx)
        {
            EnsureNotDisposeState(considerDisposeRequest: true);
            //
            var clone = (CloneableDisposable)MemberwiseClone();

            clone.RecreateDisposableImplementation();
            try {
                PopulateClone(cloneCtx: cloneCtx, clone: clone);
                if (cloneCtx?.SetCloneOrigin == true)
                {
                    clone.WriteDA(location: ref _cloneOrigin, value: this);
                }
                EnsureNotDisposeState(considerDisposeRequest: true);
                return(clone);
            }
            catch (Exception exception) {
                clone?.Dispose(exception: exception);
                throw;
            }
        }
Esempio n. 6
0
        public override async Task MutateOnClone(JObject content, ICloneContext context)
        {
            string?urlName = (string?)content[nameof(PageLocationPart.UrlName)];
            string?fullUrl = (string?)content[nameof(PageLocationPart.FullUrl)];

            if (string.IsNullOrWhiteSpace(urlName) || string.IsNullOrWhiteSpace(fullUrl))
            {
                throw new InvalidOperationException($"Cannot mutate {nameof(PageLocationPart)} if {nameof(PageLocationPart.UrlName)} or {nameof(PageLocationPart.FullUrl)} are missing.");
            }

            List <ContentItem> pages = await _contentItemsService.GetActive(ContentTypes.Page);

            string urlSearchFragment = _generator.GenerateUrlSearchFragment(fullUrl);

            IEnumerable <ContentItem> existingClones = pages.Where(x => ((string)x.Content[nameof(PageLocationPart)][nameof(PageLocationPart.FullUrl)]).Contains(urlSearchFragment));

            var result = _generator.GenerateClonedPageLocationProperties(urlName, fullUrl, existingClones);

            content[nameof(PageLocationPart.UrlName)] = result.UrlName;
            content[nameof(PageLocationPart.FullUrl)] = result.FullUrl;
            content[nameof(PageLocationPart.DefaultPageForLocation)] = false;
            content[nameof(PageLocationPart.RedirectLocations)]      = null;
        }
Esempio n. 7
0
        public CloneableDisposeNotifying Clone(ICloneContext cloneContext)
        {
            EnsureNotDisposeState(considerDisposeRequest: true);
            //
            var clone = (CloneableDisposeNotifying)MemberwiseClone();

            clone.RecreateDisposableImplementation();
            try {
                PopulateClone(cloneContext: cloneContext, clone: clone);
                if (cloneContext?.SetCloneOrigin == true)
                {
                    clone.WriteDA(location: ref _cloneOrigin, value: this);
                }
                else
                {
                    EnsureNotDisposeState(considerDisposeRequest: true);
                }
                return(clone);
            }
            catch (Exception exception) {
                DisposeMany(exception: exception, disposables: clone);
                throw;
            }
        }
Esempio n. 8
0
 // It's used by reflection from CloneObjectEx
 public static object Clone(ICloneContext context, object src)
 {
     return(Array.ConvertAll((T[])src, x => (T)context.Clone(x)));
 }
 public object Clone(ICloneContext context, object src)
 {
     return(_cache.GetOrAdd(src.GetType(), CreateObjectClone)(context, src));
 }
Esempio n. 10
0
 protected abstract void PopulateClone(ICloneContext cloneCtx, CloneableDisposable clone);
Esempio n. 11
0
 object IEonCloneable.Clone(ICloneContext cloneCtx)
 => Clone(cloneCtx: cloneCtx);
Esempio n. 12
0
 public virtual Task MutateOnClone(JObject content, ICloneContext context)
 {
     return(Task.CompletedTask);
 }
Esempio n. 13
0
 protected abstract void PopulateClone(ICloneContext cloneContext, CloneableDisposeNotifying clone);
Esempio n. 14
0
 object IEonCloneable.Clone(ICloneContext cloneContext)
 => Clone(cloneContext: cloneContext);