Example #1
0
        /// <summary>
        /// 创建索引模型
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static IIndexModel CreateIndexModel(string address)
        {
            string      extension = Path.GetExtension(address).ToLower();
            IIndexModel indexModel;

            switch (extension)
            {
            case ".exe":
            {
                indexModel = new EXEIndexModel()
                {
                    Path = address
                };
                break;
            }

            case ".dll":
            {
                indexModel = new DLLIndexModel()
                {
                    Path = address
                };
                break;
            }

            case ".png":
            case ".jpg":
            case ".jpeg":
            case ".ico":
            {
                indexModel = new ImageIndexModel()
                {
                    Path = address
                };
                break;
            }

            default:
            {
                indexModel = new CommonIndexModel()
                {
                    Path           = address,
                    AttachedEntity = File.ReadAllText(address),
                };
                break;
            }
            }

            indexModel.Index       = Path.GetFileName(address);
            indexModel.Description = Path.GetFileName(address);

            return(indexModel);
        }
Example #2
0
        /// <summary>
        /// 创建索引模型
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static IIndexModel CreateIndexModel(Document document)
        {
            var         field     = document.Get(nameof(IIndexModel.IndexType));
            IndexTypes  indexType = Enum.TryParse(field, out indexType) ? indexType : IndexTypes.Common;
            IIndexModel indexModel;

            switch (indexType)
            {
            case IndexTypes.Exe:
            {
                indexModel = new EXEIndexModel();
                break;
            }

            case IndexTypes.Dll:
            {
                indexModel = new DLLIndexModel();
                break;
            }

            case IndexTypes.Image:
            {
                indexModel = new ImageIndexModel();
                break;
            }

            case IndexTypes.Common:
            default:
            {
                indexModel = new CommonIndexModel();
                break;
            }
            }

            indexModel.FromDocument(document);
            return(indexModel);
        }