Пример #1
0
 public ConnectionsViewModel(Settings settings)
     : base()
 {
     _settings = settings;
     foreach (Connection connection in _settings.GetConnections())
     {
         ConnectionViewModel model = new ConnectionViewModel(connection);
         this.Add(model);
         model.PropertyChanged += _itemChanged;
     }
     this.CollectionChanged += (s, e) =>
         {
             ConnectionViewModel connection;
             switch (e.Action)
             {
                 case NotifyCollectionChangedAction.Add:
                     connection = (ConnectionViewModel)e.NewItems[0];
                     connection.PropertyChanged += _itemChanged;
                     _settings.AddConnection(connection.Connection);
                     break;
                 case NotifyCollectionChangedAction.Remove:
                     connection = (ConnectionViewModel)e.OldItems[0];
                     connection.PropertyChanged -= _itemChanged;
                     _settings.RemoveConnection(connection.Connection);
                     break;
             }
         };
 }
 public DialogAddChangeConnectionViewModel(ConnectionViewModel connection)
 {
     Connection = connection;
     AddValidationRule(new ValidationRule("Name", () =>
     {
         string result = null;
         if (Name == "")
         {
             result        = Localization.Localization.ConnectionNameIsRequired;
             NameIsInvalid = true;
         }
         else
         {
             NameIsInvalid = false;
         }
         return(result);
     }));
     AddValidationRule(new ValidationRule("Host", () =>
     {
         string result = null;
         if (Uri.CheckHostName(Host) == UriHostNameType.Unknown)
         {
             result        = Localization.Localization.AddressIsInvalid;
             HostIsInvalid = true;
         }
         else
         {
             HostIsInvalid = false;
         }
         return(result);
     }));
 }
Пример #3
0
        public ConnectionsViewModel(Settings settings) : base()
        {
            _settings = settings;
            foreach (Connection connection in _settings.GetConnections())
            {
                ConnectionViewModel model = new ConnectionViewModel(connection);
                this.Add(model);
                model.PropertyChanged += _itemChanged;
            }
            this.CollectionChanged += (s, e) =>
            {
                ConnectionViewModel connection;
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    connection = (ConnectionViewModel)e.NewItems[0];
                    connection.PropertyChanged += _itemChanged;
                    _settings.AddConnection(connection.Connection);
                    break;

                case NotifyCollectionChangedAction.Remove:
                    connection = (ConnectionViewModel)e.OldItems[0];
                    connection.PropertyChanged -= _itemChanged;
                    _settings.RemoveConnection(connection.Connection);
                    break;
                }
            };
        }
 public DialogAddChangeConnectionViewModel(ConnectionViewModel connection)
 {
     Connection = connection;
     AddValidationRule(new ValidationRule("Name", () =>
      {
          string result = null;
          if (Name == "")
          {
              result = Localization.Localization.ConnectionNameIsRequired;
              NameIsInvalid = true;
          }
          else
          {
              NameIsInvalid = false;
          }                 
          return result;
      }));
     AddValidationRule(new ValidationRule("Host", () =>
      {
          string result = null;
          if (Uri.CheckHostName(Host) == UriHostNameType.Unknown)
          {
              result = Localization.Localization.AddressIsInvalid;
              HostIsInvalid = true;
          }
          else
          {
              HostIsInvalid = false;
          }
          return result;
      }));
 }
Пример #5
0
 public OldConnectionsViewModel(Settings settings) : base(settings.GetOldConnections().ConvertAll(x => new ConnectionViewModel(x)))
 {
     _settings          = settings;
     CollectionChanged += (s, e) =>
     {
         if (e.Action == NotifyCollectionChangedAction.Add)
         {
             if (e.NewStartingIndex != 0)
             {
                 return;
             }
             ConnectionViewModel newConnection = (ConnectionViewModel)e.NewItems[0];
             _settings.AddOldConnection(newConnection.Connection);
             if (Count > MAX_OLD_CONNECTIONS)
             {
                 Remove(this[Count - 1]);
             }
             return;
         }
         if (e.Action == NotifyCollectionChangedAction.Remove)
         {
             ConnectionViewModel removedConnection = (ConnectionViewModel)e.OldItems[0];
             _settings.RemoveOldConnection(removedConnection.Connection);
             return;
         }
         if (e.Action == NotifyCollectionChangedAction.Move)
         {
             if (e.NewStartingIndex != 0)
             {
                 return;
             }
             ConnectionViewModel movedConnection = (ConnectionViewModel)e.NewItems[0];
             _settings.RemoveOldConnection(movedConnection.Connection);
             movedConnection.Connection.Id = -1;
             _settings.AddOldConnection(movedConnection.Connection);
         }
     };
 }