Beispiel #1
0
 protected virtual void OnDisconnected(TItem item, bool disconnected)
 {
     if (disconnected)
     {
         ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForRemovedItem(item));
     }
 }
Beispiel #2
0
        private void UpdateConnections(Connection[] conns)
        {
            var updated = false;

            // remove all the connections we have in memory that are no longer in the connection cache file
            foreach (var host in connections.Values.Except(conns).Select(x => x.Host).ToArray())
            {
                connections.Remove(host);
                updated = true;
            }

            // update existing connections and add new ones from the cache file
            foreach (var connection in conns)
            {
                if (connections.ContainsKey(connection.Host))
                {
                    connections[connection.Host] = connection;
                }
                else
                {
                    connections.Add(connection.Host, connection);
                }
                updated = true;
            }
            if (updated)
            {
                ConnectionsChanged?.Invoke();
            }
        }
Beispiel #3
0
 protected virtual void OnConnectedMany(IEnumerable <TItem> connected)
 {
     if (connected.Any())
     {
         ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForAddedCollection(connected));
     }
 }
Beispiel #4
0
 protected virtual void OnConnected(TItem item, bool success)
 {
     if (success)
     {
         ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForAddedItem(item));
     }
 }
Beispiel #5
0
        public void SaveConnection(DatabaseConnection connection)
        {
            if (connection.Id == Guid.Empty)
            {
                connection.Id = Guid.NewGuid();
            }

            string path     = GetFilePath(connection);
            var    contents = JsonConvert.SerializeObject(connection);

            File.WriteAllText(path, contents);

            ConnectionsChanged?.Invoke(this, new ConnectionsChangedEventArgs(GetConnections()));
        }
Beispiel #6
0
        private void SaveConnectionsToDisk(bool raiseChangedEvent = true)
        {
            try
            {
                var json = connections.Values.ToJson();
                cachePath.WriteAllText(json);
            }
            catch (IOException ex)
            {
                logger.Error(ex, "Error writing connection cache: {0}", cachePath);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error serializing connection cache: {0}", cachePath);
            }

            if (raiseChangedEvent)
            {
                ConnectionsChanged?.Invoke();
            }
        }
Beispiel #7
0
        private void SaveConnectionsToDisk(bool raiseChangedEvent = true)
        {
            //logger.Trace("WriteCacheToDisk Count:{0} Path:{1}", connectionCache.Count, cachePath.ToString());
            try
            {
                var json = connections.Values.ToJson();
                cachePath.WriteAllText(json);
            }
            catch (IOException ex)
            {
                logger.Error(ex, "Error writing connection cache: {0}", cachePath);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error serializing connection cache: {0}", cachePath);
            }

            if (raiseChangedEvent)
            {
                ConnectionsChanged?.Invoke();
            }
        }
Beispiel #8
0
 public void DeleteConnection(DatabaseConnection connection)
 {
     File.Delete(GetFilePath(connection));
     ConnectionsChanged?.Invoke(this, new ConnectionsChangedEventArgs(GetConnections()));
 }
Beispiel #9
0
 private void ChangeInside(object sender, EventArgs e)
 {
     ConnectionsChanged?.Invoke(this, EventArgs.Empty);
 }