/// <summary> /// Saves the media associated to a given header message and looks for /// unheaded chunks of this header to save their data on the media structure. /// </summary> /// <param name="header">Header message.</param> /// <param name="streamS">Media associated to the header message.</param> /// <param name="SaveChunk">Methodd that takes a chunk message and saves its data.</param> public void RecoverEarlyChunks(headerMsg header, struc streamS, StreamChunkHandler <chunkMsg> SaveChunk) { streamData[header.id] = streamS; streamWasFullyReceived[header.id] = false; if (amountOfEarlyChunks.ContainsKey(header.id)) { int i = 0; int count = 0; while (i < amountOfEarlyChunks[header.id] && i < unheadedChunks.Count) { var row = unheadedChunks[i].Item1; if (row.id == header.id) { SaveChunk(row); unheadedChunks.RemoveAt(i); count += 1; } i += 1; } if (amountOfEarlyChunks[header.id] != count) { RemoveStream(header.id); } amountOfEarlyChunks.Remove(header.id); } }
public bool Pars(string modelPath) { StreamReader sr = new StreamReader(modelPath); string data = sr.ReadToEnd(); sr.Close(); MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser(); string ConceptualSection = xml.GetSubTreeByParent(data, "edmx:StorageModels")[0].InnerXml; var dic = GetsRoles(ConceptualSection); var matchesEntityType = xml.GetSubTreeByParent(ConceptualSection, "EntityType"); var entityTypeList = xml.GetSubTreeByParent(ConceptualSection, "EntityType"); var associationList = xml.GetSubTreeByParent(ConceptualSection, "Association"); Queue <struc> result = new Queue <struc>(); Queue <AssociationStruct> associationResult = new Queue <AssociationStruct>(); for (int k = 0; k < associationList.Length; k++) { associationResult.Enqueue(GetAssociation(associationList[k].OuterXml)); } for (int k = 0; k < entityTypeList.Length; k++) { { struc te = new struc(); te.Fname = Filter(xml.GetAttributeValue(entityTypeList[k].OuterXml, "EntityType", "Name")); te.Props = GetProperty(entityTypeList[k].OuterXml); te.Map = GetMapForTable(xml.GetSubTreeByParent(data, "edmx:Mappings")[0].InnerXml, te.Fname); if (result.Where(p => p.Fname == te.Fname).FirstOrDefault() != null) { continue; } if (!string.IsNullOrEmpty(NameSpace)) { te.NameSpace = NameSpace; } te.ModelName = te.Map.Name; te.TableName = te.Map.StoreEntitySet; te.Fname = "frm" + te.Map.Name; result.Enqueue(te); } } var filter = Distinct(result.ToArray()); ParsedData = filter; ProcessAssociation(filter, associationResult.ToArray()); Translate(filter, dic); FormGenerator generate = new FormGenerator(); var designFile = generate.GenerateFormDesign(filter); foreach (struc t in designFile) { if (File.Exists(OutPutAddress + "\\" + t.Fname + ".Designer.cs")) { File.Delete(OutPutAddress + "\\" + t.Fname + ".Designer.cs"); } StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".Designer.cs", true); sw.Write(t.Design); sw.Close(); } var efName = regexPatterns.GetMatches(regexPatterns.GetMatch(data, regexPatterns.EntitiyName).Value, regexPatterns.GetValue)[0].Value.Replace('"', ' ').Trim(); CodeGenerator code = new CodeGenerator(); var codeFile = code.GenerateClass(filter, efName); foreach (struc t in codeFile) { if (File.Exists(OutPutAddress + "\\" + t.Fname + ".cs")) { File.Delete(OutPutAddress + "\\" + t.Fname + ".cs"); } StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".cs", true); sw.Write(t.Code); sw.Close(); } for (int i = 0; i < result.Count; i++) { if (File.Exists(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx")) { File.Delete(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"); } File.Copy(Environment.CurrentDirectory + "\\RFile.resx", OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"); } return(true); }
public void Shw(int val_1_st, string val_2_st) { struc stu = new struc(val_2_st, val_1_st); stu.DisplayInfo(); }
public bool Pars(string modelPath) { StreamReader sr = new StreamReader(modelPath); string data = sr.ReadToEnd(); sr.Close(); MessageParser.NET.Tools.XmlParser xml = new MessageParser.NET.Tools.XmlParser(); string ConceptualSection = xml.GetSubTreeByParent(data, "edmx:StorageModels")[0].InnerXml; var dic = GetsRoles(ConceptualSection); var matchesEntityType = xml.GetSubTreeByParent(ConceptualSection, "EntityType"); var entityTypeList = xml.GetSubTreeByParent(ConceptualSection, "EntityType"); var associationList = xml.GetSubTreeByParent(ConceptualSection, "Association"); Queue<struc> result = new Queue<struc>(); Queue<AssociationStruct> associationResult = new Queue<AssociationStruct>(); for (int k = 0; k < associationList.Length; k++) { associationResult.Enqueue(GetAssociation(associationList[k].OuterXml)); } for (int k = 0; k < entityTypeList.Length; k++) { { struc te = new struc(); te.Fname = Filter(xml.GetAttributeValue(entityTypeList[k].OuterXml, "EntityType", "Name")); te.Props = GetProperty(entityTypeList[k].OuterXml); te.Map = GetMapForTable(xml.GetSubTreeByParent(data, "edmx:Mappings")[0].InnerXml,te.Fname); if (result.Where(p => p.Fname == te.Fname).FirstOrDefault() != null) continue; if (!string.IsNullOrEmpty(NameSpace)) te.NameSpace = NameSpace; te.ModelName = te.Map.Name; te.TableName = te.Map.StoreEntitySet; te.Fname = "frm" + te.Map.Name; result.Enqueue(te); } } var filter = Distinct(result.ToArray()); ParsedData = filter; ProcessAssociation(filter, associationResult.ToArray()); Translate(filter, dic); FormGenerator generate = new FormGenerator(); var designFile = generate.GenerateFormDesign(filter); foreach (struc t in designFile) { if (File.Exists(OutPutAddress + "\\" + t.Fname + ".Designer.cs")) File.Delete(OutPutAddress + "\\" + t.Fname + ".Designer.cs"); StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".Designer.cs", true); sw.Write(t.Design); sw.Close(); } var efName = regexPatterns.GetMatches(regexPatterns.GetMatch(data, regexPatterns.EntitiyName).Value, regexPatterns.GetValue)[0].Value.Replace('"', ' ').Trim(); CodeGenerator code = new CodeGenerator(); var codeFile = code.GenerateClass(filter, efName); foreach (struc t in codeFile) { if (File.Exists(OutPutAddress + "\\" + t.Fname + ".cs")) File.Delete(OutPutAddress + "\\" + t.Fname + ".cs"); StreamWriter sw = new StreamWriter(OutPutAddress + "\\" + t.Fname + ".cs", true); sw.Write(t.Code); sw.Close(); } for (int i = 0; i < result.Count; i++) { if (File.Exists(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx")) File.Delete(OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"); File.Copy(Environment.CurrentDirectory + "\\RFile.resx", OutPutAddress + "\\" + result.ElementAt(i).Fname + ".resx"); } return true; }
private struc[] Distinct(struc[] input) { Queue<struc> res = new Queue<struc>(); for (int i = 0; i < input.Length; i++) { if (res.Where(p => p.Fname == input[i].Fname).FirstOrDefault() == null) res.Enqueue(input[i]); } return res.ToArray(); }
private void ProcessAssociation(struc[] data, AssociationStruct[] associatioData) { for (int i = 0; i < data.Length; i++) { var tbName = data[i].TableName; var association = associatioData.Where(p => p.DependentTableName == tbName).Distinct().ToArray(); data[i].Ass = Distinct(association); } }
private void Translate(struc[] parsedData, Dictionary<string, string> dic) { for (int i = 0; i < parsedData.Length; i++) { for (int j = 0; j < parsedData[i].Ass.Length; j++) { var temp = dic.Where(p => p.Key == parsedData[i].Ass[j].DependentTableName).FirstOrDefault(); if (temp.Value != null) { parsedData[i].Ass[j].DependentTableName = temp.Value; } temp = dic.Where(p => p.Key == parsedData[i].Ass[j].PrincipalTableName).FirstOrDefault(); if (temp.Value != null) { parsedData[i].Ass[j].PrincipalTableName = temp.Value; } } var temp2 = dic.Where(p => p.Key == parsedData[i].TableName).FirstOrDefault(); if (temp2.Value != null) { parsedData[i].TableName = temp2.Value; } } }