Example #1
0
        // 获取sessionKey,没有则新创建一个
        private static long GetSessionKey(HttpSessionStateBase session)
        {
            Object obj = session[JskeyUpload.UPLOAD_KEY];
            long   key = 0L;

            if (obj != null)
            {
                try
                {
                    key = Convert.ToInt64(obj);
                    if (key > 0)
                    {
                        session[JskeyUpload.UPLOAD_KEY] = key;
                        return(key);
                    }
                }
                catch
                {
                }
            }
            if (key > 0)
            {
                return(key);
            }
            key = JskeyUpload.GetNewSessionKey();
            session[JskeyUpload.UPLOAD_KEY] = key;
            return(key);
        }
Example #2
0
 //删除文件或清空文件夹
 private static Boolean Delete(String filePath)
 {
     try
     {
         Boolean success = true;
         if (Directory.Exists(filePath))
         {
             DirectoryInfo dir = new DirectoryInfo(filePath);
             dir.Attributes = FileAttributes.Normal & FileAttributes.Directory; // 去掉文件夹只读属性
             foreach (FileInfo file in dir.GetFiles())                          // 删除所有文件
             {
                 File.SetAttributes(file.FullName, FileAttributes.Normal);      // 去掉文件只读属性
                 File.Delete(file.FullName);
             }
             foreach (DirectoryInfo subDir in dir.GetDirectories())                    // 删除所有子文件夹
             {
                 success = JskeyUpload.Delete(subDir.FullName) && success;;
             }
             Directory.Delete(filePath);                    //删除自己
         }
         else if (File.Exists(filePath))
         {
             File.SetAttributes(filePath, FileAttributes.Normal);                    // 去掉文件只读属性
             File.Delete(filePath);
         }
         return(success);
     }
     catch
     {
         return(false);
     }
 }
Example #3
0
 /// <summary>
 /// 启动定时任务
 /// </summary>
 public void Run()
 {
     try
     {
         if (!JskeyUpload.UPLOAD_CLEAR)
         {
             return;
         }
         if (JskeyUpload.Count != 0)                //启动中
         {
             return;
         }
         if (!JskeyUpload.ExistMapValue())
         {
             _timer.Stop();
             return;                    //同样不需要启动
         }
         JskeyUpload.Count = 1;         //标记启动
         long currTime = DateTime.Now.Ticks;
         IDictionaryEnumerator dictenum = JskeyUpload.jskeyUploadMap.GetEnumerator();
         while (dictenum.MoveNext())
         {
             try
             {
                 if ((currTime - Convert.ToInt64(dictenum.Value)) > JskeyUpload.UPLOAD_TIMEOUT_TICKS)
                 {
                     JskeyUpload.DelSessionKey(Convert.ToInt64(dictenum.Key));                            //超时,移除
                 }
             }
             catch
             {
             }
         }
         if (!JskeyUpload.ExistMapValue())                //让再判断一次
         {
             _timer.Stop();
             JskeyUpload.Count = 0;
             log.Debug("--临时上传目录清理程序结束,清理完毕。--");
             //Console.WriteLine("--临时上传目录清理程序结束,清理完毕。--");
         }
     }
     catch
     {
         try
         {
             _timer.Stop();
         }
         finally
         {
             JskeyUpload.Count = 0;
             log.Error("--临时上传目录清理程序异常结束。--");
             //Console.WriteLine("--临时上传目录清理程序异常结束。--");
         }
     }
 }
Example #4
0
        private static Timer GetTimer()        //临时目录初始化,在服务器启动时执行
        {
            if (JskeyUpload.UPLOAD_CLEAR)
            {
                JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH);                //删除整个目录
            }
            Timer timer = new Timer(Convert.ToDouble(JskeyUpload.UPLOAD_TIMEOUT));

            timer.Elapsed  += new System.Timers.ElapsedEventHandler(delegate(Object source, ElapsedEventArgs e) { new JskeyUpload().Run(); });
            timer.AutoReset = true;
            timer.Enabled   = true;
            return(timer);
        }
Example #5
0
 /// <summary>
 /// 删除指定的临时子目录
 /// </summary>
 /// <param name="sessionKey">用户临时主目录</param>
 /// <param name="fileKey">用户临时子目录</param>
 /// <returns>Boolean</returns>
 public static Boolean DelFile(long sessionKey, long fileKey)
 {
     try
     {
         if (sessionKey <= 0 || fileKey <= 0)
         {
             return(false);
         }
         JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH + sessionKey + "/" + fileKey);                //删除整个目录
         return(true);
     }
     catch
     {
     }
     return(false);
 }
Example #6
0
 //删除整个临时上传目录
 private static Boolean DelSessionKey(long sessionKey)
 {
     try
     {
         if (sessionKey <= 0)
         {
             return(false);
         }
         JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH + sessionKey + "/");
         JskeyUpload.RemoveSessionKey(sessionKey);                //移除标识
         return(true);
     }
     catch
     {
         JskeyUpload.RemoveSessionKey(sessionKey);                //移除标识
     }
     return(false);
 }