public void AddPropertySource_ChangesDataDictionary()
        {
            // Arrange
            IHostingEnvironment          envir      = new HostingEnvironment();
            IDictionary <string, object> properties = new Dictionary <string, object>();

            properties["a.b.c.d"] = "value1";
            properties["a"]       = "value2";
            properties["b"]       = 10;
            PropertySource source = new PropertySource("test", properties);

            source.Name = "test";
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings(), envir);

            // Act and Assert
            provider.AddPropertySource(source);

            string value;

            Assert.True(provider.TryGet("a:b:c:d", out value));
            Assert.Equal("value1", value);
            Assert.True(provider.TryGet("a", out value));
            Assert.Equal("value2", value);
            Assert.True(provider.TryGet("b", out value));
            Assert.Equal("10", value);
        }
示例#2
0
        public Html5ModuleTokenReplace(Page page, string html5File, ModuleInstanceContext moduleContext, ModuleActionCollection moduleActions)
            : base(page)
        {
            AccessingUser  = moduleContext.PortalSettings.UserInfo;
            DebugMessages  = moduleContext.PortalSettings.UserMode != Entities.Portals.PortalSettings.Mode.View;
            ModuleId       = moduleContext.ModuleId;
            PortalSettings = moduleContext.PortalSettings;

            PropertySource["moduleaction"]  = new ModuleActionsPropertyAccess(moduleContext, moduleActions);
            PropertySource["resx"]          = new ModuleLocalizationPropertyAccess(moduleContext, html5File);
            PropertySource["modulecontext"] = new ModuleContextPropertyAccess(moduleContext);
            PropertySource["request"]       = new RequestPropertyAccess(page.Request);

            // DNN-7750
            var bizClass = moduleContext.Configuration.DesktopModule.BusinessControllerClass;

            var businessController = GetBusinessController(bizClass);

            if (businessController != null)
            {
                var tokens = businessController.GetTokens(page, moduleContext);
                foreach (var token in tokens)
                {
                    PropertySource.Add(token.Key, token.Value);
                }
            }
        }
        public void AddPropertySource_ChangesDataDictionary()
        {
            // Arrange
            IDictionary <string, object> properties = new Dictionary <string, object>
            {
                ["a.b.c.d"] = "value1",
                ["a"]       = "value2",
                ["b"]       = 10
            };
            PropertySource source = new PropertySource("test", properties)
            {
                Name = "test"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(new ConfigServerClientSettings());

            // Act and Assert
            provider.AddPropertySource(source);

            Assert.True(provider.TryGet("a:b:c:d", out string value));
            Assert.Equal("value1", value);
            Assert.True(provider.TryGet("a", out value));
            Assert.Equal("value2", value);
            Assert.True(provider.TryGet("b", out value));
            Assert.Equal("10", value);
        }
示例#4
0
 public NodeParameter()
 {
     Name           = "Property";
     PropertyType   = PropertyType.String;
     Source         = PropertySource.EnteredOnly;
     InputNodeId    = new StringField();
     PropertyFamily = PropertyFamily.Primitive;
     Property       = null;
     Value          = "";
     SubParams      = new Dictionary <string, SubNodeParameter>();
 }
示例#5
0
 //constructor
 public BookingConfiguration(BookingType booktype, string hotelName, string arrivalMonth, string arrivalDay, string duration,
                             int numberOfRooms, int room1Adults, int room1Children, int room1Infants, PropertySource source)
 {
     BookType              = booktype;
     HotelName             = hotelName;
     ArrivalMonth          = arrivalMonth;
     ArrivalDay            = arrivalDay;
     Duration              = duration;
     NumberOfRooms         = numberOfRooms;
     NumberOfAdultsRoom1   = room1Adults;
     NumberOfChildrenRoom1 = room1Children;
     NumberOfInfantsRoom1  = room1Infants;
     Source = source;
 }
示例#6
0
        public static void SetPropValue(this object target, string propName, object value)
        {
            PropertySource propSource   = target.GetProp(propName);
            PropertyInfo   propertyInfo = propSource.Property;
            object         source       = propSource.Source;

            if (propertyInfo != null && propertyInfo.CanWrite)
            {
                propertyInfo.SetValue(source, ConvertValueType(propertyInfo, value));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(string.Format("ReflectionHelper SetPropValue() : {0} icerisinde {1} isminde bir property yok!", target.GetType().Name, propName));
            }
        }
示例#7
0
            public string GetValue(string tokenText, DataRow row, string sourceColumn, string sourceType)
            {
                PropertySource.Clear();
                switch (sourceType.ToLowerInvariant())
                {
                case "createdby":
                case "changedby":
                case "userlink":
                    var userInfo = ((IUserSource)(ByName(sourceType))).GetUser(sourceColumn, row);
                    if (userInfo == null)
                    {
                        return("");
                    }
                    PropertySource["user"]    = userInfo;
                    PropertySource["profile"] = new ProfilePropertyAccess(userInfo);
                    break;

                case "download":
                case "url":
                case "image":
                    var strFileId = row[sourceColumn + DataTableColumn.Appendix_Original].AsString();
                    if (strFileId != string.Empty)
                    {
                        PropertySource["file"] = new DownloadPropertyAccess(strFileId,
                                                                            Globals.GetPortalSettings().PortalId,
                                                                            _moduleId);
                    }
                    break;

                default:
                    if ((ByName(sourceType)) is IEmailAdressSource)
                    {
                        var email = ((IEmailAdressSource)(ByName(sourceType))).GetEmailAddress(sourceColumn, row);
                        if (!string.IsNullOrEmpty(email))
                        {
                            PropertySource["gravatar"] = new GravatarPropertyAccess(email);
                        }
                    }
                    else
                    {
                        return("");
                    }
                    break;
                }

                return(ReplaceTokens(tokenText));
            }
示例#8
0
        /// <summary>
        /// Loads the Property Settings.
        /// This method is called from the base classes constructor.
        /// </summary>
        public override void Initialize()
        {
            #region Base Properties

            KeyName = PropertySource.Name;
            //Description = PropertySource.Description;

            #region Data Type Related

            SystemType = TypeHelper.ResolveSystemType(PropertySource.SystemType(), PropertySource.AllowDBNull, true);
            //DefaultValue = PropertySource.DefaultValue;
            Size      = PropertySource.Size;
            Scale     = PropertySource.Scale;
            Precision = PropertySource.Precision;
            //FixedLength =
            //Unicode =

            IsNullable = PropertySource.AllowDBNull;

            #endregion

            #endregion

            #region Column Specific Properties

            DataType   = PropertySource.DataType;
            NativeType = PropertySource.NativeType;

            //IsUnique = PropertySource.IsUnique;
            //IsForeignKey = PropertySource.IsForeignKeyMember;
            IsRowVersion = PropertySource.IsColumnRowVersion();
            IsIdentity   = PropertySource.IsColumnIdentity();
            IsComputed   = PropertySource.IsColumnComputed();
            Unicode      = PropertySource.IsUnicode();
            FixedLength  = PropertySource.IsFixedLength();

            //  Views do not define any keys, but in cases where frameworks need to define a key like entity framework a key is defined as any non-nullable column.
            if (Configuration.Instance.GenerateViewKeys)
            {
                IsPrimaryKey = !IsNullable && !FixedLength;
            }

            PropertyType = ResolvePropertyType();

            #endregion
        }
示例#9
0
        private PropertyType ResolvePropertyType()
        {
            PropertyType?type = null;

            // Concurrency
            if (!String.IsNullOrEmpty(PropertySource.ConcurrencyMode) && PropertySource.ConcurrencyMode.Equals(EdmxConstants.ConcurrencyModeFixed, StringComparison.OrdinalIgnoreCase))
            {
                type = PropertyType.Concurrency;
            }
            else if (Boolean.TrueString.Equals(PropertySource.GetAttributeValue(EdmxConstants.IsIndexCustomAttribute)))
            {
                type = PropertyType.Index;
            }

            //if (IsForeignKey) type &= Enums.PropertyType.Foreign;

            return(type ?? PropertyType.Normal);
        }
        public void Map_PrimitiveProperty_Success()
        {
            var builder = new ClassMapperBuilder(new MappingBuilderConfigStub());
            Mapper mapper = builder.Build(new TypePair(typeof(PropertySource), typeof(PropertyTarget)));

            var source = new PropertySource
            {
                Bool = true,
                Byte = 0,
                Char = 'a',
                Decimal = 4.0m,
                Float = 2.0f,
                Int = 9,
                Long = 2,
                Sbyte = 8,
                Short = 1,
                String = "test",
                Ulong = 3,
                Ushort = 7,
                DateTime = new DateTime(1990, 1, 1),
                DateTimeOffset = new DateTimeOffset(new DateTime(1998, 3, 5)),
                DateTimeNullable = null,
                DateTimeNullable1 = new DateTime(2020, 2, 4)
            };

            var actual = (PropertyTarget)mapper.Map(source);

            Assert.Equal(source.Bool, actual.Bool);
            Assert.Equal(source.Byte, actual.Byte);
            Assert.Equal(source.Char, actual.Char);
            Assert.Equal(source.Decimal, actual.Decimal);
            Assert.Equal(source.Float, actual.Float);
            Assert.Equal(source.Int, actual.Int);
            Assert.Equal(source.Long, actual.Long);
            Assert.Equal(source.Sbyte, actual.Sbyte);
            Assert.Equal(source.Short, actual.Short);
            Assert.Equal(source.String, actual.String);
            Assert.Equal(source.Ulong, actual.Ulong);
            Assert.Equal(source.Ushort, actual.Ushort);
            Assert.Equal(source.DateTime, actual.DateTime);
            Assert.Equal(source.DateTimeOffset, actual.DateTimeOffset);
            Assert.Equal(source.DateTimeNullable, actual.DateTimeNullable);
            Assert.Equal(source.DateTimeNullable1, actual.DateTimeNullable1);
        }
示例#11
0
        public void Map_PrimitiveProperty_Success()
        {
            var    builder = new ClassMapperBuilder(new MappingBuilderConfigStub());
            Mapper mapper  = builder.Build(new TypePair(typeof(PropertySource), typeof(PropertyTarget)));

            var source = new PropertySource
            {
                Bool              = true,
                Byte              = 0,
                Char              = 'a',
                Decimal           = 4.0m,
                Float             = 2.0f,
                Int               = 9,
                Long              = 2,
                Sbyte             = 8,
                Short             = 1,
                String            = "test",
                Ulong             = 3,
                Ushort            = 7,
                DateTime          = new DateTime(1990, 1, 1),
                DateTimeOffset    = new DateTimeOffset(new DateTime(1998, 3, 5)),
                DateTimeNullable  = null,
                DateTimeNullable1 = new DateTime(2020, 2, 4)
            };

            var actual = (PropertyTarget)mapper.Map(source);

            Assert.Equal(source.Bool, actual.Bool);
            Assert.Equal(source.Byte, actual.Byte);
            Assert.Equal(source.Char, actual.Char);
            Assert.Equal(source.Decimal, actual.Decimal);
            Assert.Equal(source.Float, actual.Float);
            Assert.Equal(source.Int, actual.Int);
            Assert.Equal(source.Long, actual.Long);
            Assert.Equal(source.Sbyte, actual.Sbyte);
            Assert.Equal(source.Short, actual.Short);
            Assert.Equal(source.String, actual.String);
            Assert.Equal(source.Ulong, actual.Ulong);
            Assert.Equal(source.Ushort, actual.Ushort);
            Assert.Equal(source.DateTime, actual.DateTime);
            Assert.Equal(source.DateTimeOffset, actual.DateTimeOffset);
            Assert.Equal(source.DateTimeNullable, actual.DateTimeNullable);
            Assert.Equal(source.DateTimeNullable1, actual.DateTimeNullable1);
        }
示例#12
0
        /// <summary>
        /// Loads the Property Settings.
        /// This method is called from the base classes constructor.
        /// </summary>
        public override void Initialize()
        {
            #region Base Properties

            KeyName     = PropertySource.Name;
            Description = PropertySource.Description;

            #region Data Type Related

            SystemType = TypeHelper.ResolveSystemType(PropertySource.SystemType(), PropertySource.AllowDBNull, true);
            //DefaultValue = PropertySource.DefaultValue;
            Size      = PropertySource.Size;
            Scale     = PropertySource.Scale;
            Precision = PropertySource.Precision;
            //FixedLength =
            //Unicode =

            IsNullable = PropertySource.AllowDBNull;

            #endregion

            #endregion

            #region Column Specific Properties

            DataType = PropertySource.DataType;
            ExtendedProperties["DataType"] = PropertySource.NativeType;
            NativeType = PropertySource.NativeType;
            ExtendedProperties["NativeType"] = PropertySource.NativeType;

            //IsUnique = PropertySource.IsUnique;
            //IsPrimaryKey = PropertySource.IsPrimaryKeyMember;
            //IsForeignKey = PropertySource.IsForeignKeyMember;
            IsRowVersion = PropertySource.IsColumnRowVersion();
            IsIdentity   = PropertySource.IsColumnIdentity();
            IsComputed   = PropertySource.IsColumnComputed();
            Unicode      = PropertySource.IsUnicode();
            FixedLength  = PropertySource.IsFixedLength();

            PropertyType = ResolvePropertyType();

            #endregion
        }
示例#13
0
        public TokenReplace(DynamicEntity Content, DynamicEntity Presentation, DynamicEntity ListContent, DynamicEntity ListPresentation, Dictionary <string, string> List, App app) : base()
        {
            if (HttpContext.Current != null)
            {
                HttpRequest request = HttpContext.Current.Request;
                PropertySource.Add("querystring", new FilteredNameValueCollectionPropertyAccess(request.QueryString));
                PropertySource.Add("form", new FilteredNameValueCollectionPropertyAccess(request.Form));
                PropertySource.Add("server", new FilteredNameValueCollectionPropertyAccess(request.ServerVariables));

                // Add our expando, requires that we convert it to a string/string table
                if (Content != null)
                {
                    /*Dictionary<string, object> ContentDictionary = new Dictionary<string, object>(Content.Dictionary);*/
                    PropertySource.Add("content", new DynamicEntityPropertyAccess("content", Content));
                }
                if (Presentation != null)
                {
                    /*Dictionary<string, object> PresentationDictionary = new Dictionary<string, object>(Presentation.Dictionary);*/
                    PropertySource.Add("presentation", new DynamicEntityPropertyAccess("presentation", Presentation));
                }
                if (ListContent != null)
                {
                    /*Dictionary<string, object> ContentDictionary = new Dictionary<string, object>(ListContent.Dictionary);*/
                    PropertySource.Add("listcontent", new DynamicEntityPropertyAccess("listcontent", ListContent));
                }
                if (ListPresentation != null)
                {
                    /*Dictionary<string, object> PresentationDictionary = new Dictionary<string, object>(ListPresentation.Dictionary);*/
                    PropertySource.Add("listpresentation", new DynamicEntityPropertyAccess("listpresentation", ListPresentation));
                }

                PropertySource.Add("app", new AppPropertyAccess("app", app));
                if (app.Settings != null)
                {
                    PropertySource.Add("appsettings", new DynamicEntityPropertyAccess("appsettings", app.Settings));
                }
                if (app.Resources != null)
                {
                    PropertySource.Add("appresources", new DynamicEntityPropertyAccess("appresources", app.Resources));
                }
                PropertySource.Add("list", new DictionaryPropertyAccess(List));
            }
        }
示例#14
0
        /// <summary>
        /// Loads the Property Settings.
        /// This method is called from the base classes constructor.
        /// </summary>
        public override void Initialize()
        {
            #region Base Properties

            KeyName = PropertySource.Name.Replace("@", String.Empty);
            // NOTE: This can take forever in some cases on long stored procedures.
            //Description = PropertySource.Description;

            #region Data Type Related

            SystemType = TypeHelper.ResolveSystemType(PropertySource.SystemType(), PropertySource.AllowDBNull, true);
            //DefaultValue = PropertySource.DefaultValue;
            Size      = PropertySource.Size;
            Scale     = PropertySource.Scale;
            Precision = PropertySource.Precision;

            IsNullable = PropertySource.AllowDBNull;

            #endregion

            #endregion

            #region Column Specific Properties

            DataType   = PropertySource.DataType;
            NativeType = PropertySource.NativeType;

            //IsUnique = PropertySource.IsUnique;
            //IsPrimaryKey = PropertySource.IsPrimaryKeyMember;
            //IsForeignKey = PropertySource.IsForeignKeyMember;
            IsRowVersion = PropertySource.IsColumnRowVersion();
            //IsIdentity = PropertySource.IsColumnIdentity(); // NOTE: This is not needed for a command paramater...
            IsComputed  = IsRowVersion; // PropertySource.IsColumnComputed();
            Unicode     = PropertySource.IsUnicode();
            FixedLength = PropertySource.IsFixedLength();

            #endregion

            ParameterDirection = PropertySource.Direction;

            PropertyType = ResolvePropertyType();
        }
        public override void Initialize()
        {
            var column = PropertySource.Attribute("column") ?? PropertySource.Attribute("name");
            var name   = PropertySource.Attribute("name") ?? column;

            KeyName = column.Value;
            Name    = name.Value;

            var type            = PropertySource.Attribute("type").Value;
            var lengthAttribute = PropertySource.Attribute("length");
            int?length          = null;

            if (lengthAttribute != null)
            {
                int lengthInt;
                if (Int32.TryParse(lengthAttribute.Value, out lengthInt))
                {
                    length = lengthInt;
                }
            }

            SystemType = NHibernateUtilities.FromNHibernateType(type, length);
        }
        public void AddPropertySource_ChangesDataDictionary()
        {
            // Arrange
            IDictionary<string,object> properties = new Dictionary<string, object>();
            properties["a.b.c.d"] = "value1";
            properties["a"] = "value2";
            properties["b"] = 10;
            PropertySource source = new PropertySource("test", properties );
            source.Name = "test";
            ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(new ConfigServerClientSettingsBase());

            // Act and Assert
            provider.AddPropertySource(source);

            string value;
            Assert.True(provider.TryGet("a:b:c:d", out value));
            Assert.Equal("value1", value);
            Assert.True(provider.TryGet("a", out value));
            Assert.Equal("value2", value);
            Assert.True(provider.TryGet("b", out value));
            Assert.Equal("10", value);

        }
        private void CreateSelector(IQuerySource qs)
        {
            var index = Query.CurrentSelectIndex;

            if (qs.ItemType.IsGrouping())
            {
                var factoryKey =
                    QuerySourceConverterFactory.CreateResult(
                        "Key",
                        qs.ItemType.GetGenericArguments()[0],
                        qs,
                        Query,
                        false);
                var factoryValue = QuerySourceConverterFactory.Create(qs, Query);
                var genericType  = qs.ItemType.CreateGrouping();
                if (Query.AddSelectPart(
                        qs,
                        "\"{0}\".\"Key\" AS \"{0}.Key\", \"{0}\".\"Values\" AS \"{0}\"".With(factoryValue.Name),
                        factoryValue.Name,
                        qs.ItemType,
                        (_, dr) =>
                {
                    var keyInstance = factoryKey.Instancer(dr.GetValue(index));
                    //TODO fix later
                    return(null);

                    /*var array = dr.IsDBNull(index + 1) ? new string[0] : OracleRecordConverter.ParseArray(dr.GetString(index + 1));
                     * var valueInstances = array.Select(it => factoryValue.Instancer(it));
                     * return Activator.CreateInstance(genericType, keyInstance, valueInstances);*/
                }))
                {
                    Query.CurrentSelectIndex++;
                }
            }
            else if (typeof(IOracleReader).IsAssignableFrom(qs.ItemType))
            {
                var props     = qs.ItemType.GetProperties();
                var selectors = new PropertySource[props.Length];
                for (int i = 0; i < selectors.Length; i++)
                {
                    var s = selectors[i] = new PropertySource(qs, props[i]);
                    Query.AddSelectPart(
                        s,
                        "\"{0}\".\"{1}\" AS \"{0}.{1}\"".With(s.Parent.ItemName, s.Property.Name),
                        s.ItemName,
                        s.ItemType,
                        null);
                }
                Query.AddSelectPart(
                    qs,
                    null,
                    qs.ItemName,
                    qs.ItemType,
                    (_, dr) =>
                {
                    var inst = (IOracleReader)Activator.CreateInstance(qs.ItemType);
                    inst.Read(qs.ItemName, dr, Query.Locator);
                    return(inst);
                });
            }
            else
            {
                var factory = QuerySourceConverterFactory.Create(qs, Query);
                var ii      = factory.CanBeNull && factory.AsValue;
                Query.AddSelectPart(
                    factory.QuerySource,
                    ii ? "CASE WHEN \"{0}\".URI IS NULL THEN NULL ELSE VALUE(\"{0}\") END".With(factory.Name)
                                                : factory.AsValue ? "VALUE(\"{0}\")".With(factory.Name)
                                                : "\"{0}\"".With(factory.Name),
                    factory.Name,
                    factory.Type,
                    (_, dr) => dr.IsDBNull(index) ? null : factory.Instancer(dr.GetValue(index)));
            }
        }
示例#18
0
 public PropertyNode()
 {
     Source = new PropertySource();
 }
 public override void Initialize()
 {
     KeyName = Name = _safeName = PropertySource.Attribute("name").Value;
 }
示例#20
0
        private void UpdateProperties()
        {
            if (_propertySource == null)
            {
                _propertySource = new PropertySource();
            }

            _propertySource.Name     = (IsUntitled) ? UntitledName : Path.GetFileName(Uri.LocalPath);
            _propertySource.TypeName = "Texture";

            var textBlockKey = new ComponentResourceKey(typeof(PropertyGrid), "TextBlock");

            _propertySource.Properties.Clear();
            _propertySource.Properties.Add(new CustomProperty
            {
                Category     = "Misc",
                Name         = "File name",
                Value        = this.GetName(),
                Description  = "The filename of the image.",
                PropertyType = typeof(string),
                //DataTemplateKey = textBlockKey,
                CanReset   = false,
                IsReadOnly = true,
            });
            _propertySource.Properties.Add(new CustomProperty
            {
                Category        = "Misc",
                Name            = "Size",
                Value           = Texture2D?.Width,
                Description     = "Image width in pixels.",
                PropertyType    = typeof(int),
                DataTemplateKey = textBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });
            _propertySource.Properties.Add(new CustomProperty
            {
                Category        = "Misc",
                Name            = "Height",
                Value           = Texture2D?.Height,
                Description     = "Image height in pixels.",
                PropertyType    = typeof(int),
                DataTemplateKey = textBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });
            _propertySource.Properties.Add(new CustomProperty
            {
                Category        = "Misc",
                Name            = "Format",
                Value           = Texture2D?.Format,
                Description     = null,
                PropertyType    = typeof(SurfaceFormat),
                DataTemplateKey = textBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });
            _propertySource.Properties.Add(new CustomProperty
            {
                Category        = "Misc",
                Name            = "Mipmap levels",
                Value           = Texture2D?.LevelCount,
                Description     = null,
                PropertyType    = typeof(int),
                DataTemplateKey = textBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });
        }
示例#21
0
        /// <summary>
        /// Search for the specified object name inside PropertySource and Collection Source.
        /// Multipart can be used e.g.: MyObject.MyProperty.
        /// </summary>
        /// <param name="name">Object name</param>
        /// <returns>An object or null if the name is not found</returns>
        internal object GetObjectValue(string name)
        {
            object value = null;

            string[] parts      = name.ToLower().Split('.');
            string   objectName = parts[0];

            if (PropertySource.ContainsKey(objectName))
            {
                object objectFound = PropertySource[objectName];
                int    count       = parts.Length;

                if (count > 1)
                {
                    Type         objectType = objectFound.GetType();
                    PropertyInfo property   = null;

                    for (int i = 1; i < count; i++)
                    {
                        string namePart       = parts[i];
                        Match  matchCondition = Regex.Match(namePart, IndexCondition, RegexOptions.IgnoreCase);

                        if (matchCondition.Success)
                        {
                            namePart = matchCondition.Groups["Name"].Value;
                            int index = int.Parse(matchCondition.Groups["Index"].Value);
                            property = SingleOrDefault(namePart, objectType.GetProperties());

                            if (property != null && property.PropertyType.GetInterface(_collectionTypeFullName) != null)
                            {
                                ICollection collection = property.GetValue(objectFound, null) as ICollection;

                                if (collection != null)
                                {
                                    int j = 0;
                                    foreach (object item in collection)
                                    {
                                        if (j == index)
                                        {
                                            value = item;
                                            break;
                                        }
                                        j++;
                                    }
                                    if (value != null)
                                    {
                                        property = null;
                                    }
                                }
                            }
                        }
                        else if (namePart == "count" && property != null && property.PropertyType.GetInterface(_collectionTypeFullName) != null)
                        {
                            ICollection collection = property.GetValue(objectFound, null) as ICollection;

                            if (collection != null)
                            {
                                return(collection.Count);
                            }
                        }
                        else
                        {
                            property = SingleOrDefault(namePart, objectType.GetProperties());

                            if (property != null)
                            {
                                objectType = property.GetType();
                            }
                        }
                    }

                    if (property != null)
                    {
                        value = property.GetValue(objectFound, null);
                    }
                }
                else
                {
                    value = objectFound;
                }
            }
            else if (CollectionSource.ContainsKey(objectName))
            {
                value = CollectionSource[objectName];
            }

            return(value);
        }
示例#22
0
        /// <summary>
        /// Processes the value.
        /// </summary>
        /// <returns>
        /// The <see cref="object" /> representing the processed value.
        /// </returns>
        public override object ProcessValue()
        {
            var defaultValue = this.DefaultValue;

            var recursive   = this.Recursive;
            var propName    = this.Context.PropertyDescriptor != null ? this.Context.PropertyDescriptor.Name : string.Empty;
            var altPropName = string.Empty;

            // Check for Umbraco properties attribute on class
            if (this.Context.TargetType != null)
            {
                // TODO: [LK:2017-09-26] Is there a way to optimise or avoid this?
                var classAttr = this.Context.TargetType.GetCustomAttribute <UmbracoPropertiesAttribute>();
                if (classAttr != null)
                {
                    // Apply the prefix
                    if (!string.IsNullOrWhiteSpace(classAttr.Prefix))
                    {
                        altPropName = propName;
                        propName    = classAttr.Prefix + propName;
                    }

                    // Apply global recursive setting
                    recursive |= classAttr.Recursive;

                    // Apply property source only if it's different from the default,
                    // and the current value is the default. We only do it this
                    // way because if they change it at the property level, we
                    // want that to take precedence over the class level.
                    if (classAttr.PropertySource != Ditto.DefaultPropertySource &&
                        PropertySource == Ditto.DefaultPropertySource)
                    {
                        PropertySource = classAttr.PropertySource;
                    }
                }
            }

            var umbracoPropertyName    = this.PropertyName ?? propName;
            var altUmbracoPropertyName = this.AltPropertyName ?? altPropName;

            var content = this.Value as IPublishedContent;

            if (content == null)
            {
                return(defaultValue);
            }

            object propertyValue = null;

            // Try fetching the value.
            if (!umbracoPropertyName.IsNullOrWhiteSpace())
            {
                propertyValue = GetPropertyValue(content, umbracoPropertyName, recursive);
            }

            // Try fetching the alt value.
            if ((propertyValue == null || propertyValue.ToString().IsNullOrWhiteSpace()) &&
                !string.IsNullOrWhiteSpace(altUmbracoPropertyName))
            {
                propertyValue = GetPropertyValue(content, altUmbracoPropertyName, recursive);
            }

            // Try setting the default value.
            if ((propertyValue == null || propertyValue.ToString().IsNullOrWhiteSpace()) &&
                defaultValue != null)
            {
                propertyValue = defaultValue;
            }

            return(propertyValue);
        }
示例#23
0
        protected SubNodeParameter SubParam(string name, PropertyType propertyType, object property, object defaultValue, PropertySource source = PropertySource.EnteredOnly, PropertyFamily familyType = PropertyFamily.Primitive)
        {
            var newParam = new SubNodeParameter()
            {
                Parameter = new NodeParameter()
                {
                    Name           = name,
                    PropertyType   = propertyType,
                    Property       = property,
                    Value          = defaultValue,
                    Source         = source,
                    PropertyFamily = familyType,
                    SubParams      = new Dictionary <string, SubNodeParameter>()
                }
            };

            return(newParam);
        }
示例#24
0
        protected NodeParameter Add(string name, PropertyType propertyType, object property, object defaultValue, PropertySource source = PropertySource.EnteredOnly, PropertyFamily familyType = PropertyFamily.Primitive)
        {
            NodeParameter exists;

            Parameters.TryGetValue(name, out exists);
            if (exists != null)
            {
                if (exists.PropertyType == PropertyType.Enum)
                {
                    if (!(exists.Property is Type))
                    {
                        var paramType = Type.GetType((string)exists.Property);
                        if (paramType != null)
                        {
                            exists.Value = Enum.ToObject(paramType, Convert.ToInt32(exists.Value));
                        }
                    }
                }
                else if (exists.PropertyType == PropertyType.Int)
                {
                    exists.Value = Convert.ToInt32(exists.Value);
                }
                else if (exists.PropertyType == PropertyType.Float)
                {
                    exists.Value = Convert.ToSingle(exists.Value);
                }
                else if (exists.PropertyType == PropertyType.GameObject)
                {
                    exists.Value = Convert.ToString(exists.Value);
                }
                else if (exists.PropertyType == PropertyType.StringArray)
                {
                    var s = exists.Property as JArray;
                    exists.Property = (s == null ? exists.Property : s.ToObject <string[]>());

                    exists.Value = Convert.ToInt32(exists.Value);
                }
                else if (exists.PropertyType == PropertyType.IntArray)
                {
                    var s = exists.Property as JArray;
                    exists.Property = (s == null ? exists.Property : s.ToObject <int[]>());

                    exists.Value = Convert.ToInt32(exists.Value);
                }
                return(exists);
            }


            var newParam = new NodeParameter()
            {
                Name           = name,
                PropertyType   = propertyType,
                Property       = property,
                Value          = defaultValue,
                SubParams      = new Dictionary <string, SubNodeParameter>(),
                Source         = source,
                PropertyFamily = familyType
            };


            Parameters.Add(newParam.Name, newParam);
            return(newParam);
        }
示例#25
0
        private PropertyType ResolvePropertyType()
        {
            PropertyType?type = null;

            var isPrimaryKey = Entity.HasKey && Entity.Key.Properties.Count(p => p.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)) > 0;

            if (isPrimaryKey)
            {
                type = PropertyType.Key;
            }

            // Concurrency
            if (!String.IsNullOrEmpty(PropertySource.ConcurrencyMode) && PropertySource.ConcurrencyMode.Equals(EdmxConstants.ConcurrencyModeFixed, StringComparison.OrdinalIgnoreCase))
            {
                if (!type.HasValue)
                {
                    type = PropertyType.Concurrency;
                }
                else
                {
                    type |= PropertyType.Concurrency;
                }
            }

            // http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.storegeneratedpattern.aspx
            switch (PropertySource.StoreGeneratedPattern)
            {
            case EdmxConstants.StoreGeneratedPatternIdentity:
                if (!type.HasValue)
                {
                    type = PropertyType.Identity;
                }
                else
                {
                    type |= PropertyType.Identity;
                }
                break;

            case EdmxConstants.StoreGeneratedPatternComputed:
                if (!type.HasValue)
                {
                    type = PropertyType.Computed;
                }
                else
                {
                    type |= PropertyType.Computed;
                }
                break;

            case EdmxConstants.ConcurrencyModeNone:
                break;
            }

            // Check for index.
            if (Boolean.TrueString.Equals(PropertySource.GetAttributeValue(EdmxConstants.IsIndexCustomAttribute)))
            {
                if (!type.HasValue)
                {
                    type = PropertyType.Index;
                }
                else
                {
                    type |= PropertyType.Index;
                }
            }

            //if (IsForeignKey) type &= Enums.PropertyType.Foreign;

            return(type ?? PropertyType.Normal);
        }
