protected virtual void OnDisconnected(TItem item, bool disconnected) { if (disconnected) { ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForRemovedItem(item)); } }
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(); } }
protected virtual void OnConnectedMany(IEnumerable <TItem> connected) { if (connected.Any()) { ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForAddedCollection(connected)); } }
protected virtual void OnConnected(TItem item, bool success) { if (success) { ConnectionsChanged?.Invoke(this, CollectionChangedEventArgs <TItem> .CreateForAddedItem(item)); } }
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())); }
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(); } }
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(); } }
public void DeleteConnection(DatabaseConnection connection) { File.Delete(GetFilePath(connection)); ConnectionsChanged?.Invoke(this, new ConnectionsChangedEventArgs(GetConnections())); }
private void ChangeInside(object sender, EventArgs e) { ConnectionsChanged?.Invoke(this, EventArgs.Empty); }