protected void SaveAndConvert(Datamodel.Datamodel dm, string encoding, int version) { dm.Save(DmxSavePath, encoding, version); var dmxconvert = new System.Diagnostics.Process(); dmxconvert.StartInfo = new System.Diagnostics.ProcessStartInfo() { FileName = System.IO.Path.Combine(Properties.Resources.ValveSourceBinaries, "dmxconvert.exe"), Arguments = String.Format("-i \"{0}\" -o \"{1}\" -oe {2}", DmxSavePath, DmxConvertPath, encoding), UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, }; Console.WriteLine(String.Join(" ", dmxconvert.StartInfo.FileName, dmxconvert.StartInfo.Arguments)); Assert.IsTrue(File.Exists(dmxconvert.StartInfo.FileName), String.Format("Could not find dmxconvert at {0}", dmxconvert.StartInfo.FileName)); Console.WriteLine(); dmxconvert.Start(); var err = dmxconvert.StandardOutput.ReadToEnd(); err += dmxconvert.StandardError.ReadToEnd(); dmxconvert.WaitForExit(); Console.WriteLine(err); if (dmxconvert.ExitCode != 0) throw new AssertFailedException(err); }
public Datamodel Decode(int encoding_version, string format, int format_version, Stream stream, DeferredMode defer_mode) { DM = new Datamodel(format, format_version); stream.Seek(0, SeekOrigin.Begin); Reader = new StreamReader(stream, Datamodel.TextEncoding); Reader.ReadLine(); // skip DMX header Line = 1; string next; while (true) { try { next = Decode_NextToken(); } catch (EndOfStreamException) { break; } try { Decode_ParseElement(next); } catch (Exception err) { throw new CodecException(String.Format("KeyValues2 decode failed on line {0}:\n\n{1}", Line, err.Message), err); } } return(DM); }
static byte TypeToId(Type type, int version) { bool array = Datamodel.IsDatamodelArrayType(type); var search_type = array ? Datamodel.GetArrayInnerType(type) : type; if (array && search_type == typeof(byte) && !SupportedAttributes[version].Contains(typeof(byte))) { search_type = typeof(byte[]); // Recent version of DMX support both "binary" and "uint8_array" attributes. These are the same thing! array = false; } var type_list = SupportedAttributes[version]; byte i = 0; foreach (var list_type in type_list) { if (list_type == search_type) { break; } else { i++; } } if (i == type_list.Length) { throw new CodecException(String.Format("\"{0}\" is not supported in encoding binary {1}", type.Name, version)); } if (array) { i += (byte)(type_list.Length * (version >= 9 ? 2 : 1)); } return(++i); }
public ActionResult DeleteConfirmed(int id) { Datamodel datamodel = db.Datamodels.Find(id); db.Datamodels.Remove(datamodel); db.SaveChanges(); return(RedirectToAction("Index")); }
public Encoder(Binary codec, BinaryWriter writer, Datamodel dm, int version) { EncodingVersion = version; Writer = writer; Datamodel = dm; StringDict = new StringDictionary(version, writer, dm); ElementIndices = new Dictionary <Element, int>(); ElementOrder = new List <Element>(); }
public ActionResult Edit([Bind(Include = "ID,ExampleFirstName,ExampleLastName")] Datamodel datamodel) { if (ModelState.IsValid) { db.Entry(datamodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datamodel)); }
public void Dispose() { if (Datamodel != null) { Datamodel.Dispose(); } if (ComparisonDatamodel != null) { ComparisonDatamodel.Datamodel_Right.Dispose(); } }
public ActionResult Create([Bind(Include = "ID,ExampleFirstName,ExampleLastName")] Datamodel datamodel) { if (ModelState.IsValid) { db.Datamodels.Add(datamodel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(datamodel)); }
// GET: Datamodel/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Datamodel datamodel = db.Datamodels.Find(id); if (datamodel == null) { return(HttpNotFound()); } return(View(datamodel)); }
/// <summary> /// Constructs a new <see cref="StringDictionary"/> from a <see cref="Datamodel"/> object. /// </summary> public StringDictionary(int encoding_version, BinaryWriter writer, Datamodel dm) { EncodingVersion = encoding_version; Writer = writer; Dummy = EncodingVersion == 1; if (!Dummy) { Scraped = new HashSet <Element>(); ScrapeElement(dm.Root); Strings = Strings.Distinct().ToList(); Scraped = null; } }
public void Encode(Datamodel dm, int encoding_version, Stream stream) { Writer = new KV2Writer(stream); EncodingVersion = encoding_version; Writer.Write(String.Format(CodecUtilities.HeaderPattern, "keyvalues2", encoding_version, dm.Format, dm.FormatVersion)); Writer.WriteLine(); Users = new Dictionary <Element, int>(); if (EncodingVersion >= 9 && dm.PrefixAttributes.Count > 0) { Writer.WriteTokens("$prefix_element$"); Writer.WriteLine("{"); Writer.Indent++; foreach (var attr in dm.PrefixAttributes) { WriteAttribute(attr.Key, attr.Value.GetType(), attr.Value, false); } Writer.Indent--; Writer.WriteLine("}"); } CountUsers(dm.Root); WriteElement(dm.Root); Writer.WriteLine(); foreach (var pair in Users.Where(pair => pair.Value > 1)) { if (pair.Key == dm.Root) { continue; } Writer.WriteLine(); WriteElement(pair.Key); Writer.WriteLine(); } Writer.Flush(); }
object DecodeAttribute(Datamodel dm, bool prefix) { var type = IdToType(Reader.ReadByte()); if (!Datamodel.IsDatamodelArrayType(type)) { return(ReadValue(dm, type, EncodingVersion < 4 || prefix)); } else { var count = Reader.ReadInt32(); var inner_type = Datamodel.GetArrayInnerType(type); var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) { array.Add(ReadValue(dm, inner_type, true)); } return(array); } }
object DecodeAttribute(Datamodel dm) { var types = IdToType(Reader.ReadByte()); if (types.Item2 == null) { return(ReadValue(dm, types.Item1, EncodingVersion < 4)); } else { var count = Reader.ReadInt32(); var inner_type = types.Item2; var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) { array.Add(ReadValue(dm, inner_type, true)); } return(array); } }
/// <summary> /// Perform a parallel loop over all elements and attributes /// </summary> protected void PrintContents(Datamodel.Datamodel dm) { System.Threading.Tasks.Parallel.ForEach<Datamodel.Element>(dm.AllElements, e => { System.Threading.Tasks.Parallel.ForEach(e, a => { ; }); }); }
/// <summary> /// Constructs a new instance of the LiveControl /// </summary> /// <param name="initialTimeout">The duration that the backups should be initially suspended</param> public LiveControls(Datamodel.ApplicationSettings settings) { m_state = LiveControlState.Running; m_waitTimer = new System.Windows.Forms.Timer(); m_waitTimer.Tick += new EventHandler(m_waitTimer_Tick); if (!string.IsNullOrEmpty(settings.StartupDelayDuration) && settings.StartupDelayDuration != "0") { TimeSpan ts = XervBackup.Library.Utility.Timeparser.ParseTimeSpan(settings.StartupDelayDuration); m_waitTimer.Interval = (int)ts.TotalMilliseconds; m_waitTimer.Enabled = true; m_waitTimeExpiration = DateTime.Now + ts; m_state = LiveControlState.Paused; } m_priority = settings.ThreadPriorityOverride; if (!string.IsNullOrEmpty(settings.DownloadSpeedLimit)) m_downloadLimit = Library.Utility.Sizeparser.ParseSize(settings.DownloadSpeedLimit, "kb"); if (!string.IsNullOrEmpty(settings.UploadSpeedLimit)) m_uploadLimit = Library.Utility.Sizeparser.ParseSize(settings.UploadSpeedLimit, "kb"); try { if (!Library.Utility.Utility.IsClientLinux) RegisterHibernateMonitor(); } catch { } }
void Get_TF2(Datamodel.Datamodel dm) { dm.Root.Get<Element>("skeleton").GetArray<Element>("children")[0].Any(); dm.FormatVersion = 22; // otherwise recent versions of dmxconvert fail }
public Datamodel Decode(int encoding_version, string format, int format_version, Stream stream, DeferredMode defer_mode) { stream.Seek(0, SeekOrigin.Begin); while (true) { var b = stream.ReadByte(); if (b == 0) break; } var dm = new Datamodel(format, format_version); EncodingVersion = encoding_version; Reader = new BinaryReader(stream, Datamodel.TextEncoding); if (EncodingVersion >= 9) { // Read prefix elements foreach (int prefix_elem in Enumerable.Range(0, Reader.ReadInt32())) { foreach (int attr_index in Enumerable.Range(0, Reader.ReadInt32())) { var name = ReadString_Raw(); var value = DecodeAttribute(dm); if (prefix_elem == 0) // skip subsequent elements...are they considered "old versions"? dm.PrefixAttributes[name] = value; } } } StringDict = new StringDictionary(this, Reader); var num_elements = Reader.ReadInt32(); // read index foreach (var i in Enumerable.Range(0, num_elements)) { var type = StringDict.ReadString(); var name = EncodingVersion >= 4 ? StringDict.ReadString() : ReadString_Raw(); var id_bits = Reader.ReadBytes(16); var id = new Guid(BitConverter.IsLittleEndian ? id_bits : id_bits.Reverse().ToArray()); var elem = new Element(dm, name, id, type); } // read attributes (or not, if we're deferred) foreach (var elem in dm.AllElements.ToArray()) { System.Diagnostics.Debug.Assert(!elem.Stub); var num_attrs = Reader.ReadInt32(); foreach (var i in Enumerable.Range(0, num_attrs)) { var name = StringDict.ReadString(); if (defer_mode == DeferredMode.Automatic) { CodecUtilities.AddDeferredAttribute(elem, name, Reader.BaseStream.Position); SkipAttribte(); } else { elem.Add(name, DecodeAttribute(dm)); } } } return dm; }
public object DeferredDecodeAttribute(Datamodel dm, long offset) { Reader.BaseStream.Seek(offset, SeekOrigin.Begin); return DecodeAttribute(dm); }
protected static void Populate(Datamodel.Datamodel dm, string encoding_name, int encoding_version) { dm.Root = new Element(dm, "root", RootGuid); foreach (var value in AttributeValuesFor(encoding_name, encoding_version)) { if (value == null) continue; var name = value.GetType().Name; dm.Root[name] = value; Assert.AreSame(value, dm.Root[name]); name += " array"; var list = value.GetType().MakeListType().GetConstructor(Type.EmptyTypes).Invoke(null) as IList; list.Add(value); list.Add(value); dm.Root[name] = list; Assert.AreSame(list, dm.Root[name]); } dm.Root["Recursive"] = dm.Root; dm.Root["NoName"] = new Element(); dm.Root["ElemArray"] = new ElementArray(new Element[] { new Element(dm, Guid.NewGuid()), new Element(), dm.Root, new Element(dm, "TestElement") }); dm.Root["ElementStub"] = new Element(dm, Guid.NewGuid()); }
public Encoder(Binary codec, BinaryWriter writer, Datamodel dm, int version) { EncodingVersion = version; Writer = writer; Datamodel = dm; StringDict = new StringDictionary(version, writer, dm); ElementIndices = new Dictionary<Element, int>(); ElementOrder = new List<Element>(); }
public void ShowList(Control owner, Datamodel.Schedule schedule, DateTime when) { backgroundWorker1.RunWorkerAsync(new object[] { schedule, when }); this.ShowDialog(owner); }
object ReadValue(Datamodel dm, Type type, bool raw_string) { if (type == typeof(Element)) { var index = Reader.ReadInt32(); if (index == -1) return null; else if (index == -2) { var id = new Guid(ReadString_Raw()); // yes, it's in ASCII! return dm.AllElements[id] ?? new Element(dm, id); } else return dm.AllElements[index]; } if (type == typeof(int)) return Reader.ReadInt32(); if (type == typeof(float)) return Reader.ReadSingle(); if (type == typeof(bool)) return Reader.ReadBoolean(); if (type == typeof(string)) return raw_string ? ReadString_Raw() : StringDict.ReadString(); if (type == typeof(byte[])) return (Reader.ReadBytes(Reader.ReadInt32())); if (type == typeof(TimeSpan)) return TimeSpan.FromTicks(Reader.ReadInt32() * (TimeSpan.TicksPerSecond / DatamodelTicksPerSecond)); if (type == typeof(System.Drawing.Color)) { var rgba = Reader.ReadBytes(4); return System.Drawing.Color.FromArgb(rgba[3], rgba[0], rgba[1], rgba[2]); } if (type == typeof(Vector2)) { var ords = ReadVector(2); return new Vector2(ords[0], ords[1]); } if (type == typeof(Vector3)) { var ords = ReadVector(3); return new Vector3(ords[0], ords[1], ords[2]); } if (type == typeof(Vector4)) { var ords = ReadVector(4); return new Vector4(ords[0], ords[1], ords[2], ords[3]); } if (type == typeof(Quaternion)) { var ords = ReadVector(4); return new Quaternion(ords[0], ords[1], ords[2], ords[3]); } if (type == typeof(Matrix4x4)) { var ords = ReadVector(4*4); return new Matrix4x4( ords[0], ords[1], ords[2], ords[3], ords[4], ords[5], ords[6], ords[7], ords[8], ords[9], ords[10], ords[11], ords[12], ords[13], ords[14], ords[15]); } if (type == typeof(byte)) return Reader.ReadByte(); if (type == typeof(UInt64)) return Reader.ReadUInt64(); throw new ArgumentException(type == null ? "No type provided to GetValue()" : "Cannot read value of type " + type.Name); }
/// <summary> /// Constructs a new <see cref="StringDictionary"/> from a <see cref="Datamodel"/> object. /// </summary> public StringDictionary(int encoding_version, BinaryWriter writer, Datamodel dm) { EncodingVersion = encoding_version; Writer = writer; Dummy = EncodingVersion == 1; if (!Dummy) { Scraped = new HashSet<Element>(); ScrapeElement(dm.Root); Strings = Strings.Distinct().ToList(); Scraped = null; } }
public ViewModel(Datamodel.Datamodel datamodel) { Datamodel = datamodel; }
public void Encode(Datamodel dm, int encoding_version, Stream stream) { Writer = new KV2Writer(stream); EncodingVersion = encoding_version; Writer.Write(String.Format(CodecUtilities.HeaderPattern, "keyvalues2", encoding_version, dm.Format, dm.FormatVersion)); Writer.WriteLine(); Users = new Dictionary<Element, int>(); if (EncodingVersion >= 9 && dm.PrefixAttributes.Count > 0) { Writer.WriteTokens("$prefix_element$"); Writer.WriteLine("{"); Writer.Indent++; foreach (var attr in dm.PrefixAttributes) WriteAttribute(attr.Key, attr.Value.GetType(), attr.Value, false); Writer.Indent--; Writer.WriteLine("}"); } CountUsers(dm.Root); WriteElement(dm.Root); Writer.WriteLine(); foreach (var pair in Users.Where(pair => pair.Value > 1)) { if (pair.Key == dm.Root) continue; Writer.WriteLine(); WriteElement(pair.Key); Writer.WriteLine(); } Writer.Flush(); }
public Datamodel Decode(int encoding_version, string format, int format_version, Stream stream, DeferredMode defer_mode) { stream.Seek(0, SeekOrigin.Begin); while (true) { var b = stream.ReadByte(); if (b == 0) { break; } } var dm = new Datamodel(format, format_version); EncodingVersion = encoding_version; Reader = new BinaryReader(stream, Datamodel.TextEncoding); if (EncodingVersion >= 9) { // Read prefix elements foreach (int prefix_elem in Enumerable.Range(0, Reader.ReadInt32())) { foreach (int attr_index in Enumerable.Range(0, Reader.ReadInt32())) { var name = ReadString_Raw(); var value = DecodeAttribute(dm, true); if (prefix_elem == 0) // skip subsequent elements...are they considered "old versions"? { dm.PrefixAttributes[name] = value; } } } } StringDict = new StringDictionary(this, Reader); var num_elements = Reader.ReadInt32(); // read index foreach (var i in Enumerable.Range(0, num_elements)) { var type = StringDict.ReadString(); var name = EncodingVersion >= 4 ? StringDict.ReadString() : ReadString_Raw(); var id_bits = Reader.ReadBytes(16); var id = new Guid(BitConverter.IsLittleEndian ? id_bits : id_bits.Reverse().ToArray()); var elem = new Element(dm, name, id, type); } // read attributes (or not, if we're deferred) foreach (var elem in dm.AllElements.ToArray()) { System.Diagnostics.Debug.Assert(!elem.Stub); var num_attrs = Reader.ReadInt32(); foreach (var i in Enumerable.Range(0, num_attrs)) { var name = StringDict.ReadString(); if (defer_mode == DeferredMode.Automatic) { CodecUtilities.AddDeferredAttribute(elem, name, Reader.BaseStream.Position); SkipAttribte(); } else { elem.Add(name, DecodeAttribute(dm, false)); } } } return(dm); }
object ReadValue(Datamodel dm, Type type, bool raw_string) { if (type == typeof(Element)) { var index = Reader.ReadInt32(); if (index == -1) { return(null); } else if (index == -2) { var id = new Guid(ReadString_Raw()); // yes, it's in ASCII! return(dm.AllElements[id] ?? new Element(dm, id)); } else { return(dm.AllElements[index]); } } if (type == typeof(int)) { return(Reader.ReadInt32()); } if (type == typeof(float)) { return(Reader.ReadSingle()); } if (type == typeof(bool)) { return(Reader.ReadBoolean()); } if (type == typeof(string)) { return(raw_string ? ReadString_Raw() : StringDict.ReadString()); } if (type == typeof(byte[])) { return(Reader.ReadBytes(Reader.ReadInt32())); } if (type == typeof(TimeSpan)) { return(TimeSpan.FromTicks(Reader.ReadInt32() * (TimeSpan.TicksPerSecond / DatamodelTicksPerSecond))); } if (type == typeof(System.Drawing.Color)) { var rgba = Reader.ReadBytes(4); return(System.Drawing.Color.FromArgb(rgba[3], rgba[0], rgba[1], rgba[2])); } if (type == typeof(Vector2)) { var ords = ReadVector(2); return(new Vector2(ords[0], ords[1])); } if (type == typeof(Vector3)) { var ords = ReadVector(3); return(new Vector3(ords[0], ords[1], ords[2])); } if (type == typeof(Vector4)) { var ords = ReadVector(4); return(new Vector4(ords[0], ords[1], ords[2], ords[3])); } if (type == typeof(Quaternion)) { var ords = ReadVector(4); return(new Quaternion(ords[0], ords[1], ords[2], ords[3])); } if (type == typeof(Matrix4x4)) { var ords = ReadVector(4 * 4); return(new Matrix4x4( ords[0], ords[1], ords[2], ords[3], ords[4], ords[5], ords[6], ords[7], ords[8], ords[9], ords[10], ords[11], ords[12], ords[13], ords[14], ords[15])); } if (type == typeof(byte)) { return(Reader.ReadByte()); } if (type == typeof(UInt64)) { return(Reader.ReadUInt64()); } throw new ArgumentException(type == null ? "No type provided to GetValue()" : "Cannot read value of type " + type.Name); }
public void Encode(Datamodel dm, int encoding_version, Stream stream) { using (var writer = new DmxBinaryWriter(stream)) new Encoder(this, writer, dm, encoding_version).Encode(); }
public void Encode(Datamodel dm, int encoding_version, Stream stream) { using (var writer = new DmxBinaryWriter(stream)) new Encoder(this, writer, dm, encoding_version).Encode(); }
void SkipAttribte() { var type = IdToType(Reader.ReadByte()); int count = 1; bool array = false; if (Datamodel.IsDatamodelArrayType(type)) { array = true; count = Reader.ReadInt32(); type = Datamodel.GetArrayInnerType(type); } if (type == typeof(Element)) { foreach (int i in Enumerable.Range(0, count)) { if (Reader.ReadInt32() == -2) { Reader.BaseStream.Seek(37, SeekOrigin.Current); // skip GUID + null terminator if a stub } } return; } int length; if (type == typeof(TimeSpan)) { length = sizeof(int); } else if (type == typeof(System.Drawing.Color)) { length = 4; } else if (type == typeof(bool)) { length = 1; } else if (type == typeof(byte[])) { foreach (var i in Enumerable.Range(0, count)) { Reader.BaseStream.Seek(Reader.ReadInt32(), SeekOrigin.Current); } return; } else if (type == typeof(string)) { if (!StringDict.Dummy && !array && EncodingVersion >= 4) { length = StringDict.IndiceSize; } else { foreach (var i in Enumerable.Range(0, count)) { byte b; do { b = Reader.ReadByte(); } while (b != 0); } return; } } else if (type == typeof(Vector2)) { length = sizeof(float) * 2; } else if (type == typeof(Vector3)) { length = sizeof(float) * 3; } else if (type == typeof(Vector4) || type == typeof(Quaternion)) { length = sizeof(float) * 4; } else if (type == typeof(Matrix4x4)) { length = sizeof(float) * 4 * 4; } else { length = System.Runtime.InteropServices.Marshal.SizeOf(type); } Reader.BaseStream.Seek(length * count, SeekOrigin.Current); }
object DecodeAttribute(Datamodel dm) { var type = IdToType(Reader.ReadByte()); if (!Datamodel.IsDatamodelArrayType(type)) return ReadValue(dm, type, EncodingVersion < 4); else { var count = Reader.ReadInt32(); var inner_type = Datamodel.GetArrayInnerType(type); var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) array.Add(ReadValue(dm, inner_type, true)); return array; } }
void WriteAttribute(string name, Type type, object value, bool in_array) { bool is_element = type == typeof(Element); Type inner_type = null; if (!in_array) { inner_type = Datamodel.GetArrayInnerType(type); if (inner_type == typeof(byte) && !ValidAttributes[EncodingVersion].Contains(typeof(byte))) { inner_type = null; // fall back on the "binary" type in older KV2 versions } } if (!ValidAttributes[EncodingVersion].Contains(inner_type ?? type)) { throw new CodecException(type.Name + " is not valid in KeyValues2 " + EncodingVersion); } if (inner_type != null) { is_element = inner_type == typeof(Element); Writer.WriteTokenLine(name, TypeNames[inner_type] + "_array"); if (((System.Collections.IList)value).Count == 0) { Writer.Write(" [ ]"); return; } if (is_element) { Writer.WriteLine("["); } else { Writer.Write(" ["); } Writer.Indent++; foreach (var array_value in (System.Collections.IList)value) { WriteAttribute(null, inner_type, array_value, true); } Writer.Indent--; Writer.TrimEnd(1); // remove trailing comma if (inner_type == typeof(Element)) { Writer.WriteLine("]"); } else { Writer.Write(" ]"); } return; } if (is_element) { var elem = value as Element; var id = elem == null ? "" : elem.ID.ToString(); if (in_array) { if (elem != null && Users[elem] == 1) { Writer.WriteLine(); WriteElement(elem); } else { Writer.WriteTokenLine("element", id); } Writer.Write(","); } else { if (elem != null && Users.ContainsKey(elem) && Users[elem] == 1) { Writer.WriteLine(String.Format("\"{0}\" ", name)); WriteElement(elem); } else { Writer.WriteTokenLine(name, "element", id); } } } else { if (type == typeof(bool)) { value = (bool)value ? 1 : 0; } else if (type == typeof(float)) { value = (float)value; } else if (type == typeof(byte[])) { value = BitConverter.ToString((byte[])value).Replace("-", String.Empty); } else if (type == typeof(TimeSpan)) { value = ((TimeSpan)value).TotalSeconds; } else if (type == typeof(System.Drawing.Color)) { var c = (System.Drawing.Color)value; value = String.Join(" ", new int[] { c.R, c.G, c.B, c.A }); } else if (type == typeof(UInt64)) { value = ((UInt64)value).ToString("X"); } else if (type == typeof(Vector2)) { var arr = new float[2]; ((Vector2)value).CopyTo(arr); value = string.Join(" ", arr); } else if (type == typeof(Vector3)) { var arr = new float[3]; ((Vector3)value).CopyTo(arr); value = string.Join(" ", arr); } else if (type == typeof(Vector4)) { var arr = new float[4]; ((Vector4)value).CopyTo(arr); value = string.Join(" ", arr); } else if (type == typeof(Quaternion)) { var arr = new float[4]; var q = (Quaternion)value; value = string.Join(" ", q.X, q.Y, q.Z, q.W); } else if (type == typeof(Matrix4x4)) { var arr = new float[4 * 4]; var m = (Matrix4x4)value; value = string.Join(" ", m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44); } if (in_array) { Writer.Write(String.Format(" \"{0}\",", value.ToString())); } else { Writer.WriteTokenLine(name, TypeNames[type], value.ToString()); } } }
public Datamodel Decode(int encoding_version, string format, int format_version, Stream stream, DeferredMode defer_mode) { DM = new Datamodel(format, format_version); stream.Seek(0, SeekOrigin.Begin); Reader = new StreamReader(stream, Datamodel.TextEncoding); Reader.ReadLine(); // skip DMX header Line = 1; string next; while (true) { try { next = Decode_NextToken(); } catch (EndOfStreamException) { break; } try { Decode_ParseElement(next); } catch (Exception err) { throw new CodecException(String.Format("KeyValues2 decode failed on line {0}:\n\n{1}", Line, err.Message), err); } } return DM; }
public object DeferredDecodeAttribute(Datamodel dm, long offset) { Reader.BaseStream.Seek(offset, SeekOrigin.Begin); return(DecodeAttribute(dm, false)); }