Exemplo n.º 1
0
        public static void Register(Type luFileInfoType)
        {
            LUFileInfo luFileInfo = Activator.CreateInstance(luFileInfoType) as LUFileInfo;

            if (luFileInfo == null)
            {
                throw (new ArgumentException("Is not LUFileInfo type.", "luFileInfoType"));
            }
            try {
                _LUFileInfos.Add(luFileInfo.Id, luFileInfo);

                string[] sa = luFileInfo.Extensions.Replace(" ", "").Split(',');
                if (sa.Length == 0)
                {
                    sa = new string[] { "" };
                }
                foreach (string ext in sa)
                {
                    LUFileExtension lufExt = new LUFileExtension(ext, luFileInfo);
                    if (_Extensions.ContainsKey(lufExt.Key))
                    {
                        throw (new Exception(string.Format("Extension \"{0}\" is already exist in base.", lufExt.Extension)));
                    }
                    _Extensions.Add(lufExt.Key, lufExt);
                }
            } catch {
                throw (new Exception(string.Format("LUFileInfo.Id={0} already exist", luFileInfo.Id)));
            }
        }
Exemplo n.º 2
0
        public static LUFileInfo GetLUFileInfo(FileInfo file)
        {
            LUFileExtension lufExt = null;

            LUFileExtension.LUFileExtensionKey lufExtKey = new LUFileExtension.LUFileExtensionKey(file.Extension);
            _Extensions.TryGetValue(lufExtKey, out lufExt);

            if (lufExt == null)
            {
                lufExtKey = new LUFileExtension.LUFileExtensionKey("");
                _Extensions.TryGetValue(lufExtKey, out lufExt);
            }

            if (lufExt == null)
            {
                throw (new Exception("Can`t find extension info"));
            }

            return(lufExt.LUFileInfo);
        }