Пример #1
0
        public PropertyItem GetValue(IOutput output, IPropertyProvider propertyProvider, IPropertyStore propertyStore, ProcessorItem item)
        {
            switch (Type)
            {
            case OperandType.ItemProperty:
                PropertyItem propertyItem = item.GetProperty(propertyProvider, ValueText);

                if (propertyItem != null)
                {
                    return(propertyItem);
                }

                output.WriteLine(Level.Fine, $"  &-c;Item property named '&-e;{ValueText}&-^;' doesn't exist...&-^;");
                return(null);

            case OperandType.GlobalProperty:
                PropertyItem property = propertyStore.GetProperty(ValueText);
                if (property != null)
                {
                    return(property);
                }

                output.WriteLine(Level.Fine, $"  &-c;Global property named '&-e;{ValueText}&-^;' doesn't exist...&-^;");
                return(null);

            case OperandType.NumericConstant:
                return(new PropertyItem(ValueNumeric, Unit));

            case OperandType.TextConstant:
                return(new PropertyItem(ValueText));

            default:
                return(null);
            }
        }
Пример #2
0
        public PropertyItem GetProperty(IPropertyProvider propertyProvider, ProcessorItem item, string propertyName)
        {
            string filepath = item.Value;

            switch (propertyName)
            {
            case "name":
                return(new PropertyItem(Path.GetFileNameWithoutExtension(filepath)));

            case "ext":
            case "extension":
                return(new PropertyItem(Path.GetExtension(filepath).SafeSubstring(1)));

            case "filename":
                return(new PropertyItem(Path.GetFileName(filepath)));

            case "dir":
            case "directory":
                return(new PropertyItem(Path.GetDirectoryName(filepath)));

            case "value":
                return(new PropertyItem(item.Value));

            case "ivalue":
                return(new PropertyItem(item.InitialValue));

            case "mime":
                string mime = MimeTypesMap.GetMimeType(item.Value);
                return(new PropertyItem(mime));

            case "relpath":
                PropertyItem originItem = item.GetProperty(propertyProvider, "origin");
                if (originItem.IsNumeric || originItem == null)
                {
                    return(null);
                }

                string origin = originItem.ValueText;
                if (!item.Value.StartsWith(origin))
                {
                    return(null);
                }
                return(new PropertyItem(item.Value.Substring(origin.Length + 1)));

            case "size":
            case "filesize":
                if (!File.Exists(item.Value))
                {
                    return(null);
                }
                long size = new FileInfo(item.Value).Length;
                return(new PropertyItem(size, null));

            default:
                return(null);
            }
        }
Пример #3
0
        private static PropertyItem GetPixels(ref IPropertyProvider propertyProvider, ref ProcessorItem item, double divisor)
        {
            PropertyItem propWidth = item.GetProperty(propertyProvider, "width");

            if (propWidth == null || !propWidth.IsNumeric)
            {
                return(null);
            }

            PropertyItem propHeight = item.GetProperty(propertyProvider, "height");

            if (propHeight == null || !propHeight.IsNumeric)
            {
                return(null);
            }

            return(new PropertyItem(propWidth.ValueNumber * propHeight.ValueNumber / divisor));
        }
Пример #4
0
        public void GetProperty_Origin_NotCachedProvided()
        {
            var mock = new Mock <IPropertyProvider>();

            mock.Setup(foo => foo.GetProperty(It.IsAny <IPropertyProvider>(), It.IsAny <ProcessorItem>(), "origin")).Returns(new PropertyItem("fruit"));

            var item = new ProcessorItem("Testing123", null);

            var property = item.GetProperty(mock.Object, "origin");

            Assert.Equal("fruit", property.Value);
        }
Пример #5
0
        public void GetProperty_Origin_IsCached()
        {
            var mock = new Mock <IPropertyProvider>();

            mock.Setup(foo => foo.GetProperty(It.IsAny <IPropertyProvider>(), It.IsAny <ProcessorItem>(), "origin")).Returns <PropertyItem>(null);

            var item = new ProcessorItem("Testing123", "apple");

            var property = item.GetProperty(mock.Object, "origin");

            Assert.NotNull(property); // If null, TryCachePropertyValue might not have worked.
            Assert.Equal("apple", property.Value);
        }
Пример #6
0
        public void GetProperty_ProvidedProperty_Equals()
        {
            var mock = new Mock <IPropertyProvider>();

            mock.Setup(foo => foo.GetProperty(It.IsAny <IPropertyProvider>(), It.IsAny <ProcessorItem>(), "filesize")).Returns(new PropertyItem(21.23));

            var item = new ProcessorItem("Testing123", null);

            var property = item.GetProperty(mock.Object, "filesize");

            Assert.NotNull(property); // If null, TryCachePropertyValue might not have worked.
            Assert.Equal(21.23, property.Value);
        }
Пример #7
0
        public PropertyItem GetProperty(IPropertyProvider propertyProvider, IPropertyStore propertyStore, ProcessorItem item)
        {
            switch (Type)
            {
            case PropertyType.Global:
                return(propertyStore.GetProperty(Value));

            case PropertyType.Item:
                return(item.GetProperty(propertyProvider, Value));

            case PropertyType.Text:
            default:
                return(null);
            }
        }
Пример #8
0
        public void Value_Changed_CacheCleared()
        {
            var mock = new Mock <IPropertyProvider>();

            mock.Setup(foo => foo.GetProperty(It.IsAny <IPropertyProvider>(), It.IsAny <ProcessorItem>(), "filesize")).Returns <PropertyItem>(null);

            var item = new ProcessorItem("Testing123", null);

            item.TryCachePropertyValue("filesize", new PropertyItem(21.23));

            item.Value = "Done.";

            var property = item.GetProperty(mock.Object, "filesize");

            Assert.Null(property);
        }
Пример #9
0
        public void GetProperty_NullPropertyProvider_ThrowsArgumentNullException()
        {
            var item = new ProcessorItem("Testing123", null);

            Assert.Throws <ArgumentNullException>(() => item.GetProperty(null, "filesize"));
        }
Пример #10
0
 protected PropertyItem GetProperty(IProcessorPipeline pipeline, ProcessorItem item)
 {
     return(item.GetProperty(pipeline.PropertyProvider, itemPropertyName));
 }