Exemple #1
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var num = value as int?;

            if (num == null)
            {
                return(null);
            }
            return(array.Value.FromIndexOrDefault(RateConvertingHelper.ToRating(num.Value)));
        }
Exemple #2
0
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var num = value as int?;

            if (num == null)
            {
                var dnum = value as double?;

                if (num == null)
                {
                    return(null);
                }
                num = (int)dnum.Value;
            }
            return(RateConvertingHelper.Reverse((int)num.Value));
        }
        /// <summary>
        /// 画像ファイルの情報を取得
        /// </summary>
        /// <param name="fullPath"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public ImageFileInformation GetImage(string fullPath, PropertiesLevel level)
        {
            ImageFileInformation image = null;
            var hasDecoration          = true;

            try
            {
                var name = System.IO.Path.GetFileName(fullPath);

                var isUnknownType = false;

                var width  = 0;
                var height = 0;
                var length = 0L;

                //画像ファイルのヘッダからサイズを抽出
                if (level >= PropertiesLevel.Size)
                {
                    var graphicInfo = new GraphicInformation(fullPath);

                    width         = graphicInfo.GraphicSize.Width;
                    height        = graphicInfo.GraphicSize.Height;
                    length        = graphicInfo.FileSize;
                    isUnknownType = graphicInfo.Type == GraphicFileType.Unknown;

                    //タグ・評価を付加できないファイルの場合は情報読み取りをスキップ
                    if (graphicInfo.Type != GraphicFileType.Jpeg &&
                        graphicInfo.Type != GraphicFileType.Tiff &&
                        graphicInfo.Type != GraphicFileType.Psd &&
                        graphicInfo.Type != GraphicFileType.Unknown)
                    {
                        hasDecoration = false;
                    }
                }

                var creationTime  = defaultDateTime;
                var lastWriteTime = defaultDateTime;

                //日付情報
                if (level >= PropertiesLevel.Basic)
                {
                    try
                    {
                        var file = new System.IO.FileInfo(fullPath);

                        creationTime  = ImageFileUtility.ConvertDateTime(file.CreationTime);
                        lastWriteTime = ImageFileUtility.ConvertDateTime(file.LastWriteTime);
                    }
                    catch
                    {
                        //No operation
                    }
                }


                image = new ImageFileInformation()
                {
                    DateCreated  = creationTime,
                    DateModified = lastWriteTime,
                    Name         = name,
                    Path         = fullPath,
                    Height       = height,
                    Width        = width,
                    Size         = length,
                    Rating       = 0,
                    Keywords     = null,
                    IsNotFound   = isUnknownType,
                };
            }
            catch
            {
                return(null);
            }


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


            var rating            = 0;
            HashSet <string> tags = null;

            //画像の評価・キーワード(時間かかる)
            if (level >= PropertiesLevel.Shell && hasDecoration)
            {
                try
                {
                    var fileAccesser = this.GetFile(fullPath, image.Name);


                    var kw = fileAccesser.GetDetailsOf(18);
                    if (kw != null)
                    {
                        tags = new HashSet <string>(kw
                                                    .Split(';')
                                                    .Select(x => x.Trim())
                                                    .Where(x => x != null && x.Length > 0)
                                                    .Distinct());
                    }

                    rating = 0;
                    var rateText  = fileAccesser.GetDetailsOf(19);
                    var rateArray = rateText?
                                    .Select(x => x - '0')
                                    .Where(x => x > 0 && x <= 5)
                                    .ToArray();

                    if (rateArray != null && rateArray.Length == 1)
                    {
                        rating = RateConvertingHelper.Reverse(rateArray[0]);
                    }
                }
                catch
                {
                    return(null);
                }
            }

            image.Rating   = rating;
            image.Keywords = tags;

            return(image);
        }