/// <summary> /// Initialize viewmodel /// </summary> /// <param name="path">Path instance</param> /// <param name="fileStructureService">File structure service</param> /// <param name="directoryTypeService">Directory type service</param> /// <param name="iconService">Icon service</param> /// <param name="stackService">Stack service</param> public DocumentPathViewModel(FileStructureDocumenPath path, IFileStructureService fileStructureService, IDirectoryTypeService directoryTypeService, IIconService iconService, IStackService stackService) { this.path = path; this.fileStructureService = fileStructureService; this.iconService = iconService; this.directoryTypeService = directoryTypeService; this.stackService = stackService; VisualPathElements = new ObservableCollection <FrameworkElement>(); RefreshPath(); }
/// <summary> /// Checks the document out of a workflow organization unit. /// </summary> /// <param name="workflowOperation"></param> /// <returns>Document path id</returns> public Guid DocumentCheckout(WorkflowOperation workflowOperation) { //Check if the document is still inside if (documentWorkflowOrganizationUnitAssignmentService.GetByIds(workflowOperation.DocumentId, (Guid)workflowOperation.WorkflowOrganizationId) != null) { documentWorkflowOrganizationUnitAssignmentService.DeleteByIds(workflowOperation.DocumentId, (Guid)workflowOperation.WorkflowOrganizationId); // Add path to forwarded user var workflow = documentWorkflowUserService.Get(workflowOperation.TargetUserId); if (workflow == null) { throw new DocumentWorkflowException("workflow is null"); } var targetStructure = fileStructureService.GetByInstanceDataGuid(workflow.Guid); if (targetStructure == null) { throw new DocumentWorkflowException("targetStructure is null"); } var targetPath = new FileStructureDocumenPath { DirectoryGuid = (Guid)workflowOperation.DirectoryId, WorkflowId = workflowOperation.WorkflowId, FileStructureGuid = targetStructure.Id, Id = Guid.NewGuid(), DocumentGuid = workflowOperation.DocumentId, IsProtectedPath = false, WorkflowState = DocumentWorkflowStateType.InReview }; var tracker = new DocumentWorkflowTracker { ActionName = DocumentWorkflowStateType.ForwardedCopy, CreateDateTime = DateTime.Now, DocumentId = targetPath.DocumentGuid, TargetUserId = workflowOperation.TargetUserId, UserId = workflowOperation.UserId }; documentWorkflowTrackerService.Save(tracker); fileStructureDocumentPathService.Save(targetPath); return(targetPath.Id); } throw new CoreException("S-0000009", "9ae836fb-40e8-43d3-9d57-85c17647684a", ExceptionType.Expected); }
/// <summary> /// Select document path /// </summary> /// <returns></returns> private FileStructureDocumenPath SelectPath() { // Show stack selection var selectStackItemBox = ItemBoxManager.GetItemBoxFromDB("IB_FileStructure_Stack"); selectStackItemBox.ShowDialog(); // Select instance-data if (selectStackItemBox.SelectedItem != null) { var selectDataItemBox = ItemBoxManager.GetItemBoxFromDB(selectStackItemBox.GetSelectedItemCell("StackDataItemBox").ToString()); selectDataItemBox.ShowDialog(); if (selectDataItemBox.SelectedItem != null) { var fileStructure = fileStructureService.GetByInstanceDataGuid((Guid)selectDataItemBox.GetSelectedItemCell("Guid")); if (fileStructure == null) { MessageBox.Show(localizationService.Translate("filestructure_path_no_selection"), localizationService.Translate("filestructure_path_no_selection_title"), MessageBoxButton.OK, MessageBoxImage.Information); } else { var selectPathWindow = new FileStructureWindow(); selectPathWindow.Initialize(fileStructure); selectPathWindow.IsInSelectMode = true; selectPathWindow.ShowDialog(); if (selectPathWindow.SelectedDirectory != null) { var newDocumentPath = new FileStructureDocumenPath { Id = Guid.NewGuid(), DirectoryGuid = selectPathWindow.SelectedDirectory.Id, DocumentGuid = documentId, FileStructureGuid = fileStructure.Id, WorkflowId = selectPathWindow.SelectedDirectory.WorkflowId }; return(newDocumentPath); } } } } return(null); }
/// <summary> /// Sends a copy to the target user. /// </summary> /// <param name="workflowOperation"></param> public void ForwardCopyTo(WorkflowOperation workflowOperation) { var configuration = documentWorkflowConfigurationService.Get(workflowOperation.WorkflowId); var accessProvider = unityContainer.Resolve <IDocumentWorkflowAccessProvider>(configuration.AccessProviderName); if (workflowOperation.OperationType == WorkflowOperationType.WorkflowOrganizationUnit) { SaveWorkflowOrganizationUnitAssignment(workflowOperation, configuration.StateProviderName); TrackChanges(workflowOperation, DocumentWorkflowStateType.ForwardedCopy); if (accessProvider != null && workflowOperation.WorkflowOrganizationId.HasValue) { accessProvider.SetOrganizationUnitAcess(workflowOperation.WorkflowOrganizationId.Value, workflowOperation.DocumentId, configuration); } } else { // Add path to forwarded user var workflow = documentWorkflowUserService.Get(workflowOperation.TargetUserId); if (workflow == null) { throw new DocumentWorkflowException("workflow is null"); } var targetStructure = fileStructureService.GetByInstanceDataGuid(workflow.Guid); if (targetStructure == null) { throw new DocumentWorkflowException("targetStructure is null"); } // TODO: Check for null var existingStructures = fileStructureDocumentPathService.GetByDocumentId(workflowOperation.DocumentId) .ToList(); if (existingStructures == null) { throw new DocumentWorkflowException("existingStructures is null"); } var targetPath = existingStructures.FirstOrDefault(x => x.FileStructureGuid == targetStructure.Id); if (targetPath != null) { var returnFolder = GetReturnDirectory(targetPath.FileStructureGuid, targetPath.WorkflowId.Value); targetPath.DirectoryGuid = returnFolder.Id; targetPath.WorkflowState = DocumentWorkflowStateType.InReview; } else { var firstDirectory = FindWorkflowDirectory(targetStructure, workflowOperation.WorkflowId, workflowOperation.DocumentId, workflowOperation.TargetUserId); if (firstDirectory == null) { throw new DocumentWorkflowException("existingStructures is null"); } targetPath = new FileStructureDocumenPath { DirectoryGuid = firstDirectory.Id, WorkflowId = firstDirectory.WorkflowId, FileStructureGuid = targetStructure.Id, Id = Guid.NewGuid(), DocumentGuid = workflowOperation.DocumentId, IsProtectedPath = false, WorkflowState = DocumentWorkflowStateType.InReview }; } var tracker = new DocumentWorkflowTracker { ActionName = DocumentWorkflowStateType.ForwardedCopy, CreateDateTime = DateTime.Now, DocumentId = targetPath.DocumentGuid, TargetUserId = workflowOperation.TargetUserId, UserId = workflowOperation.UserId }; documentWorkflowTrackerService.Save(tracker); fileStructureDocumentPathService.Save(targetPath); if (accessProvider != null) { accessProvider.SetUserAccess(workflowOperation.TargetUserId, workflowOperation.DocumentId, targetPath.Id, targetStructure.Id, configuration); } flowEventService.InvokeEvent("DocumentForwardedCopy", workflowOperation.Guid, workflowOperation, workflowOperation.UserId); } }
/// <summary> /// Drop event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e) { // Find RadTreeViewItem var item = e.OriginalSource as RadTreeViewItem; if (e.OriginalSource != null && e.OriginalSource is DependencyObject) { var dependencySource = (DependencyObject)e.OriginalSource; item = Framework.UI.WPFVisualTreeHelper.FindParent <RadTreeViewItem>(dependencySource); } var targetDirectory = item?.DataContext as DirectoryViewModel; // Save target filestructure before drop action if (targetDirectory.StructureViewModel.IsDirty) { targetDirectory.StructureViewModel.Save(); } //Check if the the folder is a workflow folder and has a workflow assigned if (IsWorkflowDirectory(targetDirectory)) { return; } // File drag & drop DataObject dataObject = (e.Data as DataObject); var refreshDirectoryPath = true; if (dataObject != null && dataObject.ContainsFileDropList()) { foreach (var file in dataObject.GetFileDropList()) { Helper.ArchiveHelper.ArchiveFile(targetDirectory.StructureViewModel.Model, targetDirectory.Model, file); } refreshDirectoryPath = false; } else if (dataObject != null && dataObject.GetData("FileGroupDescriptorW") != null) { var outlookDataObject = new OutlookDataObject(dataObject); string[] filenames = (string[])outlookDataObject.GetData("FileGroupDescriptorW"); var fileStreams = (MemoryStream[])outlookDataObject.GetData("FileContents"); string directory = GlobalSettings.AppDataPath + "\\Temp\\Blobs\\"; if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { //use the fileindex to get the name and data stream string filename = filenames[fileIndex]; MemoryStream filestream = fileStreams[fileIndex]; //save the file stream using its name to the application path FileStream outputStream = File.Create(directory + filename); filestream.WriteTo(outputStream); outputStream.Close(); if (filename.ToLower().EndsWith(".msg")) { try { OutlookStorage.Message msg = new OutlookStorage.Message(directory + filename); DateTime receiveDateTime = msg.ReceivedDate; msg.Dispose(); File.SetLastWriteTime(directory + filename, receiveDateTime); } catch (Exception ex) { Log.LogManagerInstance.Instance.Error(string.Format(@"Invalid mail format: {0}", filename), ex); } } else { File.SetLastWriteTime(directory + filename, DateTime.Now); } Helper.ArchiveHelper.ArchiveFile(targetDirectory.StructureViewModel.Model, targetDirectory.Model, directory + filename); } refreshDirectoryPath = false; } else if (dataObject != null && dataObject.GetData(typeof(GridViewPayload)) != null) { var service = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFileStructureDocumentPathService>(); var localizationService = CommonServiceLocator.ServiceLocator.Current.GetInstance <ILocalizationService>(); var payload = dataObject.GetData(typeof(GridViewPayload)) as GridViewPayload; foreach (var path in payload.DataObjects.OfType <FileStructureDocumenPath>()) { var copyMode = Keyboard.Modifiers == ModifierKeys.Shift; if (copyMode) { var newPath = new FileStructureDocumenPath { DirectoryGuid = targetDirectory.Model.Id, FileStructureGuid = targetDirectory.StructureViewModel.Model.Id, DocumentGuid = path.DocumentGuid, WorkflowId = targetDirectory.Model.WorkflowId }; service.Save(newPath); } else { if (path.IsProtectedPath) { MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information); continue; } path.DirectoryGuid = targetDirectory.Model.Id; path.WorkflowId = targetDirectory.Model.WorkflowId; path.FileStructureGuid = targetDirectory.StructureViewModel.Model.Id; service.Save(path); } if (targetDirectory.Model.WorkflowId != null) { var configurationService = CommonServiceLocator.ServiceLocator.Current.GetInstance <Workflow.IDocumentWorkflowConfigurationService>(); var workflow = configurationService.Get(targetDirectory.Model.WorkflowId.Value); if (!string.IsNullOrWhiteSpace(workflow.AccessProviderName)) { var accessProvider = CommonServiceLocator.ServiceLocator.Current.GetInstance <Workflow.IDocumentWorkflowAccessProvider>(workflow.AccessProviderName); accessProvider.SetUserAccess(GlobalSettings.UserId, path.DocumentGuid, path.Id, path.FileStructureGuid, workflow); } } } refreshDirectoryPath = false; // Refresh grid if (payload.Grid is CursorGridViewControl) { (payload.Grid as CursorGridViewControl).RefreshData(); } } // Save target filestructure before drop action if (refreshDirectoryPath) { targetDirectory.StructureViewModel.Save(); var directoriesToCheck = new List <DirectoryViewModel>(); directoriesToCheck.Add(targetDirectory); //Recalculating the path through the save method while (directoriesToCheck.Any()) { var innerDirectories = new List <DirectoryViewModel>(); foreach (var subDirectory in directoriesToCheck) { var guid = subDirectory.Model.Id; var list = fileStructureDocumentPathService.GetByDirectoryId(guid); foreach (FileStructureDocumenPath fileStructureDocumenPath in list) { fileStructureDocumentPathService.Save(fileStructureDocumenPath); } innerDirectories.AddRange(subDirectory.Directories); } directoriesToCheck.Clear(); directoriesToCheck.AddRange(innerDirectories); } } }
/// <summary> /// Save file structure to database /// </summary> /// <param name="obj">Object to save</param> /// <returns>True if successfull</returns> public bool Save(FileStructureDocumenPath obj) { var fileStructure = structureService.Get(obj.FileStructureGuid); obj.Path = ""; if (fileStructure != null) { var currentItem = fileStructure.Directories.FirstOrDefault(x => x.Id == obj.DirectoryGuid); while (currentItem != null) { obj.Path = obj.Path.Insert(0, $"/{currentItem.Name}"); if (currentItem.Parent != null) { currentItem = currentItem.Parent; } else { currentItem = null; break; } } } var result = repository.Save(obj); // Path has changed if (obj.PreviousPath != obj.Path || obj.PreviousWorkflowState != obj.WorkflowState) { try { fileStructureDocumentPathTrackingRepository.Save(new FileStructureDocumenPathTracking { Id = Guid.NewGuid(), DirectoryGuid = obj.DirectoryGuid, DocumentGuid = obj.DocumentGuid, WorkflowState = obj.WorkflowState, FileStructureGuid = obj.FileStructureGuid, FileStructureHash = obj.FileStructureHash, IsProtectedPath = obj.IsProtectedPath, Path = obj.Path ?? "", StorageHash = obj.StorageHash, UserId = sessionService.CurrentSession.UserId, PreviousPath = obj.PreviousPath ?? "" }); if (obj.WorkflowId.HasValue) { var workflowId = obj.WorkflowId.Value; var workflow = documentWorkflowConfigurationService.Get(workflowId); if (workflow == null) { throw new Exception($"Could not find workflow: {workflowId}"); } var stateProvider = unityContainer.Resolve <IDocumentWorkflowStateProvider>(workflow.StateProviderName); var state = stateProvider.ResolveDocumentWorkflowState(obj.DocumentGuid, workflowId); if (state == null) { throw new Exception($"Could not resolve initial state for document: {obj.DocumentGuid}"); } if (!documentWorkflowAssignmentService.Exists(obj.DocumentGuid, workflowId)) { var assignment = new DocumentWorkflowAssignment { DocumentId = obj.DocumentGuid, WorkflowId = workflowId, StateId = state.Guid }; documentWorkflowAssignmentService.Save(assignment); } else { documentWorkflowAssignmentService.SetState(obj.DocumentGuid, workflowId, state.Guid); } } } catch (Exception ex) { Log.LogManagerInstance.Instance.Error($"Could not write file structure path tracking: Document id: {obj.DocumentGuid}", ex); } } return(result); }
/// <summary> /// Delete path by object id /// </summary> /// <param name="obj">Object to delete</param> /// <returns>True if successfull</returns> public bool Delete(FileStructureDocumenPath obj) { return(repository.Delete(obj)); }