示例#1
0
 public static bool CreateFile(string path, ref string message)
 {
     return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
     {
         if (!TransactionActionHelper.CheckConditions((ref string mes) =>
         {
             if (File.Exists(path) || !Directory.Exists(Path.GetDirectoryName(path)))
             {
                 mes = "Wrong path or file exists";
                 Transaction.Current.Rollback();
                 return false;
             }
             return true;
         }, ref s))
         {
             return false;
         }
         var handle = CreateFileHandled(path, ref s);
         if (handle == null)
         {
             return false;
         }
         handle.Dispose();
         return true;
     }, ref message));
 }
示例#2
0
        public static bool CopyDirectory(string path, string pathTo)
        {
            string message = string.Empty;

            return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
            {
                if (!TransactionActionHelper.CheckConditions((ref string mes) =>
                {
                    if (!Directory.Exists(path) || Directory.Exists(pathTo))
                    {
                        mes = "Wrong path or folders are not exists";
                        return false;
                    }
                    return true;
                }, ref s))
                {
                    return false;
                }
                CopyDirectories(path, pathTo, ref s);
                if (!string.IsNullOrEmpty(s))
                {
                    Transaction.Current.Rollback();
                    return false;
                }
                return true;
            }, ref message));
        }
示例#3
0
        public static bool RemoveDirectory(string path)
        {
            string message = string.Empty;

            return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
            {
                if (!TransactionActionHelper.CheckConditions((ref string mes) =>
                {
                    if (!Directory.Exists(path))
                    {
                        Transaction.Current.Rollback();
                        message = "Wrong path or directory not exists";
                        return false;
                    }
                    return true;
                }, ref s))
                {
                    return false;
                }
                SafeTransactionHandle txHandle = null;
                try
                {
                    new TxFileManager().DeleteDirectory(path);
                }
                catch (Exception ex)
                {
                    message = ex.ToString();
                    Transaction.Current.Rollback();
                    return false;
                }
                return true;
            }, ref message));
        }
示例#4
0
        public static bool DeleteFiles(FileArgs args)
        {
            bool   response = true;
            string message  = String.Empty;

            return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
            {
                foreach (var file in args.Files)
                {
                    if (!response)
                    {
                        return false;
                    }
                    if (!TransactionActionHelper.CheckConditions((ref string mes) =>
                    {
                        if (!File.Exists(file))
                        {
                            mes = "Wrong path or file exists";
                            Transaction.Current.Rollback();
                            return false;
                        }
                        return true;
                    }, ref s))
                    {
                        return false;
                    }
                    SafeTransactionHandle txHandle = null;
                    try
                    {
                        IKernelTransaction kernelTx =
                            (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current);
                        kernelTx.GetHandle(out txHandle);
                        if (!DeleteFileTransacted(file, txHandle))
                        {
                            Transaction.Current.Rollback();
                            response = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        response = false;
                        s = ex.Message;
                        Transaction.Current.Rollback();
                    }
                    finally
                    {
                        if (txHandle != null && !txHandle.IsInvalid)
                        {
                            txHandle.Dispose();
                        }
                    }
                }
                return response;
            }, ref message));
        }
示例#5
0
 public static bool CopyFileTo(string path, string pathCopy, ref string message)
 {
     return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
     {
         if (!TransactionActionHelper.CheckConditions((ref string mes) =>
         {
             if (!File.Exists(path) || File.Exists(pathCopy))
             {
                 mes = "Wrong path or file exists";
                 Transaction.Current.Rollback();
                 return false;
             }
             return true;
         }, ref s))
         {
             return false;
         }
         bool response = false;
         SafeTransactionHandle txHandle = null;
         try
         {
             IKernelTransaction kernelTx =
                 (IKernelTransaction)TransactionInterop.GetDtcTransaction(Transaction.Current);
             kernelTx.GetHandle(out txHandle);
             response = CopyFileTransacted(path, pathCopy, IntPtr.Zero, IntPtr.Zero, false,
                                           SafeTransactionHandle.Copy.COPY_FILE_FAIL_IF_EXISTS, txHandle);
         }
         catch (Exception ex)
         {
             s = ex.Message;
             Transaction.Current.Rollback();
         }
         finally
         {
             if (txHandle != null)
             {
                 txHandle.Dispose();
             }
         }
         return response;
     }, ref message));
 }
示例#6
0
        //public static bool MoveDirectory(string path, string pathTo)
        //{
        //    bool response = true;
        //    string message = String.Empty;
        //    if (!Directory.Exists(path) || Directory.Exists(pathTo))
        //    {
        //        message = "Wrong path or folders are not exists";
        //        return false;
        //    }
        //        CopyDirectories(path, pathTo, ref message);
        //        if (!string.IsNullOrEmpty(message))
        //        {
        //            Transaction.Current.Rollback();
        //            return false;
        //        }
        //    return response;
        //}

        public static bool CreateDirectory(string path, ref string message)
        {
            return(TransactionActionHelper.DoActionWithCheckOnTransaction((ref string s) =>
            {
                if (!TransactionActionHelper.CheckConditions((ref string mes) =>
                {
                    if (Directory.Exists(path))
                    {
                        mes = "Wrong path or directory exists";
                        Transaction.Current.Rollback();
                        return false;
                    }
                    return true;
                }, ref s))
                {
                    return false;
                }
                return CreateDir(path, ref s);
            }, ref message));
        }