public void ToScaledStringFormatUnitNameTest() { long totalUnits = long.Parse(Math.Pow(2, 10).ToString()); string format = string.Empty; string unitName = " kibi"; string expected = "1 K kibi"; string actual; actual = SI2.ToScaledString(totalUnits, format, unitName); Assert.AreEqual(expected, actual); }
public void ToScaledStringDecPlacesUnitNameTest() { long totalUnits = long.Parse(Math.Pow(2, 10).ToString()); int decimalPlaces = 3; string unitName = " kibi"; string expected = "1.000 K kibi"; string actual; actual = SI2.ToScaledString(totalUnits, decimalPlaces, unitName); Assert.AreEqual(expected, actual); // Assert.Inconclusive("Verify the correctness of this test method."); }
public void Inequalities() { var si1 = new SI(42); var si2 = new SI(43); var si3 = new SI(42); Assert.True(si1 < si2); Assert.False(si1 < si3); Assert.True(si1 <= si2); Assert.True(si1 <= si3); Assert.True(si2 > si1); Assert.False(si3 > si1); Assert.True(si2 >= si1); Assert.True(si3 >= si1); Assert.True(si1.CompareTo(si2) < 0); Assert.True(si2.CompareTo(si1) > 0); Assert.True(si1.CompareTo(si1) == 0); Assert.True(si1.CompareTo(si3) == 0); Assert.True(si2 > null); Assert.True(si2 >= null); Assert.False(si2 < null); Assert.False(si2 <= null); Assert.True(null < si1); Assert.True(null <= si1); Assert.False(null > si1); Assert.False(null >= si1); Assert.True(si1.CompareTo(null) > 0); var si4 = new SI2(43, -1); var si5 = new SI2(44, -1); Assert.True(si4 > si1); Assert.True(si4 >= si1); Assert.True(si1 < si4); Assert.True(si1 <= si4); Assert.False(si4 > si2); Assert.True(si4 >= si2); Assert.False(si2 < si4); Assert.True(si2 <= si4); Assert.True(si5 > si4); Assert.True(si5 >= si4); Assert.False(si4 > si5); Assert.False(si4 >= si5); Assert.True(si4 < si5); Assert.True(si4 <= si5); Assert.False(si5 < si4); Assert.False(si5 <= si4); }
public void ToScaledStringTest() { long totalUnits = long.Parse(Math.Pow(2, 10).ToString()); string format = string.Empty; string unitName = ""; string[] symbolNames = new[] { "kilo", "mega", "giga", "tera", "peta", "exa" }; string expected = "1 kilo"; string actual; actual = SI2.ToScaledString(totalUnits, format, unitName, symbolNames); Assert.AreEqual(expected, actual); }
private void ServiceHelper_ServiceStarted(object sender, EventArgs e) { // Define a line of asterisks for emphasis string stars = new string('*', 79); // Get current process memory usage long processMemory = Common.GetProcessMemory(); // Log startup information m_serviceHelper.UpdateStatus( UpdateType.Information, "{14}{14}{0}{14}{14}" + "{1} Initializing{14}{14}" + " System Time: {2} UTC{14}{14}" + " Current Path: {3}{14}{14}" + " Machine Name: {4}{14}{14}" + " OS Version: {5}{14}{14}" + " Product Name: {6}{14}{14}" + " Working Memory: {7}{14}{14}" + " Execution Mode: {8}-bit{14}{14}" + " Processors: {9}{14}{14}" + " GC Server Mode: {10}{14}{14}" + " GC Latency Mode: {11}{14}{14}" + " Process Account: {12}\\{13}{14}{14}" + "{0}{14}", stars, ServiceName, DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff"), FilePath.TrimFileName(FilePath.RemovePathSuffix(FilePath.GetAbsolutePath("")), 61), Environment.MachineName, Environment.OSVersion.VersionString, Common.GetOSProductName(), processMemory > 0 ? SI2.ToScaledString(processMemory, 4, "B", SI2.IECSymbols) : "Undetermined", IntPtr.Size * 8, Environment.ProcessorCount, GCSettings.IsServerGC, GCSettings.LatencyMode, Environment.UserDomainName, Environment.UserName, Environment.NewLine); // Add run-time log as a service component m_serviceHelper.ServiceComponents.Add(m_runTimeLog); // Define scheduled service processes m_serviceHelper.AddScheduledProcess(ServiceHeartbeatHandler, "ServiceHeartbeat", "* * * * *"); // Define remote client service command requests (i.e., console commands) m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Restart", "Attempts to restart the host service", RestartServiceHandler)); m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Initialize", "Attempts to re-initialize algorithm processing framework.", ReinitializeAlgorithmHandler, new[] { "Reinitialize" })); m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Status", "Gets current algorithm processing framework status.", FrameworkStatusHandler, new[] { "list", "ls" })); m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("LogEvent", "Logs remote event log entries.", LogEventRequestHandler, false)); if (m_allowServiceMonitors) { // Establish plug-in service monitoring architecture - external implementations of IServiceMonitor will be auto-loaded m_serviceMonitors = new AdapterLoader <IServiceMonitor>(); m_serviceMonitors.AdapterCreated += ServiceMonitors_AdapterCreated; m_serviceMonitors.AdapterLoaded += ServiceMonitors_AdapterLoaded; m_serviceMonitors.AdapterUnloaded += ServiceMonitors_AdapterUnloaded; m_serviceMonitors.Initialize(); // Add service monitoring command m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("NotifyMonitors", "Sends a message to all service monitors", NotifyMonitorsRequestHandler)); } // Start algorithm processing framework StartAlgorithmProcessing(); // If any settings have been added to configuration file, we go ahead and save them now m_serviceHelper.SaveSettings(true); ConfigurationFile.Current.Save(); }
public void DataSetSerialization_ValidCase() { const int RowCount = ushort.MaxValue; // * 10;// * 20; //Act StringBuilder results = new StringBuilder(); Ticks stopTime, startTime; DataSet sourceDataSet = new DataSet("source"); DataTable table = sourceDataSet.Tables.Add("table1"); table.Columns.Add("col0", typeof(string)); table.Columns.Add("col1", typeof(int)); table.Columns.Add("col2", typeof(bool)); table.Columns.Add("col3", typeof(Guid)); table.Columns.Add("col4", typeof(DateTime)); table.Columns.Add("col5", typeof(TimeSpan)); table.Columns.Add("col6", typeof(byte[])); startTime = DateTime.UtcNow.Ticks; for (int i = 0; i < RowCount; i++) { DataRow row = table.NewRow(); if (Random.Boolean || Random.Boolean) { row[0] = new string((char)Random.Int16Between(32, 128), Random.Int16Between(5, 30)); } else { row[0] = DBNull.Value; } row[1] = Random.Int32; row[2] = Random.Boolean; if (Random.Boolean || Random.Boolean) { row[3] = Guid.NewGuid(); } else { row[3] = DBNull.Value; } row[4] = DateTime.UtcNow; row[5] = new TimeSpan(Random.Int64Between(Ticks.PerSecond, Ticks.PerHour)); byte[] bytes = null; if (Random.Boolean || Random.Boolean) { bytes = new byte[Random.Int16Between(0, 1000)]; Random.GetBytes(bytes); } row[6] = bytes; table.Rows.Add(row); } table = sourceDataSet.Tables.Add("table2"); table.Columns.Add("col0", typeof(ulong)); table.Columns.Add("col1", typeof(double)); table.Columns.Add("col2", typeof(byte)); table.Columns.Add("col3", typeof(char)); table.Columns.Add("col4", typeof(object)); for (int i = 0; i < Random.Int32Between(100, 500); i++) { DataRow row = table.NewRow(); if (Random.Boolean || Random.Boolean) { row[0] = Random.UInt64; } else { row[0] = DBNull.Value; } row[1] = Random.Number; row[2] = Random.Byte; if (Random.Boolean || Random.Boolean) { row[3] = (char)Random.Int16Between(32, 1024); } else { row[3] = DBNull.Value; } row[4] = Guid.NewGuid().ToString(); table.Rows.Add(row); } stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Initial random sample dataset created with {0} rows. ({1})\r\n", RowCount, (stopTime - startTime).ToElapsedTimeString(4)); results.AppendLine(); FileStream stream; string path = FilePath.GetApplicationDataFolder(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = Path.Combine(path, "DataSet.bin"); startTime = DateTime.UtcNow.Ticks; stream = new FileStream(fileName, FileMode.Create); sourceDataSet.SerializeToStream(stream); stream.Flush(); stream.Close(); stream.Dispose(); stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Dataset binary serialization time: {0}\r\n", (stopTime - startTime).ToElapsedTimeString(4)); string xmlFileName = Path.Combine(path, "DataSet.xml"); startTime = DateTime.UtcNow.Ticks; sourceDataSet.WriteXml(xmlFileName, XmlWriteMode.WriteSchema); stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Dataset XML serialization time: {0}\r\n", (stopTime - startTime).ToElapsedTimeString(4)); results.AppendLine(); DataSet destinationDataSet; startTime = DateTime.UtcNow.Ticks; stream = new FileStream(fileName, FileMode.Open); destinationDataSet = stream.DeserializeToDataSet(); stream.Close(); stream.Dispose(); stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Dataset binary deserialization time: {0}\r\n", (stopTime - startTime).ToElapsedTimeString(4)); DataSet tempDataSet; startTime = DateTime.UtcNow.Ticks; tempDataSet = new DataSet(); tempDataSet.ReadXml(xmlFileName); stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Dataset XML deserialization time: {0}\r\n", (stopTime - startTime).ToElapsedTimeString(4)); results.AppendLine(); startTime = DateTime.UtcNow.Ticks; // Validate that source and destination dataset are the same Assert.AreEqual(sourceDataSet.DataSetName, destinationDataSet.DataSetName); Assert.AreEqual(sourceDataSet.Tables.Count, destinationDataSet.Tables.Count); foreach (DataTable sourceTable in sourceDataSet.Tables) { bool tableExists = destinationDataSet.Tables.Contains(sourceTable.TableName); Assert.IsTrue(tableExists); DataTable destinationTable = destinationDataSet.Tables[sourceTable.TableName]; Assert.AreEqual(sourceTable.Columns.Count, destinationTable.Columns.Count); foreach (DataColumn sourceColumn in sourceTable.Columns) { bool columnExists = destinationTable.Columns.Contains(sourceColumn.ColumnName); Assert.IsTrue(columnExists); DataColumn destinationColumn = destinationTable.Columns[sourceColumn.ColumnName]; Assert.IsTrue(sourceColumn.DataType == destinationColumn.DataType || sourceColumn.DataType == typeof(object) && destinationColumn.DataType == typeof(string)); } Assert.AreEqual(sourceTable.Rows.Count, destinationTable.Rows.Count); for (int i = 0; i < sourceTable.Rows.Count; i++) { DataRow sourceRow = sourceTable.Rows[i]; DataRow destinationRow = destinationTable.Rows[i]; for (int j = 0; j < sourceTable.Columns.Count; j++) { if (sourceRow[j] != DBNull.Value && destinationRow[j] != DBNull.Value) { byte[] bytes = sourceRow[j] as byte[]; if (bytes != null) { Assert.IsTrue(bytes.CompareTo((byte[])destinationRow[j]) == 0); } else { Assert.AreEqual(sourceRow[j], destinationRow[j]); } } } } } stopTime = DateTime.UtcNow.Ticks; results.AppendFormat("Dataset validation time: {0}\r\n", (stopTime - startTime).ToElapsedTimeString(4)); results.AppendLine(); FileInfo xmlFile = new FileInfo(xmlFileName); FileInfo binFile = new FileInfo(fileName); results.AppendFormat("Binary serialization size = {0}\r\n", SI2.ToScaledString(binFile.Length, "B")); results.AppendFormat("XML serialization size = {0}\r\n", SI2.ToScaledString(xmlFile.Length, "B")); results.AppendFormat("Size Improvement = {0:0.00%}\r\n", (xmlFile.Length - binFile.Length) / (double)xmlFile.Length); System.Console.WriteLine(results.ToString()); }