/// <summary> /// Parses the binary header image. /// </summary> /// <param name="buffer">Binary image to parse.</param> /// <param name="startIndex">Start index into <paramref name="buffer"/> to begin parsing.</param> /// <param name="length">Length of valid data within <paramref name="buffer"/>.</param> /// <returns>The length of the data that was parsed.</returns> protected override int ParseHeaderImage(byte[] buffer, int startIndex, int length) { if (m_usePhasorDataFileFormat) { // Common frame header will have parsed all phasor data file header information at this point... State.CellCount = unchecked ((int)CommonHeader.PmuCount); return(CommonFrameHeader.DstHeaderFixedLength); } else { // Skip past header that was already parsed... startIndex += CommonFrameHeader.FixedLength; // Only need to parse what wan't already parsed in common frame header m_streamType = (StreamType)buffer[startIndex]; m_revisionNumber = (RevisionNumber)buffer[startIndex + 1]; FrameRate = BigEndian.ToUInt16(buffer, startIndex + 2); m_rowLength = BigEndian.ToUInt32(buffer, startIndex + 4); m_packetsPerSample = BigEndian.ToUInt16(buffer, startIndex + 8); State.CellCount = BigEndian.ToUInt16(buffer, startIndex + 10); // The data that's in the data stream will take precedence over what's in the // in the configuration file. The configuration file may define more PMU's than // are in the stream - in my opinion that's OK - it's when you have PMU's in the // stream that aren't defined in the INI file that you'll have trouble... return(FixedHeaderLength); } }
public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + (AccountNumber == null ? 0 : AccountNumber.GetHashCode()); hash = hash * 23 + (BillToAddressId == default(int) ? 0 : BillToAddressId.GetHashCode()); hash = hash * 23 + (Comment == null ? 0 : Comment.GetHashCode()); hash = hash * 23 + (CreditCardApprovalCode == null ? 0 : CreditCardApprovalCode.GetHashCode()); hash = hash * 23 + (CreditCardId == null ? 0 : CreditCardId.GetHashCode()); hash = hash * 23 + (CurrencyRateId == null ? 0 : CurrencyRateId.GetHashCode()); hash = hash * 23 + (CustomerId == default(int) ? 0 : CustomerId.GetHashCode()); hash = hash * 23 + (DueDate == default(DateTime) ? 0 : DueDate.GetHashCode()); hash = hash * 23 + (Freight == default(decimal) ? 0 : Freight.GetHashCode()); hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode()); hash = hash * 23 + (OnlineOrderFlag == default(bool) ? 0 : OnlineOrderFlag.GetHashCode()); hash = hash * 23 + (OrderDate == default(DateTime) ? 0 : OrderDate.GetHashCode()); hash = hash * 23 + (PurchaseOrderNumber == null ? 0 : PurchaseOrderNumber.GetHashCode()); hash = hash * 23 + (RevisionNumber == default(byte) ? 0 : RevisionNumber.GetHashCode()); hash = hash * 23 + (Rowguid == default(Guid) ? 0 : Rowguid.GetHashCode()); hash = hash * 23 + (SalesOrderNumber == null ? 0 : SalesOrderNumber.GetHashCode()); hash = hash * 23 + (SalesPersonId == null ? 0 : SalesPersonId.GetHashCode()); hash = hash * 23 + (ShipDate == null ? 0 : ShipDate.GetHashCode()); hash = hash * 23 + (ShipMethodId == default(int) ? 0 : ShipMethodId.GetHashCode()); hash = hash * 23 + (ShipToAddressId == default(int) ? 0 : ShipToAddressId.GetHashCode()); hash = hash * 23 + (Status == default(byte) ? 0 : Status.GetHashCode()); hash = hash * 23 + (SubTotal == default(decimal) ? 0 : SubTotal.GetHashCode()); hash = hash * 23 + (TaxAmt == default(decimal) ? 0 : TaxAmt.GetHashCode()); hash = hash * 23 + (TerritoryId == null ? 0 : TerritoryId.GetHashCode()); hash = hash * 23 + (TotalDue == default(decimal) ? 0 : TotalDue.GetHashCode()); return(hash); } }
public void ManMadeRevisionNumber_HasExpectedStartingValues() { var revisionNumber = new RevisionNumber(); Assert.That(revisionNumber.LocalRevisionNumber, Is.EqualTo("-1")); Assert.That(revisionNumber.LongHash, Is.EqualTo(HgRepository.EmptyRepoIdentifier)); Assert.That(revisionNumber.Hash.Length, Is.EqualTo(12)); Assert.That(revisionNumber.Hash, Is.EqualTo(revisionNumber.LongHash.Substring(0, 12))); }
/// <summary> /// Creates a new <see cref="ConfigurationFrame"/> from specified parameters. /// </summary> /// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame"/>.</param> /// <param name="configurationFileName">The required external BPA PDCstream INI based configuration file.</param> /// <param name="revisionNumber">Defines the <see cref="RevisionNumber"/> for this BPA PDCstream configuration frame.</param> /// <param name="streamType">Defines the <see cref="StreamType"/> for this BPA PDCstream configuration frame.</param> /// <param name="packetsPerSample">Number of packets per sample.</param> /// <remarks> /// <para> /// This constructor is used by a consumer to generate a BPA PDCstream configuration frame. /// </para> /// <para> /// If you are going to create multiple data packets set <paramref name="packetsPerSample"/> to a number /// greater than one. This will only start becoming necessary if you start hitting data size limits imposed /// by the nature of the transport protocol. /// </para> /// </remarks> public ConfigurationFrame(Ticks timestamp, string configurationFileName, ushort packetsPerSample, RevisionNumber revisionNumber, StreamType streamType) : base(0, new ConfigurationCellCollection(), timestamp, 30) { m_iniFile = new IniFile(configurationFileName); m_packetsPerSample = packetsPerSample; m_revisionNumber = revisionNumber; m_streamType = streamType; Refresh(false); }
private static void Main(string[] args) { var revision = new RevisionNumber(); for (int i = 0; i < 100; i++) { Console.WriteLine(revision); revision.Increment(); } Console.ReadKey(); }
/// <inheritdoc /> public override bool Execute() { // BuildNumber + "0...0" + RevisionNumber. var stamp = BuildNumber.ToString(CultureInfo.InvariantCulture); var revisionString = RevisionNumber.ToString(CultureInfo.InvariantCulture); for (int i = 0; i < 5 - revisionString.Length; i++) { stamp += "0"; } stamp += revisionString; BuildStamp = stamp; return(!Log.HasLoggedErrors); }
public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + (EmployeeId == default(int) ? 0 : EmployeeId.GetHashCode()); hash = hash * 23 + (Freight == default(decimal) ? 0 : Freight.GetHashCode()); hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode()); hash = hash * 23 + (OrderDate == default(DateTime) ? 0 : OrderDate.GetHashCode()); hash = hash * 23 + (RevisionNumber == default(byte) ? 0 : RevisionNumber.GetHashCode()); hash = hash * 23 + (ShipDate == null ? 0 : ShipDate.GetHashCode()); hash = hash * 23 + (ShipMethodId == default(int) ? 0 : ShipMethodId.GetHashCode()); hash = hash * 23 + (Status == default(byte) ? 0 : Status.GetHashCode()); hash = hash * 23 + (SubTotal == default(decimal) ? 0 : SubTotal.GetHashCode()); hash = hash * 23 + (TaxAmt == default(decimal) ? 0 : TaxAmt.GetHashCode()); hash = hash * 23 + (TotalDue == default(decimal) ? 0 : TotalDue.GetHashCode()); hash = hash * 23 + (VendorId == default(int) ? 0 : VendorId.GetHashCode()); return(hash); } }
/// <summary> /// Creates a new <see cref="ConfigurationFrame"/> from serialization parameters. /// </summary> /// <param name="info">The <see cref="SerializationInfo"/> with populated with data.</param> /// <param name="context">The source <see cref="StreamingContext"/> for this deserialization.</param> protected ConfigurationFrame(SerializationInfo info, StreamingContext context) : base(info, context) { // Deserialize configuration frame m_frameHeader = (CommonFrameHeader)info.GetValue("frameHeader", typeof(CommonFrameHeader)); m_packetsPerSample = info.GetUInt16("packetsPerSample"); m_streamType = (StreamType)info.GetValue("streamType", typeof(StreamType)); m_revisionNumber = (RevisionNumber)info.GetValue("revisionNumber", typeof(RevisionNumber)); m_iniFile = new IniFile(info.GetString("configurationFileName")); // The usePhasorDataFileFormat flag and other new elements did not exist in prior versions so we protect against possible deserialization failures try { UsePhasorDataFileFormat = info.GetBoolean("usePhasorDataFileFormat"); m_rowLength = info.GetUInt32("rowLength"); } catch (SerializationException) { UsePhasorDataFileFormat = false; m_rowLength = 0; } Refresh(false); }
/// <summary> /// Parses the binary header image. /// </summary> /// <param name="buffer">Binary image to parse.</param> /// <param name="startIndex">Start index into <paramref name="buffer"/> to begin parsing.</param> /// <param name="length">Length of valid data within <paramref name="buffer"/>.</param> /// <returns>The length of the data that was parsed.</returns> protected override int ParseHeaderImage(byte[] buffer, int startIndex, int length) { DataFrame parentFrame = Parent; DataFrameParsingState frameState = parentFrame.State; IDataCellParsingState state = State; RevisionNumber revision = parentFrame.ConfigurationFrame.RevisionNumber; int x, index = startIndex; byte analogs, digitals, phasors; // Read data buffer if using phasor data file format if (UsePhasorDataFileFormat && frameState.RemainingPdcBlockPmus == 0) { m_dataBuffer = BigEndian.ToUInt32(buffer, index); index += 4; } // Get data cell flags m_channelFlags = (ChannelFlags)buffer[index]; analogs = buffer[index + 1]; index += 2; // Parse PDCstream specific header image if (revision >= RevisionNumber.Revision2 && frameState.RemainingPdcBlockPmus == 0) { // Strip off reserved flags m_reservedFlags = (ReservedFlags)analogs & ~ReservedFlags.AnalogWordsMask; // Leave analog word count analogs &= (byte)ReservedFlags.AnalogWordsMask; } else { // Older revisions didn't allow analogs m_dataRate = analogs; analogs = 0; } if (frameState.RemainingPdcBlockPmus > 0) { // PDC Block PMU's contain exactly 2 phasors, 0 analogs and 1 digital phasors = 2; analogs = 0; digitals = 1; UsingPdcExchangeFormat = true; // Decrement remaining PDC block PMU's frameState.RemainingPdcBlockPmus--; } else { // Parse number of digitals and phasors for normal PMU cells digitals = buffer[index]; phasors = buffer[index + 1]; index += 2; if (revision >= RevisionNumber.Revision2) { // Strip off IEEE flags FormatFlags = (FormatFlags)digitals & ~FormatFlags.DigitalWordsMask; // Leave digital word count digitals &= (byte)FormatFlags.DigitalWordsMask; } // Check for PDC exchange format if (UsingPdcExchangeFormat) { // In cases where we are using PDC exchange the phasor count is the number of PMU's in the PDC block int pdcBlockPmus = phasors - 1; // <-- Current PMU counts as one frameState.RemainingPdcBlockPmus = pdcBlockPmus; frameState.CellCount += pdcBlockPmus; // PDC Block PMU's contain exactly 2 phasors, 0 analogs and 1 digital phasors = 2; analogs = 0; digitals = 1; // Get data cell flags for PDC block PMU m_channelFlags = (ChannelFlags)buffer[index]; UsingPdcExchangeFormat = true; index += 2; } else { // Parse PMU's sample number m_sampleNumber = BigEndian.ToUInt16(buffer, index); index += 2; } } // Algorithm Case: Determine best course of action when stream counts don't match counts defined in the // external INI based configuration file. Think about what *will* happen when new data appears in the // stream that's not in the config file - you could raise an event notifying consumer about the mismatch // instead of raising an exception - could even make a boolean property that would allow either case. // The important thing to consider is that to parse the cell images you have to have a defined // definition (see base class method "DataCellBase.ParseBodyImage"). If you have more items defined // in the stream than you do in the config file then you won't get the new value, too few items and you // don't have enough definitions to correctly interpret the data (that would be bad) - either way the // definitions won't line up with the appropriate data value and you won't know which one is missing or // added. I can't change the protocol so this is enough argument to just raise an error for config // file/stream mismatch. So for now we'll just throw an exception and deal with consequences :) // Note that this only applies to BPA PDCstream protocol because of external configuration. // Addendum: After running this with several protocol implementations I noticed that if a device wasn't // reporting, the phasor count dropped to zero even if there were phasors defined in the configuration // file, so the only time an exception is thrown is if there are more phasors defined in the the stream // than there are defined in the INI file... // At least this number of phasors should be already defined in BPA PDCstream configuration file if (phasors > ConfigurationCell.PhasorDefinitions.Count) { throw new InvalidOperationException( "Stream/Config File Mismatch: Phasor value count in stream (" + phasors + ") does not match defined count in configuration file (" + ConfigurationCell.PhasorDefinitions.Count + ") for " + ConfigurationCell.IDLabel); } // If analog values get a clear definition in INI file at some point, we can validate the number in the // stream to the number in the config file, in the mean time we dyanmically add analog definitions to // configuration cell as needed (they are only defined in data frame of BPA PDCstream) if (analogs > ConfigurationCell.AnalogDefinitions.Count) { for (x = ConfigurationCell.AnalogDefinitions.Count; x < analogs; x++) { ConfigurationCell.AnalogDefinitions.Add(new AnalogDefinition(ConfigurationCell, "Analog " + (x + 1), 1, 0.0D, AnalogType.SinglePointOnWave)); } } // If digital values get a clear definition in INI file at some point, we can validate the number in the // stream to the number in the config file, in the mean time we dyanmically add digital definitions to // configuration cell as needed (they are only defined in data frame of BPA PDCstream) if (digitals > ConfigurationCell.DigitalDefinitions.Count) { for (x = ConfigurationCell.DigitalDefinitions.Count; x < digitals; x++) { ConfigurationCell.DigitalDefinitions.Add(new DigitalDefinition(ConfigurationCell, "Digital Word " + (x + 1))); } } // Unlike most all other protocols the counts defined for phasors, analogs and digitals in the data frame // may not exactly match what's defined in the configuration frame as these values are defined in an external // INI file for BPA PDCstream. As a result, we manually assign the counts to the parsing state so that these // will be the counts used to parse values from data frame in the base class ParseBodyImage method state.PhasorCount = phasors; state.AnalogCount = analogs; state.DigitalCount = digitals; // Status flags and remaining data elements will parsed by base class in the ParseBodyImage method return(index - startIndex); }
public MainForm(StopLocation[] stops) { m_stops = stops; InitializeComponent(); System.IO.Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BusTracker.startup.jpg"); m_startupScreenPictureBox.Image = new Bitmap(stream); // Create shortcuts on startup if it doesn't exist. string exePath = Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName; string exeFolder = exePath.Substring(0, exePath.LastIndexOf("\\")); string shortcutPath = Path.Combine(ShortcutFolder, string.Format("{0}.lnk", AppName)); string startMenuShortcutPath = Path.Combine(StartMenuShortcutFolder, string.Format("{0}.lnk", AppName)); string startUpFolderShortcutPath = Path.Combine(StartUpFolder, string.Format("{0}.lnk", AppName)); string shortcutData = string.Format("{0}#\"{1}\"", exePath.Length, exePath); string updatePath = Path.Combine(UpdateShare, BinaryName); // Shortcut in start menu if (!File.Exists(shortcutPath) && !File.Exists(startMenuShortcutPath)) { StreamWriter f = new StreamWriter(shortcutPath); f.WriteLine(shortcutData); f.Close(); } if (!File.Exists(startUpFolderShortcutPath)) { StreamWriter f = new StreamWriter(startUpFolderShortcutPath); f.WriteLine(shortcutData); f.Close(); } m_infoFetcher = new InfoFetcher(); m_infoFetcher.BusInfoAvailable += new BusInfoAvailableEventHandler(m_infoFetcher_BusInfoAvailable); m_infoFetcher.BusInfoFetchComplete += new EventHandler(m_infoFetcher_BusInfoFetchComplete); m_infoFetcher.BusInfoSourceAvailabilityChanged += new EventHandler(m_infoFetcher_BusInfoSourceAvailabilityChanged); this.Menu = null; this.WindowState = FormWindowState.Maximized; m_stopControls = new StopControl[stops.Length]; for (int i = 0; i < m_stopControls.Length; i++) { m_stopControls[i] = new StopControl(stops[i].FriendlyName, m_stops[i].MaxBuses); m_stopControls[i].Left = 0; m_panel.Controls.Add(m_stopControls[i]); } m_panel.BackColor = ColorService.BACKGROUND; this.BackColor = ColorService.BACKGROUND; m_quitButton.BackColor = ColorService.BUTTON_BACKGROUND; m_quitButton.ForeColor = ColorService.BUTTON_FOREGROUND; m_quitButtonPanel.BackColor = m_quitButton.ForeColor; m_refreshButton.BackColor = ColorService.BUTTON_BACKGROUND; m_refreshButton.ForeColor = ColorService.BUTTON_FOREGROUND; m_refreshButtonPanel.BackColor = m_refreshButton.ForeColor; m_timeLabel.BackColor = ColorService.BACKGROUND; m_timeLabel.ForeColor = ColorService.TIME; m_timeLabel.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold); m_rebootButton.ForeColor = Color.White; m_rebootButton.BackColor = Color.Red; // Load the image for when the tracker is offline stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BusTracker.offline.jpg"); m_offlinePictureBox.Image = new Bitmap(stream); UpdateStopControlsLayout(); m_updateTimer.Enabled = true; m_currentVersion = (new FileInfo(exePath)).LastWriteTime; m_versionLabel.Text = m_currentVersion.ToShortDateString() + " " + m_currentVersion.ToShortTimeString(); m_availableVersion = (new FileInfo(updatePath)).LastWriteTime; m_availableVersionLabel.Text = m_availableVersion.ToShortDateString() + " " + m_availableVersion.ToShortTimeString(); m_revisionLabel.Text = RevisionNumber.ToString(); //ScreenOn(); }