private static String HierarchyIdToHexString(SqlHierarchyId hid) { using (var ms = new MemoryStream()) using (var binWriter = new BinaryWriter(ms)) { hid.Write(binWriter); var byteString = BitConverter.ToString(ms.ToArray()).Replace("-", ""); return(String.Format("0x{0}", byteString)); } }
public async Task <ActionResult <Domain> > PutDomain(int id, Domain domain) { Domain toInsert = new Domain(); toInsert.DomainName = domain.DomainName; toInsert.DomainTypeId = domain.DomainTypeId; toInsert.Parentt = domain.Parentt; toInsert.HighLevel = domain.HighLevel; //if (domain.Parentt == "N/A") //{ // SqlString level = new SqlString ( "/1/" ); // toInsert.Level = SqlHierarchyId.Parse("/1/"); //}else //{ // //SqlString level = new SqlString("/1/2/"); // toInsert.Level = SqlHierarchyId.Parse("/1/3/"); //} SqlHierarchyId id1 = new SqlHierarchyId(); if (id == 2) { id1 = SqlHierarchyId.Parse("/1/1/"); } using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { id1.Write(writer); toInsert.Level = stream.ToArray(); } } //_context.Domains.Add(toInsert); _context.Entry(toInsert).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DomainExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static string formatHierarchyId(object data) { SqlHierarchyId hier = (SqlHierarchyId)data; byte[] ba; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(ms)) { hier.Write(w); w.Flush(); ba = ms.ToArray(); } return("0x" + BitConverter.ToString(ba).Replace("-", "")); }
public static byte[] ToByteArray(this SqlHierarchyId id) { if (id.IsNull) { return(null); } using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { id.Write(writer); return(stream.ToArray()); } } }
public static byte[] HierarchyId2Bytes(SqlHierarchyId h) { byte[] b = null; if (!h.IsNull) { var stream = new MemoryStream(); BinaryWriter bw; bw = new BinaryWriter(stream); h.Write(bw); b = stream.ToArray(); stream.Close(); stream.Dispose(); bw.Close(); bw.Dispose(); } return(b); }
public async Task <ActionResult <Domain> > PostDomain(Domaintest domain) { Domain toInsert = new Domain(); toInsert.DomainName = domain.DomainName; toInsert.DomainTypeId = domain.DomainTypeId; toInsert.Parentt = domain.Parentt; toInsert.HighLevel = domain.HighLevel; //if (domain.Parentt == "N/A") //{ // SqlString level = new SqlString ( "/1/" ); // toInsert.Level = SqlHierarchyId.Parse("/1/"); //}else //{ // //SqlString level = new SqlString("/1/2/"); // toInsert.Level = SqlHierarchyId.Parse("/1/3/"); //} SqlHierarchyId id1 = SqlHierarchyId.Parse(domain.Path); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { id1.Write(writer); toInsert.Level = stream.ToArray(); } } _context.Domains.Add(toInsert); try { await _context.SaveChangesAsync(); } catch (Exception ex) { } return(CreatedAtAction("GetDomain", new { id = toInsert.DomainId }, toInsert)); }
public void Write(BinaryWriter writer) { _value.Write(writer); }