public void Created(ShapeCreatedContext context)
        {
            var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
/*
            if (shapeMetadata.Type.Equals("Zone") || context.Shape.ContentItem == null)
            {
                return;
            }
*/

            shapeMetadata.OnDisplaying(this.OnDisplaying);
            shapeMetadata.OnDisplayed(this.OnDisplayed);
        }
Beispiel #2
0
        public void Created(ShapeCreatedContext context)
        {
            if (!IsActivable())
            {
                return;
            }

            // prevent reentrance as some methods could create new shapes, and trigger this event
            if (_processing)
            {
                return;
            }

            _processing = true;

            if (context.ShapeType != "Layout" &&
                context.ShapeType != "DocumentZone" &&
                context.ShapeType != "PlaceChildContent" &&
                context.ShapeType != "ContentZone" &&
                context.ShapeType != "ShapeTracingMeta" &&
                context.ShapeType != "ShapeTracingTemplates" &&
                context.ShapeType != "DateTimeRelative")
            {
                var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
                var currentTheme  = _workContext.CurrentTheme;
                var shapeTable    = _shapeTableManager.GetShapeTable(currentTheme.Id);

                if (!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type))
                {
                    _processing = false;
                    return;
                }

                shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
                shapeMetadata.OnDisplaying(OnDisplaying);
            }

            _processing = false;
        }
Beispiel #3
0
 public void Created(ShapeCreatedContext context)
 {
 }
Beispiel #4
0
 public virtual void Created(ShapeCreatedContext context)
 {
 }
Beispiel #5
0
        public async Task <IShape> CreateAsync(string shapeType, Func <Task <IShape> > shapeFactory, Action <ShapeCreatingContext> creating, Action <ShapeCreatedContext> created)
        {
            ShapeDescriptor shapeDescriptor;

            (await GetShapeTableAsync()).Descriptors.TryGetValue(shapeType, out shapeDescriptor);

            var creatingContext = new ShapeCreatingContext
            {
                New          = this,
                ShapeFactory = this,
                ShapeType    = shapeType,
                OnCreated    = new List <Func <ShapeCreatedContext, Task> >(),
                CreateAsync  = shapeFactory
            };

            creating?.Invoke(creatingContext);

            // "creating" events may add behaviors and alter base type
            foreach (var ev in _events)
            {
                ev.Creating(creatingContext);
            }

            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.CreatingAsync)
                {
                    await ev(creatingContext);
                }
            }

            // Create the new instance
            var createdContext = new ShapeCreatedContext
            {
                New          = creatingContext.New,
                ShapeFactory = creatingContext.ShapeFactory,
                ShapeType    = creatingContext.ShapeType,
                Shape        = await creatingContext.CreateAsync()
            };

            var shape = createdContext.Shape as IShape;

            if (shape == null)
            {
                throw new InvalidOperationException("Invalid base type for shape: " + createdContext.Shape.GetType().ToString());
            }

            if (shape.Metadata == null)
            {
                shape.Metadata = new ShapeMetadata();
            }

            ShapeMetadata shapeMetadata = shape.Metadata;

            shape.Metadata.Type = shapeType;

            // Merge wrappers if there are any
            if (shapeDescriptor != null && shapeMetadata.Wrappers.Count + shapeDescriptor.Wrappers.Count > 0)
            {
                shapeMetadata.Wrappers.AddRange(shapeDescriptor.Wrappers);
            }

            // "created" events provides default values and new object initialization
            foreach (var ev in _events)
            {
                ev.Created(createdContext);
            }

            if (shapeDescriptor != null)
            {
                foreach (var ev in shapeDescriptor.CreatedAsync)
                {
                    await ev(createdContext);
                }
            }

            if (creatingContext != null)
            {
                foreach (var ev in creatingContext.OnCreated)
                {
                    await ev(createdContext);
                }
            }

            created?.Invoke(createdContext);

            return(createdContext.Shape);
        }