示例#1
0
 /// <summary>
 /// Met à jour les références vers le référentiel spécifié pour les ressources par défaut des videos.
 /// </summary>
 /// <param name="videos">Les videos/</param>
 /// <param name="oldReferential">L'ancien référentiel.</param>
 /// <param name="newReferential">Le nouveau référential à utiliser.</param>
 public static void UpdateReferentialReferences(IEnumerable <Video> videos, IActionReferential oldReferential, IActionReferential newReferential)
 {
     foreach (Video video in videos.Where(v => v.DefaultResource == ((Resource)oldReferential)))
     {
         video.DefaultResource = (Resource)newReferential;
     }
 }
示例#2
0
        public static void MergeReferentials(this IReferentialsService service, IActionReferential master, IActionReferential[] slaves)
        {
            var operation = new AsyncServiceOperation();

            service.MergeReferentials(master, slaves, operation.OnDone, operation.OnError);

            operation.WaitCompletion();
        }
示例#3
0
        public async Task <IHttpActionResult> MergeReferentials([DynamicBody] dynamic param)
        {
            try
            {
                IActionReferential   master = param.master;
                IActionReferential[] slaves = param.slaves;
                await _referentialService.MergeReferentials(master, slaves);

                return(Ok());
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
示例#4
0
        /// <summary>
        /// Crée une copie du référentiel spécifié, en créant un référentiel projet.
        /// </summary>
        /// <param name="referential">Le référentiel.</param>
        /// <returns>Le référentiel créé.</returns>
        public static IActionReferentialProcess CopyToNewProject(IActionReferential referential)
        {
            if (referential is ActionCategory)
            {
                return(CopyToNewProject <ActionCategory>(referential, nameof(ActionCategory.ActionCategoryId)));
            }
            if (referential is Equipment)
            {
                return(CopyToNewProject <Equipment>(referential, nameof(Resource.ResourceId)));
            }
            if (referential is Operator)
            {
                return(CopyToNewProject <Operator>(referential, nameof(Resource.ResourceId)));
            }
            if (referential is Ref1)
            {
                return(CopyToNewProject <Ref1>(referential, nameof(Ref1.RefId)));
            }
            if (referential is Ref2)
            {
                return(CopyToNewProject <Ref2>(referential, nameof(Ref2.RefId)));
            }
            if (referential is Ref3)
            {
                return(CopyToNewProject <Ref3>(referential, nameof(Ref3.RefId)));
            }
            if (referential is Ref4)
            {
                return(CopyToNewProject <Ref4>(referential, nameof(Ref4.RefId)));
            }
            if (referential is Ref5)
            {
                return(CopyToNewProject <Ref5>(referential, nameof(Ref5.RefId)));
            }
            if (referential is Ref6)
            {
                return(CopyToNewProject <Ref6>(referential, nameof(Ref6.RefId)));
            }
            if (referential is Ref7)
            {
                return(CopyToNewProject <Ref7>(referential, nameof(Ref7.RefId)));
            }

            throw new ArgumentException("Le référentiel est inconnu", nameof(referential));
        }
示例#5
0
        private void AssertReferential(IActionReferential refe1, IActionReferential refe2, string idPropertyName)
        {
            Assert.IsFalse(refe1 == null && refe2 != null ||
                           refe1 != null && refe2 == null);

            if (refe1 == null && refe2 == null)
            {
                return;
            }

            Assert.IsTrue(refe2 is IActionReferentialProcess);

            Assert.IsTrue(new EntityComparer <IActionReferential>(TestContext)
                          .MustBeDifferent(
                              "CreatedByUserId", "CreationDate", "ModifiedByUserId", "LastModificationDate")
                          .Ignore(
                              "ProjectId", "Project", idPropertyName
                              )
                          .Compare(refe1, refe2));
        }
示例#6
0
        public void Sort()
        {
            var comparer = new ReferentialsSort();

            var refNull = new Ref1Project {
                Label = null
            };
            var refEmpty = new Ref1Project {
                Label = string.Empty
            };
            var refInt1 = new Ref1Project {
                Label = "1"
            };
            var refInt3 = new Ref1Project {
                Label = "3"
            };
            var refInt200 = new Ref1Project {
                Label = "200"
            };
            var refInt1100 = new Ref1Project {
                Label = "1100"
            };
            var refStr_a = new Ref1Project {
                Label = "abcd"
            };
            var refStr_s = new Ref1Project {
                Label = "str"
            };

            var actualArray = new IActionReferential[] { refNull, refEmpty, refStr_a, refInt3, refStr_s, refInt200, refInt1, refInt1100 };

            Array.Sort(actualArray, comparer);

            var expectedArray = new IActionReferential[] { refInt1, refInt3, refInt200, refInt1100, refNull, refEmpty, refStr_a, refStr_s };

            CollectionAssert.AreEqual(expectedArray, actualArray);
        }
示例#7
0
        static TProject CopyToNewProject <TProject>(IActionReferential referential, params string[] excludedProperties)
            where TProject : IActionReferentialProcess, IObjectWithChangeTracker, new()
        {
            TProject project = new TProject();

            IDictionary <string, object> originalValues = referential.GetCurrentValues();

            List <string> excludedPropertiesDefault = new List <string>
            {
                nameof(Resource.CreationDate),
                nameof(Resource.LastModificationDate),
                nameof(Resource.ModifiedByUserId),
                nameof(Resource.CreatedByUserId)
            };

            if ((referential as IActionReferentialProcess)?.ProcessId != null)
            {
                excludedPropertiesDefault.Add(nameof(IActionReferentialProcess.ProcessId));
                excludedPropertiesDefault.Add(nameof(IActionReferentialProcess.Process));
            }

            // Vérifier que ces noms de propriétés soient corrects
            if (excludedProperties.Concat(excludedPropertiesDefault).Except(originalValues.Keys).Any())
            {
                throw new InvalidOperationException("Les noms de propriétés présents dans excludedProperties ne sont pas valides.");
            }

            foreach (KeyValuePair <string, object> kvp in originalValues)
            {
                if (!excludedProperties.Concat(excludedPropertiesDefault).Contains(kvp.Key))
                {
                    project.SetPropertyValue(kvp.Key, kvp.Value);
                }
            }

            return(project);
        }
示例#8
0
 /// <inheritdoc />
 public void OnCurrentItemChanged(IActionReferential oldValue, IActionReferential newValue)
 {
 }
示例#9
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;
                }
            }
        }
