コード例 #1
0
        /// <summary>
        /// Prédit les référentiels potentiels à merger.
        /// </summary>
        /// <param name="data">Les données contenant l'export.</param>
        public virtual async Task <ProjectImport> PredictMergedReferentialsProject(byte[] data) =>
        await Task.Run(async() =>
        {
            using (var context = ContextFactory.GetNewContext())
            {
                ProjectMigration migration = new ProjectMigration(data);

                ProjectExport project = await migration.Migrate();

                // Charger les référentiels
                Referentials dbStandardReferentials = await LoadAllStandardReferentials(context);

                Dictionary <IActionReferentialProcess, IActionReferential> referentialsProject = new Dictionary <IActionReferentialProcess, IActionReferential>();
                Dictionary <IActionReferential, IActionReferential> referentialsStd            = new Dictionary <IActionReferential, IActionReferential>();

                DetermineMergeCandidates(project.ReferentialsProject, dbStandardReferentials, referentialsProject);
                DetermineMergeCandidates(project.ReferentialsStandard, dbStandardReferentials, referentialsStd);

                return(new ProjectImport()
                {
                    ExportedProject = project,
                    ProjectReferentialsMergeCandidates = referentialsProject,
                    StandardReferentialsMergeCandidates = referentialsStd,
                });
            }
        });
コード例 #2
0
        /// <summary>
        /// Prédit les référentiels potentiels à merger.
        /// </summary>
        /// <param name="projectId">L'identifiant du projet.</param>
        /// <param name="stream">Le flux de données contenant l'export.</param>
        public virtual async Task <VideoDecompositionImport> PredictMergedReferentialsVideoDecomposition(int projectId, Stream stream) =>
        await Task.Run(async() =>
        {
            using (var context = ContextFactory.GetNewContext())
            {
                NetDataContractSerializer ser = new NetDataContractSerializer()
                {
                    Binder = new SerializationOperations.AnyVersionSerializationBinder(),
                };
                VideoDecompositionExport videoDecomposition = (VideoDecompositionExport)ser.ReadObject(stream);

                stream.Close();

                // Charger les référentiels
                Referentials dbStandardReferentials = await LoadAllStandardReferentials(context);
                Referentials dbProjectReferentials  = await LoadAllProjectReferentials(context, (await context.Projects.SingleAsync(p => p.ProjectId == projectId)).ProcessId);

                Dictionary <IActionReferentialProcess, IActionReferential> referentialsProject = new Dictionary <IActionReferentialProcess, IActionReferential>();
                Dictionary <IActionReferential, IActionReferential> referentialsStd            = new Dictionary <IActionReferential, IActionReferential>();

                DetermineMergeCandidates(videoDecomposition.ReferentialsProject, dbStandardReferentials, referentialsProject);
                DetermineMergeCandidates(videoDecomposition.ReferentialsStandard, dbStandardReferentials, referentialsStd);

                DetermineMergeCandidates(videoDecomposition.ReferentialsProject, dbProjectReferentials, referentialsProject);
                DetermineMergeCandidates(videoDecomposition.ReferentialsStandard, dbProjectReferentials, referentialsStd);

                return(new VideoDecompositionImport()
                {
                    ExportedVideoDecomposition = videoDecomposition,
                    ProjectReferentialsMergeCandidates = referentialsProject,
                    StandardReferentialsMergeCandidates = referentialsStd,
                });
            }
        });
コード例 #3
0
        /// <summary>
        /// Obtient les données pour l'écran Construire.
        /// </summary>
        /// <param name="context">Le contexte EF.</param>
        /// <param name="projectId">L'identifiant du projet.</param>
        /// <param name="natureFilter">Le filtre sur les codes de nature de scénario.</param>
        /// <returns>Les données</returns>
        public async Task <BuildData> GetBuildData(KsmedEntities context, int projectId, GetDataScenarioNatures natureFilter)
        {
            IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await GetReferentialsUse(context, projectId);

            Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed);

            BuildData data = new BuildData
            {
                Categories = referentials.Categories,
                Skills     = referentials.Skills,
                Resources  = referentials.Resources,
                Videos     = await context.Projects
                             .Include(nameof(Project.Process))
                             .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}")
                             .Where(p => p.ProjectId == projectId)
                             .SelectMany(p => p.Process.Videos)
                             .ToArrayAsync(),
                ActionTypes = (await context.ActionTypes.ToArrayAsync()).OrderBy(a => a.ActionTypeCode, new KnownActionCategoryTypes.ActionCategoryTypeDefaultOrderComparer()).ToArray()
            };

            Project project = await context.Projects.SingleAsync(p => p.ProjectId == projectId);

            data.CustomFieldsLabels = GetCustomFieldsLabels(project);

            Scenario[] scenarios = await LoadScenarios(context, projectId, referentialsUsed, natureFilter);

            ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios);

            data.Scenarios = scenarios;

            return(data);
        }
