Beispiel #1
0
        public static CommonReturn Success(object instance)
        {
            CommonReturn model = new CommonReturn();

            model.model = instance;
            return(model);
        }
Beispiel #2
0
        public static CommonReturn Failed(string msg)
        {
            CommonReturn model = new CommonReturn();

            model.isok = false;
            model.err  = msg;
            return(model);
        }
Beispiel #3
0
 /// <summary>
 /// 文件拷贝
 /// </summary>
 /// <param name="src">来源文件物理路径</param>
 /// <param name="tar">目标文件地址物理路径</param>
 /// <returns></returns>
 public static CommonReturn File_Copy(string src, string tar)
 {
     try
     {
         if (!File.Exists(src))
         {
             return(CommonReturn.Failed("[" + src + "]文件不存在"));
         }
         if (!Directory.Exists(Path.GetDirectoryName(tar)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(tar));
         }
         if (File.Exists(tar))
         {
             File.Delete(tar);
         }
         File.Copy(src, tar);
     }
     catch (Exception ex) { return(CommonReturn.Failed(ex.Message)); }
     return(CommonReturn.Success());
 }
Beispiel #4
0
 public static CommonReturn Dir_Copy(string srcdir, string tardir)
 {
     if (!Directory.Exists(srcdir))
     {
         return(CommonReturn.Failed("[" + srcdir + "]目录不存在"));
     }
     if (!Directory.Exists(tardir))
     {
         Directory.CreateDirectory(tardir);
     }
     srcdir = srcdir.Trim('\\') + "\\";
     tardir = tardir.Trim('\\') + "\\";
     //----------------------
     string[] fnames = Directory.GetFileSystemEntries(srcdir);
     foreach (string name in fnames)
     {
         try
         {
             if (Directory.Exists(name))//如果是目录则拷贝
             {
                 string currentdir = tardir + Dir_GetName(name);
                 if (!Directory.Exists(currentdir))
                 {
                     Directory.CreateDirectory(currentdir);
                 }
                 Dir_Copy(name, currentdir);//递归拷贝
             }
             else
             {
                 CommonReturn retMod = File_Copy(name, tardir + Path.GetFileName(name));
                 if (!retMod.isok)
                 {
                     throw new Exception(retMod.err);
                 }
             }
         }
         catch (Exception ex) { return(CommonReturn.Failed("[" + name + "]" + ex.Message)); }
     }
     return(CommonReturn.Success());
 }
Beispiel #5
0
        public static CommonReturn Success()
        {
            CommonReturn model = new CommonReturn();

            return(model);
        }