Exemplo n.º 1
0
        public bool DeleteAppInfo(string appName)
        {
            MyLog4NetInfo.LogInfo("调用方法:DeleteAppInfo,准备删除项目:" + appName);
            if (AppList != null && AppList.Any() && AppList.Any(o => o.AppName == appName))
            {
                using (var transactionScope = new TransactionScope())
                {
                    //删除内存中的数据
                    var effectCount = AppList.RemoveAll(o => o.AppName == appName);
                    MyLog4NetInfo.LogInfo(string.Format("删除内存中项目:{0}的数据,删除{1}!", appName, effectCount > 0?"成功":"失败"));

                    //删除info下的txt
                    File.Delete(FileProcessingHelper.AppInfoXMLPath() + appName + ".txt");
                    MyLog4NetInfo.LogInfo(string.Format("删除项目:{0} 在AppInfo文件夹下的txt文件", appName));

                    //删除upload下的文件夹
                    var deleteResult = FileProcessingHelper.DeleteDir(FileProcessingHelper.GetUpLoadFilePath() + appName);
                    MyLog4NetInfo.LogInfo(string.Format("删除项目:{0} 在UpLoadFile文件夹下的项目文件,删除{1}!", appName, deleteResult?"成功":"失败"));

                    if (effectCount > 0)
                    {
                        transactionScope.Complete();
                    }
                    MyLog4NetInfo.LogInfo(string.Format("调用方法:DeleteAppInfo,删除项目{0},最终删除结果:{1}", appName, effectCount > 0?"成功":"失败"));
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 记录日志
 /// </summary>
 /// <param name="message">日志内容</param>
 /// <param name="isLog">true为日志,false为错误日志</param>
 public void WriteLog(string message, bool isLog)
 {
     if (isLog)
     {
         MyLog4NetInfo.LogInfo(message);
     }
     else
     {
         MyLog4NetInfo.ErrorInfo(message);
     }
 }
        /// <summary>
        /// 将一个字符串反序列化为指定类型
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="xml">字符串</param>
        /// <returns></returns>
        public static T XMLDeserialize <T>(string xml)
        {
            T t = default(T);

            using (StringReader sdr = new StringReader(xml))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(T));
                    t = (T)serializer.Deserialize(sdr);
                }
                catch (Exception ex)
                {
                    MyLog4NetInfo.LogInfo(string.Format("反序列化报错,错误XML:{0},错误信息:{1},错误堆栈:{2},错误实例:{3}", xml, ex.Message, ex.StackTrace, ex.InnerException));
                }
            }
            return(t);
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetResumFile()
        {
            Count++;
            MyLog4NetInfo.LogInfo("the invoke times is:" + Count);
            //用于获取当前文件是否是续传。和续传的字节数开始点。
            var md5str = HttpContext.Current.Request.QueryString["md5str"];

            MyLog4NetInfo.LogInfo("receive params md5str is:" + md5str);
            var saveFilePath = HttpContext.Current.Server.MapPath("~/FilesDir/") + md5str;

            if (File.Exists(saveFilePath))
            {
                var fs       = File.OpenWrite(saveFilePath);
                var fslength = fs.Length.ToString();
                fs.Close();
                return(new HttpResponseMessage {
                    Content = new StringContent(fslength, System.Text.Encoding.UTF8, "text/plain")
                });
            }
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
 /// <summary>
 /// 获取指定路径下的所有文件集合
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static ApplicationEntity GetFiles(string path)
 {
     MyLog4NetInfo.LogInfo("文件日志:" + path);
     return(CommonAction.GetFiles(path));
 }
Exemplo n.º 6
0
        public void DownLoadBreak(string fileName)
        {
            MyLog4NetInfo.LogInfo("receive the paramas is :" + fileName);
            fileName = fileName.Substring(0, fileName.LastIndexOf('?'));
            fileName = HttpContext.Current.Server.MapPath("~/FilesDir/") + fileName;
            MyLog4NetInfo.LogInfo("after deal with the fileName is:" + fileName);
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            FileStream      iStream = null;

            // Buffer to read 10K bytes in chunk:
            byte[] buffer = new Byte[10240];

            // Length of the file:
            int length;

            // Total bytes to read:
            long dataToRead;

            try
            {
                string filename = Path.GetFileName(fileName);
                var    etag     = GetMD5HashFromFile(fileName);
                // Open the file.
                iStream = new FileStream(fileName, FileMode.Open,
                                         FileAccess.Read, System.IO.FileShare.Read);
                context.Response.Clear();

                // Total bytes to read:
                dataToRead = iStream.Length;
                MyLog4NetInfo.LogInfo("dataToRead is :" + dataToRead);
                long p = 0;
                context.Response.AddHeader("Accept-Ranges", "bytes");
                MyLog4NetInfo.LogInfo("context.Request.Headers[\"Range\"] is " + context.Request.Headers["Range"]);
                if (context.Request.Headers["Range"] != null)
                {
                    context.Response.StatusCode = 206;
                    p = long.Parse(context.Request.Headers["Range"].Replace("bytes=", "").Replace("-", ""));
                }
                if (p != 0)
                {
                    context.Response.AddHeader("Content-Range", "bytes " + p + "-" + ((long)(dataToRead - 1)) + "/" + dataToRead);
                }

                context.Response.Charset = "";
                context.Response.AddHeader("Content-Length", ((long)(dataToRead - p)).ToString());
                context.Response.ContentType = "application/octet-stream";
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(context.Request.ContentEncoding.GetBytes(filename)));
                context.Response.AddHeader("ETag", etag);
                context.Response.Headers.Set("ETag", etag);

                iStream.Position = p;
                dataToRead       = dataToRead - p;
                MyLog4NetInfo.LogInfo("iStream.Position=" + p + ";dataToRead=" + dataToRead);
                // Read the bytes.
                while (dataToRead > 0)
                {
                    // Verify that the client is connected.
                    if (context.Response.IsClientConnected)
                    {
                        // Read the data in buffer.
                        length = iStream.Read(buffer, 0, 10240);

                        // Write the data to the current output stream.
                        context.Response.OutputStream.Write(buffer, 0, length);

                        // Flush the data to the HTML output.
                        context.Response.Flush();

                        buffer     = new Byte[10240];
                        dataToRead = dataToRead - length;
                    }
                    else
                    {
                        //prevent infinite loop if user disconnects
                        dataToRead = -1;
                    }
                }
            }
            catch (Exception ex)
            {
                // Trap the error, if any.
                context.Response.Write("Error : " + ex.Message);
                MyLog4NetInfo.ErrorInfo(string.Format("下载文件出现了错误,错误信息:{0},错误堆栈:{1},错误实例:{2}", ex.Message, ex.StackTrace, ex.InnerException));
            }
            finally
            {
                if (iStream != null)
                {
                    //Close the file.
                    iStream.Close();
                }
                context.Response.End();
            }
        }