public void SaveBasicInfo(ClientOutput clientOutput) { string connectionString = string.Format("Data Source={0};Version=3;", ConfigurationManager.AppSettings["DatabasePath"]); try { using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); /*SQLiteCommand cmd = new SQLiteCommand(@"INSERT OR REPLACE INTO Machines * (RecCreated, ComputerID, ComputerName, [Group]) * SELECT @RecCreated, @ComputerID, @ComputerName, @Group", * dbConnection); */ SQLiteCommand cmd = new SQLiteCommand(@"update Machines set [Group] = @Group, ComputerName = @ComputerName where ComputerID = @ComputerID; INSERT INTO Machines (RecCreated, ComputerID, ComputerName, [Group]) SELECT @RecCreated, @ComputerID, @ComputerName, @Group WHERE (Select Changes() = 0);", dbConnection); cmd.Parameters.AddWithValue("@RecCreated", DateTime.Now); cmd.Parameters.AddWithValue("@ComputerID", clientOutput.ID); cmd.Parameters.AddWithValue("@ComputerName", clientOutput.PCName); cmd.Parameters.AddWithValue("@Group", clientOutput.Group); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } }
private static void ReceiveModManifest(Peer peer, byte[] data) { List <System.Guid> guids = data.Deserialize <List <System.Guid> >(); List <System.Guid> toDownload = new List <System.Guid>(); HashSet <System.Guid> loadedGuids = new HashSet <System.Guid>(Client.LoadedModFiles.Select(x => x.GUID)); foreach (System.Guid guid in guids) { if (!loadedGuids.Contains(guid) && !toDownload.Contains(guid)) { ClientOutput.Line("Missing mod " + guid); toDownload.Add(guid); } } if (toDownload.Count > 0) { ClientOutput.Line("Sending Download Request"); peer.SendReliableOrdered(new NetworkPackage(PackageIdentification.ModDownloadRequest, toDownload)); } else { ClientOutput.Line("All mods matching server"); peer.SendReliableOrdered(new NetworkPackage(PackageIdentification.RequestObjectIDManifest)); } }
private static List <ClientOutput> GetCriticalValues(List <ClientOutput> clientOutputList) { List <ClientOutput> newClientOutputList = new List <ClientOutput>(); foreach (ClientOutput co in clientOutputList) { ClientOutput newClientOutput = new ClientOutput(co.PCName, co.ID, co.Group); foreach (PluginOutputCollection pluginCollection in co.CollectionList) { PluginOutputCollection newPluginCollection = new PluginOutputCollection(); newPluginCollection.PluginName = pluginCollection.PluginName; newPluginCollection.PluginUID = pluginCollection.PluginUID; foreach (PluginOutput pluginOutput in pluginCollection.PluginOutputList) { if (pluginOutput.Values.Any(item => item.IsCritical == true)) { newPluginCollection.PluginOutputList.Add(pluginOutput); } } if (newPluginCollection.PluginOutputList.Count > 0) { newClientOutput.CollectionList.Add(newPluginCollection); } } if (newClientOutput.CollectionList.Count > 0) { newClientOutputList.Add(newClientOutput); } } return(newClientOutputList); }
private void TakeAndPostData(bool initPost = false) { string json; string serverIP = ConfigurationManager.AppSettings["ServerIP"]; string groupName = ConfigurationManager.AppSettings["GroupName"]; ClientOutput output = new ClientOutput(getPCName(), getCPUID(), groupName); PluginOutputCollection plugOutput = new PluginOutputCollection(); _log.Debug("ServerIP: " + serverIP.ToString()); _log.Debug("GroupName: " + groupName.ToString()); json = string.Empty; output.CollectionList.Clear(); if (!initPost) { foreach (var plugin in _plugins.PluginList) { plugOutput = plugin.Output(); if (plugOutput != null) { output.CollectionList.Add(plugOutput); _log.Debug("Plugin loaded: " + plugin.ToString()); } } } else { output.InitPost = true; } if (!SendPluginOutput(output)) { // Save Output to SQLite database from JSON SaveOutputToDB(JsonConvert.SerializeObject(output)); _log.Debug("Saving output to SQLite db."); return; } try { Dictionary <int, string> dbValues = new Dictionary <int, string>(); dbValues = SQLiteDB.GetStoredJson(_dbName); foreach (var item in dbValues) { ClientOutput clientOutputDB = JsonConvert.DeserializeObject <ClientOutput>(item.Value); if (SendPluginOutput(output)) { SQLiteDB.UpdateStatus(_dbName, item.Key); } } } catch (Exception err) { _log.Error("Read stored values from database", err); return; } }
public ClientOutput JSONFromSQL(string group, string computerID, string computerName) { string connectionString = string.Format("Data Source={0};Version=3;", ConfigurationManager.AppSettings["DatabasePath"]); ClientOutput clientOutput = new ClientOutput(computerName, computerID, group); try { using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(@"SELECT ComputerName, JSON, RecCreated FROM MonitoringServerStorage WHERE [Group] = @Group and ComputerID = @ComputerID ORDER BY RecCreated desc LIMIT 1", dbConnection); cmd.Parameters.AddWithValue("@Group", group); cmd.Parameters.AddWithValue("@ComputerID", computerID); SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { clientOutput.PCName = reader.GetString(0); clientOutput.CollectionList = JsonConvert.DeserializeObject <List <PluginOutputCollection> >(reader.GetString(1)); clientOutput.LastUpdate = reader.GetDateTime(2); } } } catch (Exception ex) { throw ex; } return(clientOutput); }
public void JSONToSQL(ClientOutput clientOutput) { string json; string connectionString = string.Format("Data Source={0};Version=3;", ConfigurationManager.AppSettings["DatabasePath"]); try { json = JsonConvert.SerializeObject(clientOutput.CollectionList); using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(@"INSERT INTO MonitoringServerStorage (RecCreated, ComputerID, ComputerName, [Group], JSON) VALUES (@RecCreated, @ComputerID, @ComputerName, @Group, @JSON)", dbConnection); cmd.Parameters.AddWithValue("@RecCreated", DateTime.Now); cmd.Parameters.AddWithValue("@ComputerID", clientOutput.ID); cmd.Parameters.AddWithValue("@ComputerName", clientOutput.PCName); cmd.Parameters.AddWithValue("@Group", clientOutput.Group); cmd.Parameters.AddWithValue("@JSON", json); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { listCO = new List <ClientOutput>(); listCO.Add(ClientOutput.GetSampleClientOutput()); LineSeries LineSeries = new LineSeries(); LineSeries.Title = "Series 1"; LineSeries.Values = GetValuesForLineSeries(); SeriesCollection = new SeriesCollection(); SeriesCollection.Add(LineSeries); Thread graphThread = new Thread(new ThreadStart(GraphValuesController)); try { graphThread.SetApartmentState(ApartmentState.STA); graphThread.IsBackground = true; //graphThread = new Thread(new ThreadStart(GraphValuesController)); graphThread.Start(); } catch (Exception ex) { graphThread.Abort(); throw ex; } LoadPluginOutputsCommand = new RelayCommand(LoadPluginOutputsMethod); //Labels = value => new DateTime((long)((TimeSpan.FromMinutes(5).Ticks - (TimeSpan.FromSeconds(5).Ticks * value))/*/(10000*1000*60)*/)).ToString("t"); }
public List <ClientOutput> GetBasicInfo() { List <ClientOutput> clientOutputList = new List <ClientOutput>(); string connectionString = string.Format("Data Source={0};Version=3;", ConfigurationManager.AppSettings["DatabasePath"]); try { using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(@"SELECT ComputerName, ComputerID, [Group] FROM Machines", dbConnection); SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { ClientOutput co = new ClientOutput(reader.GetString(0), reader.GetString(1), reader.GetString(2)); clientOutputList.Add(co); } } } catch (Exception ex) { throw ex; } return(clientOutputList); }
private static void SetReady(Peer peer, byte[] data) { Network.EventListener.RemoveCallback((ushort)PackageIdentification.JoinflowCompleted, SetReady); ClientOutput.Line("Client is ready, joinflow complete"); Peer.SetReady(); }
private static void ReceiveModFile(Peer peer, byte[] data) { ModFile file = data.Deserialize <ModFile>(); ClientOutput.Line("Received " + file); Client.AddModFile(file); }
public PixivBaseAPI(string AccessToken, string RefreshToken, string UserID, ClientOutput ClientLog, bool ExperimentalConnection = false) { this.AccessToken = AccessToken; this.RefreshToken = RefreshToken; this.UserID = UserID; this.ClientLog = ClientLog; this.ExperimentalConnection = ExperimentalConnection; ExpireTime = 0; }
private void TakeAndPostData(bool initPost = false) { string json; string serverIP = ConfigurationManager.AppSettings["ServerIP"]; string customerName = ConfigurationManager.AppSettings["CustomerName"]; ClientOutput output = new ClientOutput(getPCName(), getMACAddress(), customerName); PluginOutputCollection plugOutput = new PluginOutputCollection(); json = string.Empty; output.CollectionList.Clear(); if (!initPost) { foreach (var plugin in _plugins.PluginList) { plugOutput = plugin.Output(); if (plugOutput != null) { output.CollectionList.Add(plugOutput); } } } else { output.InitPost = true; } if (!SendPluginOutput(output)) { SaveOutputToDB(JsonConvert.SerializeObject(output)); return; } try { Dictionary <int, string> dbValues = new Dictionary <int, string>(); dbValues = SqliteDB.GetStoredJson(_dbName); foreach (var item in dbValues) { ClientOutput clientOutputDB = JsonConvert.DeserializeObject <ClientOutput>(item.Value); if (SendPluginOutput(output)) { SqliteDB.UpdateStatus(_dbName, item.Key); } } } catch (Exception err) { _log.Error("Read stored values from database", err); return; } }
public void SendPluginOutput(ClientOutput clientOutput) { _sqlController = new SQLiteController(); if (clientOutput.InitPost) { Groups.Add(Context.ConnectionId, "Agents"); _sqlController.SaveBasicInfo(clientOutput); MessageController.LoadTreeView(); } else { _sqlController.JSONToSQL(clientOutput); } }
public static void Connect(IPEndPoint endpoint) { if (IsConnected) { throw new System.InvalidOperationException("We already have an established connection to the server"); } ClientOutput.Line("Connecting to " + endpoint); Instance._netManager.Start(); Network.EventListener.RegisterCallback((ushort)PackageIdentification.JoinflowCompleted, SetReady); Peer = Instance._netManager.Connect(endpoint, ""); Peer.OnReady += Ready; }
private static void OneMachineView() { try { SQLiteController sqlController = new SQLiteController(); ClientOutput clientOutput = sqlController.JSONFromSQL(_group, _nodeID, _pcName); if (clientOutput != null) { GetContext().Clients.Group("Clients").PluginsMessage(clientOutput); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Add modfile during runtime from server /// This will also serialize it to disk /// </summary> public static void AddModFile(ModFile file) { if (Instance._loadedModfiles.Contains(file)) { throw new System.InvalidOperationException("Mod file has already been loaded"); } Instance._loadedModfiles.Add(file); string folder = $"{Directories.DataPath}/{Settings.ModsDirectory}/{DOWNLOADED_FILES_FOLDER}"; string fullPath = $"{folder}/{file.Name}{UMS.Utility.MOD_EXTENSION}"; Directories.EnsurePathExists(folder); ClientOutput.Line($"Serializing {file} to {fullPath}"); File.WriteAllBytes(fullPath, ByteConverter.Serialize(file)); }
public static bool Initialize() { try { Session.Initialize(); Instance._loadedModfiles = ModLoader.GetAllModFiles(); Instance.CreateClient(); Instance.SetupEvents(); ClientInitializer.Initialize(); return(true); } catch (System.Exception) { ClientOutput.HeaderError("Failed starting client"); throw; } }
public void OnKeyDownHandler(object sender, KeyEventArgs e) { var DecEncHelper = new utils.DecodingEncodingHelper(); if (connected) { if (e.Key == Key.Enter) { string msg = ClientInput.Text; if (msg.StartsWith("/")) { inputHandler.handleInput(msg.Remove(0, 1), connectedClient, ClientOutput); } else { ClientOutput.AppendText("Du: " + msg + Environment.NewLine); client.SocketObject.Send(DecEncHelper.StringToBytes($"001{msg}")); } ClientInput.Text = ""; } } }
public void LoadPluginOutputsMethod() { clientOutputs = new ObservableCollection <ClientOutput>(); ClientOutput co = ClientOutput.GetSampleClientOutput(); clientOutputs.Add(co); LineSeries LineSeries = new LineSeries(); LineSeries.Title = "Series 1"; LineSeries.Values = GetValuesForLineSeries(); SeriesCollection = new SeriesCollection(); SeriesCollection.Add(LineSeries); /*LineSeries LineSeries = new LineSeries(); * LineSeries.Title = "Series 1"; * LineSeries.Values = GetValuesForLineSeries(); */ //if (SeriesCollection != null && SeriesCollection.Count > 0) //{ // SeriesCollection[0] = new LineSeries() // { // Title = "Series 1", // Values = GetValuesForLineSeries() // }; //} //else //{ // SeriesCollection = new SeriesCollection(); // SeriesCollection.Add( // new LineSeries() // { // Title = "Series 1", // Values = GetValuesForLineSeries() // }); //} //Messenger.Default.Send<NotificationMessage>(new NotificationMessage("Plugin Outputs loaded.")); }
private bool SendPluginOutput(ClientOutput output) { bool sended = true; string serverIP = ConfigurationManager.AppSettings["ServerIP"]; HubConnection hubConnection = new HubConnection(serverIP); IHubProxy monitoringHub = hubConnection.CreateHubProxy("MyHub"); try { hubConnection.Start().ContinueWith(task => { if (task.IsFaulted) { Console.WriteLine($"There was an error opening the connection: {task.Exception.GetBaseException()}"); _log.Error($"There was an error opening the connection: {task.Exception.GetBaseException()}"); sended = false; } else { Console.WriteLine("Connected"); _log.Debug("Connected to HUB."); } }).Wait(); monitoringHub.Invoke <ClientOutput>("SendPluginOutput", output).Wait(); } catch (Exception ex) { _log.Error("Upload string Exception: ", ex); sended = false; throw ex; } finally { hubConnection.Stop(); } return(sended); }
private void Update() { if (Strength == ConnectionStrength.Connected) { if (ping_pinging == true) { ping_active_test_duration += Time.deltaTime; } else { ping_timer -= Time.deltaTime; if (ping_timer <= 0.0f) { ping_timer = ping_timer_iterator + ping_timer; ping_pinging = true; ClientOutput.Compose(Outbound.PingTest); Resources.UnloadUnusedAssets(); } } } //fps tracker framerate_deltaTime += (Time.unscaledDeltaTime - framerate_deltaTime) * 0.1f; float msec = framerate_deltaTime * 1000.0f; float fps = 1.0f / framerate_deltaTime; framerate_update_timer -= Time.deltaTime; if (framerate_update_timer <= 0.0f) { //reset timer framerate_update_timer = framerate_update_interval - framerate_update_timer; //update text connectionAndFramerateText.text = string.Format("FPS: {0} " + (Strength == ConnectionStrength.Connected ? "Ping: {1}ms" : "Offline"), (int)fps, ping_last_ms.ToString("0")); } }
public List <ClientOutput> LastValuesFromDB() { List <ClientOutput> clientOutputList = new List <ClientOutput>(); string connectionString = string.Format("Data Source={0};Version=3;", ConfigurationManager.AppSettings["DatabasePath"]); int minutesBack = 10; try { using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(@"SELECT DISTINCT ComputerName, ComputerID, [Group], JSON FROM MonitoringServerStorage where RecCreated > DATETIME('now', '-' || @minutesBack || ' minutes', 'localtime') and ComputerName is not NULL and ComputerName not in ('') GROUP BY ComputerName ORDER BY RecCreated desc", dbConnection); cmd.Parameters.AddWithValue("@minutesBack", minutesBack); SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { ClientOutput co = new ClientOutput(reader.GetString(0), reader.GetString(1), reader.GetString(2)); co.CollectionList = JsonConvert.DeserializeObject <List <PluginOutputCollection> >(reader.GetString(3)); clientOutputList.Add(co); } } } catch (Exception ex) { throw ex; } return(clientOutputList); }
public static void InitializeObjectReferenceManifest(IEnumerable <ModFile> mods, IDictionary <string, ushort> networkIDs) { ClientOutput.Line($"Initialize ObjectReferenceManifest with {mods.Count()} mods"); ObjectReferenceManifest.Initialize(mods, x => ObjectReferenceManifest.ObjectReferenceData.CreateAsClient(x, networkIDs[x.Key])); }
private static void OnNetworkError(IPEndPoint endPoint, int socketErrorCode) { ClientOutput.LineError($"Error ({socketErrorCode}) from {endPoint}"); }
private static void OnPeerDisconnected(Peer peer, DisconnectInfo info) { ClientOutput.Line($"Disconnected from server with message {info.Reason}"); }
private IChartValues GetValuesForLineSeries() { string customer = "CustomerTest"; string computerID = "C8CBB84172E0"; int valuesCount = 50; List <PluginOutputCollection> listOfPOC = new List <PluginOutputCollection>(); List <ClientOutput> clientOutputList = new List <ClientOutput>(); string connectionString = string.Format("Data Source=d:\\Monitoring\\MonitoringServerDB.sqlite; Version=3;"); try { using (SQLiteConnection dbConnection = new SQLiteConnection(connectionString)) { dbConnection.Open(); SQLiteCommand cmd = new SQLiteCommand(@"SELECT RecID, recCreated, ComputerName, JSON FROM MonitoringServerStorage WHERE Customer = @Customer and ComputerID = @ComputerID ORDER BY RecCreated desc LIMIT @ValuesCount", dbConnection); cmd.Parameters.AddWithValue("@Customer", customer); cmd.Parameters.AddWithValue("@ComputerID", computerID); cmd.Parameters.AddWithValue("@ValuesCount", valuesCount); SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { ClientOutput co = new ClientOutput(reader.GetString(2), computerID, customer); co.CollectionList = JsonConvert.DeserializeObject <List <PluginOutputCollection> >(reader.GetString(3)); clientOutputList.Add(co); } } } catch (Exception ex) { throw ex; } int i = 0; ChartValues <ObservablePoint> chartValues = new ChartValues <ObservablePoint>(); try { clientOutputList.Reverse(); foreach (ClientOutput co in clientOutputList) { foreach (PluginOutputCollection poc in co.CollectionList) { if (poc.PluginName == "Performance") { double valueY = Convert.ToDouble(poc.PluginOutputList[0].Values[0].Value.ToString().Split(' ')[0]); chartValues.Add(new ObservablePoint(i, valueY)); i++; } } } } catch (Exception ex) { } return(chartValues); }
public PixivAppAPI(string AccessToken, string RefreshToken, string UserID, ClientOutput ClientLog, bool ExperimentalConnection = false) : base(AccessToken, RefreshToken, UserID, ClientLog, ExperimentalConnection) { }
private static void OnPeerConnected(Peer peer) { ClientOutput.Line($"Connected to {peer.EndPoint} with ID {peer.ConnectionID}"); }