コード例 #4
0
 /// <summary>
 /// Met à jour les référentiels.
 /// </summary>
 /// <param name="referentials">Les référentiels</param>
 public void UpdateProjectReferentials(IEnumerable <ProjectReferential> referentials)
 {
     if (referentials != null)
     {
         Referentials        = referentials.Select(r => new ProjectReferentialInfo(r)).ToDictionary(r => r.Referential);
         ReferentialsEnabled = Referentials.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.IsEnabled);
     }
     else
     {
         Referentials        = null;
         ReferentialsEnabled = null;
     }
 }
コード例 #5
0
        /// <summary>
        /// Obtient les données pour l'écran Restituer.
        /// </summary>
        /// <param name="context">le contexte EF.</param>
        /// <param name="projectId">L'identifiant du projet.</param>
        /// <returns>
        /// Les données
        /// </returns>
        public async Task <RestitutionData> GetRestitutionData(KsmedEntities context, int projectId)
        {
            IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await GetReferentialsUse(context, projectId);

            Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed);

            ActionCategory[] categories = referentials.Categories;
            await context.Projects
            .Include(nameof(Project.Process))
            .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}")
            .Where(p => p.ProjectId == projectId)
            .SelectMany(p => p.Process.Videos)
            .ToArrayAsync();

            Scenario[] scenarios = await context.Scenarios
                                   .Where(s => s.ProjectId == projectId)
                                   .ToArrayAsync();

            await Queries.LoadScenariosDetails(context, scenarios, referentialsUsed);

            ILookup <int, KAction> actionsToLoad = scenarios
                                                   .SelectMany(a => a.Actions)
                                                   .Where(a => a.IsReduced && a.OriginalActionId.HasValue)
                                                   .ToLookup(a => a.OriginalActionId.Value, a => a);

            if (actionsToLoad.Any())
            {
                foreach (var duration in await GetActionsBuildDurations(context, actionsToLoad.Select(g => g.Key)))
                {
                    foreach (KAction action in actionsToLoad[duration.ActionId])
                    {
                        action.Reduced.Saving = duration.BuildDuration - action.BuildDuration;
                    }
                }
            }

            ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios);
            foreach (Scenario scenario in scenarios)
            {
                UpdateIsGroup(scenario);
            }

            RestitutionData data = new RestitutionData()
            {
                Scenarios        = scenarios,
                ActionCategories = categories,
            };

            return(data);
        }
コード例 #6
0
        /// <summary>
        /// Charge tous les référentiels projets du projet.
        /// </summary>
        /// <param name="context">Le contexte EF.</param>
        /// <param name="projectId">L'ide du projet.</param>
        /// <returns>Les référentiels chargés.</returns>
        private static async Task <Referentials> LoadAllProjectReferentials(KsmedEntities context, int processId)
        {
            var dbProjectReferentials = new Referentials
            {
                Categories = await context.ActionCategories.OfType <ActionCategory>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Equipments = await context.Resources.OfType <Equipment>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Operators  = await context.Resources.OfType <Operator>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref1s      = await context.Refs1.OfType <Ref1>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref2s      = await context.Refs2.OfType <Ref2>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref3s      = await context.Refs3.OfType <Ref3>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref4s      = await context.Refs4.OfType <Ref4>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref5s      = await context.Refs5.OfType <Ref5>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref6s      = await context.Refs6.OfType <Ref6>().Where(r => r.ProcessId == processId).ToArrayAsync(),
                Ref7s      = await context.Refs7.OfType <Ref7>().Where(r => r.ProcessId == processId).ToArrayAsync(),
            };

            return(dbProjectReferentials);
        }
