Exemple #1
0
        /// <summary>
        /// 文件压缩
        /// </summary>
        /// <param name="inputFolderPath"></param>
        /// <param name="outputPathAndFile"></param>
        /// <param name="password"></param>
        public static void ZipElementFiles(string inputFolderPath, string outputPathAndFile, string password)
        {
            ArrayList ar         = GenerateFileList(inputFolderPath); // generate file list
            int       TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;

            // find number of chars to remove     // from orginal file path
            TrimLength += 1; //remove '\'
            FileStream ostream;

            byte[]          obuffer;
            string          outPath    = outputPathAndFile;
            ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); // create zip stream

            try
            {
                if (password != null && password != String.Empty)
                {
                    oZipStream.Password = password;
                }
                oZipStream.SetLevel(9);    // maximum compression
                ZipEntry oZipEntry;
                foreach (string Fil in ar) // for each file, generate a zipentry
                {
                    oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
                    oZipStream.PutNextEntry(oZipEntry);

                    if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
                    {
                        ostream = File.OpenRead(Fil);
                        obuffer = new byte[ostream.Length];
                        ostream.Read(obuffer, 0, obuffer.Length);
                        oZipStream.Write(obuffer, 0, obuffer.Length);
                        ostream.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                X2Error.Log("ZipElementFiles", ex, "ZipElementFiles");
                throw ex;
            }
            finally
            {
                oZipStream.Finish();
                oZipStream.Close();
            }
        }
Exemple #2
0
 /// <summary>
 /// 可逆编码的解码
 /// </summary>
 /// <param name="str"></param>
 /// <param name="num"></param>
 /// <returns></returns>
 public static string DecodeAscii(string str, int num)
 {
     try
     {
         string dtext = "";
         for (int i = 0; i < str.Length; i += 2)
         {
             dtext += AsciiToChar(int.Parse(str.Substring(i, 2)) + num);
         }
         ///部分特殊字符需要解码
         return(HttpUtility.UrlDecode(dtext));
     }
     catch (Exception ex)
     {
         X2Error.Log("DecodeAscii_Error", ex, string.Format("{0} Encryption error", str));
         return("");
     }
 }
Exemple #3
0
        /// <summary>
        /// 初始化旧的配置文件为新的配置模式
        /// </summary>
        public static void InitOldConfig()
        {
            string configPath = string.Format("{0}\\{1}", System.AppDomain.CurrentDomain.BaseDirectory, "settings.config");

            if (X2Lib.IO.X2File.IsExist(configPath))
            {
                return;
            }
            else
            {
                try
                {
                    string xmlContent = @"<appSettings></appSettings>";
                    X2Lib.IO.X2File.SaveFieContent(configPath, xmlContent);

                    Dictionary <string, string> defalultKeyValues = new Dictionary <string, string>();
                    defalultKeyValues.Add("X2PlatformVersion", GetAppSetting("X2PlatformVersion") ?? "2.8.2.1");
                    defalultKeyValues.Add("X2LANGUAGE", GetAppSetting("X2PlatformVersion") ?? "en");
                    defalultKeyValues.Add("X2DefaultLayout", GetAppSetting("X2DefaultLayout") ?? "autoId");
                    defalultKeyValues.Add("AppTitle", GetAppSetting("AppTitle") ?? "DRAKEX2_HZDEV");
                    defalultKeyValues.Add("X2VistorAccount", GetAppSetting("X2VistorAccount") ?? "test2;admin");
                    defalultKeyValues.Add("UserTag", GetAppSetting("UserTag") ?? "12345");
                    defalultKeyValues.Add("X2SearchSet", GetAppSetting("X2SearchSet") ?? "true;true");
                    defalultKeyValues.Add("SMSTemplate", GetAppSetting("SMSTemplate") ?? "{0}您好,有{1}条{2},请您处理");
                    defalultKeyValues.Add("X2HOSTPASS", GetAppSetting("X2HOSTPASS") ?? "123");
                    defalultKeyValues.Add("VisitMode", GetAppSetting("VisitMode") ?? "VISITMODE;test2");

                    string   todoConfig  = GetAppSetting("SendSmsType");
                    string[] accountList = todoConfig.Split(';');

                    if (!string.IsNullOrEmpty(todoConfig) && accountList.Length == 3)
                    {
                        defalultKeyValues.Add("ToDoSmsIsOpen", accountList[0]);
                        defalultKeyValues.Add("ToDoMailIsOpen", accountList[1]);
                        defalultKeyValues.Add("ToDoRemindFrequency", accountList[2]);
                    }
                    else
                    {
                        defalultKeyValues.Add("ToDoSmsIsOpen", GetAppSetting("ToDoSmsIsOpen") ?? "false");
                        defalultKeyValues.Add("ToDoMailIsOpen", GetAppSetting("ToDoMailIsOpen") ?? "false");
                        defalultKeyValues.Add("ToDoRemindFrequency", GetAppSetting("ToDoRemindFrequency") ?? "60");
                    }

                    defalultKeyValues.Add("X2SystemAccount", GetAppSetting("X2SystemAccount") ?? "");
                    defalultKeyValues.Add("X2SystemSmtpHost", GetAppSetting("X2SystemSmtpHost") ?? "");
                    defalultKeyValues.Add("SmsAccount", GetAppSetting("SmsAccount") ?? "");
                    defalultKeyValues.Add("SmsGatewayUrl", GetAppSetting("SmsGatewayUrl") ?? "");
                    defalultKeyValues.Add("SmsServerName", GetAppSetting("SmsServerName") ?? "");

                    #region  除
                    //foreach (string item in ConfigurationManager.AppSettings)
                    //{
                    //    if (item == "FullTextSearchConnectionString")
                    //    {
                    //        continue;
                    //    }

                    //    switch (item)
                    //    {
                    //        case "X2PlatformVersion":
                    //            if (defalultKeyValues.ContainsKey("X2PlatformVersion"))
                    //            {
                    //                defalultKeyValues["X2PlatformVersion"] = ConfigurationManager.AppSettings[item];
                    //            }
                    //            else
                    //            {
                    //                defalultKeyValues.Add("X2PlatformVersion", ConfigurationManager.AppSettings[item]);
                    //            }
                    //            break;

                    //        case "X2LANGUAGE":
                    //            defalultKeyValues.Add("X2LANGUAGE", ConfigurationManager.AppSettings[item]);
                    //            break;

                    //        case "X2DefaultLayout":
                    //            defalultKeyValues.Add("X2DefaultLayout", ConfigurationManager.AppSettings[item]);
                    //            break;

                    //        default:
                    //            break;
                    //    }
                    //}
                    #endregion

                    SetValues(defalultKeyValues);
                    UpdateConfig(defalultKeyValues);
                }
                catch (Exception ex)
                {
                    X2Error.Log("Error__InitOldConfig", ex, "InitOldConfig");
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 目录压缩
        /// </summary>
        /// <param name="inputFolderPath">源目录文件</param>
        /// <param name="outputPathAndFile">压缩包路径</param>
        /// <param name="password">压缩包密码</param>
        public static void ZipFolderFiles(string inputFolderPath, string outputPathAndFile, string password)
        {
            ///所有的文件信息
            ArrayList allFiles = GenerateFileList(inputFolderPath);

            ///父目录的长度
            int parentFolderLength = (Directory.GetParent(inputFolderPath)).ToString().Length;

            ///添加 '\\'长度
            parentFolderLength += 2;

            FileStream ostream;

            byte[] obuffer;
            ///压缩包的路径
            string outPath = outputPathAndFile;
            ///创建压缩文件
            ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath));

            ///防止文件被不同线程操作
            lock (objLock)
            {
                try
                {
                    ///压缩包密码
                    if (password != null && password != String.Empty)
                    {
                        oZipStream.Password = password;
                    }

                    ///压缩等级
                    oZipStream.SetLevel(9);
                    ZipEntry oZipEntry;

                    ///遍历所有文件,写入压缩包
                    foreach (string file in allFiles)
                    {
                        ///去除父目录得到文件相对路径
                        oZipEntry = new ZipEntry(file.Substring(parentFolderLength));
                        oZipStream.PutNextEntry(oZipEntry);

                        ///文件结构直接写入
                        if (!file.EndsWith(@"/"))
                        {
                            ostream = File.OpenRead(file);
                            obuffer = new byte[ostream.Length];
                            ostream.Read(obuffer, 0, obuffer.Length);
                            oZipStream.Write(obuffer, 0, obuffer.Length);
                            ostream.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    X2Error.Log("Zip.ElementFiles", ex, "Zip.ElementFiles");
                    throw ex;
                }
                finally
                {
                    ///数据的释放
                    oZipStream.Finish();
                    oZipStream.Close();
                }
            }
        }