private void MergeReferentials() { // Référentiels projet foreach (var refe in _import.ExportedVideoDecomposition.ReferentialsProject) { // Ajouter au tableau de remap s'il y a une correspondance. if (_import.ProjectReferentialsMergeCandidates.ContainsKey(refe)) { _referentialsToRemap[refe] = _import.ProjectReferentialsMergeCandidates[refe]; } else { refe.Process = _targetScenario.Project.Process; } } // Référentiels standard foreach (var refe in _import.ExportedVideoDecomposition.ReferentialsStandard) { if (_import.StandardReferentialsMergeCandidates.ContainsKey(refe)) { _referentialsToRemap[refe] = _import.StandardReferentialsMergeCandidates[refe]; } else { var refProject = ReferentialsFactory.CopyToNewProject(refe); // Associer au projet refProject.Process = _targetScenario.Project.Process; _referentialsToRemap[refe] = refProject; } } }
private void ImportReferentials() { // Référentiels process foreach (var refe in _import.ExportedVideoDecomposition.ReferentialsProject) { refe.Process = _targetScenario.Project.Process; } // Référentiels standard foreach (var refe in _import.ExportedVideoDecomposition.ReferentialsStandard) { var refProject = ReferentialsFactory.CopyToNewProject(refe); _referentialsToRemap[refe] = refProject; // Associer au process refProject.Process = _targetScenario.Project.Process; } }
/// <summary> /// Clone les liens Référentiel - Action de l'ancienne tâche pour les mettre dans la nouvelle tâche. /// </summary> /// <param name="oldAction">L'ancienne tâche.</param> /// <param name="newAction">La nouvelle tâche.</param> private static void CloneReferentialActionsLinks(KAction oldAction, KAction newAction) { // Ref1 foreach (var actionLink in oldAction.Ref1) { newAction.Ref1.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref2 foreach (var actionLink in oldAction.Ref2) { newAction.Ref2.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref3 foreach (var actionLink in oldAction.Ref3) { newAction.Ref3.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref4 foreach (var actionLink in oldAction.Ref4) { newAction.Ref4.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref5 foreach (var actionLink in oldAction.Ref5) { newAction.Ref5.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref6 foreach (var actionLink in oldAction.Ref6) { newAction.Ref6.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } // Ref7 foreach (var actionLink in oldAction.Ref7) { newAction.Ref7.Add(ReferentialsFactory.CloneReferentialActionsLink(actionLink, true, false)); } }
public void ConvertToNewProjectTest() { var std = new ActionCategoryStandard() { ActionTypeCode = "ABCD", ActionValueCode = "EFGH", Color = "#AB", Label = "Label", ActionCategoryId = 10, CreatedByUserId = 1, CreationDate = DateTime.Now, ModifiedByUserId = 2, LastModificationDate = DateTime.Now, }; var project = (ActionCategoryProject)ReferentialsFactory.CopyToNewProject(std); Assert.AreEqual(std.ActionTypeCode, project.ActionTypeCode); Assert.AreEqual(std.ActionValueCode, project.ActionValueCode); Assert.AreEqual(std.Color, project.Color); Assert.AreEqual(std.Label, project.Label); Assert.AreEqual(default(int), project.ActionCategoryId); Assert.AreEqual(default(int), project.CreatedByUserId); Assert.AreEqual(default(int), project.ModifiedByUserId); Assert.AreEqual(default(DateTime), project.CreationDate); Assert.AreEqual(default(DateTime), project.LastModificationDate); Assert.IsNull(project.Project); Assert.AreEqual(default(int), project.ProjectId); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new Ref2Standard())); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new Ref4Standard())); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new Ref3Standard())); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new EquipmentStandard())); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new OperatorStandard())); Assert.IsNotNull(ReferentialsFactory.CopyToNewProject(new Ref1Standard())); }
/// <summary> /// Importe le projet spécifié. /// </summary> /// <param name="context">Le contexte.</param> /// <param name="import">Le projet exporté.</param> /// <param name="mergeReferentials"><c>true</c> pour fusionner les référentiels.</param> /// <param name="videosDirectory">Le dossier où se situent les vidéos.</param> /// <returns>Le projet créé.</returns> private async Task <Project> ImportProject(KsmedEntities context, ProjectImport import, bool mergeReferentials, string videosDirectory) { // Projet var p = import.ExportedProject.Project; p.ProjectId = default(int); MarkAsAdded(p); // Ajouter l'utilisateur courant en tant qu'analyste créateur var owner = await context.Users.FirstAsync(u => !u.IsDeleted && u.Username == _securityContext.CurrentUser.Username); p.Process.Owner = owner; p.Process.UserRoleProcesses.Add(new UserRoleProcess() { User = owner, RoleCode = KnownRoles.Analyst, }); // Videos foreach (var video in p.Process.Videos) { if (video.DefaultResourceId.HasValue && video.DefaultResource == null) { // Bug présent dans certains exports de la version 2.5.0.0. Supprimer le lien vers la ressource par défaut. video.DefaultResourceId = null; } video.VideoId = default(int); MarkAsAdded(video); video.FilePath = IOHelper.ChangeDirectory(video.FilePath, videosDirectory); } var referentialsToRemap = new Dictionary <IActionReferential, IActionReferential>(); if (!mergeReferentials) { // Référentiels process foreach (var refe in import.ExportedProject.ReferentialsProject) { MarkAsAdded(refe); } // Référentiels standard foreach (var refe in import.ExportedProject.ReferentialsStandard) { var refProject = ReferentialsFactory.CopyToNewProject(refe); // Associer au process refProject.Process = p.Process; referentialsToRemap[refe] = refProject; } } else { // Référentiels process foreach (var refe in import.ExportedProject.ReferentialsProject) { // Ajouter au tableau de remap s'il y a une correspondance. if (import.ProjectReferentialsMergeCandidates.ContainsKey(refe)) { referentialsToRemap[refe] = import.ProjectReferentialsMergeCandidates[refe]; } else { MarkAsAdded(refe); } } // Référentiels standard foreach (var refe in import.ExportedProject.ReferentialsStandard) { if (import.StandardReferentialsMergeCandidates.ContainsKey(refe)) { referentialsToRemap[refe] = import.StandardReferentialsMergeCandidates[refe]; } else { var refProject = ReferentialsFactory.CopyToNewProject(refe); // Associer au process refProject.Process = p.Process; referentialsToRemap[refe] = refProject; } } } // Scénarios foreach (var scenario in p.Scenarios.Where(s => s.OriginalScenarioId.HasValue)) { // Remapper l'original scenario.Original = p.Scenarios.Single(s => s.ScenarioId == scenario.OriginalScenarioId); } foreach (var scenario in p.Scenarios) { foreach (var action in scenario.Actions.Where(a => a.OriginalActionId.HasValue)) { // Remapper l'original action.Original = p.Scenarios.SelectMany(s => s.Actions).Single(a => a.ActionId == action.OriginalActionId); } } foreach (var scenario in p.Scenarios) { scenario.ScenarioId = default(int); MarkAsAdded(scenario); // Supprimer le WebPublicationGuid scenario.WebPublicationGuid = null; // Actions foreach (var action in scenario.Actions) { action.ActionId = default(int); MarkAsAdded(action); // Actions réduites if (action.IsReduced) { MarkAsAdded(action.Reduced); } } } // Remapper les référentiels du projet, des actions et des vidéos foreach (var oldReferential in referentialsToRemap.Keys) { ReferentialsHelper.UpdateReferentialReferences(p, oldReferential, referentialsToRemap[oldReferential]); } foreach (var scenario in p.Scenarios) { if (scenario.Original != null) { context.Scenarios.ApplyChanges(scenario); ObjectContextExt.SetRelationShipReferenceValue(context, scenario, scenario.Original, s => s.OriginalScenarioId); foreach (var action in scenario.Actions) { if (action.Original != null) { context.KActions.ApplyChanges(action); ObjectContextExt.SetRelationShipReferenceValue(context, action, action.Original, a => a.OriginalActionId); } } } } var resources = p.Scenarios.SelectMany(s => s.Actions).Select(a => a.Resource).Distinct().ToArray(); context.Projects.ApplyChanges(p); if (mergeReferentials) { ServicesDiagnosticsDebug.CheckNotInContext(context, referentialsToRemap.Keys); ServicesDiagnosticsDebug.CheckObjectStateManagerState(context, EntityState.Unchanged, referentialsToRemap.Values); } ServicesDiagnosticsDebug.CheckReferentialsState(); await context.SaveChangesAsync(); return(p); }