示例#10
0
 /// <summary>
 /// Initialise une nouvelle instance de la classe <see cref="ReferentialGridItem"/>.
 /// </summary>
 /// <param name="referential">Le référentiel.</param>
 /// <param name="label">Le libellé du référentiel.</param>
 public ReferentialGridItem(IActionReferential referential, string label)
 {
     this.Referential = referential;
     this.Content     = label;
 }
示例#11
0
 /// <inheritdoc />
 protected override ReferentialGridItem CreateNewReferentialItemImpl(IActionReferential referential, string label)
 {
     return(new ReferentialGridItem(referential, label));
 }
示例#12
0
 /// <summary>
 /// Met à jour les références vers le référentiel spécifié pour les actions.
 /// </summary>
 /// <param name="actions">Les actions/</param>
 /// <param name="oldReferential">L'ancien référentiel.</param>
 /// <param name="newReferential">Le nouveau référential à utiliser.</param>
 public static void UpdateReferentialReferences(IEnumerable <KAction> actions, IActionReferential oldReferential, IActionReferential newReferential)
 {
     foreach (KAction action in actions)
     {
         if (action.Category == oldReferential)
         {
             action.Category = (ActionCategory)newReferential;
             continue;
         }
         if (action.Resource == oldReferential)
         {
             action.Resource = (Resource)newReferential;
             continue;
         }
         if (action.Ref1.Any(c => c.Ref1 == oldReferential))
         {
             foreach (Ref1Action actionLink in action.Ref1.Where(c => c.Ref1 == oldReferential))
             {
                 actionLink.Ref1 = (Ref1)newReferential;
             }
             continue;
         }
         if (action.Ref2.Any(c => c.Ref2 == oldReferential))
         {
             foreach (Ref2Action actionLink in action.Ref2.Where(c => c.Ref2 == oldReferential))
             {
                 actionLink.Ref2 = (Ref2)newReferential;
             }
             continue;
         }
         if (action.Ref3.Any(c => c.Ref3 == oldReferential))
         {
             foreach (Ref3Action actionLink in action.Ref3.Where(c => c.Ref3 == oldReferential))
             {
                 actionLink.Ref3 = (Ref3)newReferential;
             }
             continue;
         }
         if (action.Ref4.Any(c => c.Ref4 == oldReferential))
         {
             foreach (Ref4Action actionLink in action.Ref4.Where(c => c.Ref4 == oldReferential))
             {
                 actionLink.Ref4 = (Ref4)newReferential;
             }
             continue;
         }
         if (action.Ref5.Any(c => c.Ref5 == oldReferential))
         {
             foreach (Ref5Action actionLink in action.Ref5.Where(c => c.Ref5 == oldReferential))
             {
                 actionLink.Ref5 = (Ref5)newReferential;
             }
             continue;
         }
         if (action.Ref6.Any(c => c.Ref6 == oldReferential))
         {
             foreach (Ref6Action actionLink in action.Ref6.Where(c => c.Ref6 == oldReferential))
             {
                 actionLink.Ref6 = (Ref6)newReferential;
             }
             continue;
         }
         if (action.Ref7.Any(c => c.Ref7 == oldReferential))
         {
             foreach (Ref7Action actionLink in action.Ref7.Where(c => c.Ref7 == oldReferential))
             {
                 actionLink.Ref7 = (Ref7)newReferential;
             }
             continue;
         }
     }
 }