示例#26
0
        public override void Initialize()
        {
            // ReSharper disable PossibleNullReferenceException
            var name   = PropertySource.Attribute("name").Value;
            var type   = PropertySource.Attribute("type").Value;
            var column = PropertySource.Attribute("column").Value;

            var lengthAttribute = PropertySource.Attribute("length");
            int?length          = null;

            if (lengthAttribute != null)
            {
                int lengthInt;
                if (Int32.TryParse(lengthAttribute.Value, out lengthInt))
                {
                    length = lengthInt;
                }
            }

            KeyName = _safeName = column;
            Name    = name;

            GetterAccess = "public";
            SetterAccess = "public";

            var notnull = PropertySource.Attribute(NHibernateUtilities.NotNull);

            if (notnull == null)
            {
                IsNullable = false;
            }
            else
            {
                bool notnullValue;
                IsNullable = Boolean.TryParse(notnull.Value, out notnullValue) && !notnullValue;
            }

            SystemType = IsNullable
                ? NHibernateUtilities.FromNHibernateNullableType(type, length)
                : NHibernateUtilities.FromNHibernateType(type, length);

            ExtendedProperties.Add(NHibernateUtilities.NHibernateType, type);

            var generator = PropertySource.Descendant("generator", ((NHibernateEntity)Entity).XmlNamespace);

            if (generator != null)
            {
                ExtendedProperties.Add(NHibernateUtilities.GeneratorClass, generator.Attribute("class").Value);
            }

            var customAttributes = PropertySource
                                   .Attributes()
                                   .Where(a => !DefaultAttributes.Contains(a.Name.ToString()));

            foreach (var customAttribute in customAttributes)
            {
                // Special case, always preserve length from DB.
                if (customAttribute.Name.ToString() == "length")
                {
                    continue;
                }

                ExtendedProperties.Add(customAttribute.Name.ToString(), customAttribute.Value);
            }
            // ReSharper restore PossibleNullReferenceException
        }
        private void UpdateProperties()
        {
            if (_modelPropertySource == null)
            {
                _modelPropertySource = new PropertySource();
            }

            _currentPropertySource = _modelPropertySource;

            _modelPropertySource.Name     = this.GetName();
            _modelPropertySource.TypeName = "3D Model";
            _modelPropertySource.Properties.Clear();

            if (State != ModelDocumentState.Loaded)
            {
                return;
            }

            // Try to load drmdl file.
            string drmdlFile = Path.ChangeExtension(Uri.LocalPath, "drmdl");

            if (UseDigitalRuneGraphics && File.Exists(drmdlFile))
            {
                _modelPropertySource.Properties.Add(new CustomProperty
                {
                    Category = "General",
                    Name     = "Model description",
                    Value    = drmdlFile,
                    //Description = ,
                    PropertyType    = typeof(string),
                    DataTemplateKey = OpenLinkKey,
                    CanReset        = false,
                    IsReadOnly      = true,
                });
            }

            int numberOfVertices   = 0;
            int numberOfPrimitives = 0;

            if (UseDigitalRuneGraphics)
            {
                foreach (var mesh in ModelNode.GetDescendants().OfType <MeshNode>().Select(mn => mn.Mesh))
                {
                    foreach (var submesh in mesh.Submeshes)
                    {
                        numberOfVertices   += submesh.VertexCount;
                        numberOfPrimitives += submesh.PrimitiveCount;
                    }
                }
            }
            else
            {
                foreach (var meshPart in Model.Meshes.SelectMany(m => m.MeshParts))
                {
                    numberOfVertices   += meshPart.NumVertices;
                    numberOfPrimitives += meshPart.PrimitiveCount;
                }
            }

            _modelPropertySource.Properties.Add(new CustomProperty
            {
                Category = "General",
                Name     = "Triangles",
                Value    = numberOfPrimitives,
                //Description = ,
                PropertyType    = typeof(int),
                DataTemplateKey = TextBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });

            _modelPropertySource.Properties.Add(new CustomProperty
            {
                Category = "General",
                Name     = "Vertices",
                Value    = numberOfVertices,
                //Description = ,
                PropertyType    = typeof(int),
                DataTemplateKey = TextBlockKey,
                CanReset        = false,
                IsReadOnly      = true,
            });

            // Try to load drmat files.
            if (UseDigitalRuneGraphics)
            {
                string drmdlFolder = Path.GetDirectoryName(drmdlFile);
                var    drmatFiles  = new HashSet <string>();
                var    textures    = new HashSet <string>();
                var    xDocument   = XDocument.Load(drmdlFile);
                foreach (var submeshElement in xDocument.Descendants("Submesh"))
                {
                    var materialAttribute = submeshElement.Attributes("Material").FirstOrDefault();
                    if (materialAttribute == null)
                    {
                        continue;
                    }

                    string drmatFile = GetAbsolutePath(drmdlFolder, materialAttribute.Value);
                    if (!File.Exists(drmatFile))
                    {
                        continue;
                    }

                    drmatFiles.Add(drmatFile);
                    string drmatFolder = Path.GetDirectoryName(drmatFile);

                    // Collect all referenced texture filenames.
                    var drmatXDocument = XDocument.Load(drmatFile);
                    foreach (var textureElement in drmatXDocument.Descendants("Texture"))
                    {
                        var fileAttribute = textureElement.Attributes("File").FirstOrDefault();
                        if (fileAttribute == null)
                        {
                            continue;
                        }

                        string textureFile = GetAbsolutePath(drmatFolder, fileAttribute.Value);
                        textures.Add(textureFile);
                    }
                }

                int i = 0;
                foreach (var drmatFile in drmatFiles)
                {
                    _modelPropertySource.Properties.Add(new CustomProperty
                    {
                        Category = "Materials",
                        Name     = Invariant($"Material {i}"),
                        Value    = drmatFile,
                        //Description = ,
                        PropertyType    = typeof(string),
                        DataTemplateKey = OpenLinkKey,
                        CanReset        = false,
                        IsReadOnly      = true,
                    });
                    i++;
                }

                i = 0;
                foreach (var texture in textures)
                {
                    _modelPropertySource.Properties.Add(new CustomProperty
                    {
                        Category = "Textures",
                        Name     = Invariant($"Texture {i}"),
                        Value    = texture,
                        //Description = ,
                        PropertyType    = typeof(string),
                        DataTemplateKey = OpenLinkKey,
                        CanReset        = false,
                        IsReadOnly      = true,
                    });
                    i++;
                }

                _animationPropertyViewModels.Clear();
                if (HasAnimations)
                {
                    var mesh = ModelNode.GetDescendants().OfType <MeshNode>().First().Mesh;
                    foreach (var entry in mesh.Animations)
                    {
                        var animationPropertyViewModel = new AnimationPropertyViewModel(this)
                        {
                            Name      = entry.Key,
                            Animation = entry.Value,
                        };
                        _animationPropertyViewModels.Add(animationPropertyViewModel);

                        _modelPropertySource.Properties.Add(new CustomProperty
                        {
                            Category = "Animations",
                            Name     = "\"" + entry.Key + "\"",
                            Value    = animationPropertyViewModel,
                            //Description = ,
                            PropertyType = typeof(AnimationPropertyViewModel),
                            CanReset     = false,
                            IsReadOnly   = true,
                        });
                    }
                }
            }

            if (_documentService.ActiveDocument == this)
            {
                // This document is active and can control tool windows.
                if (_propertiesService != null)
                {
                    _propertiesService.PropertySource = _currentPropertySource;
                }
            }
        }
