Esempio n. 1
0
        /// <summary>
        /// Edit file structure
        /// </summary>
        /// <param name="parameter">Grid parameter</param>
        /// <returns>Grid invoke result, to control grid refresh</returns>
        public static GridInvokeMethodResult EditFileStructure(GridFunctionParameter parameter)
        {
            foreach (var id in parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["Id"]))
            {
                var fileStructureWindow = new FileStructureWindow();

                // Get and copy
                var fileStructure = fileStructureService.Get(id);

                fileStructureWindow.Initialize(fileStructure);
                fileStructureWindow.WindowMode = Framework.UI.WindowMode.Edit;
                fileStructureWindow.Show();

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

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

            // Do not refresh grid if no data is passed
            return(new GridInvokeMethodResult {
                RefreshGrid = false
            });
        }
        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;
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the name of the return-directory, the default is always the first directory.
        /// </summary>
        /// <param name="workflowOperation">The current workflow-operation.</param>
        /// <returns>The directory that is either the return directory or the first directory of this specific filestructure.</returns>
        public Directory GetReturnDirectory(Guid fileStructureId, Guid workflowId)
        {
            var fileStructure = fileStructureService.Get(fileStructureId);

            foreach (var directory in fileStructure.Directories)
            {
                if (directory.IsReturnDirectory && directory.WorkflowId == workflowId)
                {
                    return(directory);
                }
            }

            return(fileStructure.Directories.FirstOrDefault());
        }
        /// <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;
        }
        /// <summary>
        /// Refresh path information
        /// </summary>
        internal void RefreshPath()
        {
            Model.Path = "";
            VisualPathElements.Clear();
            var fileStructure = fileStructureService.Get(Model.FileStructureGuid);



            if (fileStructure != null)
            {
                var currentItem = fileStructure.Directories.FirstOrDefault(x => x.Id == path.DirectoryGuid);
                while (currentItem != null)
                {
                    var type = directoryTypeService.Get(currentItem.DirectoryTypeId);

                    var label = new Label();
                    label.Content             = currentItem.Name;
                    label.VerticalAlignment   = VerticalAlignment.Center;
                    label.HorizontalAlignment = HorizontalAlignment.Center;

                    VisualPathElements.Insert(0, label);

                    var image = new Image();
                    image.Width               = 16;
                    image.Height              = 16;
                    image.VerticalAlignment   = VerticalAlignment.Center;
                    image.HorizontalAlignment = HorizontalAlignment.Center;
                    image.Source              = iconService.GetByIdAsImage(type.IconId);

                    VisualPathElements.Insert(0, image);

                    if (currentItem.Parent != null)
                    {
                        currentItem = currentItem.Parent;

                        // If a parent exists, we need an arrow in the left side
                        var arrow = new Image();
                        arrow.Width               = 16;
                        arrow.Height              = 16;
                        arrow.VerticalAlignment   = VerticalAlignment.Center;
                        arrow.HorizontalAlignment = HorizontalAlignment.Center;
                        arrow.Margin              = new Thickness(3, 0, 3, 0);
                        arrow.Source              = iconService.GetByNameAsImage("filestructure_separator_16x");

                        VisualPathElements.Insert(0, arrow);
                    }
                    else
                    {
                        currentItem = null;
                        break;
                    }
                }

                if (fileStructure.StackGuid != null && fileStructure.InstanceDataGuid != null)
                {
                    var displayContent = stackService.GetInstanceDataContent((Guid)fileStructure.StackGuid, (Guid)fileStructure.InstanceDataGuid);

                    var arrow = new Image();
                    arrow.Width               = 16;
                    arrow.Height              = 16;
                    arrow.VerticalAlignment   = VerticalAlignment.Center;
                    arrow.HorizontalAlignment = HorizontalAlignment.Center;
                    arrow.Margin              = new Thickness(3, 0, 3, 0);
                    arrow.Source              = iconService.GetByNameAsImage("filestructure_separator_16x");

                    VisualPathElements.Insert(0, arrow);

                    var label = new Label();
                    label.Content             = displayContent;
                    label.VerticalAlignment   = VerticalAlignment.Center;
                    label.HorizontalAlignment = HorizontalAlignment.Center;

                    VisualPathElements.Insert(0, label);

                    var image = new Image();
                    image.Width               = 16;
                    image.Height              = 16;
                    image.VerticalAlignment   = VerticalAlignment.Center;
                    image.HorizontalAlignment = HorizontalAlignment.Center;
                    image.Source              = iconService.GetByNameAsImage("filestructure_root_16x");

                    VisualPathElements.Insert(0, image);
                }
            }
        }
        /// <summary>
        /// Initialize viewmodel
        /// </summary>
        /// <param name="documentId">Document id</param>
        public DocumentPathOverViewViewModel(Guid documentId)
        {
            this.documentId = documentId;

            documentPathService  = ServiceLocator.Current.GetInstance <IFileStructureDocumentPathService>();
            fileStructureService = ServiceLocator.Current.GetInstance <IFileStructureService>();
            directoryTypeService = ServiceLocator.Current.GetInstance <IDirectoryTypeService>();
            iconService          = ServiceLocator.Current.GetInstance <IIconService>();
            localizationService  = ServiceLocator.Current.GetInstance <ILocalizationService>();
            stackService         = ServiceLocator.Current.GetInstance <IStackService>();
            documentWorkflowAssignmentService = ServiceLocator.Current.GetInstance <IDocumentWorkflowAssignmentService>();

            removedPaths = new List <DocumentPathViewModel>();

            paths = new ObservableCollection <DocumentPathViewModel>();
            foreach (var path in documentPathService.GetByDocumentId(documentId))
            {
                var pathVM = new DocumentPathViewModel(path, fileStructureService, directoryTypeService, iconService, stackService)
                {
                    Parent = this
                };

                paths.Add(pathVM);
            }

            // Add new document path
            addDocumentPathCommand = new RelayCommand((p) =>
            {
                var newDocumentPath = SelectPath();

                if (newDocumentPath != null)
                {
                    if (CheckPathExists(newDocumentPath.Id, newDocumentPath.DirectoryGuid, newDocumentPath.FileStructureGuid))
                    {
                        MessageBox.Show(localizationService.Translate("filestructure_path_exists"), localizationService.Translate("filestructure_path_exists_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }

                    var newDocumentPathVM = new DocumentPathViewModel(newDocumentPath, fileStructureService, directoryTypeService, iconService, stackService)
                    {
                        Parent = this
                    };

                    Paths.Add(newDocumentPathVM);
                }
            });

            // Change document path
            changeDocumentPathCommand = new RelayCommand((p) =>
            {
                var selectedPath = p as DocumentPathViewModel;

                if (selectedPath.IsProtectedPath)
                {
                    MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                var fileStructure = fileStructureService.Get(selectedPath.Model.FileStructureGuid);


                var selectPathWindow = new FileStructureWindow();
                selectPathWindow.Initialize(fileStructure);
                selectPathWindow.IsInSelectMode = true;

                selectPathWindow.Loaded += (s, e) =>
                {
                    selectPathWindow.ViewModel.SelectedDirectory = selectPathWindow.ViewModel.RawDirectories.FirstOrDefault(x => x.Model.Id == selectedPath.Model.DirectoryGuid);
                };

                selectPathWindow.ShowDialog();

                if (selectPathWindow.SelectedDirectory != null)
                {
                    if (CheckPathExists(selectedPath.Model.Id, selectPathWindow.SelectedDirectory.Id, fileStructure.Id))
                    {
                        MessageBox.Show(localizationService.Translate("filestructure_path_exists"), localizationService.Translate("filestructure_path_exists_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }

                    selectedPath.Model.DirectoryGuid = selectPathWindow.SelectedDirectory.Id;
                    selectedPath.Model.WorkflowId    = selectPathWindow.SelectedDirectory.WorkflowId;
                    selectedPath.RefreshPath();
                }
            });

            // Remove document path
            removeDocumentPathCommand = new RelayCommand((p) =>
            {
                var selectedPath = p as DocumentPathViewModel;

                if (selectedPath.IsProtectedPath)
                {
                    MessageBox.Show(localizationService.Translate("filestructure_path_protected"), localizationService.Translate("filestructure_path_protected_title"), MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                var messageBoxResult = MessageBox.Show(localizationService.Translate("filestructure_remove_path"), localizationService.Translate("filestructure_remove_path_title"), MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    removedPaths.Add(selectedPath);
                    paths.Remove(selectedPath);
                }
            });
        }
Esempio n. 7
0
        /// <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);
        }