public void WirteFile() { string path = @"D:\杆塔项目\other\【0715】结构计算\Tower library"; DirectoryInfo root = new DirectoryInfo(path); DirectoryInfo[] dics = root.GetDirectories(); StruTemplateLibGeneral item; foreach (DirectoryInfo ParentInfo in dics) { foreach (FileInfo info in ParentInfo.GetFiles("*.dat")) { using (FileStream fsRead = new FileStream(info.FullName, FileMode.Open, FileAccess.Read)) { item = new StruTemplateLibGeneral(); byte[] buffer = new byte[fsRead.Length]; // int r = fsRead.Read(buffer, 0, buffer.Length); //返回本次实际读取到的有效字节数 item.FileName = Path.GetFileNameWithoutExtension(info.FullName); item.Category = ParentInfo.Name; item.FileExtension = info.Extension; item.Content = System.Text.Encoding.Default.GetString(buffer);//使用utf-8编码格式 struTemplateLibGeneralService.Add(item); } } } }
private void ParseEndElements(Dictionary <string, ClassInfo> table, string className) { ParentInfo parent = stack.Pop(); ClassInfo classInfo = table[className]; Dictionary <string, PropertyInfo> classMembers = classInfo.Properties; foreach (KeyValuePair <string, int> child in parent.ChildCount) { string childName = child.Key; int childCount = child.Value; int existingChildCount = 0; if (classMembers.ContainsKey(childName)) { existingChildCount = classMembers[childName].Occurrences; } else { PropertyInfo property = new PropertyInfo(childName, false); classMembers[childName] = property; } if (childCount > existingChildCount) { classMembers[childName].Occurrences = childCount; } } }
public IActionResult GetParentInfo() { int id = userIdentity.GetCurrentUser().Result.Id; ParentInfo info = ds.ReadParentInfo(id); info.UserId = id; return(Ok(info)); }
private Dictionary <string, ClassInfo> Parse(XmlTextReader reader) { XmlNamespaceManager nps = new XmlNamespaceManager(reader.NameTable); Dictionary <string, ClassInfo> table = new Dictionary <string, ClassInfo>(); ParentInfo parent = null; string previousNode = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement) { ////Got an element. This will be the name of a class. string className = reader.LocalName; if (className.Equals("rss", StringComparison.OrdinalIgnoreCase)) { nps = new XmlNamespaceManager(reader.NameTable); for (int index = 0; index < reader.AttributeCount; index++) { { reader.MoveToAttribute(index); if (reader.Name.StartsWith("xmlns")) { nps.AddNamespace(reader.LocalName, reader.Value); } } } } if (reader.IsStartElement() || reader.IsEmptyElement) { ParseStartElements(reader, table, parent, nps, className); } else { ParseEndElements(table, className); } previousNode = className; } else if (reader.NodeType == XmlNodeType.Text) { if (!string.IsNullOrEmpty(previousNode)) { ClassInfo classInfo = table[previousNode]; classInfo.IsText = true; } } } return(table); }
private static int ImportCustomer(CsvReader csv) { int accointId = 0; //Import Parent ParentInfo p = new ParentInfo(); p.FromCsv(csv); // using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext()) { ParticipantRepo repo = new ParticipantRepo(dbContext); //If participant exist var existingParent = repo.GetAllParents().FirstOrDefault(x => x.LastName.ToLower() == p.LastName.ToLower() && x.Email == p.Email); if (existingParent != null) { accointId = existingParent.AccountInfoId; //TODO-1 //Update changes } else { //repo.AddAccount(new AccountInfo { LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now}); p.AccountInfo = new AccountInfo { LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now }; repo.AddParent(p); } try { //Save to DB dbContext.SaveChanges(); } catch (DbEntityValidationException exc) { string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray(); throw new DbEntityValidationException(String.Join("; ", validationErrorMessages)); } } return(accointId); }
public void ParticipantTests_AddParent_Mock() { ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object) { IncludeNavigationProperties = false }; //Mock Parent ParentInfo p = new ParentInfo() { Id = 2, LastName = "Baravik", FirstName = "Mark", AccountInfoId = 2 }; int count1 = repo.PrivateClassesDBContext.ParentInfoes.Count(); Assert.IsTrue(count1 == 2); repo.AddParent(p); int count2 = repo.PrivateClassesDBContext.ParentInfoes.Count(); Assert.IsTrue(count2 == 3); }
IEnumerator InitializeCoroutine() { yield return(null); _locationManager = GetComponent <LocationManager>(); parentInfo = ParentInfo.GetOrCreateParentInfo("parentInfo", new Vector2Int(1396900000, 359500000) /*(int)_locationManager.Latitude, (int)_locationManager.Longitude)*/, MapUtility.WorldScale); gameObject.AddComponent <ArowMapDynamicLoadManager>().Initialize(unityChan, new Vector2Int(1396900000, 359500000)); //(int)_locationManager.Latitude, (int)_locationManager.Longitude)); yield return(new WaitUntil(() => { try { if (_null.activeSelf) { return true; } } catch { } return false; })); // 高い位置から地面へ Ray を飛ばす。 var rayOriginHeight = 1000f; // 取得した経度緯度を AROW の経度緯度に合わせる。 var rate = 10000000; var origin = new Vector3( (_locationManager.Longitude * rate - parentInfo.WorldCenter.x) * parentInfo.WorldScale.x, rayOriginHeight, (_locationManager.Latitude * rate - parentInfo.WorldCenter.y) * parentInfo.WorldScale.y ); origin = new Vector3(0, rayOriginHeight, 0); Debug.Log(origin.ToString()); RaycastHit hitInfo; if (Physics.Raycast(origin, Vector3.down, out hitInfo)) { // 地面にぶつかったら ユニティちゃんを移動させる。 unityChan.transform.position = hitInfo.point; Debug.Log(unityChan.transform.position.ToString()); Debug.Log(hitInfo.point.ToString()); } yield break; }
public JsonResult GetParentInfoBySearch(long centerId, long classRoomId, long filterType, string searchText = "") { ParentInfo info = new ParentInfo(); ParentInfoModel model = new ParentInfoModel(); try { info.CenterId = centerId; info.ClassRoomId = classRoomId; info.SearchText = searchText; info.FilterType = filterType; info.AgencyId = new Guid(Session["AgencyId"].ToString()); info.UserId = new Guid(Session["UserID"].ToString()); info.RoleId = new Guid(Session["RoleId"].ToString()); // model = new CenterData().GetParentInfoBySearch(info); model = new CenterData().ParentContactInfo(info); } catch (Exception ex) { clsError.WriteException(ex); } return(Json(model)); }
public void ParticipantIntegationTests_AddSecondParentWithExistingAccount() { using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext()) { ParentInfo parent_2 = new ParentInfo() { LastName = "Doe", FirstName = "Jane", Email = "*****@*****.**" }; ParticipantRepo repo = new ParticipantRepo(dbContext); try { //Get Account var allAccounts = repo.GetAllAccounts(); var a = allAccounts.SingleOrDefault(x => x.LastName == parent_2.LastName && x.Email.Trim() == parent_2.Email); Assert.IsNotNull(a, "Account not found"); parent_2.AccountInfo = a; //repo.AddParent(parent_2); //dbContext.SaveChanges(); } catch (DbEntityValidationException exc) { string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray(); Assert.Fail(String.Join("; ", validationErrorMessages)); } catch (Exception exc) { Assert.Fail(exc.ToString()); } var parentRes_2 = repo.GetAllParents().SingleOrDefault(p => p.LastName.Trim() == parent_2.LastName && p.FirstName.Trim() == parent_2.FirstName); Assert.IsNotNull(parentRes_2, "Parent 2"); Assert.IsNotNull(parentRes_2.AccountInfo, "AccountInfo is NULL"); Assert.IsTrue(parentRes_2.AccountInfoId > 0, "AccountId"); } }
private void btnMyProfile_Click(object sender, EventArgs e) { ParentInfo info = null; try { info = ParentDAL.GetParentInfo(this.ParentID); } catch (ArgumentOutOfRangeException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProfileWindow wnd = new ProfileWindow(info, "Job", info.Job); wnd.FormClosed += ((o, s) => { this.Show(); }); wnd.Owner = this; wnd.Show(); this.Hide(); }
public void ParticipantIntegationTests_AddParentWithAccount() { using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext()) { ParentInfo parent_1 = new ParentInfo() { LastName = "Doe", FirstName = "John", Email = "*****@*****.**" }; AccountInfo a = new AccountInfo { LastName = parent_1.LastName, Email = parent_1.Email }; parent_1.AccountInfo = a; ParticipantRepo repo = new ParticipantRepo(dbContext); try { repo.AddParent(parent_1); dbContext.SaveChanges(); } catch (DbEntityValidationException exc) { string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray(); Assert.Fail(String.Join("; ", validationErrorMessages)); } catch (Exception exc) { Assert.Fail(exc.ToString()); } var parentRes_1 = repo.GetAllParents().SingleOrDefault(p => p.LastName == parent_1.LastName && p.FirstName == parent_1.FirstName); Assert.IsNotNull(parentRes_1, "Parent 1"); Assert.IsNotNull(parentRes_1.AccountInfo, "AccountInfo is NULL"); Assert.IsTrue(parentRes_1.AccountInfoId > 0, "AccountId"); } }
/// <summary> /// DateSet转IEnumerable /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ds"></param> /// <returns></returns> public static IEnumerable <T> ToCollection <T>(this DataSet ds) where T : new() { if (ds == null || ds.Tables.Count == 0) { return(Enumerable.Empty <T>()); } IDictionary <String, IList> Map = new Dictionary <String, IList>(); IList <T> Parent = new List <T>(); T ParentInstance = new T(); foreach (DataTable dt in ds.Tables) { foreach (DataRow row in dt.Rows) { PropertyInfo[] PropertInfosParent = ParentInstance.GetType().GetProperties(); foreach (PropertyInfo ParentInfo in PropertInfosParent) { if (ParentInfo.PropertyType.IsGenericType) { Type ChildType = ParentInfo.PropertyType.GetGenericArguments().FirstOrDefault(); var ChildInstrance = Activator.CreateInstance(ChildType); PropertyInfo[] PropertInfosChild = ChildInstrance.GetType().GetProperties(); foreach (PropertyInfo ChildInfo in PropertInfosChild) { if (dt.Columns.Contains(ChildInfo.Name)) { if (!ChildInfo.CanWrite) { continue; } object value = row[ChildInfo.Name]; if (value != DBNull.Value) { ChildInfo.SetValue(ChildInstrance, value); } } } var FirstValue = ChildInstrance.GetType().GetProperties().FirstOrDefault().GetValue(ChildInstrance, null); if (FirstValue != null) { Type DynamicList = typeof(List <>).MakeGenericType(ChildType); IList ChildListType = null; if (!Map.ContainsKey(ChildType.FullName)) { ChildListType = Activator.CreateInstance(DynamicList) as IList; Map.Add(ChildType.FullName, ChildListType); } else { ChildListType = Map[ChildType.FullName]; } ChildListType.Add(ChildInstrance); ParentInfo.SetValue(ParentInstance, ChildListType); } } else { if (dt.Columns.Contains(ParentInfo.Name)) { if (!ParentInfo.CanWrite) { continue; } object value = row[ParentInfo.Name]; if (value != DBNull.Value) { ParentInfo.SetValue(ParentInstance, value); } } } } } } Parent.Add(ParentInstance); return(Parent); }
private void ParseStartElements(XmlTextReader reader, Dictionary<string, ClassInfo> table, ParentInfo parent, XmlNamespaceManager nps, string className) { if (stack.Count != 0) { ////Get the parent parent = stack.Peek(); ////Get the child element from inside the parent if (parent.ChildCount.ContainsKey(className)) { ////increment the Occurrence of the child element inside the parent int childCount = parent.ChildCount[className]; parent.ChildCount[className] = ++childCount; } else { ////if child does not exist in the parent add it with Occurrence = 1 parent.ChildCount.Add(className, 1); } } if (!reader.IsEmptyElement) { ////If its not an empty element push it in the stack which ////contains all parent elements stack.Push(new ParentInfo()); } ClassInfo classInfo; if (!table.TryGetValue(className, out classInfo)) { ////Create a ClassInfo every time we hit an element and it is not already ////contained in the global table. classInfo = new ClassInfo(className); table.Add(className, classInfo); } if (reader.LocalName != reader.Name) { string lookupName = reader.Prefix == "xmlns" ? reader.LocalName : reader.Prefix; classInfo.Namespace = nps.LookupNamespace(lookupName); } ////Add any new attributes that are not already defined in the classInfo.... for (int index = 0; index < reader.AttributeCount; index++) { reader.MoveToAttribute(index); string localName = reader.LocalName; if (!classInfo.Properties.ContainsKey(localName) && (!reader.Name.StartsWith("xmlns"))) { PropertyInfo propertyInfo = new PropertyInfo(localName, true); classInfo.Properties[propertyInfo.Name] = propertyInfo; } } }
public void AddParent(ParentInfo parent) { PrivateClassesDBContext.ParentInfoes.Add(parent); }
private IList<IInfoClass> GetInfoListWithParent() { var child1 = new ChildInfo { AnyChildProperty = ChildValue1 }; var child2 = new ChildInfo { AnyChildProperty = ChildValue2 }; var parent1 = new ParentInfo { AnyParentProperty = ParentValue1 }; var parent2 = new ParentInfo { AnyParentProperty = ParentValue2 }; child1.BaseInfo = parent1; child2.BaseInfo = parent2; return new List<IInfoClass> { child1, child2 }; }
public void SetValue(object rootObj, object value) { var obj = ParentInfo == null ? rootObj : ParentInfo.GetValue(rootObj); Info.SetValue(GetParentValue(rootObj), value); }
private object GetParentValue(object rootObj) { var obj = ParentInfo == null ? rootObj : ParentInfo.GetValue(rootObj); return(obj); }
private void ParseStartElements(XmlTextReader reader, Dictionary <string, ClassInfo> table, ParentInfo parent, XmlNamespaceManager nps, string className) { if (stack.Count != 0) { ////Get the parent parent = stack.Peek(); ////Get the child element from inside the parent if (parent.ChildCount.ContainsKey(className)) { ////increment the Occurrence of the child element inside the parent int childCount = parent.ChildCount[className]; parent.ChildCount[className] = ++childCount; } else { ////if child does not exist in the parent add it with Occurrence = 1 parent.ChildCount.Add(className, 1); } } if (!reader.IsEmptyElement) { ////If its not an empty element push it in the stack which ////contains all parent elements stack.Push(new ParentInfo()); } ClassInfo classInfo; if (!table.TryGetValue(className, out classInfo)) { ////Create a ClassInfo every time we hit an element and it is not already ////contained in the global table. classInfo = new ClassInfo(className); table.Add(className, classInfo); } if (reader.LocalName != reader.Name) { string lookupName = reader.Prefix == "xmlns" ? reader.LocalName : reader.Prefix; classInfo.Namespace = nps.LookupNamespace(lookupName); } ////Add any new attributes that are not already defined in the classInfo.... for (int index = 0; index < reader.AttributeCount; index++) { reader.MoveToAttribute(index); string localName = reader.LocalName; if (!classInfo.Properties.ContainsKey(localName) && (!reader.Name.StartsWith("xmlns"))) { PropertyInfo propertyInfo = new PropertyInfo(localName, true); classInfo.Properties[propertyInfo.Name] = propertyInfo; } } }
} //Read public void Write(FileStream stream) { List <string> strings = new List <string>(0); BinaryWriter writer = new BinaryWriter(stream); writer.WriteZeroes(0xC); headerEntry.offset = writer.BaseStream.Position; writer.Write(headerEntry.unkStrCode32); strings.Add(headerEntry.name); writer.WriteZeroes(0x10); dataOffset = (uint)writer.BaseStream.Position; int entryCount = entries.Count; for (int i = 0; i < entryCount; i++) { Entry entry = entries[i]; entry.offset = writer.BaseStream.Position; writer.Write(entry.unkStrCode32); strings.Add(entry.name); writer.WriteZeroes(8); writer.Write(entry.unknown0); writer.Write(entry.unknown1); writer.WriteZeroes(0x8); writer.Write(entry.unknown2); writer.Write(entry.unknown3); writer.WriteZeroes(0xC); for (int j = 0; j < 4; j++) { writer.Write(entry.position[j]); } for (int j = 0; j < 4; j++) { writer.Write(entry.rotation[j]); } for (int j = 0; j < 4; j++) { writer.Write(entry.scale[j]); } } //for for (int i = 0; i < entryCount; i++) { Entry entry = entries[i]; ParentInfo parentInfo = entry.parentInfo; entry.parentSectionOffset = (ulong)(writer.BaseStream.Position - entry.offset); writer.Write(parentInfo.unknown0); parentInfo.offset0 = writer.BaseStream.Position; writer.Write(parentInfo.unkStrCode32_0); writer.WriteZeroes(4); parentInfo.offset1 = writer.BaseStream.Position; writer.Write(parentInfo.unkStrCode32_1); writer.WriteZeroes(4); } //for List <Tuple <string, long> > stringList = new List <Tuple <string, long> >(0); stringList.Add(new Tuple <string, long>(headerEntry.name, writer.BaseStream.Position)); headerEntry.nameOffset = (ulong)(writer.BaseStream.Position - headerEntry.offset); writer.Write(headerEntry.name.ToCharArray()); writer.WriteZeroes(1); for (int i = 0; i < entryCount; i++) { Entry entry = entries[i]; ParentInfo parentInfo = entry.parentInfo; if (!stringList.Contains(stringList.Find(x => x.Item1 == entry.name))) { stringList.Add(new Tuple <string, long>(entry.name, writer.BaseStream.Position)); entry.nameOffset = (ulong)(writer.BaseStream.Position - entry.offset); writer.Write(entry.name.ToCharArray()); writer.WriteZeroes(1); } //if else { Tuple <string, long> tuple = stringList.Find(x => x.Item1 == entry.name); entry.nameOffset = (ulong)(tuple.Item2 - entry.offset); } //else if (!stringList.Contains(stringList.Find(x => x.Item1 == parentInfo.parentString))) { stringList.Add(new Tuple <string, long>(parentInfo.parentString, writer.BaseStream.Position)); parentInfo.nameOffset0 = (uint)(writer.BaseStream.Position - parentInfo.offset0); writer.Write(parentInfo.parentString.ToCharArray()); writer.WriteZeroes(1); } //if else { Tuple <string, long> tuple = stringList.Find(x => x.Item1 == parentInfo.parentString); parentInfo.nameOffset0 = (uint)(tuple.Item2 - parentInfo.offset0); } //else if (!stringList.Contains(stringList.Find(x => x.Item1 == parentInfo.parentName))) { stringList.Add(new Tuple <string, long>(parentInfo.parentName, writer.BaseStream.Position)); parentInfo.nameOffset1 = (uint)(writer.BaseStream.Position - parentInfo.offset1); writer.Write(parentInfo.parentName.ToCharArray()); writer.WriteZeroes(1); } //if else { Tuple <string, long> tuple = stringList.Find(x => x.Item1 == parentInfo.parentName); parentInfo.nameOffset1 = (uint)(tuple.Item2 - parentInfo.offset1); } //else } //for fileLength = (uint)writer.BaseStream.Position; //Offset writing time! writer.BaseStream.Position = 4; writer.Write(dataOffset); writer.Write(fileLength); writer.BaseStream.Position = headerEntry.offset + 4; writer.Write(headerEntry.nameOffset); for (int i = 0; i < entryCount; i++) { Entry entry = entries[i]; ParentInfo parentInfo = entry.parentInfo; writer.BaseStream.Position = entry.offset + 4; writer.Write(entry.nameOffset); writer.BaseStream.Position += 0x18; writer.Write(entry.parentSectionOffset); writer.BaseStream.Position = parentInfo.offset0 + 4; writer.Write(parentInfo.nameOffset0); writer.BaseStream.Position = parentInfo.offset1 + 4; writer.Write(parentInfo.nameOffset1); } //for } //write
public void Read(FileStream stream) { BinaryReader reader = new BinaryReader(stream); long offset; reader.BaseStream.Position += 4; dataOffset = reader.ReadUInt32(); fileLength = reader.ReadUInt32(); headerEntry.offset = reader.BaseStream.Position; headerEntry.unkStrCode32 = reader.ReadUInt32(); headerEntry.nameOffset = reader.ReadUInt64(); headerEntry.name = ReadName(reader, headerEntry.offset + (long)headerEntry.nameOffset); reader.BaseStream.Position = dataOffset; while (true) { uint breakInt = reader.ReadUInt32(); if (breakInt == 1) { break; } Entry entry = new Entry(); entry.offset = reader.BaseStream.Position - 4; entry.unkStrCode32 = breakInt; entry.nameOffset = reader.ReadUInt64(); entry.unknown0 = reader.ReadUInt32(); entry.unknown1 = reader.ReadUInt32(); reader.BaseStream.Position += 0x8; entry.unknown2 = reader.ReadUInt32(); entry.unknown3 = reader.ReadUInt32(); entry.parentSectionOffset = reader.ReadUInt64(); reader.BaseStream.Position += 0x4; entry.position = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); entry.rotation = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); entry.scale = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); offset = reader.BaseStream.Position; entry.name = ReadName(reader, entry.offset + (long)entry.nameOffset); reader.BaseStream.Position = offset; entries.Add(entry); } //while reader.BaseStream.Position -= 4; int entryCount = entries.Count; for (int i = 0; i < entryCount; i++) { ParentInfo parentInfo = new ParentInfo(); parentInfo.unknown0 = reader.ReadUInt32(); parentInfo.offset0 = reader.BaseStream.Position; parentInfo.unkStrCode32_0 = reader.ReadUInt32(); parentInfo.nameOffset0 = reader.ReadUInt32(); parentInfo.offset1 = reader.BaseStream.Position; parentInfo.unkStrCode32_1 = reader.ReadUInt32(); parentInfo.nameOffset1 = reader.ReadUInt32(); offset = reader.BaseStream.Position; parentInfo.parentString = ReadName(reader, parentInfo.offset0 + parentInfo.nameOffset0); parentInfo.parentName = ReadName(reader, parentInfo.offset1 + parentInfo.nameOffset1); entries[i].parentInfo = parentInfo; reader.BaseStream.Position = offset; } //for } //Read