Exemplo n.º 1
0
        /// <summary>
        /// 提取表情
        /// </summary>
        /// <param name="fileName">表情包文件名</param>
        /// <param name="fileStream">表情包文件流</param>
        public void ExtractEmoticon(string fileName, Stream fileStream)
        {
            if (fileStream == null || !fileStream.CanRead)
            {
                return;
            }

            string directoryName = fileName.Substring(0, fileName.LastIndexOf("."));
            string fullPath      = _emotionSettings.EnableDirectlyUrl ? _emotionSettings.DirectlyRootUrl : WebUtility.GetPhysicalFilePath(_emotionSettings.EmoticonPath) + "\\" + directoryName + "\\";

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            //将表情包存储到指定目录
            SaveEmoticonPackage(fileName, fullPath, fileStream);

            #region 解压压缩包

            Ionic.Zip.ReadOptions ro = new Ionic.Zip.ReadOptions();
            ro.Encoding = System.Text.Encoding.Default;

            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(fullPath + fileName, ro))
            {
                foreach (Ionic.Zip.ZipEntry zipEntry in zip)
                {
                    zipEntry.Extract(fullPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                }
            }

            #endregion

            //组装表情及分类的实体
            PopulateEmotionCategory(directoryName, fullPath);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 提取皮肤
        /// </summary>
        /// <param name="presentAreaKey">呈现区域</param>
        /// <param name="fileName">皮肤文件名</param>
        /// <param name="fileStream">皮肤文件流</param>
        public void ExtractThemeAppearance(string presentAreaKey, string fileName, Stream fileStream)
        {
            if (fileStream == null || !fileStream.CanRead)
                return;
            string tempKey = fileName.Substring(0, fileName.LastIndexOf("."));
            string tempPath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/temp/{1}", presentAreaKey, tempKey));

            if (!Directory.Exists(tempPath))
                Directory.CreateDirectory(tempPath);

            string fileFullName = Path.Combine(tempPath, fileName);
            //将皮肤包存储到指定目录
            SaveThemeAppearancePackage(fileFullName, fileStream);

            #region 解压压缩包

            Ionic.Zip.ReadOptions ro = new Ionic.Zip.ReadOptions();
            ro.Encoding = System.Text.Encoding.UTF8;

            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(fileFullName, ro))
            {
                foreach (Ionic.Zip.ZipEntry zipEntry in zip)
                {
                    zipEntry.Extract(tempPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                }
            }
            #endregion

            string[] themeConfigFileNames = Directory.GetFiles(tempPath, "Theme.config", SearchOption.AllDirectories);
            if (themeConfigFileNames != null && themeConfigFileNames.Length > 0)
            {
                var themeConfigFileName = themeConfigFileNames[0];
                XElement themeElement = XElement.Load(themeConfigFileName);
                if (themeElement == null)
                {
                    Directory.Delete(tempPath, true);
                    throw new ExceptionFacade("Theme.config配置文件格式不正确");
                }

                var parentDirectory = Directory.GetParent(themeConfigFileName);

                //解析外观
                string appearancesPath = Path.Combine(parentDirectory.FullName, "Appearances");
                int displayOrder = GetThemeAppearances(presentAreaKey, null).Max(n => n.DisplayOrder) + 1;
                string themeKey = string.Empty;
                foreach (var appearanceDirectory in Directory.GetDirectories(appearancesPath))
                {
                    string appearanceConfig = Path.Combine(appearanceDirectory, "Appearance.config");
                    XElement appearanceElement = XElement.Load(appearanceConfig);
                    if (appearanceElement == null)
                    {
                        Directory.Delete(appearanceDirectory, true);
                        throw new ExceptionFacade("Appearance.config配置文件格式不正确");
                    }
                    string appearanceKey = appearanceDirectory.TrimEnd('\\').Substring(appearanceDirectory.LastIndexOf("\\") + 1);
                    ThemeAppearance themeAppearance = new ThemeAppearance(appearanceElement, appearanceKey);
                    themeAppearance.DisplayOrder = displayOrder;
                    displayOrder++;
                    if (appearanceRepository.Get(themeAppearance.Id) != null)
                        appearanceRepository.Update(themeAppearance);
                    else
                    {
                        appearanceRepository.Insert(themeAppearance);
                    }
                    if (string.IsNullOrEmpty(themeKey))
                        themeKey = themeAppearance.ThemeKey;
                }
                //解析主题
                Theme theme = new Theme(themeElement, themeKey);
                if (GetTheme(theme.Id) != null)
                {
                    themeRepository.Update(theme);
                }
                else
                    themeRepository.Insert(theme);

                string themePath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}", presentAreaKey, themeKey));

                //移动目录
                if (Directory.Exists(themePath))
                    Directory.Delete(themePath, true);
                parentDirectory.MoveTo(themePath);
                if (Directory.Exists(tempPath))
                    Directory.Delete(tempPath, true);
            }
            else
            {
                string[] appearanceConfigFileNames = Directory.GetFiles(tempPath, "Appearance.config", SearchOption.AllDirectories);
                if (appearanceConfigFileNames != null && appearanceConfigFileNames.Length > 0)
                {
                    string appearanceConfigFileName = appearanceConfigFileNames[0];
                    XElement appearanceDocument = XElement.Load(appearanceConfigFileName);
                    if (appearanceDocument == null)
                    {
                        Directory.Delete(tempPath, true);
                        throw new ExceptionFacade("Appearance.config配置文件格式不正确");
                    }
                    //获取父级目录
                    var parentDirectory = Directory.GetParent(appearanceConfigFileName);
                    ThemeAppearance themeAppearance = new ThemeAppearance(appearanceDocument, parentDirectory.Name);
                    themeAppearance.DisplayOrder = GetThemeAppearances(presentAreaKey, null).Max(n => n.DisplayOrder) + 1;
                    string appearancesPath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}/Appearances/", presentAreaKey, themeAppearance.ThemeKey));
                    //更新数据库
                    if (appearanceRepository.Get(themeAppearance.Id) != null)
                        appearanceRepository.Update(themeAppearance);
                    else
                        appearanceRepository.Insert(themeAppearance);

                    string appearancePath = Path.Combine(appearancesPath, themeAppearance.AppearanceKey);
                    //移动目录
                    if (Directory.Exists(appearancePath))
                        Directory.Delete(appearancePath, true);
                    parentDirectory.MoveTo(appearancePath);
                    if (Directory.Exists(tempPath))
                        Directory.Delete(tempPath, true);
                }
                else
                {
                    Directory.Delete(tempPath, true);
                    throw new ExceptionFacade("找不到Appearance.config文件,您上传的不是皮肤包");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 提取皮肤
        /// </summary>
        /// <param name="presentAreaKey">呈现区域</param>
        /// <param name="fileName">皮肤文件名</param>
        /// <param name="fileStream">皮肤文件流</param>
        public void ExtractThemeAppearance(string presentAreaKey, string fileName, Stream fileStream)
        {
            if (fileStream == null || !fileStream.CanRead)
            {
                return;
            }
            string tempKey  = fileName.Substring(0, fileName.LastIndexOf("."));
            string tempPath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/temp/{1}", presentAreaKey, tempKey));

            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }

            string fileFullName = Path.Combine(tempPath, fileName);

            //将皮肤包存储到指定目录
            SaveThemeAppearancePackage(fileFullName, fileStream);

            #region 解压压缩包

            Ionic.Zip.ReadOptions ro = new Ionic.Zip.ReadOptions();
            ro.Encoding = System.Text.Encoding.UTF8;

            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(fileFullName, ro))
            {
                foreach (Ionic.Zip.ZipEntry zipEntry in zip)
                {
                    zipEntry.Extract(tempPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                }
            }
            #endregion

            string[] themeConfigFileNames = Directory.GetFiles(tempPath, "Theme.config", SearchOption.AllDirectories);
            if (themeConfigFileNames != null && themeConfigFileNames.Length > 0)
            {
                var      themeConfigFileName = themeConfigFileNames[0];
                XElement themeElement        = XElement.Load(themeConfigFileName);
                if (themeElement == null)
                {
                    Directory.Delete(tempPath, true);
                    throw new ExceptionFacade("Theme.config配置文件格式不正确");
                }

                var parentDirectory = Directory.GetParent(themeConfigFileName);

                //解析外观
                string appearancesPath = Path.Combine(parentDirectory.FullName, "Appearances");
                int    displayOrder    = GetThemeAppearances(presentAreaKey, null).Max(n => n.DisplayOrder) + 1;
                string themeKey        = string.Empty;
                foreach (var appearanceDirectory in Directory.GetDirectories(appearancesPath))
                {
                    string   appearanceConfig  = Path.Combine(appearanceDirectory, "Appearance.config");
                    XElement appearanceElement = XElement.Load(appearanceConfig);
                    if (appearanceElement == null)
                    {
                        Directory.Delete(appearanceDirectory, true);
                        throw new ExceptionFacade("Appearance.config配置文件格式不正确");
                    }
                    string          appearanceKey   = appearanceDirectory.TrimEnd('\\').Substring(appearanceDirectory.LastIndexOf("\\") + 1);
                    ThemeAppearance themeAppearance = new ThemeAppearance(appearanceElement, appearanceKey);
                    themeAppearance.DisplayOrder = displayOrder;
                    displayOrder++;
                    if (appearanceRepository.Get(themeAppearance.Id) != null)
                    {
                        appearanceRepository.Update(themeAppearance);
                    }
                    else
                    {
                        appearanceRepository.Insert(themeAppearance);
                    }
                    if (string.IsNullOrEmpty(themeKey))
                    {
                        themeKey = themeAppearance.ThemeKey;
                    }
                }
                //解析主题
                Theme theme = new Theme(themeElement, themeKey);
                if (GetTheme(theme.Id) != null)
                {
                    themeRepository.Update(theme);
                }
                else
                {
                    themeRepository.Insert(theme);
                }

                string themePath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}", presentAreaKey, themeKey));

                //移动目录
                if (Directory.Exists(themePath))
                {
                    Directory.Delete(themePath, true);
                }
                parentDirectory.MoveTo(themePath);
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
            else
            {
                string[] appearanceConfigFileNames = Directory.GetFiles(tempPath, "Appearance.config", SearchOption.AllDirectories);
                if (appearanceConfigFileNames != null && appearanceConfigFileNames.Length > 0)
                {
                    string   appearanceConfigFileName = appearanceConfigFileNames[0];
                    XElement appearanceDocument       = XElement.Load(appearanceConfigFileName);
                    if (appearanceDocument == null)
                    {
                        Directory.Delete(tempPath, true);
                        throw new ExceptionFacade("Appearance.config配置文件格式不正确");
                    }
                    //获取父级目录
                    var             parentDirectory = Directory.GetParent(appearanceConfigFileName);
                    ThemeAppearance themeAppearance = new ThemeAppearance(appearanceDocument, parentDirectory.Name);
                    themeAppearance.DisplayOrder = GetThemeAppearances(presentAreaKey, null).Max(n => n.DisplayOrder) + 1;
                    string appearancesPath = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}/Appearances/", presentAreaKey, themeAppearance.ThemeKey));
                    //更新数据库
                    if (appearanceRepository.Get(themeAppearance.Id) != null)
                    {
                        appearanceRepository.Update(themeAppearance);
                    }
                    else
                    {
                        appearanceRepository.Insert(themeAppearance);
                    }

                    string appearancePath = Path.Combine(appearancesPath, themeAppearance.AppearanceKey);
                    //移动目录
                    if (Directory.Exists(appearancePath))
                    {
                        Directory.Delete(appearancePath, true);
                    }
                    parentDirectory.MoveTo(appearancePath);
                    if (Directory.Exists(tempPath))
                    {
                        Directory.Delete(tempPath, true);
                    }
                }
                else
                {
                    Directory.Delete(tempPath, true);
                    throw new ExceptionFacade("找不到Appearance.config文件,您上传的不是皮肤包");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 提取表情
        /// </summary>
        /// <param name="fileName">表情包文件名</param>
        /// <param name="fileStream">表情包文件流</param>
        public void ExtractEmoticon(string fileName, Stream fileStream)
        {
            if (fileStream == null || !fileStream.CanRead)
                return;

            string directoryName = fileName.Substring(0, fileName.LastIndexOf("."));
            string fullPath = _emotionSettings.EnableDirectlyUrl ? _emotionSettings.DirectlyRootUrl : WebUtility.GetPhysicalFilePath(_emotionSettings.EmoticonPath) + "\\" + directoryName + "\\";

            if (!Directory.Exists(fullPath))
                Directory.CreateDirectory(fullPath);

            //将表情包存储到指定目录
            SaveEmoticonPackage(fileName, fullPath, fileStream);

            #region 解压压缩包

            Ionic.Zip.ReadOptions ro = new Ionic.Zip.ReadOptions();
            ro.Encoding = System.Text.Encoding.Default;

            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(fullPath + fileName, ro))
            {
                foreach (Ionic.Zip.ZipEntry zipEntry in zip)
                {
                    zipEntry.Extract(fullPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                }
            }

            #endregion

            //组装表情及分类的实体
            PopulateEmotionCategory(directoryName, fullPath);
        }