示例#28
0
        /// <summary>
        /// Processes the value.
        /// </summary>
        /// <returns>
        /// The <see cref="object" /> representing the processed value.
        /// </returns>
        public override object ProcessValue()
        {
            var defaultValue = this.DefaultValue;

            var recursive   = this.Recursive;
            var propName    = this.Context.PropertyInfo != null ? this.Context.PropertyInfo.Name : string.Empty;
            var altPropName = string.Empty;

            // Check for Umbraco properties attribute on class
            if (Ditto.TryGetTypeAttribute(this.Context.TargetType, out UmbracoPropertiesAttribute classAttr))
            {
                // Apply the prefix
                if (string.IsNullOrWhiteSpace(classAttr.Prefix) == false)
                {
                    altPropName = propName;
                    propName    = classAttr.Prefix + propName;
                }

                // Apply global recursive setting
                recursive |= classAttr.Recursive;

                // Apply property source only if it's different from the default,
                // and the current value is the default. We only do it this
                // way because if they change it at the property level, we
                // want that to take precedence over the class level.
                if (classAttr.PropertySource != Ditto.DefaultPropertySource && PropertySource == Ditto.DefaultPropertySource)
                {
                    PropertySource = classAttr.PropertySource;
                }
            }

            var umbracoPropertyName    = this.PropertyName ?? propName;
            var altUmbracoPropertyName = this.AltPropertyName ?? altPropName;

            var content = this.Value as IPublishedContent;

            if (content == null)
            {
                return(defaultValue);
            }

            object propertyValue = null;

            // Try fetching the value.
            if (string.IsNullOrWhiteSpace(umbracoPropertyName) == false)
            {
                propertyValue = GetPropertyValue(content, umbracoPropertyName, recursive);
            }

            // Try fetching the alt value.
            if ((propertyValue == null || (propertyValue is string tmp && string.IsNullOrWhiteSpace(tmp))) &&
                string.IsNullOrWhiteSpace(altUmbracoPropertyName) == false)
            {
                propertyValue = GetPropertyValue(content, altUmbracoPropertyName, recursive);
            }

            // Try setting the default value.
            if ((propertyValue == null || (propertyValue is string tmp2 && string.IsNullOrWhiteSpace(tmp2))) &&
                defaultValue != null)
            {
                propertyValue = defaultValue;
            }

            return(propertyValue);
        }