/// <summary>
        /// Save changes
        /// </summary>
        public void Save()
        {
            // Remove path
            foreach (var path in removedPaths)
            {
                documentPathService.Delete(path.Model);
            }

            removedPaths.Clear();

            foreach (var path in paths)
            {
                var fileStructure = fileStructureService.Get(path.Model.FileStructureGuid);

                if (path.Model.WorkflowId != null && path.Model.WorkflowId == Guid.Empty)
                {
                    path.Model.WorkflowId = null;
                }

                documentPathService.Save(path.Model);
            }

            IsDirty = false;
        }
Пример #2
0
        /// <summary>
        /// Sends the document to the target user id user.
        /// </summary>
        /// <param name="workflowOperation"></param>
        public void ForwardTo(WorkflowOperation workflowOperation)
        {
            var configuration  = documentWorkflowConfigurationService.Get(workflowOperation.WorkflowId);
            var accessProvider = unityContainer.Resolve <IDocumentWorkflowAccessProvider>(configuration.AccessProviderName);

            if (workflowOperation.OperationType == WorkflowOperationType.User)
            {
                // 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 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,
                        FileStructureGuid = targetStructure.Id,
                        Id              = Guid.NewGuid(),
                        DocumentGuid    = workflowOperation.DocumentId,
                        WorkflowId      = workflowOperation.WorkflowId,
                        IsProtectedPath = false,
                        WorkflowState   = DocumentWorkflowStateType.InReview
                    };
                }

                var tracker = new DocumentWorkflowTracker
                {
                    ActionName     = DocumentWorkflowStateType.Forwarded,
                    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);
                }
            }
            else
            {
                SaveWorkflowOrganizationUnitAssignment(workflowOperation, configuration.StateProviderName);
                TrackChanges(workflowOperation, DocumentWorkflowStateType.Forwarded);
                if (accessProvider != null && workflowOperation.WorkflowOrganizationId.HasValue)
                {
                    accessProvider.SetOrganizationUnitAcess(workflowOperation.WorkflowOrganizationId.Value, workflowOperation.DocumentId, configuration);
                }
            }

            var path = fileStructureDocumentPathService.Get(workflowOperation.DocumentPath);

            path.WorkflowState = DocumentWorkflowStateType.Completed;
            fileStructureDocumentPathService.Save(path);

            flowEventService.InvokeEvent("DocumentForwarded", workflowOperation.Guid, workflowOperation, workflowOperation.UserId);
        }
Пример #3
0
        /// <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);
                }
            }
        }