/// <summary>
 ///     Initializes a new instance of the <see cref="FileOperationResult" /> class.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="opperation">The opperation.</param>
 /// <param name="exception">The exception.</param>
 public FileOperationResult(string fileName, FileOperation opperation, Exception exception)
 {
     FileName = fileName;
     FileOperation = opperation;
     Succeeded = false;
     Message = exception.Message;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="FileOperationResult" /> class.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="opperation">The opperation.</param>
 /// <param name="succeeded">if set to <c>true</c> [succeeded].</param>
 /// <param name="message">The message.</param>
 public FileOperationResult(string fileName, FileOperation opperation, bool succeeded, string message)
 {
     FileName = fileName;
     FileOperation = opperation;
     Succeeded = succeeded;
     Message = message;
 }
        /// <summary>
        /// Processes the command.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        public void ProcessCommand(FileOperation fileOperation)
        {
            TraceService.WriteLine("FileOperationService::ProcessCommand");

            TraceService.WriteDebugLine("Platform=" + fileOperation.PlatForm);
            TraceService.WriteDebugLine("CommandType=" + fileOperation.CommandType);
            TraceService.WriteDebugLine("Directory=" + fileOperation.Directory);
            TraceService.WriteDebugLine("File=" + fileOperation.File);
            TraceService.WriteDebugLine("From=" + fileOperation.From);
            TraceService.WriteDebugLine("To=" + fileOperation.To);

            IProjectService projectService = this.visualStudioService.GetProjectServiceBySuffix(fileOperation.PlatForm);

            if (projectService != null)
            {
                IEnumerable<IProjectItemService> fileItemServices = this.GetFileItems(fileOperation, projectService);

                foreach (IProjectItemService projectItemService in fileItemServices)
                {
                    if (fileOperation.CommandType == "ReplaceText")
                    {
                        this.ReplaceText(fileOperation, projectService, projectItemService);
                    }
                    else if (fileOperation.CommandType == "Properties")
                    {
                        this.UpdateProperty(fileOperation, projectItemService);
                    }
                }
            }
            else
            {
                TraceService.WriteLine("Platform " + fileOperation.PlatForm + " not found");
            }
        }
Example #4
0
        public static void Queue(FileOperation operation, bool toTop = false)
        {
            if ((operation.Kind == TFileOperationKind.Copy || operation.Kind == TFileOperationKind.Move || operation.Kind == TFileOperationKind.Convert)
                && operation.DestMedia != null)
                operation.DestMedia.MediaStatus = TMediaStatus.CopyPending;
            if (operation.Kind == TFileOperationKind.Convert)
            {
                lock (_queueConvertOperation.SyncRoot)
                    if (!_queueConvertOperation.Any(fe => fe.Equals(operation)))
                    {
                        if (toTop)
                            _queueConvertOperation.Insert(0, operation);
                        else
                            _queueConvertOperation.Add(operation);
                        if (!_isRunningConvertOperation)
                        {
                            _isRunningConvertOperation = true;
                            ThreadPool.QueueUserWorkItem(o => _runOperation(_queueConvertOperation, ref _isRunningConvertOperation));
                        }
                    }
            }
            if (operation.Kind == TFileOperationKind.Export)
            {
                lock (_queueExportOperation.SyncRoot)
                    if (!_queueExportOperation.Any(fe => fe.Equals(operation)))
                    {
                        if (toTop)
                            _queueExportOperation.Insert(0, operation);
                        else
                            _queueExportOperation.Add(operation);
                        if (!_isRunningExportOperation)
                        {
                            _isRunningExportOperation = true;
                            ThreadPool.QueueUserWorkItem(o => _runOperation(_queueExportOperation, ref _isRunningExportOperation));
                        }
                    }

            }
            if (operation.Kind == TFileOperationKind.Copy
                || operation.Kind == TFileOperationKind.Delete
                || operation.Kind == TFileOperationKind.Loudness
                || operation.Kind == TFileOperationKind.Move)
            {
                lock (_queueSimpleOperation.SyncRoot)
                    if (!_queueSimpleOperation.Any(fe => fe.Equals(operation)))
                    {
                        if (toTop)
                            _queueSimpleOperation.Insert(0, operation);
                        else
                            _queueSimpleOperation.Add(operation);
                        if (!_isRunningSimpleOperation)
                        {
                            _isRunningSimpleOperation = true;
                            ThreadPool.QueueUserWorkItem(o => _runOperation(_queueSimpleOperation, ref _isRunningSimpleOperation));
                        }
                    }
            }
            if (OperationAdded != null)
                OperationAdded(operation);
        }
Example #5
0
 public static void MoveDirectoryToRecycleBin(
     string directoryPath)
 {
     using (var fo = new FileOperation(new FileOperationProgressSink()))
     {
         fo.SetOperationFlags(FileOperationDeleteFlags);
         fo.DeleteItem(ZlpPathHelper.GetFullPath(directoryPath));
         fo.PerformOperations();
     }
 }
 private void OnOperationCompleted(FileOperation operation)
 {
     Application.Current.Dispatcher.BeginInvoke((Action)(() =>
     {
         if (_clearFinished)
         {
             foreach (FileOperationViewmodel vm in _operationList.ToList())
                 if (vm.IsFileOperation(operation))
                     _operationList.Remove(vm);
         }
     }), null);
 }
Example #7
0
File: Menu.cs Project: oleeq2/ToDo
        public bool FileOperationMenu(out FileOperation state,out string path)
        {
            bool ret;
            Console.Write("1. Load from file \n" +
                          "2. Save to file   \n" +
                          "> ");

            if (!FileOperation.TryParse(Console.ReadLine(), out state))
            {
                ret = false;
                path = string.Empty;
            }
            else
            {
                string tmp_path;
                ret = getPathMenu(state,out tmp_path);
                path = tmp_path;
            }
            return ret;
        }
        /// <summary>
        /// Gets the file items.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        /// <param name="projectService">The project service.</param>
        /// <returns>The files to have operations on.</returns>
        private IEnumerable<IProjectItemService> GetFileItems(
            FileOperation fileOperation, 
            IProjectService projectService)
        {
            TraceService.WriteLine("FileOperationService::GetFileItems");

            List<IProjectItemService> fileItemServices = new List<IProjectItemService>();

            if (string.IsNullOrEmpty(fileOperation.Directory) == false)
            {
                IProjectItemService projectItemService = projectService.GetFolder(fileOperation.Directory);

                if (projectItemService != null)
                {
                    if (string.IsNullOrEmpty(fileOperation.File) == false)
                    {
                        fileItemServices.Add(projectItemService.GetProjectItem(fileOperation.File));
                    }

                    else
                    {
                        IEnumerable<IProjectItemService> projectItemServices = projectItemService.GetCSharpProjectItems();

                        foreach (IProjectItemService childProjectItemService in projectItemServices)
                        {
                            TraceService.WriteDebugLine("FileOperationService::GetFileItems File=" + childProjectItemService.Name);
                            fileItemServices.Add(childProjectItemService);
                        }
                    }
                }
                else
                {
                    TraceService.WriteDebugLine("Directory " + fileOperation.Directory + " not found");
                }
            }
            else
            {
                fileItemServices.Add(projectService.GetProjectItem(fileOperation.File));
            }

            TraceService.WriteDebugLine("FileOperationService::GetFileItems fileItemServicesCount=" + fileItemServices.Count);

            return fileItemServices;
        }
Example #9
0
 public QueueItem(FileSystemItem fileSystemItem, FileOperation fileOperation, object payload = null)
 {
     FileSystemItem = fileSystemItem;
     Operation = fileOperation;
     Payload = payload;
 }
 /// <summary>
 /// Updates the property.
 /// </summary>
 /// <param name="fileOperation">The file operation.</param>
 /// <param name="projectItemService">The project item service.</param>
 private void UpdateProperty(
     FileOperation fileOperation, 
     IProjectItemService projectItemService)
 {
     if (projectItemService.ProjectItem != null)
     {
         projectItemService.ProjectItem.Properties.Item(fileOperation.From).Value = fileOperation.To;
         TraceService.WriteDebugLine("**Properties Updates**");
     }
 }
        /// <summary>
        /// Replaces the text.
        /// </summary>
        /// <param name="fileOperation">The file operation.</param>
        /// <param name="projectService">The project service.</param>
        /// <param name="projectItemService">The project item service.</param>
        private void ReplaceText(
            FileOperation fileOperation,
            IProjectService projectService,
            IProjectItemService projectItemService)
        {
            if (projectService == null)
            {
                return;
            }

            if (projectItemService == null)
            {
                return;
            }

            string to = fileOperation.To.Replace("$rootnamespace$", projectService.Name);

            to = to.Replace("$CoreProject$", this.settingsService.CoreProjectSuffix.Substring(1));
            to = to.Replace("$FormsProject$", this.settingsService.XamarinFormsProjectSuffix.Substring(1));
            to = to.Replace("$iOSProject$", this.settingsService.iOSProjectSuffix.Substring(1));
            to = to.Replace("$DroidProject$", this.settingsService.DroidProjectSuffix.Substring(1));
            to = to.Replace("$WindosPhonedProject$", this.settingsService.WindowsPhoneProjectSuffix.Substring(1));
            to = to.Replace("$WindosUniversalProject$", this.settingsService.WindowsUniversalProjectSuffix.Substring(1));
            to = to.Replace("$WpfProject$", this.settingsService.WpfProjectSuffix.Substring(1));

            string from = fileOperation.From;

            TraceService.WriteDebugLine("from=" + @from + " to" + to);

            if (@from != to)
            {
                projectItemService.ReplaceText(fileOperation.From, to);
                TraceService.WriteDebugLine("**Replaced**");
            }
            else
            {
                TraceService.WriteDebugLine("No need to replace!");
            }
        }
    private VirtualFolderInfo PerformFolderOperation(string virtualFolderPath, string destinationPath, FileOperation operation)
    {
      if (virtualFolderPath == null) throw new ArgumentNullException("virtualFolderPath");
      if (destinationPath == null) throw new ArgumentNullException("destinationPath");

      //get folder info for source and destination, thus validating the scope of both
      string absoluteSource;
      var sourceFolder = GetFolderInfoInternal(virtualFolderPath, true, out absoluteSource);
      string absoluteDestination;
      GetFolderInfoInternal(destinationPath, false, out absoluteDestination);

      string operationName = operation == FileOperation.Move ? "move" : "copy";

      if (sourceFolder.IsRootFolder)
      {
        string msg = String.Format("Cannot {0} root folder (attempted destination: '{1}').", operationName, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      if (String.Equals(absoluteSource, absoluteDestination, StringComparison.InvariantCultureIgnoreCase))
      {
        string msg = String.Format("Cannot {0} folder to '{1}' - source and destination are the same.", operationName, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      var sourceDir = new DirectoryInfo(absoluteSource);
      if (sourceDir.IsParentOf(absoluteDestination))
      {
        string msg = String.Format("Cannot {0} folder '{1}' to '{2}' - destination folder is a child of the folder.", operationName, virtualFolderPath, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      if (Directory.Exists(absoluteDestination))
      {
        string msg = "Cannot {0} folder '{1}' to '{2}' - the destination folder already exists.";
        msg = String.Format(msg, operationName, virtualFolderPath, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceOverwriteException(msg);
      }


      try
      {
        switch(operation)
        {
          case FileOperation.Move:
            Directory.Move(absoluteSource, absoluteDestination);
            break;
          case FileOperation.Copy:
            PathUtil.CopyDirectory(absoluteSource, absoluteDestination, false);
            break;
          default:
            VfsLog.Fatal("Unsupported file operation received: {0}", operation);
            throw new ArgumentOutOfRangeException("operation");
        }

        return GetFolderInfo(absoluteDestination);
      }
      catch (Exception e)
      {
        string msg = String.Format("An error occurred while trying to {0} directory '{1}' to '{2}'.",
                                          operationName, virtualFolderPath, destinationPath);
        VfsLog.Warn(e, msg);
        throw new ResourceAccessException(msg, e);
      }
    }
        public static void FileOperationToBreakLeaseRequestCall(FileOperation operation, OperatorType operatorType, ModelDialectRevision dialect)
        {
            Condition.IsTrue(state == ModelState.Connected);
            Condition.IsNull(request);
            Condition.IsNotNull(smb2Lease);
            Condition.IsFalse(smb2Lease.Breaking);
            Condition.IsFalse(smb2Lease.LeaseState == (uint)LeaseStateValues.SMB2_LEASE_NONE);
            Condition.IsTrue(dialect <= config.MaxSmbVersionSupported);

            if (operatorType == OperatorType.SameClientId || operatorType == OperatorType.SameClientGuidDifferentLeaseKey)
            {
                switch (negotiateDialect)
                {
                    case DialectRevision.Smb2002:
                        Condition.IsTrue(dialect == ModelDialectRevision.Smb2002);
                        break;
                    case DialectRevision.Smb21:
                        Condition.IsTrue(dialect == ModelDialectRevision.Smb21);
                        break;
                    case DialectRevision.Smb30:
                        Condition.IsTrue(dialect == ModelDialectRevision.Smb30);
                        break;
                    case DialectRevision.Smb302:
                        Condition.IsTrue(dialect == ModelDialectRevision.Smb302);
                        break;
                    default:
                        Condition.Fail();
                        break;
                }
            }
            else
            {
                // Limit the dialect which is used by second client for se exploration.
                Condition.IsTrue(dialect == ModelDialectRevision.Smb2002);
            }

            request = new ModelFileOperationRequest(operation, operatorType, dialect);
        }
Example #14
0
	void DoFileOperation(FileOperation operation, UserMadeChoiceEventArgs e, string singleEntry)
	{
		if (operation == FileOperation.Nothing)
			return;

		string source = this.curPath;
		string target = targetFolder.Text;
		try
		{
			target = target.Trim().Trim('/', '\\');
			target = BXPath.ToVirtualRelativePath(target);
		}
		catch
		{
			ShowError(Encode(string.Format(GetMessageRaw("FormattedErrorMassage.SpecifiedPathIsInvalid"), targetFolder.Text)));
			return;
		}

		List<string> files;
		if (e == null)
		{
			if (singleEntry == null)
				return;
			files = new List<string>();
			files.Add(singleEntry);
		}
		else
			files = FormFileList(e);

		if (files.Count == 0)
			return;

		this.errorTemplateNoRightsToDelete = String.Format("{0}: {{0}}", GetMessageRaw("Message.InsufficientRightsToDelete"));
		this.errorTemplateUnknownSource = String.Format("{0}: {{0}}", GetMessageRaw("Message.UnknownItem"));
		this.errorTemplateUnableToDelete = String.Format("{0}: {{0}}", GetMessageRaw("Message.UnableToDelete"));
		this.errorTemplateTargetExists = String.Format("{0}: {{0}} -> {{1}}", GetMessageRaw("Message.TargetItemAlreadyExists"));
		this.errorTemplateUnableToWrite = String.Format("{0}: {{0}} -> {{1}}", GetMessageRaw("Message.UnableToWrite"));
		this.errorTemplateCantCopyIntoItself = String.Format("{0}: {{0}} -> {{1}}", GetMessageRaw("Message.CantCopyIntoItself"));

		if ((operation & FileOperation.Copy) > 0 && !CheckForCopyOperation(source, target))
			return;

		for (int i = 0; i < files.Count; i++)
		{
			try
			{
				string filename = files[i];
				string sourcePath = BXPath.Combine(source, filename);

				bool isFile;
				if (BXSecureIO.FileExists(sourcePath))
					isFile = true;
				else if (BXSecureIO.DirectoryExists(sourcePath))
					isFile = false;
				else
					throw new Exception(String.Format(this.errorTemplateUnknownSource, sourcePath));

				if ((operation & FileOperation.Copy) > 0)
					DoFileCopyMove(sourcePath, BXPath.Combine(target, filename), (operation & FileOperation.Delete) > 0, isFile);
				else if ((operation & FileOperation.Delete) > 0)
					DoFileDelete(sourcePath, isFile);
			}
			catch (Exception ex)
			{
				ShowError(Encode(ex.Message));
			}
		}
		ShowOk();
		fileManGrid.MarkAsChanged();
	}
        public void FileOperationToBreakLeaseRequest(FileOperation operation, OperatorType operatorType, ModelDialectRevision dialect, out LeasingConfig c)
        {
            c = leasingConfig;

            LeasingClientInfo clientInfo = clients[(int)operatorType];

            // Avoid to fail because Windows issue
            if (dialect == ModelDialectRevision.Smb2002)
            {
                clientInfo.ClientGuid = Guid.NewGuid();
            }

            if (!clientInfo.IsInitialized)
            {
                InitializeClient(clientInfo, dialect);
            }

            if (operation == FileOperation.WRITE_DATA)
            {
                #region WRITE_DATA

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    status = clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN_IF,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                byte[] data = Encoding.ASCII.GetBytes("Write data to break READ caching.");
                ushort creditCharge = Smb2Utility.CalculateCreditCharge((uint)data.Length, ModelUtility.GetDialectRevision(dialect));

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.WriteRequest(creditCharge, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId,
                    0, clientInfo.FileId, Channel_Values.CHANNEL_NONE, WRITE_Request_Flags_Values.None, new byte[0], data);
                clientInfo.MessageId += (ulong)creditCharge;

                #endregion
            }
            else if (operation == FileOperation.SIZE_CHANGED)
            {
                #region SIZE_CHANGED

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    status = clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                FileEndOfFileInformation changeSizeInfo;
                changeSizeInfo.EndOfFile = 512;

                byte[] inputBuffer;
                inputBuffer = TypeMarshal.ToBytes<FileEndOfFileInformation>(changeSizeInfo);

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.SetInfoRequest(
                    1,
                    1,
                    clientInfo.Flags,
                    clientInfo.MessageId++,
                    clientInfo.SessionId,
                    clientInfo.TreeId,
                    SET_INFO_Request_InfoType_Values.SMB2_0_INFO_FILE,
                    (byte)FileInformationClasses.FileEndOfFileInformation,
                    SET_INFO_Request_AdditionalInformation_Values.NONE,
                    clientInfo.FileId,
                    inputBuffer);

                #endregion
            }
            else if (operation == FileOperation.RANGE_LOCK)
            {
                #region RANGE_LOCK

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    status = clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                clientInfo.Locks = new LOCK_ELEMENT[1];
                clientInfo.LockSequence = 0;
                clientInfo.Locks[0].Offset = 0;
                clientInfo.Locks[0].Length = (ulong)1 * 1024 / 2;
                clientInfo.Locks[0].Flags = LOCK_ELEMENT_Flags_Values.LOCKFLAG_SHARED_LOCK;

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.LockRequest(
                    1,
                    1,
                    clientInfo.Flags,
                    clientInfo.MessageId++,
                    clientInfo.SessionId,
                    clientInfo.TreeId,
                    clientInfo.LockSequence++,
                    clientInfo.FileId,
                    clientInfo.Locks
                    );

                #endregion
            }
            else if (operation == FileOperation.OPEN_OVERWRITE)
            {
                #region OPEN_OVERWRITE
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.CreateRequest(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                    AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                    ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                    originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                    CreateDisposition_Values.FILE_OVERWRITE,
                    File_Attributes.NONE,
                    ImpersonationLevel_Values.Impersonation,
                    SecurityFlags_Values.NONE,
                    clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                    clientInfo.CreateContexts);

                #endregion
            }
            else if (operation == FileOperation.OPEN_WITHOUT_OVERWRITE)
            {
                #region OPEN_WITHOUT_OVERWRITE
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                if (!clientInfo.IsOpened)
                {
                    clientInfo.LastOperationMessageId = clientInfo.MessageId;
                    clientInfo.Client.CreateRequest(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts);
                }

                #endregion
            }
            else if (operation == FileOperation.OPEN_SHARING_VIOLATION)
            {
                #region OPEN_SHARING_VIOLATION
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                if (!clientInfo.IsOpened)
                {
                    clientInfo.LastOperationMessageId = clientInfo.MessageId;
                    clientInfo.Client.CreateRequest(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts);
                }
                #endregion
            }
            else if (operation == FileOperation.OPEN_SHARING_VIOLATION_WITH_OVERWRITE)
            {
                #region OPEN_SHARING_VIOLATION_WITH_OVERWRITE
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                if (!clientInfo.IsOpened)
                {
                    clientInfo.LastOperationMessageId = clientInfo.MessageId;
                    clientInfo.Client.CreateRequest(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OVERWRITE,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts);
                }

                #endregion
            }
            else if (operation == FileOperation.DELETED)
            {
                #region DELETED
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        (originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE) | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                FileDispositionInformation deleteInfo;
                deleteInfo.DeletePending = 1;

                byte[] inputBuffer;
                inputBuffer = TypeMarshal.ToBytes<FileDispositionInformation>(deleteInfo);

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.SetInfoRequest(
                    1,
                    1,
                    clientInfo.Flags,
                    clientInfo.MessageId++,
                    clientInfo.SessionId,
                    clientInfo.TreeId,
                    SET_INFO_Request_InfoType_Values.SMB2_0_INFO_FILE,
                    (byte)FileInformationClasses.FileDispositionInformation,
                    SET_INFO_Request_AdditionalInformation_Values.NONE,
                    clientInfo.FileId,
                    inputBuffer);
                #endregion
            }
            else if (operation == FileOperation.RENAMEED)
            {
                #region RENAMEED
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    status = clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.File,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        originalClient.IsDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        clientInfo.CreateContexts == null ? RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE : RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                        clientInfo.CreateContexts,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                string newFileName = originalClient.ParentDirectory + "\\" + Guid.NewGuid().ToString();
                FileRenameInformation info = new FileRenameInformation();
                info.ReplaceIfExists = 1;
                info.FileName = ConvertStringToByteArray(newFileName);
                info.FileNameLength = (uint)info.FileName.Length;
                info.RootDirectory = FileRenameInformation_RootDirectory_Values.V1;
                info.Reserved = new byte[7];

                byte[] inputBuffer;
                inputBuffer = TypeMarshal.ToBytes<FileRenameInformation>(info);

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.SetInfoRequest(
                    1,
                    1,
                    clientInfo.Flags,
                    clientInfo.MessageId++,
                    clientInfo.SessionId,
                    clientInfo.TreeId,
                    SET_INFO_Request_InfoType_Values.SMB2_0_INFO_FILE,
                    (byte)FileInformationClasses.FileRenameInformation,
                    SET_INFO_Request_AdditionalInformation_Values.NONE,
                    clientInfo.FileId,
                    inputBuffer);

                originalClient.File = newFileName;
                #endregion
            }
            else if (operation == FileOperation.PARENT_DIR_RENAMED)
            {
                #region PARENT_DIR_RENAMED
                if (clientInfo.IsOpened)
                {
                    clientInfo.Reset(operatorType == OperatorType.SecondClient);

                    InitializeClient(clientInfo, dialect);
                }

                uint status = Smb2Status.STATUS_SUCCESS;

                Packet_Header header;
                CREATE_Response createResponse;
                Smb2CreateContextResponse[] serverCreateContexts;

                if (!clientInfo.IsOpened)
                {
                    status = clientInfo.Client.Create(1, 64, clientInfo.Flags, clientInfo.MessageId++, clientInfo.SessionId, clientInfo.TreeId, originalClient.ParentDirectory,
                        AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE,
                        ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
                        CreateOptions_Values.FILE_DIRECTORY_FILE,
                        CreateDisposition_Values.FILE_OPEN,
                        File_Attributes.NONE,
                        ImpersonationLevel_Values.Impersonation,
                        SecurityFlags_Values.NONE,
                        RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                        null,
                        out clientInfo.FileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
                    Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Expect that creation succeeds.");
                }

                string newFileName = "LeasingDir_" + Guid.NewGuid().ToString();
                FileRenameInformation info = new FileRenameInformation();
                info.ReplaceIfExists = 0;
                info.FileName = ConvertStringToByteArray(newFileName);
                info.FileNameLength = (uint)info.FileName.Length;
                info.RootDirectory = FileRenameInformation_RootDirectory_Values.V1;
                info.Reserved = new byte[7];

                byte[] inputBuffer;
                inputBuffer = TypeMarshal.ToBytes<FileRenameInformation>(info);

                clientInfo.LastOperationMessageId = clientInfo.MessageId;
                clientInfo.Client.SetInfoRequest(
                    1,
                    1,
                    clientInfo.Flags,
                    clientInfo.MessageId++,
                    clientInfo.SessionId,
                    clientInfo.TreeId,
                    SET_INFO_Request_InfoType_Values.SMB2_0_INFO_FILE,
                    (byte)FileInformationClasses.FileRenameInformation,
                    SET_INFO_Request_AdditionalInformation_Values.NONE,
                    clientInfo.FileId,
                    inputBuffer);
                // Does not need to update these two fields File and ParentDirectory in orginal client because the operation will fail.
                #endregion
            }

            lastOperation = new BreakOperation(operation, operatorType);
        }
Example #16
0
File: Menu.cs Project: oleeq2/ToDo
        public bool getPathMenu(FileOperation rw,out string path)
        {
            bool ret = true;
            bool flag = false;
            path = String.Empty;
            do
            {
                string str = _getPath();
                if (rw == FileOperation.Write)
                {
                    if (File.Exists(str))
                    {
                        bool ans = _askUser("File exists override? ");
                        if (!ans)
                        {
                            flag = true;
                            continue;
                        }
                        else
                        {
                            path = str;
                        }
                    }
                    path = str;
                }
                path = str;
            }while(flag);

            return ret;
        }
 private bool ConfirmCommand(FileOperation type, bool isPlural)
 {
     var title = Resx.ResourceManager.GetString(type.ToString());
     var message = Resx.ResourceManager.GetString(string.Format(isPlural ? "{0}ConfirmationPlural" : "{0}ConfirmationSingular", type));
     return WindowManager.Confirm(title, message);
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="FileOperationResult" /> class.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="opperation">The opperation.</param>
 /// <param name="succeeded">if set to <c>true</c> [succeeded].</param>
 public FileOperationResult(string fileName, FileOperation opperation, bool succeeded)
 {
     FileName = fileName;
     FileOperation = opperation;
     Succeeded = succeeded;
 }
 private void OnOperationAdded(FileOperation operation)
 {
     Application.Current.Dispatcher.BeginInvoke((Action)( ()=>
         _operationList.Add(new FileOperationViewmodel(operation)))
         , null);
 }
		public MaterialFileOeprationInfo(Material m, FileOperation op)
		{
			material = m;
			operation = op;
		}
Example #21
0
        /// <summary>
        /// Perform action on the file
        /// </summary>
        /// <param name="operation">what to do?</param>
        /// <param name="itemTag">File info</param>
        private void handleFileOperation(FileOperation operation, FileInfo fileInfo)
        {
            switch (operation)
            {
                case FileOperation.Open:
                    SelectedFile = fileInfo.FullName;
                    if (EvtFileOpen != null)
                    {
                        EvtFileOpen.BeginInvoke(this, new EventArgs(), null, null);
                    }

                    break;

                case FileOperation.Delete:
                    handleDeleteFile(fileInfo);
                    break;
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="operation">The type of file operation.</param>
 /// <param name="operatorType">The type of the operator.</param>
 public BreakOperation(FileOperation operation, OperatorType operatorType)
 {
     this.Operation = operation;
     this.Operator = operatorType;
 }
Example #23
0
        private static void DirectoryOperation(string sourceDirectory, string destinationDirectory, bool overwriteExistingFiles, bool forceWritable, FileOperation operation)
        {
            if ((sourceDirectory == null) || (sourceDirectory.Trim() == string.Empty))
            {
                throw new ArgumentNullException("sourceDirectory");
            }
            if ((destinationDirectory == null) || (destinationDirectory.Trim() == string.Empty))
            {
                throw new ArgumentNullException("destinationDirectory");
            }
            if (!Directory.Exists(sourceDirectory))
            {
                throw new DirectoryNotFoundException(sourceDirectory);
            }
            if (!Directory.Exists(destinationDirectory))
            {
                if (operation == FileOperation.Move)
                {
                    Directory.Move(sourceDirectory, destinationDirectory);
                    return;
                }
                if (operation == FileOperation.Copy)
                {
                    Directory.CreateDirectory(destinationDirectory);
                }
            }
            foreach (string str2 in Directory.GetFiles(sourceDirectory))
            {
                FileAttributes attributes = File.GetAttributes(str2);
                int num = ((int)attributes) & 2;
                int num2 = ((int)attributes) & 4;
                if ((num <= 0) && (num2 <= 0))
                {
                    string fileName = str2.Substring(str2.LastIndexOf(@"\") + 1);
                    string path = destinationDirectory + @"\" + fileName;
                    bool flag = false;
                    if (File.Exists(path))
                    {
                        if (overwriteExistingFiles)
                        {
                            SetFileReadOnly(path, false);
                            if (operation == FileOperation.Move)
                            {
                                File.Delete(path);
                            }
                        }
                        else if (operation == FileOperation.Move)
                        {
                            SetFileReadOnly(fileName, false);
                            File.Delete(fileName);
                            flag = true;
                        }
                    }
                    switch (operation)
                    {
                        case FileOperation.Copy:
                            File.Copy(str2, path, overwriteExistingFiles);
                            if (forceWritable)
                            {
                                SetFileReadOnly(destinationDirectory + @"\" + fileName, false);
                            }
                            break;

                        case FileOperation.Move:
                            if (!flag)
                            {
                                File.Move(str2, path);
                            }
                            break;
                    }
                }
            }
            foreach (string str in Directory.GetDirectories(sourceDirectory))
            {
                string str5 = str.Substring(str.LastIndexOf(@"\") + 1);
                DirectoryOperation(str, destinationDirectory + @"\" + str5, overwriteExistingFiles, forceWritable, operation);
                if ((operation == FileOperation.Copy) && forceWritable)
                {
                    SetFileReadOnly(destinationDirectory + @"\" + str5, false);
                }
            }
            if (operation == FileOperation.Move)
            {
                SetFileReadOnly(sourceDirectory, false);
                Directory.Delete(sourceDirectory);
            }
        }
 public ModelFileOperationRequest(
     FileOperation operation,
     OperatorType operatorType,
     ModelDialectRevision dialect)
     : base(0)
 {
     this.Operation = operation;
     this.OptorType = operatorType;
     this.Dialect = dialect;
 }
Example #25
0
 private static void UpdateRemoteIndex(file file, FileOperation op)
 {
 }