Ejemplo n.º 1
0
        public void Import(TriggerManager triggerManager)
        {
            var serialized = fileDialogs.TryChooseAndReadTextFile();

            if (serialized != null)
            {
                var deserializedTriggers = serializer.Deserialize <TriggersDto>(serialized);
                ConflictResolution?globalConflictResolutionChoice = null;
                foreach (var triggerEntity in deserializedTriggers.TriggerEntities)
                {
                    var existingTrigger = triggerManager.FindTriggerByName(triggerEntity.Name);
                    if (existingTrigger != null)
                    {
                        if (globalConflictResolutionChoice != null)
                        {
                            ResolveUsing(globalConflictResolutionChoice.Value, triggerManager, triggerEntity, existingTrigger);
                            continue;
                        }

                        var message = "Imported trigger seems to already exists:\r\n" +
                                      "\r\n" +
                                      $"Imported trigger: {triggerEntity.GetDescription()}\r\n" +
                                      $"Existing trigger: {existingTrigger.GetDescription()}\r\n" +
                                      "\r\n" +
                                      "What should we do?";
                        var userChoice = new ConflictResolveDialog();
                        userChoice.SetText(message);
                        userChoice.ShowDialog();

                        ResolveUsing(userChoice.ConflictResolution, triggerManager, triggerEntity, existingTrigger);

                        if (userChoice.UseThisResolutionForAllConflicts)
                        {
                            globalConflictResolutionChoice = userChoice.ConflictResolution;
                        }
                    }
                    else
                    {
                        ResolveUsing(ConflictResolution.ImportAsNew, triggerManager, triggerEntity, null);
                    }
                }
            }
        }