Ejemplo n.º 1
0
        public RenderingItem([CanBeNull] IRenderingContainer renderingContainer, [NotNull] DatabaseUri databaseUri, [NotNull] XElement element, bool isDuplicate) : this(renderingContainer, databaseUri, element)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(element, nameof(element));

            hasParameters = isDuplicate;
            if (!isDuplicate)
            {
                return;
            }

            UniqueId = Guid.NewGuid().ToString("B").ToUpperInvariant();

            var idProperty = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"id", StringComparison.InvariantCultureIgnoreCase) == 0);

            if (idProperty != null)
            {
                var n = idProperty.Value as string;
                if (!string.IsNullOrEmpty(n))
                {
                    n = n.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
                }
                else
                {
                    n = Name;
                }

                disableRenaming  = true;
                idProperty.Value = GetNewControlId(n.GetSafeCodeIdentifier());
                disableRenaming  = false;
            }
        }
Ejemplo n.º 2
0
        public void GetRenderingParameters([NotNull] ItemUri itemUri, [NotNull] Action completed)
        {
            Assert.ArgumentNotNull(itemUri, nameof(itemUri));
            Assert.ArgumentNotNull(completed, nameof(completed));

            if (hasParameters)
            {
                return;
            }

            hasParameters = true;

            ExecuteCompleted c = delegate(string response, ExecuteResult result)
            {
                if (!DataService.HandleExecute(response, result))
                {
                    return;
                }

                var root = response.ToXElement();
                if (root == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(Name))
                {
                    Name = root.GetAttributeValue("name");
                }

                Icon                = new Icon(itemUri.DatabaseUri.Site, root.GetAttributeValue("icon"));
                PlaceHolders        = root.GetAttributeValue("placeholders");
                DataSourceLocation  = root.GetAttributeValue("dsl");
                DataSourceTemplate  = root.GetAttributeValue("dst");
                FilePath            = root.GetAttributeValue("path");
                ParameterTemplateId = root.GetAttributeValue("templateid");

                ApplyDefaultParameters(root);
                ParseTemplate(root);

                var idProperty = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"id", StringComparison.InvariantCultureIgnoreCase) == 0);
                if (idProperty != null && string.IsNullOrEmpty(idProperty.Value as string))
                {
                    disableRenaming  = true;
                    idProperty.Value = GetNewControlId(Name.GetSafeCodeIdentifier() + "1");
                    disableRenaming  = false;
                }

                ReloadPropertyDescriptors();

                RaiseParametersLoaded();

                completed();
            };

            AppHost.Server.Layouts.GetRenderingParameters(itemUri, c);
        }
Ejemplo n.º 3
0
        public string GetControlId()
        {
            var property = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"Id", StringComparison.InvariantCultureIgnoreCase) == 0);

            if (property == null)
            {
                return(string.Empty);
            }

            return(property.Value as string ?? string.Empty);
        }
Ejemplo n.º 4
0
        public void SetParameterValue([NotNull] string parameterName, [CanBeNull] object value)
        {
            Assert.ArgumentNotNull(parameterName, nameof(parameterName));

            var property = DynamicProperties.FirstOrDefault(p => p.Name == parameterName);

            if (property != null)
            {
                property.Value = value;
            }
        }
Ejemplo n.º 5
0
        public void ChangeRendering([NotNull] RenderingItem newRenderingItem, [NotNull] Action completed)
        {
            Assert.ArgumentNotNull(completed, nameof(completed));
            Assert.ArgumentNotNull(newRenderingItem, nameof(newRenderingItem));

            Name          = newRenderingItem.Name;
            ItemUri       = newRenderingItem.ItemUri;
            ItemId        = newRenderingItem.ItemId;
            hasParameters = true;
            Icon          = newRenderingItem.Icon;

            ExecuteCompleted c = delegate(string response, ExecuteResult result)
            {
                if (!DataService.HandleExecute(response, result))
                {
                    return;
                }

                var root = response.ToXElement();
                if (root == null)
                {
                    return;
                }

                PlaceHolders        = root.GetAttributeValue("placeholders");
                DataSourceLocation  = root.GetAttributeValue("dsl");
                DataSourceTemplate  = root.GetAttributeValue("dst");
                FilePath            = root.GetAttributeValue("path");
                ParameterTemplateId = root.GetAttributeValue("templateid");

                var id = GetControlId();

                ParseTemplate(root);

                var idProperty = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"id", StringComparison.InvariantCultureIgnoreCase) == 0);
                if (idProperty != null && string.IsNullOrEmpty(idProperty.Value as string))
                {
                    idProperty.Value = id;
                }

                ReloadPropertyDescriptors();

                RaiseParametersLoaded();

                completed();
            };

            AppHost.Server.Layouts.GetRenderingParameters(newRenderingItem.ItemUri, c);
        }
Ejemplo n.º 6
0
        public string GetDisplayName()
        {
            var result = string.Empty;

            var id = DynamicProperties.FirstOrDefault(p => string.Compare(p.Name, @"id", StringComparison.InvariantCultureIgnoreCase) == 0);

            if (id != null)
            {
                result = id.Value as string ?? string.Empty;
            }

            if (string.IsNullOrEmpty(result))
            {
                result = Name;
            }

            return(result);
        }
Ejemplo n.º 7
0
        public string GetParameterValue([NotNull] string parameterName)
        {
            Assert.ArgumentNotNull(parameterName, nameof(parameterName));

            var property = DynamicProperties.FirstOrDefault(p => p.Name == parameterName);

            if (property == null)
            {
                return(null);
            }

            var value = property.Value;

            if (value == null)
            {
                return(null);
            }

            return(value.ToString());
        }