Example #1
0
        public void PropertyCollection_Returns_Null_On_FirstOrDefault_When_Empty()
        {
            var list       = new List <Property>();
            var collection = new PropertyCollection(list);

            var first  = collection.FirstOrDefault();
            var second = collection.FirstOrDefault(x => x.Alias.InvariantEquals("Test"));

            Assert.That(first, Is.Null);
            Assert.That(first == null, Is.True);
            Assert.That(second == null, Is.True);
        }
Example #2
0
        // Вспомогательные методы для простых свойств свойств элементов печатного представления

        private static PropertyEditorBase AddCategory(PropertyCollection properties, string categoryCaption)
        {
            var propertyDefinition = properties.FirstOrDefault(p => p.Caption == categoryCaption);

            return((propertyDefinition == null)
                ? AddProperty <PropertyEditorObject>(properties, null, null, categoryCaption)
                : propertyDefinition.Editor);
        }
Example #3
0
        private string GetUmbracoPropertyValue(PropertyCollection properties, string propertyAlias)
        {
            if (!properties.HasValues())
            {
                return(null);
            }

            var property = properties.FirstOrDefault(prop => prop.Alias == propertyAlias);

            if (!property.HasValues())
            {
                return(null);
            }

            return(string.Join(string.Empty, property.Values.Select(value => value.EditedValue?.ToString() ?? string.Empty).ToList()));
        }
Example #4
0
        public EventViewModel(ILogger Logger, string Brush, IEnumerable <PropertyViewModel> Properties) : base(Logger)
        {
            AssertParameterNotNull(Properties, "Properties");

            this.Brush = Brush;
            properties = new PropertyCollection <PropertyViewModel>();
            foreach (PropertyViewModel property in Properties)
            {
                properties[property.Name] = property;
            }

            timeStamp = properties.FirstOrDefault(item => item is TimeStampPropertyViewModel) as TimeStampPropertyViewModel;
            if (timeStamp == null)
            {
                timeStamp = new TimeStampPropertyViewModel(Logger, "Date", DateTime.MinValue);
            }

            Pages = new PagesViewModel(Logger);
            Pages.Add(new PropertiesPageViewModel(Logger, properties));
            Pages.AddRange(Properties.OfType <InlinePropertyViewModel>().SelectMany(item => item.Documents).Select(item => new XmlPageViewModel(Logger, item)));
            Pages.SelectedItem = Pages.FirstOrDefault();
        }
Example #5
0
        public bool ApplyUpdate(IMEPackage package, PropertyCollection properties, MergeFileChange1 mfc)
        {
            var propKeys = PropertyName.Split('.');

            PropertyCollection operatingCollection = properties;

            int i = 0;

            while (i < propKeys.Length - 1)
            {
                var matchingProp = operatingCollection.FirstOrDefault(x => x.Name.Instanced == propKeys[i]);
                if (matchingProp is StructProperty sp)
                {
                    operatingCollection = sp.Properties;
                }

                // ARRAY PROPERTIES NOT SUPPORTED
                i++;
            }

            Log.Information($@"Applying property update: {PropertyName} -> {PropertyValue}");
            switch (PropertyType)
            {
            case @"FloatProperty":
                FloatProperty fp = new FloatProperty(float.Parse(PropertyValue, CultureInfo.InvariantCulture), propKeys.Last());
                operatingCollection.AddOrReplaceProp(fp);
                break;

            case @"IntProperty":
                IntProperty ip = new IntProperty(int.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(ip);
                break;

            case @"BoolProperty":
                BoolProperty bp = new BoolProperty(bool.Parse(PropertyValue), propKeys.Last());
                operatingCollection.AddOrReplaceProp(bp);
                break;

            case @"NameProperty":
                var index      = 0;
                var baseName   = PropertyValue;
                var indexIndex = PropertyValue.IndexOf(@"|", StringComparison.InvariantCultureIgnoreCase);
                if (indexIndex > 0)
                {
                    baseName = baseName.Substring(0, indexIndex);
                    index    = int.Parse(baseName.Substring(indexIndex + 1));
                }

                NameProperty np = new NameProperty(new NameReference(baseName, index), PropertyName);
                operatingCollection.AddOrReplaceProp(np);
                break;

            case @"ObjectProperty":
                // This does not support porting in, only relinking existing items
                ObjectProperty op = new ObjectProperty(0, PropertyName);
                if (PropertyValue != null && PropertyValue != @"M3M_NULL")     //M3M_NULL is a keyword for setting it to null to satisfy the schema
                {
                    var entry = package.FindEntry(PropertyValue);
                    if (entry == null)
                    {
                        throw new Exception(M3L.GetString(M3L.string_interp_mergefile_failedToUpdateObjectPropertyItemNotInPackage, PropertyName, PropertyValue, PropertyValue, package.FilePath));
                    }
                    op.Value = entry.UIndex;
                }
                operatingCollection.AddOrReplaceProp(op);
                break;

            case @"EnumProperty":
                var          enumInfo = PropertyValue.Split('.');
                EnumProperty ep       = new EnumProperty(enumInfo[0], mfc.OwningMM.Game, PropertyName);
                ep.Value = NameReference.FromInstancedString(enumInfo[1]);
                operatingCollection.AddOrReplaceProp(ep);
                break;

            case @"StrProperty":
                var sp = new StrProperty(PropertyValue, propKeys.Last());
                operatingCollection.AddOrReplaceProp(sp);
                break;

            default:
                throw new Exception(M3L.GetString(M3L.string_interp_mergefile_unsupportedPropertyType, PropertyType));
            }
            return(true);
        }