コード例 #7
0
        /// <summary>
        /// Détermine les candidats pour la fusion des référentiels.
        /// </summary>
        /// <typeparam name="TCandidateReferential">Le type de référentiel pour les candidats.</typeparam>
        /// <typeparam name="TReplacementReferential">Le type de réferentiel pour les remplacements.</typeparam>
        /// <param name="referentials">Les référentiels à tester.</param>
        /// <param name="dbStandardReferentials">Les référentiels standard en base.</param>
        /// <param name="candidatesCollection">La collection de candidats au merge.</param>
        private void DetermineMergeCandidates <TCandidateReferential, TReplacementReferential>(TCandidateReferential[] referentials, Referentials dbStandardReferentials,
                                                                                               IDictionary <TCandidateReferential, TReplacementReferential> candidatesCollection)
            where TCandidateReferential : IActionReferential
        {
            foreach (var referential in referentials)
            {
                IEnumerable <IActionReferential> collection;

                if (referential is ActionCategory)
                {
                    collection = dbStandardReferentials.Categories;
                }
                else if (referential is Equipment)
                {
                    collection = dbStandardReferentials.Equipments;
                }
                else if (referential is Operator)
                {
                    collection = dbStandardReferentials.Operators;
                }
                else if (referential is Ref1)
                {
                    collection = dbStandardReferentials.Ref1s;
                }
                else if (referential is Ref2)
                {
                    collection = dbStandardReferentials.Ref2s;
                }
                else if (referential is Ref3)
                {
                    collection = dbStandardReferentials.Ref3s;
                }
                else if (referential is Ref4)
                {
                    collection = dbStandardReferentials.Ref4s;
                }
                else if (referential is Ref5)
                {
                    collection = dbStandardReferentials.Ref5s;
                }
                else if (referential is Ref6)
                {
                    collection = dbStandardReferentials.Ref6s;
                }
                else if (referential is Ref7)
                {
                    collection = dbStandardReferentials.Ref7s;
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(referentials));
                }

                IActionReferential matchingReferential = collection.FirstOrDefault(r => string.Compare(r.Label, referential.Label, StringComparison.CurrentCultureIgnoreCase) == 0);

                if (matchingReferential != null && !candidatesCollection.ContainsKey(referential))
                {
                    candidatesCollection[referential] = (TReplacementReferential)matchingReferential;
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Obtient toutes les données du projet spécifié.
        /// </summary>
        /// <param name="projectId">L'identifiant du projet.</param>
        public virtual async Task <RestitutionData> GetFullProjectDetails(int projectId) =>
        await Task.Run(async() =>
        {
            using (var context = ContextFactory.GetNewContext(_securityContext.CurrentUser, _localizationManager))
            {
                IDictionary <ProcessReferentialIdentifier, bool> referentialsUsed = await _sharedScenarioActionsOperations.GetReferentialsUse(context, projectId);
                Referentials referentials = await Queries.LoadAllReferentialsOfProject(context, projectId, referentialsUsed);

                //await context.Videos.Where(v => v.ProjectId == projectId).ToArrayAsync();
                await context.ScenarioNatures.ToArrayAsync();
                await context.ScenarioStates.ToArrayAsync();
                await context.ActionTypes.ToArrayAsync();
                await context.ActionValues.ToArrayAsync();

                Project project = await context.Projects
                                  .Include(nameof(Project.Process))
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.Videos)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}.{nameof(UserRoleProcess.User)}")
                                  .Include($"{nameof(Project.Process)}.{nameof(Procedure.UserRoleProcesses)}.{nameof(UserRoleProcess.User)}.{nameof(User.DefaultLanguage)}")
                                  .Include(nameof(Project.Scenarios))
                                  .Include($"{nameof(Project.Scenarios)}.{nameof(Scenario.Actions)}")
                                  .Include(nameof(Project.Objective))
                                  .FirstAsync(s => s.ProjectId == projectId);

                project.ScenariosCriticalPath = PrepareService.GetSummary(project, true);

                // Scénarios
                foreach (Scenario scenario in project.Scenarios.Where(s => s.OriginalScenarioId.HasValue))
                {
                    // Remapper l'original
                    scenario.Original = project.Scenarios.Single(s => s.ScenarioId == scenario.OriginalScenarioId);

                    ScenarioCriticalPath matchingCriticalItem = project.ScenariosCriticalPath.FirstOrDefault(i => i.Id == scenario.ScenarioId);
                    if (matchingCriticalItem != null)
                    {
                        matchingCriticalItem.OriginalLabel = scenario.Original.Label;
                    }
                }

                ProjectReferential[] projectReferentials = await context.ProjectReferentials.Where(pr => pr.ProjectId == projectId).ToArrayAsync();

                User user = await context.Users.FirstAsync(u => u.UserId == project.CreatedByUserId);

                ModificationsUsers modificationsUsers = new ModificationsUsers
                {
                    CreatedByFullName      = (await context.Users.FirstAsync(u => u.UserId == project.ModifiedByUserId)).FullName,
                    LastModifiedByFullName = (await context.Users.FirstAsync(u => u.UserId == project.ModifiedByUserId)).FullName
                };

                Scenario[] scenarios = await context.Scenarios
                                       .Where(s => s.ProjectId == projectId)
                                       .ToArrayAsync();

                await Queries.LoadScenariosDetails(context, scenarios, referentialsUsed);

                ILookup <int, KAction> actionsToLoad = scenarios
                                                       .SelectMany(a => a.Actions)
                                                       .Where(a => a.IsReduced && a.OriginalActionId.HasValue)
                                                       .ToLookup(a => a.OriginalActionId.Value, a => a);

                if (actionsToLoad.Any())
                {
                    foreach (var duration in await _sharedScenarioActionsOperations.GetActionsBuildDurations(context, actionsToLoad.Select(g => g.Key)))
                    {
                        foreach (KAction action in actionsToLoad[duration.ActionId])
                        {
                            action.Reduced.Saving = duration.BuildDuration - action.BuildDuration;
                        }
                    }
                }

                ScenarioActionHierarchyHelper.MapScenariosActionsOriginals(scenarios);

                return(new RestitutionData()
                {
                    Project = project,
                    ProjectCreatedByUser = user,
                    Scenarios = scenarios,
                    ActionCategories = referentials.Categories,
                    ModificationsUsers = modificationsUsers,
                    ReferentialsUse = projectReferentials,
                });
            }
        });