private void Initialize()
        {
            Dispatcher.BeginInvoke((Action)(() =>
            {
                FileStructure fileStructure = null;
                if (instanceDataChanged || Content == null)
                {
                    fileStructureControl = new FileStructureControl();
                    Content = fileStructureControl;
                }
                fileStructure = fileStructureService.GetByInstanceDataGuid(InstanceDataGuid);
                if (fileStructure == null)
                {
                    MessageBoxResult selectFromTemplateResult = MessageBoxResult.None;

                    selectFromTemplateResult = MessageBox.Show(localizationService.Translate("filestructure_select_template_msg"), localizationService.Translate("filestructure_select_template_title"), MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (selectFromTemplateResult == MessageBoxResult.No)
                    {
                        // Create new, maybe from template?
                        fileStructure = new FileStructure
                        {
                            InstanceDataGuid = InstanceDataGuid,
                            StackGuid = StackHelper.Singleton.GetStackGuidByName(StackName),
                            IsTemplate = false
                        };
                    }
                    else
                    {
                        AsyncItemBox templateItemBox = null;
                        templateItemBox = ItemBoxManager.GetItemBoxFromDB("IB_FileStructureTemplate");
                        templateItemBox.ShowDialog();

                        if (templateItemBox.SelectedItem != null)
                        {
                            var templateId = (Guid)templateItemBox.GetSelectedItemCell("Id");
                            var template = fileStructureService.Get(templateId);

                            // Copy template and connect with instance data entry
                            fileStructure = template.Copy();
                            fileStructure.IsTemplate = false;
                            fileStructure.InstanceDataGuid = InstanceDataGuid;
                            fileStructure.StackGuid = StackHelper.Singleton.GetStackGuidByName(StackName);
                        }
                    }
                }

                if (fileStructure == null)
                {
                    return;
                }

                fileStructureService.Save(fileStructure);
                // Initialize data context and keep load order
                fileStructureControl.Initialize(fileStructure);
                instanceDataChanged = false;
            }));
        }
Exemplo n.º 2
0
        internal Control_DocumentWorkflow(DBInternPage DBInternPage)
        {
            InitializeComponent();

            documentWorkflowUserService        = CommonServiceLocator.ServiceLocator.Current.GetInstance <IDocumentWorkflowUserService>();
            documentWorkflowAppSettingsService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IDocumentWorkflowAppSettingsService>();
            fileStructureService        = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFileStructureService>();
            sessionService              = CommonServiceLocator.ServiceLocator.Current.GetInstance <ISessionService>();
            documentWorkflowAppSettings = documentWorkflowAppSettingsService.Get(DBInternPage.Guid);

            if (documentWorkflowAppSettings == null || string.IsNullOrWhiteSpace(documentWorkflowAppSettings.InternalName))
            {
                MessageBox.Show("Konfiguration nicht vorhanden", "...");
                return;
            }

            PageName = documentWorkflowAppSettings.PublicName;

            documentWorkflowUser = documentWorkflowUserService.Get(sessionService.CurrentSession.UserId);

            if (documentWorkflowUser == null)
            {
                documentWorkflowUser = new DocumentWorkflowUser
                {
                    UserId    = sessionService.CurrentSession.UserId,
                    IsDeleted = false
                                // TODO: Set current tenant
                };

                documentWorkflowUserService.Save(documentWorkflowUser);
            }

            fileStructureConfiguration = fileStructureService.GetByInstanceDataGuid(documentWorkflowUser.Guid);
            if (fileStructureConfiguration == null)
            {
                fileStructureConfiguration = new FileStructure
                {
                    IsTemplate       = false,
                    InstanceDataGuid = documentWorkflowUser.Guid,
                    Id        = Guid.NewGuid(),
                    Name      = documentWorkflowAppSettings.PublicName,
                    StackGuid = stackGuid
                };

                fileStructureService.Save(fileStructureConfiguration);
            }

            fileStructureConfiguration.Name = $"{documentWorkflowAppSettings.PublicName}({Framework.Base.UserManager.Singleton.GetFriendlyName(sessionService.CurrentSession.UserId)})";

            fileStructureControl.Initialize(fileStructureConfiguration);

            Loaded += ControlLoaded;
        }
        /// <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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Open file structure editor for instance data
        /// </summary>
        /// <param name="parameter">Grid parameter</param>
        /// <returns>Grid invoke result, to control grid refresh</returns>
        public static GridInvokeMethodResult OpenFileStructureEditor(GridFunctionParameter parameter)
        {
            var fileStructureWindow = new FileStructureWindow();

            // TODO: Maybe change to foreach....
            var instanceDataGuid = parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["Guid"]).FirstOrDefault();
            var stackGuid        = parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["StackGuid"]).FirstOrDefault();

            var fileStructure = fileStructureService.GetByInstanceDataGuid(instanceDataGuid);

            if (fileStructure == null)
            {
                var selectFromTemplateResult = MessageBox.Show(localizationService.Translate("filestructure_select_template_msg"), localizationService.Translate("filestructure_select_template_title"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                if (selectFromTemplateResult == MessageBoxResult.Cancel)
                {
                    return new GridInvokeMethodResult {
                               RefreshGrid = false
                    }
                }
                ;

                if (selectFromTemplateResult == MessageBoxResult.No)
                {
                    // Create new, maybe from template?
                    fileStructure = new FileStructure
                    {
                        InstanceDataGuid = instanceDataGuid,
                        StackGuid        = stackGuid,
                        IsTemplate       = false
                    };
                }
                else
                {
                    var templateItemBox = ItemBoxManager.GetItemBoxFromDB("IB_FileStructureTemplate");
                    templateItemBox.ShowDialog();

                    if (templateItemBox.SelectedItem != null)
                    {
                        var templateId = (Guid)templateItemBox.GetSelectedItemCell("Id");
                        var template   = fileStructureService.Get(templateId);

                        // Copy template and connect with instance data entry
                        fileStructure                  = template.Copy();
                        fileStructure.IsTemplate       = false;
                        fileStructure.InstanceDataGuid = instanceDataGuid;
                        fileStructure.StackGuid        = stackGuid;
                    }
                }

                // Exit if no file structure is created
                if (fileStructure == null)
                {
                    return new GridInvokeMethodResult {
                               RefreshGrid = false
                    }
                }
                ;
            }

            // Initialize window
            fileStructureWindow.Initialize(fileStructure);

            fileStructureWindow.Show();

            // Refresh grid after closed
            fileStructureWindow.Closed += (s, e) =>
            {
                parameter.GridView.RefreshData();
            };

            return(new GridInvokeMethodResult
            {
                RefreshGrid = false,
                Window = fileStructureWindow
            });
        }

        #endregion
    }
}