Exemple #1
0
        /// <summary>
        /// Sauvegarde le scénario spécifié.
        /// </summary>
        /// <param name="context">Le contexte EF.</param>
        /// <param name="allScenarios">Tous les scénarios liés.</param>
        /// <param name="recursive"><c>true</c> pour appliquer les changements récursivement sur les scénarios dérivés.</param>
        public static Task SaveBuildScenario(KsmedEntities context, Scenario[] allScenarios, Scenario updatedScenario, bool recursive)
        {
            // Consolider les solutions
            string[] distinctSolutionsLabels = updatedScenario.Actions
                                               .Where(a => a.IsReduced && !string.IsNullOrWhiteSpace(a.Reduced.Solution))
                                               .Select(a => a.Reduced.Solution)
                                               .Distinct()
                                               .ToArray();

            // Ajouter les nouvelles solutions
            foreach (string solutionLabel in distinctSolutionsLabels)
            {
                if (!updatedScenario.Solutions.Any(s => s.SolutionDescription == solutionLabel))
                {
                    // Créer une nouvelle solution
                    Solution solution = new Solution()
                    {
                        SolutionDescription = solutionLabel,
                    };
                    updatedScenario.Solutions.Add(solution);
                }
            }

            EnsureEmptySolutionExists(updatedScenario);

            // Supprimer les anciennes solutions
            Solution[] allSolutions = updatedScenario.Solutions.Where(s => !s.IsEmpty).ToArray();
            foreach (Solution sol in allSolutions)
            {
                if (!distinctSolutionsLabels.Contains(sol.SolutionDescription))
                {
                    sol.MarkAsDeleted();
                    updatedScenario.Solutions.Remove(sol);
                }
            }

            // Copier le temps original
            foreach (KActionReduced reduced in updatedScenario.Actions
                     .Where(a => a.IsReduced)
                     .Select(a => a.Reduced)
                     .Where(r => r.OriginalBuildDuration == default(long)))
            {
                reduced.OriginalBuildDuration = reduced.Action.BuildDuration;
            }

            // Appliquer l'état Approved
            UdpateSolutionsApprovedState(updatedScenario);

            ActionsRecursiveUpdate.UpdateActions(context, updatedScenario, allScenarios, out KAction[] actionsToDelete, out IList <KAction> actionsWithOriginal);

            KAction[] allActions = allScenarios
                                   .SelectMany(s => s.Actions)
                                   .Where(a => a.IsNotMarkedAsUnchanged || (a.IsReduced && a.Reduced.IsNotMarkedAsUnchanged))
                                   .ToArray();

            foreach (KAction action in allActions)
            {
                context.KActions.ApplyChanges(action);
                if (action.IsReduced)
                {
                    context.KActionsReduced.ApplyChanges(action.Reduced);
                }
            }

            foreach (KAction action in actionsWithOriginal)
            {
                SetActionsOriginalReference(context, action);
            }


            foreach (Scenario scenario in allScenarios.Where(s => s.IsNotMarkedAsUnchanged))
            {
                context.Scenarios.ApplyChanges(scenario);
            }

            foreach (Solution solution in updatedScenario.Solutions)
            {
                context.Solutions.ApplyChanges(solution);
            }

            // Vérifier que tout est correct
            ActionsTimingsMoveManagement.DebugCheckAllWBS(allScenarios.Where(s => s.IsNotMarkedAsUnchanged));

            return(context.SaveChangesAsync());
        }
Exemple #2
0
        /// <summary>
        /// Sauvegarde les actions spécifiées.
        /// </summary>
        /// <param name="context">Le contexte.</param>
        /// <param name="allScenarios">Tous les scénarios liés.</param>
        /// <param name="updatedScenario">Le scénario qui a été mis à jour.</param>
        /// <param name="recursive"><c>true</c> pour appliquer les changements récursivement sur les scénarios dérivés.</param>
        public static Task SaveAcquireData(KsmedEntities context, Scenario[] allScenarios, Scenario updatedScenario, bool recursive)
        {
            KAction[]       actionsToDelete;
            IList <KAction> actionsWithOriginal;

            if (recursive)
            {
                ActionsRecursiveUpdate.UpdateActions(context, updatedScenario, allScenarios, out actionsToDelete, out actionsWithOriginal);
            }
            else
            {
                actionsWithOriginal = null;
                actionsToDelete     = updatedScenario.Actions.Where(a => a.IsMarkedAsDeleted).ToArray();
                updatedScenario.CriticalPathIDuration = ActionsTimingsMoveManagement.GetInternalCriticalPathDuration(updatedScenario);
            }

            // Consolider les solutions vides
            EnsureEmptySolutionExists(updatedScenario);
            UdpateSolutionsApprovedState(updatedScenario);

            KAction[] allActions = allScenarios
                                   .SelectMany(s => s.Actions)
                                   .Where(a => a.IsNotMarkedAsUnchanged)
                                   .ToArray();

            foreach (KAction action in allActions)
            {
                if (!action.IsReduced)
                {
                    ApplyNewReduced(action, KnownActionCategoryTypes.I);
                }
                context.KActions.ApplyChanges(action);
                context.KActionsReduced.ApplyChanges(action.Reduced);
            }

            if (actionsWithOriginal != null)
            {
                foreach (KAction action in actionsWithOriginal)
                {
                    SetActionsOriginalReference(context, action);
                }
            }

            foreach (Scenario scenario in allScenarios.Where(s => s.IsNotMarkedAsUnchanged))
            {
                context.Scenarios.ApplyChanges(scenario);
            }

            context.Scenarios.ApplyChanges(updatedScenario);

            foreach (KAction action in actionsToDelete)
            {
                action.Predecessors.Clear();
                action.Successors.Clear();
                action.MarkAsDeleted();

                // Ne pas appeler ApplyChanges car les self tracking le gèrent mal (plantage lors de la sauvegarde)
                // Ajouter l'action au contexte si elle n'y est pas attachée
                if (!context.ObjectStateManager.TryGetObjectStateEntry(action, out ObjectStateEntry entry))
                {
                    context.AddObject(KsmedEntities.KActionsEntitySetName, action);
                    context.ObjectStateManager.ChangeObjectState(action, EntityState.Deleted);
                }
                else
                {
                    context.KActions.DeleteObject(action);
                }
            }

            // Vérifier que tout est correct
            if (recursive)
            {
                ActionsTimingsMoveManagement.DebugCheckAllWBS(allScenarios.Where(s => s.IsNotMarkedAsUnchanged));
            }

            return(context.SaveChangesAsync());
        }