Ejemplo n.º 1
0
        /// <summary>
        /// 解压文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUnRar_Click(object sender, EventArgs e)
        {
            String file = DropRar.SelectedValue;

            if (String.IsNullOrEmpty(file))
            {
                return;
            }
            String unpath = Server.MapPath(txtToPath.Text);

            try
            {
                SevenZipSharpHelper.Decompress(file, unpath);
                Alert(Label3, "解压成功!", "line1px_3");
            }
            catch (Exception ex)
            {
                Alert(Label3, ex.Message, "line1px_2");
            }
            //if (!Directory.Exists(unpath)) Directory.CreateDirectory(unpath);

            //Process Process1 = new Process();
            //Process1.StartInfo.FileName = Server.MapPath("/App_Data/Rar.exe");
            //Process1.StartInfo.Arguments = "x -t -o+ -p- " + " " + file + " " + unpath;
            //Process1.Start();
            //while (!Process1.HasExited) { }
            //if (Process1.ExitCode == 0)
            //{
            //    Alert(Label2, "文件解压成功!", "line1px_3");
            //}
            //Process1.Close();
        }
Ejemplo n.º 2
0
        void Application_Start(object sender, EventArgs e)
        {
            #region 数据库配置

            var    config   = SiteParameter.Config;
            String ConnType = XmlConfig.AppSettings("ConnType");
            db.CurrDbType       = config.DataType;
            db.ConnectionString = config.ConnectionString;
            //String ConnType = XmlConfig.AppSettings("ConnType");
            //db.CurrDbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), ConnType, true);
            //db.ConnectionString = XmlConfig.ConnectionStrings(ConnType);

            #endregion

            #region LogNet4日志初始化

            FileInfo logConfig = new FileInfo(Server.MapPath("/App_Data/Log4Net.xml"));
            log4net.Config.XmlConfigurator.Configure(logConfig);

            #endregion

            #region 清空ViewState和Sessions数据

            SQLitePageStatePersister.ClearData();
            FilePageStatePersister.ClearFile();
            //启动定时清理任务
            TaskClear.Initialize();

            #endregion

            //注册虚拟路径
            SiteVirtualPath.AppInitialize();
            //设置7z库路径
            SevenZipSharpHelper.SetZipPath(Server.MapPath("/Bin/7z.dll"));
        }
Ejemplo n.º 3
0
        public override void Write(Byte[] buffer, int offset, int count)
        {
            Byte[] data = SevenZipSharpHelper.Compress(buffer);
            String txt  = Convert.ToBase64String(data, Base64FormattingOptions.InsertLineBreaks);

            data = Encoding.UTF8.GetBytes(txt);
            deflateStream.Write(data, 0, data.Length);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 保存页面状态
 /// </summary>
 public override void Save()
 {
     if (ViewState != null || ControlState != null)
     {
         Pair data = new Pair(ViewState, ControlState);
         //序列化,压缩
         String strbase64 = new ObjectStateFormatter().Serialize(data);
         String strzip    = SevenZipSharpHelper.Compress(strbase64);
         //把页面状态注册到页面上
         Page.ClientScript.RegisterHiddenField(STATEKEY, strzip);
     }
 }
Ejemplo n.º 5
0
        public override void OnActionExecuted(HttpActionExecutedContext context)
        {
            HttpResponseMessage Response = context.Response;
            HttpContent         content  = Response.Content;

            Byte[] buffer = content == null ? new Byte[0] : content.ReadAsByteArrayAsync().Result;
            buffer = SevenZipSharpHelper.Compress(buffer);

            Response.Content = new ByteArrayContent(buffer);
            //Response.Content.Headers.Add("Content-encoding", "7z");
            Response.Content.Headers.Remove("Content-Type");
            Response.Content.Headers.Add("Content-Type", "application/octet-stream");
            base.OnActionExecuted(context);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 加载页面状态
        /// </summary>
        public override void Load()
        {
            //取得保存在客户端的状态内容
            String postbackstate = Page.Request.Form[STATEKEY];

            if (!String.IsNullOrEmpty(postbackstate))
            {
                //解压,反序列化
                //asp.net的viewstate包括控件状态和视图状态
                //存储两个相关对象
                postbackstate = SevenZipSharpHelper.Decompress(postbackstate);
                ObjectStateFormatter format = new ObjectStateFormatter();

                Pair data = (Pair)format.Deserialize(postbackstate);
                ViewState    = data.First;
                ControlState = data.Second;
            }
        }
Ejemplo n.º 7
0
 public override void Write(Byte[] buffer, int offset, int count)
 {
     Byte[] data = SevenZipSharpHelper.Compress(buffer);
     deflateStream.Write(data, 0, data.Length);
 }
Ejemplo n.º 8
0
        protected void Application_Start()
        {
            //db.CurrDbType = DatabaseType.ACCESS;
            //db.DbName = Server.MapPath("~/App_Data/data.mdb");
            db.CurrDbType       = DatabaseType.SqLite;
            db.ConnectionString = "Data Source=|DataDirectory|data.db;Version=3;Pooling=True;Max Pool Size=100;Cache Size=8000;Page Size=4096;Synchronous=Off;Journal Mode=Off;";

            #region LogNet4日志初始化

            FileInfo logConfig = new FileInfo(Server.MapPath("/App_Data/Log4Net.xml"));
            log4net.Config.XmlConfigurator.Configure(logConfig);

            #endregion

            //7z压缩
            SevenZipSharpHelper.SetZipPath(HttpRuntime.BinDirectory + "7z.dll");

            //Removing X-AspNetMvc-Version
            MvcHandler.DisableMvcResponseHeader = true;

            // using Newtonsoft.Json
            // POST JSON String 动态类型 字段别名
            //ModelBinders.Binders.Add(typeof(JObject), new JsonModelBinder());
            //ModelBinders.Binders.Add(typeof(JArray), new JsonModelBinder());
            ModelBinders.Binders.DefaultBinder = new JsonModelBinder();

            // Newtonsoft.Json POST JSON String 实体模型
            //ValueProviderFactories.Factories.Remove(ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault());//删除MVC默认适配器
            //ValueProviderFactories.Factories.Add(new JsonNetValueProviderFactory());//加入JSON.NET 解析适配器

            // MVC POST JSON String 字段实名
            //ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());//MVC默认适配器 (注:此处可不用手动添加,默认MVC已经加入)

            //MVC JSON.NET 默认参数设置
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
#if DEBUG
                Formatting = Formatting.Indented,
#else
                Formatting = Formatting.None,
#endif
                Culture = new CultureInfo("it-IT")
                {
                    NumberFormat = new NumberFormatInfo
                    {
                        NumberDecimalDigits   = 2,
                        CurrencyDecimalDigits = 2
                    },
                    DateTimeFormat = new DateTimeFormatInfo
                    {
                        TimeSeparator = ":"
                    }
                },
                //NullValueHandling = NullValueHandling.Ignore,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                //ContractResolver = new CamelCasePropertyNamesContractResolver(),
                DateFormatHandling = DateFormatHandling.IsoDateFormat,
                DateFormatString   = "yyyy-MM-dd HH:mm:ss",
                Converters         = { new StringEnumConverter() }
            };

            //路由调试
            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }