private static void WriteSDR(XmlWriter myxml, SDR sdr) { foreach (SDR.Member member in sdr.Members) { myxml.WriteStartElement("qsvg:sdrMember"); myxml.WriteAttributeString("type", Enum.GetName(typeof(SDR.DataTypeIndex), member.DataType)); if (member.DataType == SDR.DataTypeIndex.SDR) { object[] items = member.Items; for (int i = 0; i < items.Length; i++) { SDR sdr2 = (SDR)items[i]; WriteSDR(myxml, sdr2); } } else { object[] objArray = member.Items; for (int j = 0; j < objArray.Length; j++) { object objectValue = RuntimeHelpers.GetObjectValue(objArray[j]); myxml.WriteStartElement("qsvg:sdrItem"); if (objectValue != null) { myxml.WriteAttributeString("value", objectValue.ToString()); } myxml.WriteEndElement(); } } myxml.WriteEndElement(); } }
public void TestTemporalMemoryExplicit() { int[] input1 = new int[] { 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 }; int[] input2 = new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; int[] input3 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; int[] input4 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input5 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input6 = new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; int[] input7 = new int[] { 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }; int[][] inputs = { input1, input2, input3, input4, input5, input6, input7 }; Parameters p = GetParameters(); Connections con = new Connections(); p.Apply(con); TemporalMemory tm = new TemporalMemory(); TemporalMemory.Init(con); ComputeCycle cc = null; for (int x = 0; x < 602; x++) { foreach (int[] i in inputs) { cc = tm.Compute(con, ArrayUtils.Where(i, ArrayUtils.WHERE_1), true); } } TEST_AGGREGATION[TM_EXPL] = SDR.AsCellIndices(cc.activeCells); }
protected override void ProcessPayload(int len) { //Get the opcode ushort opcode = BitConverter.ToUInt16(buffer, 0); //Switch on this switch (opcode) { case OP_BUTTON_PRESS: SDR.OnInput(new Input.UserInputEventArgs { down = true, key = (Input.UserInputKey)BitConverter.ToUInt16(buffer, HEADER_LENGTH + 0) }); break; case OP_AUDIO_SUBCRIBE: audioStreamer.SubscribeEvent(); break; case OP_AUDIO_UNSUBCRIBE: audioStreamer.UnsubscribeEvent(); break; case OP_SCREENCAP_SUBSCRIBE: screenStreamer.SubscribeEvent(); break; case OP_SCREENCAP_UNSUBSCRIBE: screenStreamer.UnsubscribeEvent(); break; } }
public void customerId() { connection.Open(); string query = "select max(CustomerId) from Customer"; SqlDataAdapter SDA = new SqlDataAdapter(query, connection); SqlDataReader SDR; SDR = SDA.SelectCommand.ExecuteReader(); if (SDR.Read()) { string valuee = SDR[0].ToString(); if (valuee == "") { label13.Text = "10000"; } else { int a; a = int.Parse(SDR[0].ToString()); a = a + 1; // +1 ponieważ wartości id mają być auto-inkrementowane label13.Text = a.ToString(); } } connection.Close(); }
public string GetDateFormat(string STR_COMPANY_ID) { conn = new SqlConnection(strConn); conn.Open(); DataSet ds = new DataSet(); string szReturn = ""; try { string query = "SELECT isnull( SZ_FORMAT_VALUE,'') FROM TXN_WC_PRINT_CONFIGURATION WHERE SZ_COMPANY_ID='" + STR_COMPANY_ID + "' AND SZ_FORMAT_CODE= 'Date' AND SZ_TYPE='WC'"; comm = new SqlCommand(query, conn); comm.CommandTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["CommandTimeOut"].ToString()); SqlDataReader SDR; SDR = comm.ExecuteReader(); while (SDR.Read()) { szReturn = SDR[0].ToString(); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } finally { conn.Close(); } return(szReturn); }
public BDRData(string distribution, string dimension, DataSet set, bool extended, SDR sdr1, SDR sdr2, int split, DirectoryInfo data) : base(distribution, dimension, set, extended, "BDR", String.Format("{0}.{1}.{2}", sdr1, sdr2, split), data) { _sdr1 = sdr1; _sdr2 = sdr2; _split = (int) Math.Round(split/100.0*NumDimension, 0); }
public SDRData(RawData data, SDR sdr) : base("SDR", sdr.ToString(), data, Features.Mode.Local) { _sdr = sdr; FileInfo = new FileInfo(string.Format(@"{0}\..\{1}\{2}.{3}.{4}.csv", data.FileInfo.Directory, "SDR", Distribution, Dimension, Set)); Read(false); }
public Form1() { InitializeComponent(); SDR.Configure(emulatedDisplay1, this); worker = new Thread(SDR.Run); worker.Name = "SDR Worker"; worker.IsBackground = true; worker.Start(); }
private void OnInputControlBtnClicked(object sender, EventArgs e) { Enum.TryParse <UserInputKey>((string)((Button)sender).Tag, out UserInputKey key); SDR.OnInput(new UserInputEventArgs { down = true, key = key }); }
public override CheckResult Check(SDR sdr) { var res = new CheckResult(); if (Parcel.Prior != sdr.Prior) { res.IsPass = false; res.Messages.Add(Name); } return res; }
public override CheckResult Check(SDR sdr) { var copySdr = Parcel.Sdrs.ToList(); copySdr.Add(sdr); var res = new CheckResult(); if (copySdr.Select(x => x.Amount).Sum() > Max_Num) { res.IsPass = false; res.Messages.Add(Name); } return res; }
static void Main(string[] args) { //Create parts FramebufferDisplay display = new FramebufferDisplay(); EmbeddedDevice device = new EmbeddedDevice(); //Create session SDR.Configure(display, device); //Go SDR.Run(); }
public override CheckResult Check(SDR sdr) { var copySdr = Parcel.Sdrs.ToList(); copySdr.Add(sdr); var res = new CheckResult(); if (copySdr.Count(x => x.SDRType.ToLower() == Garment_Type) > Max_Num) { res.IsPass = false; res.Messages.Add(Name); } return res; }
public static bool class9(CGMElement element, SVGContext mycontext, XmlTextWriter myxml) { if (element.ElementId == 1) { string str = mycontext.Reader.ReadS(); SDR sdr = mycontext.Reader.ReadSDR(); myxml.WriteStartElement("qsvg:sdrData"); myxml.WriteAttributeString("type", str); WriteSDR(myxml, sdr); myxml.WriteEndElement(); return(true); } return(false); }
public void TestAsCellIndices() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); cn.SetColumnDimensions(new[] { 64, 64 }); cn.SetCellsPerColumn(4); TemporalMemory.Init(cn); int[] expectedIndexes = { 0, 3, 4, 16383 }; HashSet <Cell> cells = cn.GetCellSet(expectedIndexes); int[] cellIndices = SDR.AsCellIndices(cells); Assert.IsTrue(Arrays.AreEqual(cellIndices, expectedIndexes)); }
public void TestCellsAsColumnIndicesList() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); cn.SetColumnDimensions(new[] { 64, 64 }); cn.SetCellsPerColumn(4); TemporalMemory.Init(cn); int[] expectedIndexes = { 0, 3, 4, 4095 }; int[] inputIndices = expectedIndexes.Select(i => i * cn.GetCellsPerColumn()).ToArray(); List <Cell> cells = new List <Cell>(cn.GetCellSet(inputIndices)); int[] result = SDR.CellsToColumns(cells, cn.GetCellsPerColumn()); Assert.IsTrue(Arrays.AreEqual(expectedIndexes, result)); }
public void TestTemporalMemoryThroughLayer() { Parameters p = GetParameters(); int[] input1 = new int[] { 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 }; int[] input2 = new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; int[] input3 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; int[] input4 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input5 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input6 = new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; int[] input7 = new int[] { 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }; int[][] inputs = { input1, input2, input3, input4, input5, input6, input7 }; Layer <int[]> l = new Layer <int[]>(p, null, null, new TemporalMemory(), null, null); int timeUntilStable = 600; l.Subscribe(Observer.Create <IInference>( output => { }, Console.WriteLine, () => { } )); // @Override public void onCompleted() { } // @Override public void onError(Throwable e) { e.printStackTrace(); } // @Override public void onNext(Inference output) { } //}); // Now push some warm up data through so that "onNext" is called above for (int j = 0; j < timeUntilStable; j++) { for (int i = 0; i < inputs.Length; i++) { l.Compute(inputs[i]); } } for (int j = 0; j < 2; j++) { for (int i = 0; i < inputs.Length; i++) { l.Compute(inputs[i]); } } ComputeCycle cc = l.GetInference().GetComputeCycle(); TEST_AGGREGATION[TM_LYR] = SDR.AsCellIndices(cc.activeCells); }
public override UserInputResult OnInput(UserInputEventArgs input) { if (input.down && input.key == UserInputKey.UP) { currentTab = Math.Max(0, currentTab - 1); } if (input.down && input.key == UserInputKey.DOWN) { currentTab = Math.Max(tabs.Length - 1, currentTab + 1); } if (input.down && input.key == UserInputKey.B) { SDR.CloseActiveFrame(); return(UserInputResult.HandledSelf); } Invalidate(); return(UserInputResult.HandledSelf); }
private static Func <IInference, int, int> CreateDayOfWeekInferencePrintout(bool on) { int cycles = 1; return((IInference inf, int cellsPerColumn) => { Classification <Object> result = inf.GetClassification("dayOfWeek"); double day = MapToInputData((int[])inf.GetLayerInput()); if (day == 1.0) { if (on) { Console.WriteLine("\n========================="); Console.WriteLine("CYCLE: " + cycles); } cycles++; } if (on) { Console.WriteLine("RECORD_NUM: " + inf.GetRecordNum()); Console.WriteLine("ScalarEncoder Input = " + day); Console.WriteLine("ScalarEncoder Output = " + Arrays.ToString(inf.GetEncoding())); Console.WriteLine("SpatialPooler Output = " + Arrays.ToString(inf.GetFeedForwardActiveColumns())); if (inf.GetPreviousPredictiveCells() != null) { Console.WriteLine("TemporalMemory Previous Prediction = " + Arrays.ToString(SDR.CellsAsColumnIndices(inf.GetPreviousPredictiveCells(), cellsPerColumn))); } Console.WriteLine("TemporalMemory Actives = " + Arrays.ToString(SDR.AsColumnIndices(inf.GetSdr(), cellsPerColumn))); Console.Write("CLAClassifier prediction = " + result.GetMostProbableValue(1) + " --> " + result.GetMostProbableValue(1)); Console.WriteLine(" | CLAClassifier 1 step prob = " + Arrays.ToString(result.GetStats(1)) + "\n"); } return cycles; }); }
private void Work() { //Open and set try { SDR.Source = new RtlSdrSource(0, 900001); } catch (HardwareNotFoundException) { SDR.ShowFatalError("Radio Not Connected", "Make sure there is a radio connected and restart."); return; } catch (Exception ex) { SDR.ShowFatalError("Unknown Radio Opening Error", ex); return; } //Configure SDR.CenterFrequency = 93700000; SDR.ManualGainLevel = 20; SDR.SwitchActiveFrame(new SpectrumFrame(SDR.Display)); }
public void TestAsColumnIndices() { int cellsPerColumn = 4; int[] expectedIndexes = { 0, 3, 4, 4095 }; int[] inputIndexes = expectedIndexes.Select(i => i * cellsPerColumn).ToArray(); int[] result = SDR.AsColumnIndices(inputIndexes, cellsPerColumn); Assert.IsTrue(Arrays.AreEqual(expectedIndexes, result)); // Test failure expectedIndexes = new[] { 0, 3, 4, 4, 4095 }; // Has duplicate ("4") inputIndexes = expectedIndexes.Select(i => i * cellsPerColumn).ToArray(); result = SDR.AsColumnIndices(inputIndexes, cellsPerColumn); // "true" is Erroneous state Assert.IsFalse(Arrays.AreEqual(expectedIndexes, result)); // Test correct state fixes above int[] arrInputIndexes = { 0, 3, 4, 4, 4095 }; // Has duplicate ("4") expectedIndexes = new[] { 0, 3, 4, 4095 }; // Has duplicate ("4") inputIndexes = arrInputIndexes.Select(i => i * cellsPerColumn).ToArray(); result = SDR.AsColumnIndices(inputIndexes, cellsPerColumn); // "false" is correct state Assert.IsTrue(Arrays.AreEqual(expectedIndexes, result)); }
private Net.Network.Network CreateAndRunTestTemporalMemoryNetwork() { Publisher manual = Publisher.GetBuilder() .AddHeader("dayOfWeek") .AddHeader("darr") .AddHeader("B").Build(); Sensor <ObservableSensor <String[]> > sensor = Sensor <ObservableSensor <string[]> > .Create( ObservableSensor <string[]> .Create, SensorParams.Create(SensorParams.Keys.Obs, new Object[] { "name", manual })); Parameters p = GetParameters(); Map <String, Map <String, Object> > settings = NetworkTestHarness.SetupMap( null, // map 20, // n 0, // w 0, // min 0, // max 0, // radius 0, // resolution null, // periodic null, // clip true, // forced "dayOfWeek", // fieldName "darr", // fieldType (dense array as opposed to sparse array or "sarr") "SDRPassThroughEncoder"); // encoderType p.SetParameterByKey(Parameters.KEY.FIELD_ENCODING_MAP, settings); Net.Network.Network network = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer("1", p) .Add(new TemporalMemory()) .Add(sensor))); network.Start(); network.Observe().Subscribe(i => { }, e => Console.WriteLine(e)); // new Subscriber<Inference>() { // @Override public void onCompleted() { } // @Override public void onError(Throwable e) { e.printStackTrace(); } // @Override public void onNext(Inference i) { } //}); int[] input1 = new int[] { 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 }; int[] input2 = new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; int[] input3 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; int[] input4 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input5 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input6 = new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; int[] input7 = new int[] { 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }; int[][] inputs = { input1, input2, input3, input4, input5, input6, input7 }; // Run until TemporalMemory is "warmed up". int timeUntilStable = 602; for (int j = 0; j < timeUntilStable; j++) { for (int i = 0; i < inputs.Length; i++) { manual.OnNext(Arrays.ToString(inputs[i])); } } manual.OnComplete(); ILayer l = network.Lookup("r1").Lookup("1"); try { l.GetLayerThread().Wait(); Console.WriteLine(Arrays.ToString(SDR.AsCellIndices(l.GetConnections().GetActiveCells()))); } catch (Exception e) { Assert.AreEqual(typeof(ThreadInterruptedException), e.GetType()); } return(network); }
public static void ShowMenu() { SDR.SwitchActiveFrame(new MenuFrame(SDR.Display)); }
public void TestThreadedPublisher() { Publisher manual = Publisher.GetBuilder() .AddHeader("dayOfWeek") .AddHeader("darr") .AddHeader("B").Build(); Sensor <ObservableSensor <string[]> > sensor = Sensor <ObservableSensor <string[]> > .Create( ObservableSensor <string[]> .Create, SensorParams.Create(SensorParams.Keys.Obs, new Object[] { "name", manual })); Parameters p = GetParameters(); Map <String, Map <String, Object> > settings = NetworkTestHarness.SetupMap( null, // map 20, // n 0, // w 0, // min 0, // max 0, // radius 0, // resolution null, // periodic null, // clip true, // forced "dayOfWeek", // fieldName "darr", // fieldType (dense array as opposed to sparse array or "sarr") "SDRPassThroughEncoder"); // encoderType p.SetParameterByKey(Parameters.KEY.FIELD_ENCODING_MAP, settings); Net.Network.Network network = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("1", p) .Add(new TemporalMemory()) .Add(sensor))); network.Start(); network.Observe().Subscribe(Observer.Create <IInference>( output => { }, Console.WriteLine, () => { } )); int[] input1 = new int[] { 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 }; int[] input2 = new int[] { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; int[] input3 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; int[] input4 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input5 = new int[] { 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0 }; int[] input6 = new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }; int[] input7 = new int[] { 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }; int[][] inputs = { input1, input2, input3, input4, input5, input6, input7 }; // Now push some warm up data through so that "onNext" is called above int timeUntilStable = 602; for (int j = 0; j < timeUntilStable; j++) { for (int i = 0; i < inputs.Length; i++) { manual.OnNext(Arrays.ToString(inputs[i])); } } manual.OnComplete(); ILayer l = network.Lookup("r1").Lookup("1"); try { l.GetLayerThread().Wait(); ComputeCycle cc = l.GetInference().GetComputeCycle(); TEST_AGGREGATION[TM_NAPI] = SDR.AsCellIndices(cc.activeCells); } catch (Exception e) { Debug.WriteLine(e.ToString()); Assert.IsInstanceOfType(e, typeof(ThreadAbortException)); } }
private void PostaviPodatke() { // Otvaranje veze s bazom podataka con.Open(); // Objekti klase String koji u sebi sadrže upite za prikaz podataka iz // tablica Studij, Gradovi i StatusStudenta String upitStudij = "SELECT ID_Studij, Naziv_Studija FROM Studij"; String upitGrad = "SELECT ID_Grad, Naziv_Grada FROM Gradovi ORDER BY " + " Naziv_Grada ASC"; String upitStatus = "SELECT ID_Status, Naziv_Statusa FROM StatusStudenta"; // Objekti klase SqlCommand SqlCommand SCSt = new SqlCommand(upitStudij, con); SqlCommand SCG = new SqlCommand(upitGrad, con); SqlCommand SCSs = new SqlCommand(upitStatus, con); // Objekt klase SqlDataReader SqlDataReader SDR; //Pozivanje metode SqlCommand-e za studij SDR = SCSt.ExecuteReader(); // Popunjavanje podatkovne tablice dataStudij DataTable dataStudij = new DataTable(); dataStudij.Columns.Add("ID_Studij", typeof(int)); dataStudij.Columns.Add("Naziv_Studija", typeof(string)); dataStudij.Load(SDR); // Definiranje prave vrijednosti studij i vrijednosti koja će se prikazati // to jest, naziv studija Studij.DataSource = dataStudij; Studij.DisplayMember = "Naziv_Studija"; Studij.ValueMember = "ID_Studij"; // Zatvaranje čitača podataka SDR.Close(); // Pozivanje metode SQLCommand-e za gradove SDR = SCG.ExecuteReader(); // Popunjavanje Podatkovne tablice dataGrad DataTable dataGrad = new DataTable(); dataGrad.Columns.Add("ID_Grad", typeof(int)); dataGrad.Columns.Add("Naziv_Grada", typeof(string)); dataGrad.Columns.Add("PostanskiBroj", typeof(int)); dataGrad.Columns.Add("ID_Drzave", typeof(int)); dataGrad.Load(SDR); // Definiranje prave vrijednosti studij i vrijednosti koja će se prikazati // to jest, naziv grada GradStudenta.DataSource = dataGrad; GradStudenta.DisplayMember = "Naziv_Grada"; GradStudenta.ValueMember = "ID_Grad"; // Zatvaranje čitača podataka SDR.Close(); // Pozivanje metode SQLCommand-e za status studenta SDR = SCSs.ExecuteReader(); // Popunjavanje Podatkovne tablice dataStatus DataTable dataStatus = new DataTable(); dataStatus.Columns.Add("ID_Status", typeof(int)); dataStatus.Columns.Add("Naziv_Statusa", typeof(string)); dataStatus.Load(SDR); // Definiranje prave vrijednosti studij i vrijednosti koja će se prikazati // to jest naziv statusa studenta StatusStudenta.DataSource = dataStatus; StatusStudenta.DisplayMember = "Naziv_Statusa"; StatusStudenta.ValueMember = "ID_Status"; // Zatvaranje čitača podataka SDR.Close(); // Zatvaranje veze s bazom con.Close(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SDR obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public List <Stdf4Record> ReadStdf4(BinaryReader reader) { List <Stdf4Record> records; if (this.OnlyParse) { records = null; } else { records = new List <Stdf4Record>(capacity: this.InitialListCapacity); } int pos = 0; int recordNumber = 0; Stdf4Record rec; StdfValueConverter converter = new StdfValueConverter(); try { ushort recordLength; while (true) { if (this.ReverseBytesOnRead) { this._twoBytes[1] = reader.ReadByte(); this._twoBytes[0] = reader.ReadByte(); recordLength = BitConverter.ToUInt16(_twoBytes, 0); } else { recordLength = reader.ReadUInt16(); } var stdfMajorType = reader.ReadByte(); var stdfMinorType = reader.ReadByte(); int stdfRecordType = (((int)stdfMajorType) << 8) | (int)stdfMinorType; // for a FAR record, always read 6 bytes since we don't know the byte order yet. // Also avoiding a cast here. byte[] bytes; if (stdfRecordType == 10) { recordLength = 2; } bytes = reader.ReadBytes(recordLength); pos += recordLength + 4; recordNumber += 1; //Three most common record types without a cast and outside the switch statement if (this._debugLevel >= 3) { // Fall through to case statement for lots of printing. } else if (stdfRecordType == 3850) { if (this.OnlyParse) { var ignore_PTR = new PTR(bytes, converter); } else { records.Add(new PTR(bytes, converter)); } continue; } else if (stdfRecordType == 1290) { if (this.OnlyParse) { var ignore_PIR = new PIR(bytes, converter); } else { records.Add(new PIR(bytes, converter)); } continue; } if (this._debugLevel >= 3 || (this.Verbose && stdfMajorType != 5 && stdfMajorType != 10 && stdfMajorType != 15)) { Console.WriteLine(string.Empty); Console.WriteLine($" Record {recordNumber} is {recordLength} bytes long (0x{recordLength:X2}) of type {stdfMajorType} - {stdfMinorType} ({stdfRecordType})."); if (this._debugLevel > 0) { Console.Write((new LavaData.Util.Debug.HexDump(bytes)).ToString()); if (this._debugLevel > 1) { // We want the record length and record type/sub-type. var newBytes = new byte[bytes.Length + 4]; (newBytes[0], newBytes[1]) = converter.UshortToBytes(recordLength); newBytes[2] = stdfMajorType; newBytes[3] = stdfMinorType; for (int i = 0; i < bytes.Length; i++) { newBytes[i + 4] = bytes[i]; } Console.WriteLine((new LavaData.Util.Debug.HexDump(newBytes).ToHexByteString())); } } } rec = null; if (Enum.IsDefined(typeof(Stdf4RecordType), stdfRecordType)) { Stdf4RecordType recordType = (Stdf4RecordType)stdfRecordType; switch ((Stdf4RecordType)stdfRecordType) { case Stdf4RecordType.PTR: // UNREACHABLE CODE -- handled above, except with debug >=3 rec = new PTR(bytes, converter); break; case Stdf4RecordType.PIR: // UNREACHABLE CODE -- handled above, except with debug >=3 rec = new PIR(bytes, converter); break; case Stdf4RecordType.PRR: rec = new PRR(bytes, converter); break; case Stdf4RecordType.FAR: var far = new FAR(bytes, converter); converter.CpuType = far.CpuType; this.ReverseBytesOnRead = converter.ReverseBytesOnRead; rec = far; break; //Data collected on a per lot basis; 1-NN Records case Stdf4RecordType.MIR: rec = new MIR(bytes, converter); break; case Stdf4RecordType.MRR: rec = new MRR(bytes, converter); break; case Stdf4RecordType.PCR: rec = new PCR(bytes, converter); break; case Stdf4RecordType.HBR: rec = new HBR(bytes, converter); break; case Stdf4RecordType.SBR: rec = new SBR(bytes, converter); break; case Stdf4RecordType.PMR: throw new Stdf4ParserException("PMR Not Implemented"); case Stdf4RecordType.PGR: throw new Stdf4ParserException("PGR Not Implemented"); case Stdf4RecordType.RDR: throw new Stdf4ParserException("RDR Not Implemented"); case Stdf4RecordType.SDR: rec = new SDR(bytes, converter); break; // Data collected per Wafer; 2-NN Records. case Stdf4RecordType.WIR: rec = new WIR(bytes, converter); break; case Stdf4RecordType.WRR: rec = new WRR(bytes, converter); break; case Stdf4RecordType.WCR: rec = new WCR(bytes, converter); break; case Stdf4RecordType.TSR: //throw new Stdf4ParserException("TSR Not Implemented"); break; // Generic Data; 50-NN Records. case Stdf4RecordType.GDR: //throw new Stdf4ParserException("GDR Not Implemented"); break; case Stdf4RecordType.DTR: rec = new DTR(bytes, converter); break; default: Console.WriteLine($" Unhandled STDF4 Record Type: {recordType} ({stdfMajorType} - {stdfMinorType})."); break; } if (rec != null) { if (this._debugLevel >= 3 || (this.Verbose && stdfRecordType != 1300)) { // Don't print PRR (1300), lots of them, except at a high debug level. Console.WriteLine(rec.ToString()); } if (!this.OnlyParse) { records.Add(rec); } } } else { Console.WriteLine($" No ENUM Defined for STDF4 Record Type: {stdfMajorType} - {stdfMinorType}."); } } } catch (EndOfStreamException) { if (this.Verbose) { Console.WriteLine("Read to the end of the stream!"); } } catch (Exception ex) { Console.WriteLine("Unhandled Exception: " + ex.Message); Console.WriteLine(ex.StackTrace); } if (this.Verbose) { Console.WriteLine($"Read {recordNumber} records."); } return(records); }
/// <summary> /// 检查寄件 /// </summary> /// <param name="sdr"></param> /// <returns></returns> public abstract CheckResult Check(SDR sdr);
private void PackageVehicleData() { #region Package try { con.Open(); string query_select_Package = "SELECT Package_Maximum_Km, Package_Maximum_Hours, Extra_Km_Charge, Waiting_Charge, Driver_Overnight_Charge, Vehicle_Park_Charge, Driver_Charge FROM Package WHERE Package_Name = '" + BookedPackage_txt.Text + "'"; SqlCommand cmd_Package = new SqlCommand(query_select_Package, con); cmd_Package.ExecuteNonQuery(); SqlDataReader SDR; SDR = cmd_Package.ExecuteReader(); if (SDR.HasRows) { while (SDR.Read()) { MaximumKm = SDR.GetInt32(0); MaximumHours = SDR.GetInt32(1); ExtraKmFee = SDR.GetSqlMoney(2); WaitingFee = SDR.GetSqlMoney(3); NightDriverFee = SDR.GetSqlMoney(4); NightParkingFee = SDR.GetSqlMoney(5); DriverFee = SDR.GetSqlMoney(6); HireWaitingCharge_txt.Text = WaitingFee.ToString(); HireOverNightStayCharge_txt.Text = NightDriverFee.ToString(); HireExtraKmCharge_txt.Text = ExtraKmFee.ToString(); } } } catch (Exception ex) { MessageBox.Show("Something went wrong." + ex); } finally { con.Close(); } #endregion #region Vehicle try { con.Open(); string query_select_Vehicle = "SELECT Base_Charge FROM Vehicles WHERE Vehicle_Type = '" + BookedVehicleTypes_txt.Text + "'"; SqlCommand cmd_Vehicle = new SqlCommand(query_select_Vehicle, con); cmd_Vehicle.ExecuteNonQuery(); SqlDataReader SDR; SDR = cmd_Vehicle.ExecuteReader(); if (SDR.HasRows) { while (SDR.Read()) { BaseCharge = SDR.GetSqlMoney(0); BaseHireCharge_txt.Text = BaseCharge.ToString(); } } } catch (Exception ex) { MessageBox.Show("Something went wrong." + ex); } finally { con.Close(); } #endregion }