示例#13
0
        /// <summary>
        /// Met à jour les références vers le référentiel spécifié pour le projet.
        /// Cela inclue les référentiels sur <see cref="Project"/>, les ressources par défaut pour les vidéos et les référentiels des actions des scénarios.
        /// </summary>
        /// <param name="project">Le projet./</param>
        /// <param name="oldReferential">L'ancien référentiel.</param>
        /// <param name="newReferential">Le nouveau référential à utiliser.</param>
        public static void UpdateReferentialReferences(Project project, IActionReferential oldReferential, IActionReferential newReferential)
        {
            // Les actions
            UpdateReferentialReferences(project.Scenarios.SelectMany(s => s.Actions), oldReferential, newReferential);

            // Les resources par défaut des vidéos du projet
            if (oldReferential is Resource)
            {
                UpdateReferentialReferences(project.Process.Videos, oldReferential, newReferential);
            }

            // Les référentiels du projet
            if (oldReferential is ActionCategory && (oldReferential as ActionCategory).ProcessId != null)
            {
                project.Process.ActionCategories.Remove((ActionCategory)oldReferential);
                if (newReferential is ActionCategory && (newReferential as ActionCategory).ProcessId != null)
                {
                    project.Process.ActionCategories.Add((ActionCategory)newReferential);
                }
            }
            else if (oldReferential is Equipment && (oldReferential as Equipment).ProcessId != null)
            {
                project.Process.Equipments.Remove((Equipment)oldReferential);
                if (newReferential is Equipment && (newReferential as Equipment).ProcessId != null)
                {
                    project.Process.Equipments.Add((Equipment)newReferential);
                }
            }
            else if (oldReferential is Operator && (oldReferential as Operator).ProcessId != null)
            {
                project.Process.Operators.Remove((Operator)oldReferential);
                if (newReferential is Operator && (newReferential as Operator).ProcessId != null)
                {
                    project.Process.Operators.Add((Operator)newReferential);
                }
            }
            else if (oldReferential is Ref1)
            {
                if ((oldReferential as Ref1).ProcessId != null)
                {
                    project.Process.Refs1.Remove((Ref1)oldReferential);
                }
                if (newReferential is Ref1 && (newReferential as Ref1).ProcessId != null)
                {
                    project.Process.Refs1.Add((Ref1)newReferential);
                }
            }
            else if (oldReferential is Ref2)
            {
                if ((oldReferential as Ref2).ProcessId != null)
                {
                    project.Process.Refs2.Remove((Ref2)oldReferential);
                }
                if (newReferential is Ref2 && (newReferential as Ref2).ProcessId != null)
                {
                    project.Process.Refs2.Add((Ref2)newReferential);
                }
            }
            else if (oldReferential is Ref3)
            {
                if ((oldReferential as Ref3).ProcessId != null)
                {
                    project.Process.Refs3.Remove((Ref3)oldReferential);
                }
                if (newReferential is Ref3 && (newReferential as Ref3).ProcessId != null)
                {
                    project.Process.Refs3.Add((Ref3)newReferential);
                }
            }
            else if (oldReferential is Ref4)
            {
                if ((oldReferential as Ref4).ProcessId != null)
                {
                    project.Process.Refs4.Remove((Ref4)oldReferential);
                }
                if (newReferential is Ref4 && (newReferential as Ref4).ProcessId != null)
                {
                    project.Process.Refs4.Add((Ref4)newReferential);
                }
            }
            else if (oldReferential is Ref5)
            {
                if ((oldReferential as Ref5).ProcessId != null)
                {
                    project.Process.Refs5.Remove((Ref5)oldReferential);
                }
                if (newReferential is Ref5 && (newReferential as Ref5).ProcessId != null)
                {
                    project.Process.Refs5.Add((Ref5)newReferential);
                }
            }
            else if (oldReferential is Ref6)
            {
                if ((oldReferential as Ref6).ProcessId != null)
                {
                    project.Process.Refs6.Remove((Ref6)oldReferential);
                }
                if (newReferential is Ref6 && (newReferential as Ref6).ProcessId != null)
                {
                    project.Process.Refs6.Add((Ref6)newReferential);
                }
            }
            else if (oldReferential is Ref7)
            {
                if ((oldReferential as Ref7).ProcessId != null)
                {
                    project.Process.Refs7.Remove((Ref7)oldReferential);
                }
                if (newReferential is Ref7 && (newReferential as Ref7).ProcessId != null)
                {
                    project.Process.Refs7.Add((Ref7)newReferential);
                }
            }
        }
示例#14
0
 /// <inheritdoc />
 public void UninitializeRemovedItem(IActionReferential item)
 {
 }
示例#15
0
 /// <inheritdoc />
 public void OnCurrentItemChanged(IActionReferential oldValue, IActionReferential newValue)
 {
     this.Types.Container = (ActionCategory)newValue;
 }