public void Load(string content) { JsonObject jsonObject = null; try { jsonObject = JsonObject.Parse(content); } catch (Exception e) { ErrorFactory.ThrowError(ErrorCode.ConfigurationLoadingFailedJsonSerialization, e); } Validate(jsonObject); try { Server = new ServerConfigData(jsonObject.GetNamedObject("server")); OAuth = new OAuthConfigData(jsonObject.GetNamedObject("oauth")); Mag = new MagConfigData(jsonObject.GetNamedObject("mag")); Custom = new CustomConfigData(jsonObject.GetNamedObject("custom")); } catch (Exception e) { ErrorFactory.ThrowError(ErrorCode.ConfigurationLoadingFailedJsonValidation, e); } }
public SensorNetServer() { InitializeComponent(); descriptionUpdater = new VoidDelegate(UpdateServerDescription); closeDelegate = new VoidDelegate(this.Close); log.Name = "log"; log.LogMessage += new LogMessageEventHandler(log_LogMessage); log.Start(); #region copy data files if (!Directory.Exists(Application.UserAppDataPath)) { Directory.CreateDirectory(Application.UserAppDataPath ); } if (!File.Exists(Application.UserAppDataPath + "\\" + SensorNetConfig.ServerDatabase)) { File.Copy(Application.StartupPath + "\\" + SensorNetConfig.ServerDatabase, Application.UserAppDataPath + "\\" + SensorNetConfig.ServerDatabase); } database = DatabaseHelper.ConnectToSQL("Data Source=\"" + Application.UserAppDataPath + "\\" + SensorNetConfig.ServerDatabase + "\""); #endregion #region Regestry data setup RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(SensorNetConfig.ConfigKeyName); bool createNewConfig = true; object regKey = registryKey.GetValue("ServerID"); if (regKey != null) { Guid serverID = new Guid((string)regKey); CurrentServerData = DatabaseHelper.GetServerByID(database, serverID); if (CurrentServerData != null) { createNewConfig = false; } } if (createNewConfig) { // Show server config before starting server (which is automatically done when config box is closed) Bitmap serverPic = new Bitmap(Application.StartupPath + "/defaultImage.jpg"); CurrentServerData = new ServerConfigData(Guid.Empty, "New Server", "Location", "Description", JpegImage.GetBytes(serverPic)); configMenuItem_Click(this, new EventArgs()); } else { //If config isn't needed, start now registryKey.Close(); StartServer(); } #endregion }
static void Main(string[] args) { theLogger = new ConsoleLogger(); theLogger.Info("test"); theLogger.Warn("test"); theLogger.Error("test"); theServer = new FedNetServer(ServerConfigData.getDefault(new Athentificateur()), theLogger); theServer.MessageReceived += TheServer_MessageReceived; theServer.StartServer(); Console.ReadLine(); //theServer.sendBroadcastMessage("test", "test", MessagePriority.LowAndFast); //Console.ReadLine(); theServer.StopServer(); Console.ReadLine(); }
private void viewRemoteServiceExecutableLogFileToolStripMenuItem_Click(object sender, EventArgs e) { if (this.SourceControl is DataGridView) { DataGridView dgvServerStatus = (DataGridView)this.SourceControl; if (dgvServerStatus.SelectedCells.Count == 0) { return; } this.Cursor = Cursors.WaitCursor; //this.statGeneral.Text = "Retrieving Remote Service Executable log file..."; //this.statProgBar.Style = ProgressBarStyle.Marquee; try { string serverName = string.Empty; string remoteEndpoint = string.Empty; string text = string.Empty; if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is ServerConfigData) { ServerConfigData server = (ServerConfigData)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = server.ActiveServiceEndpoint; serverName = server.ServerName; } else if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is BuildRecord) { BuildRecord buildRec = (BuildRecord)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = buildRec.RemoteEndPoint; serverName = buildRec.RemoteServerName; } text = buildManager.GetServiceLog(remoteEndpoint); SqlSync.ScriptDisplayForm frmScript = new ScriptDisplayForm(text, serverName, "Service Executable Log from " + serverName, SqlSync.Highlighting.SyntaxHightlightType.LogFile); frmScript.Show(); } catch (Exception exe) { MessageBox.Show("Sorry... There was an error attempting to retrieve the log file.\r\n " + exe.Message, "Problem!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { this.Cursor = Cursors.Default; //this.statGeneral.Text = "Ready."; //this.statProgBar.Style = ProgressBarStyle.Blocks; } } }
private void viewExecutionCommitsLogToolStripMenuItem_Click(object sender, EventArgs e) { if (this.SourceControl is DataGridView) { DataGridView dgvServerStatus = (DataGridView)this.SourceControl; if (dgvServerStatus.SelectedCells.Count == 0) { return; } try { string serverName = string.Empty; string text = string.Empty; string remoteEndpoint = string.Empty; if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is ServerConfigData) { ServerConfigData server = (ServerConfigData)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = server.ActiveServiceEndpoint; text = buildManager.GetCommitsLog(server.ActiveServiceEndpoint); serverName = server.ServerName; } else if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is BuildRecord) { BuildRecord buildRec = (BuildRecord)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = buildRec.RemoteEndPoint; text = buildManager.GetSpecificSummaryLogFile(buildRec.RemoteEndPoint, SummaryLogType.Commits, buildRec.submissionDate); serverName = buildRec.RemoteServerName; } SqlSync.ScriptDisplayForm frmScript = new ScriptDisplayForm(text, serverName, "Commits Log from " + serverName, SqlSync.Highlighting.SyntaxHightlightType.RemoteServiceLog, remoteEndpoint); frmScript.LoggingLinkClicked += new LoggingLinkClickedEventHandler(frmScript_LoggingLinkClicked); frmScript.Show(); } catch (System.ServiceModel.CommunicationObjectFaultedException comExe) { MessageBox.Show("There was a communication issue retrieving the log file.\r\nTo try to clear the communication error, try closing this page and reopening. If that does not work, you may need to restart the service on the target remote execution server.\r\n\r\nError Message:\r\n" + comExe.Message, "Whoops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exe) { MessageBox.Show("There was an issue retrieving the log file.\r\n" + exe.Message, "Whoops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//private void viewBuildRequestHistoryForThisRemoteServiceToolStripMenuItem_Click(object sender, EventArgs e) //{ // if (this.SourceControl is DataGridView) // { // DataGridView dgvServerStatus = (DataGridView)this.SourceControl; // if (dgvServerStatus.SelectedCells.Count == 0) // return; // ServerConfigData server = (ServerConfigData)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; // string message; // IList<BuildRecord> history = buildManager.GetBuildServiceHistory(server.TcpServiceEndpoint, out message); // if (history.Count == 0 && message.Length > 0) // { // MessageBox.Show(message, "Can't get the history", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } // BuildHistoryForm frmHist = new BuildHistoryForm(history, server.ServerName, server.TcpServiceEndpoint); // frmHist.ShowDialog(); // } //} private void retrieveAllApplicableErrorLogsToolStripMenuItem_Click(object sender, EventArgs e) { if (this.SourceControl is DataGridView) { DataGridView dgvServerStatus = (DataGridView)this.SourceControl; if (dgvServerStatus.SelectedCells.Count == 0) { return; } string serverName = string.Empty; string text = string.Empty; string remoteEndpoint = string.Empty; DateTime submissionDate = DateTime.MaxValue; if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is ServerConfigData) { ServerConfigData server = (ServerConfigData)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = server.ActiveServiceEndpoint; serverName = server.ServerName; } else if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is BuildRecord) { BuildRecord buildRec = (BuildRecord)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; remoteEndpoint = buildRec.RemoteEndPoint; serverName = buildRec.RemoteServerName; submissionDate = buildRec.submissionDate; } if (DialogResult.OK == saveFileDialog1.ShowDialog()) { if (buildManager.GetConsolidatedErrorLogs(remoteEndpoint, submissionDate, saveFileDialog1.FileName)) { if (DialogResult.Yes == MessageBox.Show("Successfully retrieved error logs. Do you want to open the zip file now?", "Open", MessageBoxButtons.YesNo)) { System.Diagnostics.Process.Start(saveFileDialog1.FileName); } } else { MessageBox.Show("Sorry, there was an error retrieving the error logs. Please check the application log and try again", "Whoops. Something didn't work!", MessageBoxButtons.OK); } } } }
private void txtDetailedLogTarget_KeyDown(object sender, KeyEventArgs e) { if (this.SourceControl is DataGridView) { DataGridView dgvServerStatus = (DataGridView)this.SourceControl; if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) { if (dgvServerStatus.SelectedCells.Count == 0 || txtDetailedLogTarget.Text.Length == 0) { return; } try { string serverName = string.Empty; string text = string.Empty; if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is ServerConfigData) { ServerConfigData server = (ServerConfigData)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; text = buildManager.GetDetailedDatabaseLog(server.ActiveServiceEndpoint, txtDetailedLogTarget.Text); serverName = server.ServerName; } else if (dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem is BuildRecord) { BuildRecord buildRec = (BuildRecord)dgvServerStatus.Rows[dgvServerStatus.SelectedCells[0].RowIndex].DataBoundItem; text = buildManager.GetSpecificDetailedDatabaseLog(buildRec.RemoteEndPoint, txtDetailedLogTarget.Text, buildRec.submissionDate); serverName = buildRec.RemoteServerName; } SqlSync.ScriptDisplayForm frmScript = new ScriptDisplayForm(text, serverName, "Detailed Log from " + txtDetailedLogTarget.Text); frmScript.Show(); txtDetailedLogTarget.Text = string.Empty; } catch (Exception exe) { MessageBox.Show("There was an issue retrieving the log file.\r\n" + exe.Message, "Whoops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public OrderChangelog GenerateInitialChangelog(int datasetId) { string downloadUriBase = ServerConfigData.DownloadUriBase().TrimEnd('/'); using (geosyncEntities db = new geosyncEntities()) { var initialChangelog = (from d in db.StoredChangelogs where d.DatasetId == datasetId && d.StartIndex == 1 && d.Stored == true && d.Status == "finished" orderby d.DateCreated descending select d).FirstOrDefault(); if (initialChangelog != null && initialChangelog.DownloadUri != null) { Uri uri = new Uri(initialChangelog.DownloadUri); ChangelogManager.DeleteFileOnServer(uri); db.StoredChangelogs.DeleteObject(initialChangelog); db.SaveChanges(); } } LastChangeId = 1; // StartIndex always 1 on initial changelog int endIndex = Convert.ToInt32(GetLastIndex(datasetId)); int count = 1000; // TODO: Get from dataset table Logger.Info("GenerateInitialChangelog START"); StoredChangelog ldbo = new StoredChangelog(); ldbo.Stored = true; ldbo.Status = "queued"; ldbo.StartIndex = (int)LastChangeId; ldbo.DatasetId = datasetId; ldbo.DateCreated = DateTime.Now; //TODO make filter //TODO check if similar stored changelog is already done using (geosyncEntities db = new geosyncEntities()) { // Store changelog info in database db.StoredChangelogs.AddObject(ldbo); OrderChangelog resp = new OrderChangelog(); resp.changelogId = ldbo.ChangelogId.ToString(); //New thread and do the work.... // We're coming back to the thread handling later... //string sourceFileName = "Changelogfiles/41_changelog.xml"; Directory.CreateDirectory(destPath); // Loop and create xml files while (OptimizedChangelLogIndex < OptimizedChangeLog.Count) { string partFileName = DateTime.Now.Ticks + ".xml"; string fullPathWithFile = Path.Combine(destPath, partFileName); MakeChangeLog((int)LastChangeId, count, PDbConnectInfo, _pWfsUrl, fullPathWithFile, datasetId); LastChangeId += 1; } // Save endIndex to database ldbo.EndIndex = endIndex; // New code to handle FTP download ChangeLogHandler chgLogHandler = new ChangeLogHandler(ldbo, Logger); string inFile = ""; try { inFile = destPath; chgLogHandler.CreateZipFileFromFolder(inFile, zipFile, destFileName); ldbo.Status = "queued"; File.Copy(tmpzipFile, streamFileLocation); File.Delete(tmpzipFile); ldbo.Status = "finished"; } catch (Exception ex) { Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex); throw ex; } try { string downLoadUri = string.Format(@"{0}/{1}", downloadUriBase, zipFile); ldbo.DownloadUri = downLoadUri; } catch (Exception ex) { Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex); throw ex; } try { db.SaveChanges(); } catch (Exception ex) { Logger.ErrorException( string.Format( "Failed on SaveChanges, Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog startIndex:{0} count:{1} changelogId:{2}", LastChangeId, count, ldbo.ChangelogId), ex); throw ex; } Logger.Info( "Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog" + " startIndex:{0}" + " count:{1}" + " changelogId:{2}", LastChangeId, count, ldbo.ChangelogId); Logger.Info("GenerateInitialChangelog END"); return(resp); } }
private OrderChangelog _OrderChangelog(int startIndex, int count, string todoFilter, int datasetId) { string downloadUriBase = ServerConfigData.DownloadUriBase().TrimEnd('/'); using (geosyncEntities db = new geosyncEntities()) { ChangelogManager chlmng = new ChangelogManager(db); chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.working); //System.IO.File.Copy(Utils.BaseVirtualAppPath + sourceFileName, Utils.BaseVirtualAppPath + destFileName); try { if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } MakeChangeLog(startIndex, count, PDbConnectInfo, _pWfsUrl, destPath + destFileName + ".xml", datasetId); } catch (Exception ex) { chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.cancelled); Logger.ErrorException( string.Format("Failed to make Change Log {0}", destPath + destFileName + ".xml"), ex); throw ex; } // New code to handle FTP download ChangeLogHandler chgLogHandler = new ChangeLogHandler(Logger); string inFile = ""; try { inFile = destPath; chgLogHandler.CreateZipFileFromFolder(inFile, zipFile, destFileName); File.Copy(tmpzipFile, streamFileLocation); File.Delete(tmpzipFile); } catch (Exception ex) { chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.cancelled); Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex); throw ex; } try { string downLoadUri = string.Format(@"{0}/{1}", downloadUriBase, zipFile); chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.finished); chlmng.SetDownloadURI(_currentOrderChangeLog.changelogId, downLoadUri); } catch (Exception ex) { Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex); throw ex; } Logger.Info( "Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog" + " startIndex:{0}" + " count:{1}" + " changelogId:{2}", startIndex, count, _currentOrderChangeLog.changelogId); Logger.Info("OrderChangelog END"); return(_currentOrderChangeLog); } }
protected void dvServerConfig_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { string URL = ServerConfigData.DownloadUriBase(); IList <Int32> ID = DatasetsData.GetListOfDatasetIDs(); }