public void Test_chip_example_from() { byte[] data = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00" ); LogicChip chip = LogicChip.From(data, 4, "ll....lll"); Debug.Write(chip.ToString()); Assert.AreEqual(chip.FindElement(ElementOID.PrimaryItemIdentifier).Text, "123456789012"); Assert.AreEqual(chip.FindElement(ElementOID.SetInformation).Text, "1203"); Assert.AreEqual(chip.FindElement(ElementOID.ShelfLocation).Text, "QA268.L55"); Assert.AreEqual(chip.FindElement(ElementOID.OwnerInstitution).Text, "US-InU-Mu"); }
public void Test_chip_layout_2() { LogicChip chip = new LogicChip(); chip.NewElement(ElementOID.PII, "123456789012").WillLock = true; chip.NewElement(ElementOID.SetInformation, "1203"); chip.NewElement(ElementOID.ShelfLocation, "QA268.L55"); chip.NewElement(ElementOID.OwnerInstitution, "US-InU-Mu").WillLock = true; Debug.Write(chip.ToString()); var result = chip.GetBytes(4 * 9, 4, GetBytesStyle.None, out string block_map); string result_string = Element.GetHexString(result, "4"); byte[] correct = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00" ); Assert.IsTrue(result.SequenceEqual(correct)); Assert.AreEqual(block_map, "ww....www"); }
public void Test_encode_mb11_1() { LogicChip chip = new LogicChip(); chip.NewElement(ElementOID.SetInformation, "1203"); chip.NewElement(ElementOID.ShelfLocation, "QA268.L55"); chip.NewElement(ElementOID.OwnerInstitution, "US-InU-Mu").CompactMethod = CompactionScheme.SevenBitCode; // 如果让 GetBytes() 自动选择压缩方案,这个元素会被选择 ISIL 压缩方案 Debug.Write(chip.ToString()); var result = chip.GetBytes(4 * 9, 4, GetBytesStyle.ReserveSequence, out string block_map); string result_string = Element.GetHexString(result, "4"); byte[] correct = Element.FromHexString( @"02 01 D0 14 02 04B3 4607 441C b6E2 E335 D653 08AB 4D6C 9DD5 56CD EB" ); Assert.IsTrue(result.SequenceEqual(correct)); // Assert.AreEqual(block_map, "ww....www"); }
static void ParseTagInfo(TagInfo tagInfo, out string pii, out string type, out LogicChip chip) { pii = null; chip = null; type = ""; if (tagInfo == null) { return; } // Exception: // 可能会抛出异常 ArgumentException TagDataException chip = LogicChip.From(tagInfo.Bytes, (int)tagInfo.BlockSize, "" // tag.TagInfo.LockStatus ); pii = chip.FindElement(ElementOID.PII)?.Text; var typeOfUsage = chip.FindElement(ElementOID.TypeOfUsage)?.Text; if (typeOfUsage != null && typeOfUsage.StartsWith("8")) { type = "patron"; } else { type = "book"; } }
public LightGraph(LogicChip logicGraph, int width, int height) { this.width = width; this.height = height; this.LGUtilities = new LGUtilities(this); this.logicGraph = logicGraph; }
/// <summary> /// Creates a Logic Graph from the data in this Class /// </summary> public LogicChip getLogicGraph() { LogicChip result = new LogicChip(this.Width, this.Height, this.Name); foreach (GraphComponentData gcd in this.Components) { Type type = Type.GetType(gcd.Type); LightComponent lightComponent = null; if (type.IsSubclassOf(typeof(LightComponent))) { if (!type.IsSubclassOf(typeof(LinkComponent))) { lightComponent = (LightComponent)Activator.CreateInstance( type, new object[] { new Vector2Int(gcd.Position[0], gcd.Position[1]), gcd.Rotaiton, gcd.Flipped }); } else { if (type == typeof(GraphOutput)) { lightComponent = new GraphOutput(new Vector2Int(gcd.Position[0], gcd.Position[1]), gcd.Rotaiton, gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND)); } else if (type == typeof(GraphInput)) { lightComponent = new GraphInput(new Vector2Int(gcd.Position[0], gcd.Position[1]), gcd.Rotaiton, gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE)); } else { throw new Exception(type + " is not supported when loading data"); } } if (type.IsSubclassOf(typeof(LogicComponent))) { LogicComponent logic = (LogicComponent)lightComponent; logic.setState(); } } else { throw new Exception("Type " + type + " is not accepted from LogicGraphData"); } if (lightComponent != null) { lightComponent.setValues(gcd.Values); result.LightGraph.addComponent(lightComponent); } } return(result); }
public void Test_chip_layout_1() { byte[] data = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00" ); LogicChip chip = LogicChip.From(data, 4, "ll....lll"); Debug.Write(chip.ToString()); chip.Elements[0].SetLocked(true); chip.Elements[4].SetLocked(true); chip.SetIsNew(false); chip.Sort(4 * 9, 4, true); Assert.IsTrue(chip.Elements[0].OID == ElementOID.PrimaryItemIdentifier); Assert.IsTrue(chip.Elements[1].OID == ElementOID.ContentParameter); Assert.IsTrue(chip.Elements[2].OID == ElementOID.SetInformation); Assert.IsTrue(chip.Elements[3].OID == ElementOID.ShelfLocation); Assert.IsTrue(chip.Elements[4].OID == ElementOID.OwnerInstitution); }
public void test_logicChip_7() { // ganchuang 2 byte[] data = ByteArray.GetTimeStampByteArray("91020312D68700000201B80300650110660100670100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); LogicChip chip = LogicChip.From(data, 4); Debug.Write(chip.ToString()); }
public void test_logicChip_4() { // jiangxi jingyuan 2 byte[] data = ByteArray.GetTimeStampByteArray("11030AA9770000000000000000000000000000000000000000000000000000000000000000000000"); LogicChip chip = LogicChip.From(data, 4); Debug.Write(chip.ToString()); }
public void test_logicChip_5() { // byte[] data = ByteArray.GetTimeStampByteArray("C102071100B0C30C30C600000203A80008830203D6593F0000250110370210405F080599A713063F"); LogicChip chip = LogicChip.From(data, 4); Debug.Write(chip.ToString()); }
public static string GetPII(TagInfo tagInfo) { LogicChip chip = LogicChip.From(tagInfo.Bytes, (int)tagInfo.BlockSize, "" // tagInfo.LockStatus ); return(chip.FindElement(ElementOID.PII)?.Text); }
public void setUp(LogicChip logicGraph, Vector2 bottomLeftWorld, LogicGraphManager logicGraphManager) { this.logicGraph = logicGraph; this.bottomLeftWorld = bottomLeftWorld; this.transform.position = bottomLeftWorld; this.changeSize(logicGraph.LightGraph.Width, logicGraph.LightGraph.Height); this.makeComponentManager(logicGraph, bottomLeftWorld); this.logicGraphManager = logicGraphManager; }
// 填充所有的册记录信息 void FillEntityInfo() { LibraryChannel channel = this.GetChannel(); try { var items = (List <ListViewItem>) this.Invoke(new Func <List <ListViewItem> >(() => { List <ListViewItem> results = new List <ListViewItem>(); results.AddRange(this.listView_tags.Items.Cast <ListViewItem>()); return(results); })); foreach (ListViewItem item in items) { ItemInfo item_info = (ItemInfo)item.Tag; var tag_info = item_info.OneTag.TagInfo; if (tag_info == null) { continue; } LogicChip chip = LogicChip.From(tag_info.Bytes, (int)tag_info.BlockSize); string pii = chip.FindElement(ElementOID.PII)?.Text; if (string.IsNullOrEmpty(pii)) { continue; } long lRet = channel.GetItemInfo(null, pii, "xml", out string xml, "", out string biblio, out string strError); if (lRet == -1) { // TODO: 给 item 设置出错状态 continue; } item_info.Xml = xml; } } catch (Exception ex) { // TODO: 如何报错?让操作者从册信息界面上可以看出报错 } finally { this.ReturnChannel(channel); } }
public string GetDescription() { StringBuilder text = new StringBuilder(); text.Append($"UID:\t{UID}\r\n"); text.Append($"AFI:\t{Element.GetHexString(AFI)}\r\n"); text.Append($"DSFID:\t{Element.GetHexString(DSFID)}\r\n"); text.Append($"EAS:\t{EAS}\r\n"); text.Append($"MaxBlockCount:\t{MaxBlockCount}\r\n"); text.Append($"BlockSize:\t{BlockSize}\r\n"); if (this.OriginBytes != null) { text.Append($"\r\n初始字节内容:\r\n{GetBytesString(this.OriginBytes, this.BlockSize, this.OriginLockStatus)}\r\n"); } // 2020/6/22 text.Append($"\r\n锁定位置:\r\n{this.OriginLockStatus}\r\n\r\n"); { LogicChip chip = LogicChip.From(this.OriginBytes, this.BlockSize, this.OriginLockStatus); text.Append($"初始元素:(共 {chip.Elements.Count} 个)\r\n"); int i = 0; foreach (Element element in chip.Elements) { text.Append($"{++i}) {element.ToString()}\r\n"); } } try { // 注意 GetBytes() 调用后,元素排列顺序会发生变化 byte[] bytes = this.GetBytes( this.MaxBlockCount * this.BlockSize, this.BlockSize, GetBytesStyle.None, out string block_map); text.Append($"\r\n当前字节内容:\r\n{GetBytesString(bytes, this.BlockSize, block_map)}\r\n"); } catch (Exception ex) { text.Append($"\r\n当前字节内容:\r\n构造 Bytes 过程出现异常: {ex.Message}\r\n"); } { text.Append($"当前元素:(共 {this.Elements.Count} 个)\r\n"); int i = 0; foreach (Element element in this.Elements) { text.Append($"{++i}) {element.ToString()}\r\n"); } } return(text.ToString()); }
public void saveButton() { //saves the current state of all the terminals string path = Application.dataPath + "/Default/Resources/Default/Saves"; EnterTextContent saveContent = new EnterTextContent("Enter in the name for your save", (string enteredText) => { string illegal = enteredText + "~" + System.DateTime.Now.ToString(); string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch))); illegal = r.Replace(illegal, " "); Save.makeDirectory(path, illegal); path += "/" + illegal + "/"; string terminalFolder = "Terminals"; Save.makeDirectory(path, terminalFolder); path += "/" + terminalFolder; foreach (TerminalController ter in this.terminalManager.TerminalControllers) { //makes terminal directory Save.makeDirectory(path, ter.Terminal.Name); string tempPath = path + "/" + ter.Terminal.Name + "/"; //saves terminal json Save.saveJson <TerminalData>(new TerminalData(ter.Terminal), tempPath, ter.Terminal.Name + ".json"); //saves the connections Save.saveJson <TExtensionConnectionsData>(new TExtensionConnectionsData(ter.Terminal), tempPath, typeof(TExtensionConnectionsData).ToString() + ".json"); //makes directory for logic graphs Save.makeDirectory(tempPath, "LogicGraphs"); tempPath += "/LogicGraphs"; for (int i = 0; i < ter.Terminal.extensionLength(); i++) { TExtension extension = ter.Terminal.extensionAt(i); if (extension.GetType() == typeof(LogicChip)) { string name = extension.Name + ".json"; LogicChip lg = (LogicChip)extension; Save.saveJson <LogicGraphData>(new LogicGraphData(lg), tempPath, name); } } } }, () => { }, 50); WindowManager.Instance.spawnWindow(new Window("Save Game", 200, 200, saveContent)); }
void GetTagInfo(ListViewItem item) { OneTag tag = (OneTag)item.Tag; RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out string strError); if (channel == null) { strError = "StartRfidChannel() error"; goto ERROR1; } try { GetTagInfoResult result = channel.Object.GetTagInfo("*", tag.UID); if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } tag.TagInfo = result.TagInfo; LogicChip chip = LogicChip.From(result.TagInfo.Bytes, (int)result.TagInfo.BlockSize); this.Invoke((Action)(() => { string pii = chip.FindElement(ElementOID.PII)?.Text; ListViewUtil.ChangeItemText(item, COLUMN_PII, pii); if (pii == this.SelectedPII) { item.Font = new Font(item.Font, FontStyle.Bold); } })); return; } catch (Exception ex) { strError = "ListTags() 出现异常: " + ex.Message; goto ERROR1; } finally { EndRfidChannel(channel); } ERROR1: this.Invoke((Action)(() => { ListViewUtil.ChangeItemText(item, COLUMN_PII, "error:" + strError); // TODO: 把 item 修改为红色背景,表示出错的状态 })); }
public static string GetPII(TagInfo tagInfo) { // Exception: // 可能会抛出异常 ArgumentException TagDataException LogicChip chip = LogicChip.From(tagInfo.Bytes, (int)tagInfo.BlockSize, "" // tagInfo.LockStatus ); return(chip.FindElement(ElementOID.PII)?.Text); }
public void test_logicChip_11() { // 汪总提供 // string bytes = @"E102074535353536373200000201B8030C1B81E130103A1AC9AB4C48BF65011266010067010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575F4F4B"; byte[] data = Element.FromHexString(bytes); LogicChip chip = LogicChip.From(data, 4); Debug.Write(chip.ToString()); }
/// <summary> /// Creates savable data from a LogicGraph /// </summary> public LogicGraphData(LogicChip graph) { this.Name = graph.Name; this.Width = graph.LightGraph.Width; this.Height = graph.LightGraph.Height; List <LightComponent> comps = graph.LightGraph.getAllGraphComponents(); foreach (LightComponent comp in comps) { Components.Add(new GraphComponentData(comp)); } }
private void makeComponentManager(LogicChip logicGraph, Vector3 bottomLeft) { GameObject go = new GameObject("ComponentManager"); go.transform.SetParent(this.transform, false); LogicGraphComponentManager cm = go.AddComponent <LogicGraphComponentManager>(); this.componentManager = cm; cm.loadComponents(logicGraph, bottomLeft); this.updateVisuals(); }
static string GetLockStatus(string map, int index) { char ch = LogicChip.GetBlockStatus(map, index); if (ch == 'l') { return("locked"); } if (ch == 'w') { return("will lock"); } return(""); }
static void SetContent(LogicChip chip) { chip.SetElement(ElementOID.PII, "1234567890"); chip.SetElement(ElementOID.SetInformation, "1203"); chip.SetElement(ElementOID.ShelfLocation, "QA268.L55"); chip.SetElement(ElementOID.OwnerInstitution, "US-InU-Mu"); chip.SetElement(ElementOID.LocalDataA, "1234567890"); chip.SetElement(ElementOID.LocalDataB, "1234567890"); chip.SetElement(ElementOID.LocalDataC, "1234567890"); chip.SetElement(ElementOID.Title, "1234567890 1234567890 1234567890"); chip.SetElement(ElementOID.AOI, "1234567890"); chip.SetElement(ElementOID.SOI, "1234567890"); chip.SetElement(ElementOID.AIBI, "1234567890"); }
private void populateExtensions() { //populates the list with all the extensions GameObject itemPrefab = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["ItemButton"]; for (int i = 0; i < this.terminalController.Terminal.extensionLength(); i++) { int index = i; GameObject item = GameObject.Instantiate(itemPrefab); item.transform.SetParent(this.listDisplay, false); Transform graphButton = item.transform.Find("SelectButton"); Transform deleteButton = item.transform.Find("DeleteButton"); graphButton.Find("Text").GetComponent <Text>().text = this.terminalController.Terminal.extensionAt(index).Name; graphButton.GetComponent <Button>().onClick.AddListener(() => { if (this.terminalController.Terminal.extensionAt(index).GetType() == typeof(LogicChip)) { LogicChip graph = (LogicChip)this.terminalController.Terminal.extensionAt(index); LogicGraphContent lgContent = new LogicGraphContent(graph, terminalController.GraphManager); Window win = new Window(graph.Name, 200, 200, lgContent); WindowManager.Instance.spawnWindow(win); } }); deleteButton.GetComponent <Button>().onClick.AddListener(() => { //removes the logic graph window if (this.terminalController.Terminal.extensionAt(index).GetType() == typeof(LogicChip)) { LogicChip graph = (LogicChip)this.terminalController.Terminal.extensionAt(index); LogicGraphContent lgContent = new LogicGraphContent(graph, terminalController.GraphManager); WindowController wc = WindowManager.Instance.getControllerByData(lgContent); if (wc != null) { WindowManager.Instance.destroyWindow(wc); } } this.terminalController.Terminal.removeExtension(this.terminalController.Terminal.extensionAt(index)); this.refreshExtensionList(); }); } }
bool NotifyTag(string reader_name, string uid) { if (_sendKeyEnabled.Value == false) { return(false); } InventoryInfo info = new InventoryInfo { UID = uid }; GetTagInfoResult result0 = Program.Rfid.GetTagInfo(reader_name, info); if (result0.Value == -1) { // TODO: 如何报错?写入操作历史? // Program.MainForm.OutputText($"读取标签{info.UID}信息时出错:{result0.ToString()}", 2); return(false); } LogicChip chip = LogicChip.From(result0.TagInfo.Bytes, (int)result0.TagInfo.BlockSize, "" // result0.TagInfo.LockStatus ); Element pii = chip.FindElement(ElementOID.PII); Element typeOfUsage = chip.FindElement(ElementOID.TypeOfUsage); StringBuilder text = new StringBuilder(); if (pii == null) { text.Append($"uid:{info.UID}"); } else { text.Append($"pii:{pii.Text}"); } if (typeOfUsage != null) { text.Append($",tou:{typeOfUsage.Text}"); } Program.MainForm.Invoke((Action)(() => { // 发送 UID SendKeys.SendWait($"{text}\r"); })); return(true); }
static void SetField(ChipItem item, LogicChip chip, string fieldName) { ElementOID oid = Element.GetOidByName(fieldName); Element element = chip.FindElement(oid); if (element != null) { var info = item.GetType().GetProperty(fieldName); info.SetValue(item, element.Text); item.SetLocked(fieldName, element == null ? false : element.Locked); } }
static byte[] BuildBytes( int block_size, int max_block_count, string pii) { LogicChip chip = new LogicChip(); chip.NewElement(ElementOID.PII, pii); chip.NewElement(ElementOID.OMF, "BA"); return(chip.GetBytes(block_size * max_block_count, block_size, GetBytesStyle.None, out string block_map)); }
public void Test_chip2_layout_1() { LogicChip chip = new LogicChip(); chip.NewElement(ElementOID.PII, "B123456"); chip.NewElement(ElementOID.OMF, "BA"); Debug.Write(chip.ToString()); var result = chip.GetBytes(4 * 28, 4, GetBytesStyle.None, out string block_map); string result_string = Element.GetHexString(result, "4"); Debug.Write(chip.ToString()); }
public LogicGraphController displayLogicGraph(LogicChip graph, Vector3 bottomLeft) { GameObject graphPrefab = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["Graph"]; GameObject go = Instantiate(graphPrefab).gameObject; Vector3 offset = new Vector3(graph.LightGraph.Width / 2, graph.LightGraph.Height / 2, 0); go.transform.position = bottomLeft + offset; LogicGraphController lgc = go.GetComponent <LogicGraphController>(); lgc.setUp(graph, bottomLeft, this); this.graphControllers.Add(lgc); return(lgc); }
public static GetPIIResult GetPII(TagInfo tagInfo) { // Exception: // 可能会抛出异常 ArgumentException TagDataException LogicChip chip = LogicChip.From(tagInfo.Bytes, (int)tagInfo.BlockSize, "" // tagInfo.LockStatus ); return(new GetPIIResult { PII = chip.FindElement(ElementOID.PII)?.Text, OI = chip.FindElement(ElementOID.OI)?.Text, AOI = chip.FindElement(ElementOID.AOI)?.Text, }); }
public void loadComponents(LogicChip logicGraph, Vector3 bottomLeft) { //loads all of the components on to the graph this.bottomLeftofGraph = bottomLeft; List <LightComponent> graphComponents = logicGraph.LightGraph.getAllGraphComponents(); //makes all the components foreach (GraphComponent gc in graphComponents) { //creates the gameobject GraphComponentController gcc = createComponent(gc); this.addComponent(gcc); } this.reconnectRays(); }