public void UpdateRecord(SRecord sRecord) { try { using (var cli = new DBGContext()) { Record UR; UR = cli.Records.Include(x => x.LinkPlayer).FirstOrDefault(x => x.LinkPlayer.PlayerId == sRecord.LinkPlayer.PlayerId && x.Mode == sRecord.Mode); if (UR == null) { UR = new Record() { LinkPlayer = cli.Players.FirstOrDefault(x => x.PlayerId == sRecord.LinkPlayer.PlayerId), Mode = sRecord.Mode }; cli.Records.Add(UR); } if (UR.Score < sRecord.Score) { UR.Score = sRecord.Score; } if (UR.MaxSpeed < sRecord.MaxSpeed) { UR.MaxSpeed = sRecord.MaxSpeed; } if (UR.MaxTime < sRecord.MaxTime) { UR.MaxTime = sRecord.MaxTime; } cli.SaveChanges(); } } catch { } }
/// <summary> /// Write the output hex file. /// </summary> /// <param name="aisStream">File stream of input binary ais data.</param> /// <param name="outFileName">Name of the output hex file.</param> static void ais2hex(Byte[] aisData, String outFileName) { // Do the AIS binary to S-Record conversion Byte[] val = SRecord.bin2srec(aisData, 0x42000000, 32); // Write out the Motorola S-Record hex file FileStream hexOut = new FileStream(outFileName, FileMode.Create, FileAccess.Write); hexOut.Write(val, 0, val.Length); hexOut.Close(); }
/// <summary> /// Gets the result message data. /// </summary> /// <param name="resultData">The result data.</param> /// <returns></returns> private static string GetResultMessageData(string resultData) { List <string> resultsDataList = new List <string>(); List <string> errorCodes = new List <string>(); for (int index = 0; index < resultData.Length; index = index + 200) { resultsDataList.Add(resultData.Substring(index, 200)); } foreach (string result in resultsDataList) { switch (result.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture)) { case "M": MRecord mRecord = new MRecord().Convert(result); errorCodes = errorCodes.Union(mRecord.ClaimRejectionReasons.Union(mRecord.ClaimDenialReasons) .Union(mRecord.ClaimBackToProviderReasons)).ToList(); break; case "N": NRecord nRecord = new NRecord().Convert(result); errorCodes = errorCodes.Union(nRecord.ClaimSuspensionReasons.Union(nRecord.LineRejectionReasons) .Union(nRecord.LineDenialReasons)).ToList(); break; case "O": ORecord oRecord = new ORecord().Convert(result); errorCodes = errorCodes.Union(oRecord.Diagnosis1.Union(oRecord.Diagnosis2) .Union(oRecord.Diagnosis3).Union(oRecord.Diagnosis4).Union(oRecord.Diagnosis5)).ToList(); break; case "R": RRecord rRecord = new RRecord().Convert(result); errorCodes = errorCodes.Union(rRecord.ProcedureEdits).ToList(); break; case "S": SRecord sRecord = new SRecord().Convert(result); errorCodes = errorCodes.Union(sRecord.Modifier1.Union(sRecord.Modifier2) .Union(sRecord.Modifier3).Union(sRecord.Modifier4).Union(sRecord.Modifier5).Union(sRecord.DateEdit).Union(sRecord.RevenueEdit)).ToList(); break; } } return(FilteredCodes(errorCodes)); }
private static void TestSRecord(String title, String fileName, byte[] data) { SRecord srec = new SRecord(); StreamWriter sw = new StreamWriter(fileName); // Create a new S0 record with the title SRecordStructure srecs = srec.NewRecord(0, 0, Encoding.ASCII.GetBytes(title), title.Length); srec.Write(sw); // Create a S1 data record srec.NewRecord(1, 0, data, data.Length); srec.Write(sw); // Create a S5 transmission record srec.NewRecord(5, 1, null, 0); srec.Write(sw); // Create a S9 program start record srec.NewRecord(9, 0, null, 0); srec.Write(sw); sw.Close(); Console.WriteLine("Wrote Motorola S-Record formatted file: " + fileName); Console.WriteLine("Reading back Motorola S-Record file:"); // Open up the new file and attempt to read the records and print to the console StreamReader sr = new StreamReader(fileName); srecs = srec.Read(sr); Console.WriteLine((srecs != null)? srec.Print() : "Could not read record!"); srecs = srec.Read(sr); Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!"); srecs = srec.Read(sr); Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!"); srecs = srec.Read(sr); Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!"); sr.Close(); }
public SDatabase Install(SRecord r, long c) { var obs = objects; var st = ((STable)obs[r.table]) + r; if (r.uid >= STransaction._uid) { obs += (r.uid, r); } obs += (r.table, st); var nms = names + (st.name, st); for (var b = st.indexes.First(); b != null; b = b.Next()) { var x = (SIndex)objects[b.Value.Item1]; obs += (x.uid, x + (r, r.uid)); if (x.references == r.table && !x.Contains(r)) { throw new Exception("Referential constraint"); } } return(New(obs, nms, c)); }
/// <summary>Searches the disk for an extents file (or gets it from cache)</summary> /// <returns>Error.</returns> /// <param name="fileId">File identifier.</param> /// <param name="file">Extents file.</param> Errno ReadExtentsFile(short fileId, out ExtentFile file) { file = new ExtentFile(); if (!_mounted) { return(Errno.AccessDenied); } if (fileId < 4 || (fileId == 4 && _mddf.fsversion != LISA_V2 && _mddf.fsversion != LISA_V1)) { return(Errno.InvalidArgument); } if (_extentCache.TryGetValue(fileId, out file)) { return(Errno.NoError); } // A file ID that cannot be stored in the S-Records File if (fileId >= _srecords.Length) { return(Errno.InvalidArgument); } ulong ptr = _srecords[fileId].extent_ptr; // An invalid pointer denotes file does not exist if (ptr == 0xFFFFFFFF || ptr == 0x00000000) { return(Errno.NoSuchFile); } // Pointers are relative to MDDF ptr += _mddf.mddf_block + _volumePrefix; LisaTag.PriamTag extTag; // This happens on some disks. // This is a filesystem corruption that makes LisaOS crash on scavenge. // This code just allow to ignore that corruption by searching the Extents File using sector tags if (ptr >= _device.Info.Sectors) { bool found = false; for (ulong i = 0; i < _device.Info.Sectors; i++) { DecodeTag(_device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out extTag); if (extTag.FileId != fileId * -1) { continue; } ptr = i; found = true; break; } if (!found) { return(Errno.InvalidArgument); } } // Checks that the sector tag indicates its the Extents File we are searching for DecodeTag(_device.ReadSectorTag(ptr, SectorTagType.AppleSectorTag), out extTag); if (extTag.FileId != (short)(-1 * fileId)) { return(Errno.NoSuchFile); } byte[] sector = _mddf.fsversion == LISA_V1?_device.ReadSectors(ptr, 2) : _device.ReadSector(ptr); if (sector[0] >= 32 || sector[0] == 0) { return(Errno.InvalidArgument); } file.filenameLen = sector[0]; file.filename = new byte[file.filenameLen]; Array.Copy(sector, 0x01, file.filename, 0, file.filenameLen); file.unknown1 = BigEndianBitConverter.ToUInt16(sector, 0x20); file.file_uid = BigEndianBitConverter.ToUInt64(sector, 0x22); file.unknown2 = sector[0x2A]; file.etype = sector[0x2B]; file.ftype = (FileType)sector[0x2C]; file.unknown3 = sector[0x2D]; file.dtc = BigEndianBitConverter.ToUInt32(sector, 0x2E); file.dta = BigEndianBitConverter.ToUInt32(sector, 0x32); file.dtm = BigEndianBitConverter.ToUInt32(sector, 0x36); file.dtb = BigEndianBitConverter.ToUInt32(sector, 0x3A); file.dts = BigEndianBitConverter.ToUInt32(sector, 0x3E); file.serial = BigEndianBitConverter.ToUInt32(sector, 0x42); file.unknown4 = sector[0x46]; file.locked = sector[0x47]; file.protect = sector[0x48]; file.master = sector[0x49]; file.scavenged = sector[0x4A]; file.closed = sector[0x4B]; file.open = sector[0x4C]; file.unknown5 = new byte[11]; Array.Copy(sector, 0x4D, file.unknown5, 0, 11); file.release = BigEndianBitConverter.ToUInt16(sector, 0x58); file.build = BigEndianBitConverter.ToUInt16(sector, 0x5A); file.compatibility = BigEndianBitConverter.ToUInt16(sector, 0x5C); file.revision = BigEndianBitConverter.ToUInt16(sector, 0x5E); file.unknown6 = BigEndianBitConverter.ToUInt16(sector, 0x60); file.password_valid = sector[0x62]; file.password = new byte[8]; Array.Copy(sector, 0x63, file.password, 0, 8); file.unknown7 = new byte[3]; Array.Copy(sector, 0x6B, file.unknown7, 0, 3); file.overhead = BigEndianBitConverter.ToUInt16(sector, 0x6E); file.unknown8 = new byte[16]; Array.Copy(sector, 0x70, file.unknown8, 0, 16); file.unknown10 = BigEndianBitConverter.ToInt16(sector, 0x17E); file.LisaInfo = new byte[128]; Array.Copy(sector, 0x180, file.LisaInfo, 0, 128); int extentsCount = 0; int extentsOffset; if (_mddf.fsversion == LISA_V1) { file.length = BigEndianBitConverter.ToInt32(sector, 0x200); file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x204); extentsOffset = 0x208; } else { file.length = BigEndianBitConverter.ToInt32(sector, 0x80); file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x84); extentsOffset = 0x88; } for (int j = 0; j < 41; j++) { if (BigEndianBitConverter.ToInt16(sector, extentsOffset + (j * 6) + 4) == 0) { break; } extentsCount++; } file.extents = new Extent[extentsCount]; for (int j = 0; j < extentsCount; j++) { file.extents[j] = new Extent { start = BigEndianBitConverter.ToInt32(sector, extentsOffset + (j * 6)), length = BigEndianBitConverter.ToInt16(sector, extentsOffset + (j * 6) + 4) } } ; _extentCache.Add(fileId, file); if (!_debug) { return(Errno.NoError); } if (_printedExtents.Contains(fileId)) { return(Errno.NoError); } AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filenameLen = {1}", fileId, file.filenameLen); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filename = {1}", fileId, StringHandlers.CToString(file.filename, Encoding)); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown1 = 0x{1:X4}", fileId, file.unknown1); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].file_uid = 0x{1:X16}", fileId, file.file_uid); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown2 = 0x{1:X2}", fileId, file.unknown2); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].etype = 0x{1:X2}", fileId, file.etype); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].ftype = {1}", fileId, file.ftype); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown3 = 0x{1:X2}", fileId, file.unknown3); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtc = {1}", fileId, file.dtc); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dta = {1}", fileId, file.dta); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtm = {1}", fileId, file.dtm); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtb = {1}", fileId, file.dtb); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dts = {1}", fileId, file.dts); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].serial = {1}", fileId, file.serial); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown4 = 0x{1:X2}", fileId, file.unknown4); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].locked = {1}", fileId, file.locked > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].protect = {1}", fileId, file.protect > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].master = {1}", fileId, file.master > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].scavenged = {1}", fileId, file.scavenged > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].closed = {1}", fileId, file.closed > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].open = {1}", fileId, file.open > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown5 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + "{10:X2}{11:X2}", fileId, file.unknown5[0], file.unknown5[1], file.unknown5[2], file.unknown5[3], file.unknown5[4], file.unknown5[5], file.unknown5[6], file.unknown5[7], file.unknown5[8], file.unknown5[9], file.unknown5[10]); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].release = {1}", fileId, file.release); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].build = {1}", fileId, file.build); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].compatibility = {1}", fileId, file.compatibility); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].revision = {1}", fileId, file.revision); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown6 = 0x{1:X4}", fileId, file.unknown6); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password_valid = {1}", fileId, file.password_valid > 0); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password = {1}", fileId, Encoding.GetString(file.password)); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown7 = 0x{1:X2}{2:X2}{3:X2}", fileId, file.unknown7[0], file.unknown7[1], file.unknown7[2]); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].overhead = {1}", fileId, file.overhead); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown8 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + "{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}", fileId, file.unknown8[0], file.unknown8[1], file.unknown8[2], file.unknown8[3], file.unknown8[4], file.unknown8[5], file.unknown8[6], file.unknown8[7], file.unknown8[8], file.unknown8[9], file.unknown8[10], file.unknown8[11], file.unknown8[12], file.unknown8[13], file.unknown8[14], file.unknown8[15]); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].length = {1}", fileId, file.length); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown9 = 0x{1:X8}", fileId, file.unknown9); for (int ext = 0; ext < file.extents.Length; ext++) { AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].start = {2}", fileId, ext, file.extents[ext].start); AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].length = {2}", fileId, ext, file.extents[ext].length); } AaruConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown10 = 0x{1:X4}", fileId, file.unknown10); _printedExtents.Add(fileId); return(Errno.NoError); } /// <summary>Reads all the S-Records and caches it</summary> Errno ReadSRecords() { if (!_mounted) { return(Errno.AccessDenied); } // Searches the S-Records place using MDDF pointers byte[] sectors = _device.ReadSectors(_mddf.srec_ptr + _mddf.mddf_block + _volumePrefix, _mddf.srec_len); // Each entry takes 14 bytes _srecords = new SRecord[sectors.Length / 14]; for (int s = 0; s < _srecords.Length; s++) { _srecords[s] = new SRecord { extent_ptr = BigEndianBitConverter.ToUInt32(sectors, 0x00 + (14 * s)), unknown = BigEndianBitConverter.ToUInt32(sectors, 0x04 + (14 * s)), filesize = BigEndianBitConverter.ToUInt32(sectors, 0x08 + (14 * s)), flags = BigEndianBitConverter.ToUInt16(sectors, 0x0C + (14 * s)) } } ; return(Errno.NoError); } } }
static void Main(string[] args) { string filePath = null; string fileExt = null; bool help = false; bool isDfuFile = false; // Vendor and Product IDs are required, set them to invalid int vid = 0x10000, pid = 0x10000; // version is optional, FF means forced update int vmajor = 0xFF, vminor = 0xFF; // parameter parsing OptionSet optionSet = new OptionSet() .Add("?|help|h", "Prints out the options.", option => help = option != null) .Add("i|image=", "Path of the image file to download. Supported formats are DFU, Intel HEX and Motorola SREC.", option => filePath = option) .Add("d|device=", "USB Device Vendor and Product ID in XXXX:XXXX format. Ignored if the file format is DFU.", option => { var result = UsbIdRegex.Match(option); if (!result.Success) { help = true; } else { vid = UInt16.Parse(result.Groups["vid"].Value, NumberStyles.HexNumber); pid = UInt16.Parse(result.Groups["pid"].Value, NumberStyles.HexNumber); } }) .Add("v|version=", "Firmware version in D.D format. Ignored if the file format is DFU.", option => { var result = VersionRegex.Match(option); if (!result.Success) { help = true; } else { vmajor = Byte.Parse(result.Groups["major"].Value); vminor = Byte.Parse(result.Groups["minor"].Value); } }); try { // try to get required arguments optionSet.Parse(args); fileExt = Path.GetExtension(filePath); isDfuFile = Dfu.IsExtensionSupported(fileExt); if (!isDfuFile && ((vid > 0xFFFF) || (pid > 0xFFFF))) { help = true; } } catch (Exception) { help = true; } if (help) { // print help text and exit Console.Error.WriteLine("Usage:"); optionSet.WriteOptionDescriptions(Console.Error); Environment.Exit(-1); } // DFU device event printers int prevCursor = -1; EventHandler <ProgressChangedEventArgs> printDownloadProgress = (obj, e) => { if (prevCursor == Console.CursorTop) { Console.SetCursorPosition(0, Console.CursorTop - 1); } Console.WriteLine("Download progress: {0}%", e.ProgressPercentage); prevCursor = Console.CursorTop; }; EventHandler <ErrorEventArgs> printDevError = (obj, e) => { Console.Error.WriteLine("The DFU device reported the following error: {0}", e.GetException().Message); }; Device device = null; try { Version fileVer = new Version(vmajor, vminor); Dfu.FileContent dfuFileData = null; RawMemory memory = null; // find the matching file parser by extension if (isDfuFile) { dfuFileData = Dfu.ParseFile(filePath); Console.WriteLine("DFU image parsed successfully."); // DFU file specifies VID, PID and version, so override any arguments vid = dfuFileData.DeviceInfo.VendorId; pid = dfuFileData.DeviceInfo.ProductId; fileVer = dfuFileData.DeviceInfo.ProductVersion; } else if (IntelHex.IsExtensionSupported(fileExt)) { memory = IntelHex.ParseFile(filePath); Console.WriteLine("Intel HEX image parsed successfully."); } else if (SRecord.IsExtensionSupported(fileExt)) { memory = SRecord.ParseFile(filePath); Console.WriteLine("SRecord image parsed successfully."); } else { throw new ArgumentException("Image file format not recognized."); } // find the DFU device device = Device.OpenFirst(UsbDevice.AllDevices, vid, pid); device.DeviceError += printDevError; if (isDfuFile) { // verify protocol version if (dfuFileData.DeviceInfo.DfuVersion != device.DfuDescriptor.DfuVersion) { throw new InvalidOperationException(String.Format("DFU file version {0} doesn't match device DFU version {1}", dfuFileData.DeviceInfo.DfuVersion, device.DfuDescriptor.DfuVersion)); } } // if the device is in normal application mode, reconfigure it if (device.InAppMode()) { bool skipUpdate = fileVer <= device.Info.ProductVersion; // skip update when it's deemed unnecessary if (skipUpdate) { Console.WriteLine("The device is already up-to-date (version {0}), skipping update (version {1}).", device.Info.ProductVersion, fileVer); return; } Console.WriteLine("Device found in application mode, reconfiguring device to DFU mode..."); device.Reconfigure(); // in case the device detached, we must find the DFU mode device if (!device.IsOpen()) { // clean up old device first device.DeviceError -= printDevError; device.Dispose(); device = null; device = Device.OpenFirst(UsbDevice.AllDevices, vid, pid); device.DeviceError += printDevError; } } else { Console.WriteLine("Device found in DFU mode."); } // perform upgrade device.DownloadProgressChanged += printDownloadProgress; if (isDfuFile) { device.DownloadFirmware(dfuFileData); } else { device.DownloadFirmware(memory); } device.DownloadProgressChanged -= printDownloadProgress; Console.WriteLine("Download successful, manifesting update..."); device.Manifest(); // if the device detached, clean up if (!device.IsOpen()) { device.DeviceError -= printDevError; device.Dispose(); device = null; } // TODO find device again to verify new version Console.WriteLine("The device has been successfully upgraded."); } catch (Exception e) { Console.Error.WriteLine("Device Firmware Upgrade failed with exception: {0}.", e.ToString()); Environment.Exit(-1); } finally { if (device != null) { device.Dispose(); } } }
private List <DrillResult> DrillRegularResult(CrawlOriData pCrawlOriData) { StringBuilder sHtmlSb = new StringBuilder(pCrawlOriData.Data.ToString()); //执行清洗操作 if (CleanRule != null && CleanRule.Length > 0) { string[] sCleanRules = CleanRule.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); if (sCleanRules.Length > 0) { for (int i = 0; i < sCleanRules.Length; i++) { string[] sCleanRule = sCleanRules[i].Split('|'); if (sCleanRule.Length == 1) { sHtmlSb.Replace(sCleanRule[0], ""); } else if (sCleanRule.Length == 2) { sHtmlSb.Replace(sCleanRule[0], sCleanRule[1]); } } } } List <DrillResult> Records = new List <DrillResult>(); //对当前html进行一个规则实例化-富血模型类 RegScriptTransactor sRegScriptTransactor = new RegScriptTransactor(sHtmlSb.ToString()); //(多个)记录区-规则提取 DrillRegularRules.ForEach(t => { if (sRegScriptTransactor.CanExe(t)) { if (t.DrillType == 0) { string sName = t.FeatureType == 0 ? LineFeatureType.链接.ToString() : LineFeatureType.图片.ToString(); DrillResult sDrillResult = new DrillResult(); string[] sRdData = sRegScriptTransactor.GetUrls(t, pCrawlOriData.Url); //是否能找到记录区 if (sRdData != null && sRdData.Length > 0) { RegularMetaFeild sFeild = null; if (t.Feilds != null && t.Feilds.Count >= 5) { sFeild = t.Feilds[1]; } //生成结果集 for (int j = 0; j < sRdData.Length; j++) { sDrillResult.Records.Add(new DrillCRecord(Plot.Name, sName, sRdData[j])); } } Records.Add(sDrillResult); } else { //高级自定义提取 //规则结果对象 DrillResult sDrillResult = new DrillResult(); //获取记录区片段 string[] sRegionHtmls = sRegScriptTransactor.GetRecordHtmls(t); if (sRegionHtmls != null) { for (int j = 0; j < sRegionHtmls.Length; j++) { RegScriptTransactor sRegionTransactor = new RegScriptTransactor(sRegionHtmls[j]); DrillCRecord sDrillCRecord = new DrillCRecord(); //sDrillCRecord.DbModelID = sDrillRule.MetaModalID; SRecord sCRecord = new SRecord(); sDrillCRecord.Record = sCRecord; //sCRecord.DbID = sDrillRule.DbID; //sCRecord.Meta = new string[sDrillRule.Feilds.Count]; for (int k = 0; k < t.Feilds.Count; k++) { RegularMetaFeild sRegularMetaFeild = t.Feilds[k]; if (sRegularMetaFeild.Name == "来源链接") { sCRecord.Url = pCrawlOriData.Url; } else if (sRegularMetaFeild.Rule != null) { string sValue = sRegionTransactor.Exe(sRegularMetaFeild.Rule); sCRecord.Url = sValue; if (sRegularMetaFeild.BindType > 0 && sValue != null && sValue.Trim().Length > 0) { string[] sUrls = sValue.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); if (sUrls != null && sUrls.Length > 0) { Dictionary <string, string> sUrlDic = new Dictionary <string, string>(); for (int ii = 0; ii < sUrls.Length; ii++) { string sUrl = sUrls[ii].Trim(); if (sUrlDic.ContainsKey(sUrl.ToLower()) == false) { sUrlDic[sUrl.ToLower()] = sUrl; string[] sUrlSpans = sUrl.Split('\t'); if (sUrlSpans.Length > 1 && (sUrlSpans[1].StartsWith("http://") || sUrlSpans[1].StartsWith("https://"))) { //sDrillCRecord.AddDownload(sUrlSpans[1], pData.Url, sRegularMetaFeild.BindType); } else if (sUrlSpans[0].StartsWith("http://") || sUrlSpans[0].StartsWith("https://")) { //sDrillCRecord.AddDownload(sUrlSpans[0], pData.Url, sRegularMetaFeild.BindType); } } } } } } } sDrillResult.Records.Add(sDrillCRecord); } } Records.Add(sDrillResult); }; } }); return(Records); }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code</returns> static Int32 Main(String[] args) { // Assumes that in AssemblyInfo.cs, the version is specified as 1.0.* or the like, // with only 2 numbers specified; the next two are generated from the date. System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000, v.Revision*2 is seconds since local midnight Int32 buildYear = new DateTime(v.Build * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999).Year; // Begin main code Console.Clear(); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI AIS Hex File Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Now proceed with main program FileStream tempAIS_fs = null; Byte[] AISData, convertedData; AISGen_OMAP_L138 generator = new AISGen_OMAP_L138(); // Update the default INI file name to the one supplied on the command line if (cmdParams.iniFileName == null) { cmdParams.iniFileName = generator.DeviceNameShort + ".ini"; } // Read the INI data from file INISection[] iniSecs = INI.Parse(new FileStream(cmdParams.iniFileName, FileMode.Open, FileAccess.Read)); // Force section-by-section CRC checks (may be overridden in INI file) generator.CRCType = CRCCheckType.SECTION_CRC; // Do the AIS generation try { AISData = AISGen.GenAIS(cmdParams.inputfileName, generator, iniSecs); } catch (Exception e) { System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); Console.WriteLine(e.StackTrace); Console.WriteLine("Unhandled Exception!!! Application will now exit."); return(-1); } tempAIS_fs = new FileStream(cmdParams.outFileName, FileMode.Create, FileAccess.Write); switch (cmdParams.convType) { case ConvType.Exec2Bin: tempAIS_fs.Write(AISData, 0, (int)AISData.Length); break; case ConvType.Exec2CArray: convertedData = CArray.bin2CArray(AISData, 4); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); break; case ConvType.Exec2Srec: convertedData = SRecord.bin2srec(AISData, 0x60000000, 32); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); break; case ConvType.Exec2Text: Console.WriteLine("Mode Not supported."); //Byte[] val = SRecord.bin2srec(aisData, 0x60000000, 32); break; } tempAIS_fs.Close(); Console.WriteLine("Conversion is complete."); return(0); }
/// <summary> /// Main program. /// </summary> /// <param name="args">Input commandline arguments</param> /// <returns>Return code</returns> static Int32 Main(String[] args) { IniFile myIniFile; // From Common/AIS/HexAIS_version.cs System.Version v = GetVersion(); // From Common/AIS/HexAIS_version.cs Int32 buildYear = GetBuildYear(); // Begin main code Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(" TI AIS Hex File Generator for " + devString); Console.WriteLine(" (C) " + buildYear + ", Texas Instruments, Inc."); Console.WriteLine(" Ver. " + v.Major + "." + v.Minor.ToString("D2")); Console.WriteLine("-----------------------------------------------------"); Console.Write("\n\n"); // Parse the input command line parameters ProgramCmdParams cmdParams = ParseCmdLine(args); if (!cmdParams.valid) { DispHelp(); return(-1); } // Now proceed with main program FileStream tempAIS_fs = null; Byte[] AISData, convertedData; AISGen_OMAP_L137 generator = new AISGen_OMAP_L137(); // Update the default INI file name to the one supplied on the command line if (cmdParams.iniFileName == null) { Console.WriteLine("No ini file provided. Using default, {0}", generator.DeviceNameShort + ".ini"); cmdParams.iniFileName = generator.DeviceNameShort + ".ini"; } // Read the INI data from file if (File.Exists(cmdParams.iniFileName)) { myIniFile = new IniFile(new FileStream(cmdParams.iniFileName, FileMode.Open, FileAccess.Read), cmdParams.iniFileName); } else { Console.WriteLine("File {0} not found.", cmdParams.iniFileName); return(-1); } // Put entryPoint in General Ini section (may be overridden by INI InputFile sections) myIniFile.InsertValue("General", "EntryPoint", "0x" + cmdParams.entryPoint.ToString("X8")); // Force section-by-section CRC checks (may be overridden in INI file) generator.AISCRCType = AisCRCCheckType.SECTION_CRC; // Do the AIS generation try { AISData = AISGen.GenAIS(generator, cmdParams.inputFileName, myIniFile); } catch (Exception e) { System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true); Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); Console.WriteLine("Unhandled Exception!!! Application will now exit."); return(-1); } // Check if SecureAISGen completed successfully if (AISData == null) { Console.WriteLine("AIS generation failed."); return(-1); } using (tempAIS_fs = new FileStream(cmdParams.outFileName, FileMode.Create, FileAccess.Write)) { // Convert the AIS data to the correct output format switch (cmdParams.convType) { case ConvType.Exec2Bin: tempAIS_fs.Write(AISData, 0, (int)AISData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", AISData.Length, cmdParams.outFileName); break; case ConvType.Exec2CArray: convertedData = CArray.bin2CArray(cmdParams.cArrayName, AISData, 4); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", convertedData.Length, cmdParams.outFileName); break; case ConvType.Exec2Srec: convertedData = SRecord.bin2srec(AISData, (UInt32)cmdParams.srecAddr, 32); tempAIS_fs.Write(convertedData, 0, (int)convertedData.Length); Console.WriteLine("Wrote {0} bytes to file {1}.", convertedData.Length, cmdParams.outFileName); break; case ConvType.Exec2Text: Console.WriteLine("Mode Not supported."); break; } } Console.WriteLine("Conversion is complete."); return(0); }
static void Main(string[] args) { AtmelGeneric generic; IntelHex ihex; SRecord srec; StreamReader sr = null; if (args.Length < 2) { Console.WriteLine("Usage: TestGIS_RecDump.exe <file format> <file>"); Console.WriteLine("This program will print the records saved in a generic, Intel HEX, or Motorola\nS-Record formatted file.\n"); Console.WriteLine(" <file format> can be generic, ihex, or srecord."); Console.WriteLine(" <file> is the path to the formatted object file."); Environment.Exit(-1); } try { sr = new StreamReader(args[1]); } catch (Exception e) { Console.WriteLine("Error opening file: " + e.Message); Environment.Exit(-1); } if (string.Compare(args[0], "generic") == 0) { generic = new AtmelGeneric(); AtmelGenericStructure gen_s; while (true) { gen_s = generic.Read(sr); if (gen_s != null) { Console.WriteLine(generic.Print(true)); } else { break; } } } else if (string.Compare(args[0], "ihex") == 0) { ihex = new IntelHex(); IntelHexStructure ihex_s; while (true) { ihex_s = ihex.Read(sr); if (ihex_s != null) { Console.WriteLine(ihex.Print(true)); } else { break; } } } else if (string.Compare(args[0], "srecord") == 0) { srec = new SRecord(); SRecordStructure srec_s; while (true) { srec_s = srec.Read(sr); if (srec_s != null) { Console.WriteLine(srec.Print(true)); } else { break; } } } else { Console.WriteLine("Unknown file format specified!"); sr.Close(); Environment.Exit(-1); } sr.Close(); }
public DrillCRecord() { Record = new SRecord(); }
protected void OnSave(object sender, EventArgs e) { HexRecord hr = new HexRecord(); this.textview_debug.Buffer.Text = "Hex Record Test:\n"; string a = " :10010000214601360121470136007EFE09D2190140"; string b = ":00000001FF "; string c = " :100110002146017EB7C20001FF5F16002148011988"; this.textview_debug.Buffer.Text += (a + "\n"); hr.parse(a); this.textview_debug.Buffer.Text += hr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (b + "\n"); hr.parse(b); this.textview_debug.Buffer.Text += hr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (c + "\n"); hr.parse(c); this.textview_debug.Buffer.Text += hr.generate(); SRecord sr = new SRecord(); this.textview_debug.Buffer.Text += "\nS Record Test:\n"; string d = " S00F000068656C6C6F202020202000003C"; string ee = "S11F00007C0802A6900100049421FFF07C6C1B787C8C23783C6000003863000026"; string f = " S5030003F9 "; this.textview_debug.Buffer.Text += (d + "\n"); sr.parse(d); this.textview_debug.Buffer.Text += sr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (ee + "\n"); sr.parse(ee); this.textview_debug.Buffer.Text += sr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (f + "\n"); sr.parse(f); this.textview_debug.Buffer.Text += sr.generate(); this.textview_debug.Buffer.Text += "\n"; TiTxtRecord tr = new TiTxtRecord(); this.textview_debug.Buffer.Text += "TI Txt Record Test:\n"; string g = "@FABC"; string h = "31 40 00 03 B2 40 80 5A 20 01 D2 D3 22 00 D2 E3 "; string i = "q "; string j = " 21 00 3F 40 E8 FD 1F 83 FE 23 F9 3F "; this.textview_debug.Buffer.Text += (g + "\n"); tr.parse(g); this.textview_debug.Buffer.Text += tr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (h + "\n"); tr.parse(h); this.textview_debug.Buffer.Text += tr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (i + "\n"); tr.parse(i); this.textview_debug.Buffer.Text += tr.generate(); this.textview_debug.Buffer.Text += "\n"; this.textview_debug.Buffer.Text += (j + "\n"); tr.parse(j); this.textview_debug.Buffer.Text += tr.generate(); this.textview_debug.Buffer.Text += "\n"; Console.WriteLine("have a try"); }
public static void Flash(string filePath, int BinMemOffset = 0, int vid = 0x0483, int pid = 0xDF11) { // version is optional, FF means forced update int vmajor = 0xFF, vminor = 0xFF; var fileExt = Path.GetExtension(filePath); var isDfuFile = Dfu.IsExtensionSupported(fileExt); EventHandler <ProgressChangedEventArgs> printDownloadProgress = (obj, e) => { Progress(e.ProgressPercentage, "Download progress"); Console.WriteLine("Download progress: {0}%", e.ProgressPercentage); }; EventHandler <ErrorEventArgs> printDevError = (obj, e) => { Progress(-1, String.Format("The DFU device reported the following error: {0}", e.GetException().Message)); Console.Error.WriteLine("The DFU device reported the following error: {0}", e.GetException().Message); }; LibUsbDfu.Device device = null; try { Version fileVer = new Version(vmajor, vminor); Dfu.FileContent dfuFileData = null; RawMemory memory = null; // find the matching file parser by extension if (isDfuFile) { dfuFileData = Dfu.ParseFile(filePath); Console.WriteLine("DFU image parsed successfully."); // DFU file specifies VID, PID and version, so override any arguments vid = dfuFileData.DeviceInfo.VendorId; pid = dfuFileData.DeviceInfo.ProductId; fileVer = dfuFileData.DeviceInfo.ProductVersion; } else if (IntelHex.IsExtensionSupported(fileExt)) { memory = IntelHex.ParseFile(filePath); Console.WriteLine("Intel HEX image parsed successfully."); } else if (SRecord.IsExtensionSupported(fileExt)) { memory = SRecord.ParseFile(filePath); Console.WriteLine("SRecord image parsed successfully."); } else if (BinMemOffset > 0) { memory = new RawMemory(); memory.TryAddSegment(new Segment((ulong)BinMemOffset, File.ReadAllBytes(filePath))); } else { throw new ArgumentException("Image file format not recognized."); } // find the DFU device if (vid == 0 && pid == 0) { LibUsbDfu.Device.TryOpen(UsbDevice.AllDevices.First(), out device); } else { device = LibUsbDfu.Device.OpenFirst(UsbDevice.AllDevices, vid, pid); } device.DeviceError += printDevError; if (isDfuFile) { // verify protocol version if (dfuFileData.DeviceInfo.DfuVersion != device.DfuDescriptor.DfuVersion) { throw new InvalidOperationException(String.Format("DFU file version {0} doesn't match device DFU version {1}", dfuFileData.DeviceInfo.DfuVersion, device.DfuDescriptor.DfuVersion)); } } // if the device is in normal application mode, reconfigure it if (device.InAppMode()) { bool skipUpdate = fileVer <= device.Info.ProductVersion; // skip update when it's deemed unnecessary if (skipUpdate) { Console.WriteLine("The device is already up-to-date (version {0}), skipping update (version {1}).", device.Info.ProductVersion, fileVer); return; } Console.WriteLine("Device found in application mode, reconfiguring device to DFU mode..."); device.Reconfigure(); // in case the device detached, we must find the DFU mode device if (!device.IsOpen()) { // clean up old device first device.DeviceError -= printDevError; device.Dispose(); device = null; device = LibUsbDfu.Device.OpenFirst(UsbDevice.AllDevices, vid, pid); device.DeviceError += printDevError; } } else { Console.WriteLine("Device found in DFU mode."); } // perform upgrade device.DownloadProgressChanged += printDownloadProgress; if (isDfuFile) { device.DownloadFirmware(dfuFileData); } else { device.DownloadFirmware(memory); } device.DownloadProgressChanged -= printDownloadProgress; Console.WriteLine("Download successful, manifesting update..."); Progress(100, "Download successful, manifesting update..."); device.Manifest(); // if the device detached, clean up if (!device.IsOpen()) { device.DeviceError -= printDevError; device.Dispose(); device = null; } // TODO find device again to verify new version Console.WriteLine("The device has been successfully upgraded."); Progress(100, "The device has been successfully upgraded."); } catch (Exception e) { Console.Error.WriteLine("Device Firmware Upgrade failed with exception: {0}.", e.ToString()); //Environment.Exit(-1); Progress(-1, String.Format("Device Firmware Upgrade failed with exception: {0}.", e.ToString())); } finally { if (device != null) { device.Dispose(); } } }