/// <summary> /// Analyzes the specified <see cref="BaseDescriptor"/> into an object. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public object Analyze(BaseDescriptor descriptor) { var builder = new Builder(); object result = builder.BuildObject(descriptor); return(result); }
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { PropertyDescriptorCollection props = BaseDescriptor.GetProperties(attributes); props = FilterProperties(props); return(props); }
/// <summary> /// Serializes the specified object. /// </summary> /// <param name="obj">The object.</param> /// <param name="stream">The stream.</param> public void Serialize(object obj, Stream stream) { var interpertor = new Interpreter(); //Creates internal object model from an object, which XmlStreamWrite will write into a stream BaseDescriptor descriptor = interpertor.Interpret(obj, MemberFilter); StreamFactory.CreateWriter().Write(stream, descriptor); }
/// <summary> /// De serializes the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns>The object which deserialize</returns> public object Deserialize(Stream stream) { //Creates internal object model from a stream, which Interpreter will analyze into an object BaseDescriptor descriptor = StreamFactory.CreateReader().Read(stream); var interperter = new Interpreter(); var result = interperter.Analyze(descriptor); return(result); }
/// <summary> /// Interprets the specified object into <see cref="BaseDescriptor"/>. /// </summary> /// <param name="obj">The object.</param> /// <param name="p_memberFilter"></param> /// <returns></returns> /// <exception cref="System.ArgumentException">Cannot serialize null</exception> public BaseDescriptor Interpret(object obj, Predicate <string> p_memberFilter) { if (obj == null) { throw new ArgumentException("Cannot serialize null"); } var parser = new Parser(p_memberFilter); BaseDescriptor result = parser.ParseDescriptor(obj, string.Empty, obj.GetType()); return(result); }
public void UniqueId_VariesWithActionDescriptorType() { // Arrange var descriptor1 = new BaseDescriptor(); var descriptor2 = new DerivedDescriptor(); // Act var id1 = descriptor1.UniqueId; var id2 = descriptor2.UniqueId; // Assert Assert.NotEqual(id1, id2); }
public override bool Parse(QtParser parser) { if (!base.Parse(parser)) { return(false); } parser.GetUInt(Attribute.Version, "{0:X8}"); // TODO: the sequence of descriptors is taken (mostly) from ffmpeg // TODO: verify that this is the actual sequence seen in (all) 3GPP files BaseDescriptor descriptor = ReadDescriptor(parser); if (descriptor.Tag == DescriptorClassTag.ES_DescrTag) { parser.GetUShort(); // ID parser.GetByte(); // priority } else { parser.GetUShort(); // ID } descriptor = ReadDescriptor(parser); if (descriptor.Tag == DescriptorClassTag.DecoderConfigDescrTag) { parser.GetByte(Attribute.ObjectTypeIndication); // 0x20 Visual ISO/IEC 14496-2 parser.GetByte(Attribute.StreamType); parser.GetThreeBytes(Attribute.BufferSizeDB); // 3 bytes parser.GetUInt(Attribute.MaxBitrate); parser.GetUInt(Attribute.AvgBitrate); descriptor = ReadDescriptor(parser); if ((parser.Position + descriptor.Length) > parser.Length) { return(false); } if (descriptor.Tag == DescriptorClassTag.DecSpecificInfoTag) { // Extra data can be empty (0 bytes) if (descriptor.Length > 0) { ExtraData = parser.GetDataPacket(parser.Position, descriptor.Length); } Attributes.Add(new FormattedAttribute <Attribute, long>(Attribute.DecSpecificInfoSize, descriptor.Length)); } parser.Position += Math.Min(descriptor.Length, parser.Length - parser.Position); } return(this.Valid); }
/// <summary> /// Handles the specified element. /// </summary> /// <param name="element">The element.</param> /// <param name="chain">The source chain which we relay to build our object model</param> /// <returns></returns> public BaseDescriptor Handle(XElement element, DescriptorRecreationChain chain) { BaseDescriptor result = null; if (CanHandle(element)) { result = HandleInternal(element, chain); } else if (Next != null) { result = Next.Handle(element, chain); } return(result); }
/// <summary> /// Reads the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns>The requested <see cref="BaseDescriptor"/> of the object</returns> public BaseDescriptor Read(Stream stream) { XElement root = XElement.Load(stream); ValidateStreamRoot(root); DescriptorRecreationChain chainRecreation = RecreationChainBuilder.StartWith(new PrimitiveDescriptorRecreationChain()) .AddObjectRecreation() .AddNullRecreation() .AddCopyReferenceRecreation() .BuildChain(); BaseDescriptor descriptor = chainRecreation.Handle(root.Elements().First(), chainRecreation); return(descriptor); }
protected void LoadSchemaInfo(BaseDescriptor baseDescr, Entity subj, string defLabel, MemoryStore sink) { // avoid dup types var typeSt = new Statement(subj, NS.Rdf.typeEntity, (Entity)baseDescr.RdfType); if (!sink.Contains(typeSt)) { sink.Add(typeSt); } string label = baseDescr.RdfsLabel != null ? baseDescr.RdfsLabel : defLabel; // and multiple labels if (!sink.Contains(new Statement(subj, NS.Rdfs.labelEntity, null))) { sink.Add(new Statement(subj, NS.Rdfs.labelEntity, new Literal(label))); } if (baseDescr.RdfsComment != null) { sink.Add(new Statement(subj, NS.Rdfs.commentEntity, new Literal(baseDescr.RdfsComment))); } }
public void UniqueId_VariesWithActionDescriptorType() { // Arrange var descriptor1 = new BaseDescriptor(); var descriptor2 = new DerivedDescriptor(); // Act var id1 = descriptor1.UniqueId; var id2 = descriptor2.UniqueId; // Assert Assert.NotEqual(id1, id2); }
/// <summary> /// Writes the specified <param name="dataDescriptor"/> into <param name="stream"></param>. /// </summary> /// <param name="stream">The stream.</param> /// <param name="dataDescriptor">The data descriptor.</param> public void Write(Stream stream, BaseDescriptor dataDescriptor) { XElement root = new XElement("serializeInfo", dataDescriptor.AcceptVisit(this)); root.Save(stream); }
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return(FilterProperties(BaseDescriptor.GetProperties())); }
/// <summary> /// Builds the object from <see cref="BaseDescriptor"/>. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public object BuildObject(BaseDescriptor descriptor) { object instance = descriptor.AcceptVisit(this); return(instance); }
private string GetHtmlModelString(BaseDescriptor tag, string dataType) { int hidden = 0; string data = ""; string dateFormat = ""; string jsDateFormat = ""; string valueFormat = ""; switch (tag.TagType) { case HTMLEnumerate.HTMLTagTypes.Input: { var textBoxHtmlTag = tag as TextBoxDescriptor; if (textBoxHtmlTag != null) { dateFormat = textBoxHtmlTag.DateFormat; jsDateFormat = textBoxHtmlTag.JavaScriptDateFormat; valueFormat = textBoxHtmlTag.ValueFormat; } break; } case HTMLEnumerate.HTMLTagTypes.DropDownList: { var dropTag = (DropDownListDescriptor)tag; if (dropTag.SourceType == SourceType.ViewData && DropDownOptions.ContainsKey(tag.Name)) { dropTag.DataSource(DropDownOptions[tag.Name]); } data = dropTag.GetOptions(); dataType = "Select"; break; } case HTMLEnumerate.HTMLTagTypes.MutiSelect: { var muliTag = (MutiSelectDescriptor)tag; if (muliTag.SourceType == SourceType.ViewData && DropDownOptions.ContainsKey(tag.Name)) { muliTag.DataSource(DropDownOptions[tag.Name]); } data = muliTag.GetOptions(); dataType = "Select"; break; } case HTMLEnumerate.HTMLTagTypes.File: dataType = "None"; break; case HTMLEnumerate.HTMLTagTypes.PassWord: dataType = "None"; break; case HTMLEnumerate.HTMLTagTypes.Hidden: hidden = 1; break; default: break; } if (!tag.GridSetting.Searchable) { dataType = "None"; } if (!tag.GridSetting.Visiable) { hidden = 1; } string displayName = string.IsNullOrEmpty(tag.DisplayName) ? tag.Name : tag.DisplayName; StringBuilder columnBuilder = new StringBuilder(); columnBuilder.AppendFormat("{0}:{{", tag.Name); columnBuilder.AppendFormat("DisplayName:'{0}',", displayName.Replace("\"", "\\\"").Replace("\'", "\\\'")); columnBuilder.AppendFormat("Name:'{0}',", tag.Name); columnBuilder.AppendFormat("Width:{0},", tag.GridSetting.ColumnWidth); columnBuilder.AppendFormat("DataType:'{0}',", dataType); columnBuilder.AppendFormat("DateFormat:'{0}',", dateFormat); columnBuilder.AppendFormat("JsDateFormat:'{0}',", jsDateFormat); columnBuilder.AppendFormat("ValueFormat:'{0}',", valueFormat); columnBuilder.AppendFormat("Hidden:{0},", hidden); columnBuilder.AppendFormat("Data:\"{0}\"", data); columnBuilder.Append("},"); return(columnBuilder.ToString()); }
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return(BaseDescriptor.GetPropertyOwner(pd)); }
string ICustomTypeDescriptor.GetClassName() { return(BaseDescriptor.GetClassName()); }
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return(BaseDescriptor.GetEvents(attributes)); }
object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return(BaseDescriptor.GetEditor(editorBaseType)); }
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { return(BaseDescriptor.GetDefaultProperty()); }
TypeConverter ICustomTypeDescriptor.GetConverter() { return(BaseDescriptor.GetConverter()); }
string ICustomTypeDescriptor.GetComponentName() { return(BaseDescriptor.GetComponentName()); }
EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return(BaseDescriptor.GetEvents()); }
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return(BaseDescriptor.GetDefaultEvent()); }
System.ComponentModel.AttributeCollection ICustomTypeDescriptor.GetAttributes() { return(BaseDescriptor.GetAttributes()); }