public void PlaceBlocksByName(JsonPID jsonPID, string blockName) { var blocks = jsonPID.BlocksSearch(blockName).ToList(); if (blocks == null || blocks.Count == 0) { throw new ArgumentNullException("Block not found " + blockName); } using (var tr = _db.TransactionManager.StartTransaction()) { ObjectId blockId = GetBlockTable(blockName); //var defultLayers = new LayerCreator(); var currentSpace = tr.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; using (var blockDefinition = tr.GetObject(blockId, OpenMode.ForWrite, false) as BlockTableRecord) { CreateInternal_IdAttributeDefinition(blockDefinition, tr); // adds Internal_Id attribute to parent foreach (var block in blocks) { InsertBlockRefenceFromBlockDefinition(currentSpace, block, blockDefinition, tr); } } tr.Commit(); } }
public void ReadBtrForSeri(Database db, string fileName) { ExtensionMethod.ExecuteActionOnModelSpace(db, (tr, btrModelSpace) => { var jsonLineSetup = new JsonLineSetup(); var jsonBlockSetup = new JsonBlockSetup(); var jsonPID = new JsonPID(); InternalCounter = 1; foreach (ObjectId objectId in btrModelSpace) { using (var item = objectId.GetObject(OpenMode.ForWrite)) { if (item is BlockReference) { BlockReference blockReference = item as BlockReference; if (blockReference == null) { continue; } var btrObjectId = blockReference.DynamicBlockTableRecord; //must be Dynamic to find every blocks var blockDefinition = btrObjectId.GetObject(OpenMode.ForRead) as BlockTableRecord; if (blockDefinition.Name != "PID-PS-FRAME") { jsonPID.Blocks.Add(jsonBlockSetup.SetupBlockProperty(blockDefinition, tr, blockReference)); InternalCounter++; } } if (item == null) { continue; } if (item is Line || item is Polyline || item is Polyline2d || item is Polyline3d) { //jsonLineToSerialize.Add(jsonLineSetup.SetupLineProperty(item)); jsonPID.Lines.Add(jsonLineSetup.SetupLineProperty(item, jsonBlockSetup)); InternalCounter++; } } } jsonPID.Blocks.Sort(); jsonPID.Lines.Sort(); var seralizer = new JsonStringBuilderSerialize(); seralizer.StringBuilderSerialize(jsonPID, fileName); }); }
public void BlockCollector(JsonPID jsonPID1, JsonPID jsonPID2, DeepEx deepEx) { var dictBlock1 = new Dictionary <int, JsonBlockProperty>(); var dictBlock2 = new Dictionary <int, JsonBlockProperty>(); for (int i = 0; i < jsonPID1.Blocks.Count; i++) { try { dictBlock1.Add(jsonPID1.Blocks[i].Attributes.Internal_Id, jsonPID1.Blocks[i]); } catch (ArgumentException ex) { Console.Write($"InternalId already exist: {jsonPID1.Blocks[i].Attributes.Internal_Id},{ex}"); } } for (int i = 0; i < jsonPID2.Blocks.Count; i++) { try { dictBlock2.Add(jsonPID2.Blocks[i].Attributes.Internal_Id, jsonPID2.Blocks[i]); } catch (ArgumentException ex) { Console.Write($"InternalId already exist: {jsonPID2.Blocks[i].Attributes.Internal_Id},{ex}"); } } foreach (var i in dictBlock1) { if (dictBlock2.TryGetValue(i.Key, out JsonBlockProperty compareValue)) { deepEx.BlockCompare(i.Value, compareValue); deepEx.BlockCustomCompare(i.Value, compareValue); deepEx.BlockAttributesCompare(i.Value, compareValue); } } }
public void StringBuilderSerialize(JsonPID jsonPID, string fileName) { //string fileJson = "JsonStringBuilder.json"; string dirPath = @"E:\Jszomor\source\repos\jszomorCAD\jCAD.PID_Builder\"; //work var path = System.IO.Path.Combine(dirPath, fileName); var serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, //DefaultValueHandling = DefaultValueHandling.Ignore, Formatting = Formatting.Indented }; using (StreamWriter sw = new StreamWriter(path)) { using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, jsonPID); } } return; }
public void LineCollector(JsonPID jsonPID1, JsonPID jsonPID2, DeepEx deepEx) { var dictLines1 = new Dictionary <int, JsonLineProperty>(); var dictLines2 = new Dictionary <int, JsonLineProperty>(); for (int i = 0; i < jsonPID1.Lines.Count; i++) { try { dictLines1.Add(jsonPID1.Lines[i].Internal_Id, jsonPID1.Lines[i]); } catch (ArgumentException ex) { Console.Write($"InternalId already exist: {jsonPID1.Lines[i].Internal_Id},{ex}"); } } for (int i = 0; i < jsonPID2.Lines.Count; i++) { try { dictLines1.Add(jsonPID2.Lines[i].Internal_Id, jsonPID1.Lines[i]); } catch (ArgumentException ex) { Console.Write($"InternalId already exist: {jsonPID2.Lines[i].Internal_Id},{ex}"); } } foreach (var i in dictLines1) { if (dictLines2.TryGetValue(i.Key, out JsonLineProperty compareValue)) { //deepEx.LineTypeComparer(i.Value, compareValue); deepEx.LineCompare(i.Value, compareValue); } } }
public dynamic HandleMessage() { dynamic result = null; switch (_type) { case "adminlist": try { JsonPID pid = JsonSerializer.Deserialize <JsonPID>(_content); result = pid; } catch (JsonException ex) { result = ex.Message; } break; case "deleteuser": try { DeleteUser pid = JsonSerializer.Deserialize <DeleteUser>(_content); result = pid; } catch (JsonException ex) { result = ex.Message; } break; case "items": try { JsonPID pid = JsonSerializer.Deserialize <JsonPID>(_content); result = pid; } catch (JsonException ex) { result = ex.Message; } break; case "buy": try { StoreBuy buy = JsonSerializer.Deserialize <StoreBuy>(_content); result = buy; } catch (JsonException ex) { result = ex.Message; } break; case "clientregister": try { Register register = JsonSerializer.Deserialize <Register>(_content); result = register; } catch (JsonException ex) { result = ex.Message; } break; case "clientlogin": try { Login login = JsonSerializer.Deserialize <Login>(_content); result = login; } catch (JsonException ex) { result = ex.Message; } break; case "queuegame": try { JsonPID jsonPID = JsonSerializer.Deserialize <JsonPID>(_content); result = jsonPID; } catch (JsonException ex) { result = ex.Message; } break; case "gameaction": try { GameAction gameAction = JsonSerializer.Deserialize <GameAction>(_content); result = gameAction; } catch (JsonException ex) { result = ex.Message; } break; case "echo": try { JsonPID jsonPID = JsonSerializer.Deserialize <JsonPID>(_content); result = jsonPID; // result = long.Parse(result.pId); } catch (JsonException ex) { result = ex.Message; } break; default: break; } return(result); }