public static void NullCull_ComplextType_IsSetToDefaultOfObject() { var ct = new ComplexTypes(); ct.NullCull(); Assert.NotNull(ct.PrimitiveTypes); }
internal static void SetNodeData(Node node, object data, Type type, FileStyle style) { if (data == null) { throw new Exception("you can't serialize null"); } string dataAsString = data as string; if (type == typeof(string) && (dataAsString.ContainsNewLine() || node.ChildNodes.Count > 0)) { BaseTypes.SerializeSpecialStringCase(dataAsString, node, style); } else if (BaseTypes.IsBaseType(type)) { node.Value = BaseTypes.SerializeBaseType(data, type, style); } else if (CollectionTypes.TrySetCollection(node, data, type, style)) { return; } else { ComplexTypes.SetComplexNode(node, data, type, style); } }
internal static object GetNodeData(Node node, Type type) { try { if (type == typeof(string) && node.Value == MultiLineStringNode.Terminator && node.ChildLines.Count > 0) { return(BaseTypes.ParseSpecialStringCase(node)); } if (BaseTypes.IsBaseType(type)) { return(BaseTypes.ParseBaseType(node.Value, type)); } var collection = CollectionTypes.TryGetCollection(node, type); if (collection != null) { return(collection); } if (!String.IsNullOrEmpty(node.Value)) { return(ComplexTypeShortcuts.GetFromShortcut(node.Value, type)); } return(ComplexTypes.RetrieveComplexType(node, type)); } catch (Exception e) { throw new Exception($"Error getting data of type {type} from node: {e.Message}"); } }
/// <summary> /// Merges the map. /// </summary> /// <param name="config">The configuration.</param> /// <exception cref="GoliathDataException"> /// </exception> public void MergeMap(MapConfig config) { foreach (var entity in config.EntityConfigs) { if (EntityConfigs.Contains(entity.FullName)) { continue; } EntityConfigs.Add(entity); } foreach (var complexType in config.ComplexTypes) { if (ComplexTypes.Contains(complexType.FullName)) { continue; } ComplexTypes.Add(complexType); } config.MapStatements(config.Settings.Platform); MapStatements(Settings.Platform); LoadMappedStatements(config.MappedStatements); }
/// <summary> Non-generic version of SaveAsObject. You probably want to use SaveAsObject. </summary> /// <param name="type"> what type to save this object as </param> /// <param name="savethis"> the object to save </param> public void SaveAsObjectNonGeneric(Type type, object savethis) { bool _autosave = AutoSave; AutoSave = false; // don't write to disk when we don't have to try { foreach (var f in ComplexTypes.GetValidFields(type)) { SetNonGeneric(f.FieldType, f.Name, f.GetValue(savethis)); } foreach (var p in ComplexTypes.GetValidProperties(type)) { SetNonGeneric(p.PropertyType, p.Name, p.GetValue(savethis)); } } finally { AutoSave = _autosave; } if (AutoSave) { SaveAllData(); } }
/// <summary> /// Parse a JToken object to construct a DataType. /// </summary> /// <param name="json">The JToken object to be parsed</param> /// <returns>The new DataType instance from the Json string</returns> /// <exception cref="NotImplementedException">Not implemented for "udt" type</exception> /// <exception cref="ArgumentException"></exception> protected static DataType ParseDataTypeFromJson(JToken json) { if (json.Type == JTokenType.Object) // {name: address, type: {type: struct,...},...} { JToken type; var typeJObject = (JObject)json; if (typeJObject.TryGetValue("type", out type)) { Type complexType; if ((complexType = ComplexTypes.FirstOrDefault(ct => NormalizeTypeName(ct.Name) == type.ToString())) != default(Type)) { return((ComplexType)Activator.CreateInstance(complexType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance , null, new object[] { typeJObject }, null)); // create new instance of ComplexType } if (type.ToString() == "udt") { // TODO throw new NotImplementedException(); } } throw new ArgumentException(string.Format("Could not parse data type: {0}", type)); } else // {name: age, type: bigint,...} // TODO: validate more JTokenType other than Object { return(ParseAtomicType(json)); } }
/// <summary> /// Creates and adds a new complex type to the conceptual model. /// </summary> /// <param name="name">Type name for the new complex type.</param> /// <returns>A ModelComplexType corresponding to the new complex type.</returns> public ModelComplexType AddComplexType(string name) { try { if (!EntityTypes.Any(et => et.Name == name) && !ComplexTypes.Any(ct => ct.Name == name)) { ModelComplexType ct = new ModelComplexType(ParentFile, this, name); _modelComplexTypes.Add(name, ct); ct.NameChanged += new EventHandler <NameChangeArgs>(ct_NameChanged); ct.Removed += new EventHandler(ct_Removed); return(ct); } else { throw new ArgumentException("A type with the name " + name + " already exist in the model."); } } catch (Exception ex) { try { if (!ex.Data.Contains("EDMXType")) { ex.Data.Add("EDMXType", this.GetType().Name); } if (!ex.Data.Contains("EDMXObjectName")) { ex.Data.Add("EDMXObjectName", this.ContainerName); } } catch { } throw; } }
/// <summary> /// Format the RPC server as text. /// </summary> /// <param name="remove_comments">True to remove comments from the output.</param> /// <returns>The formatted RPC server.</returns> public string FormatAsText(bool remove_comments) { INdrFormatter formatter = DefaultNdrFormatter.Create(remove_comments ? DefaultNdrFormatterFlags.RemoveComments : DefaultNdrFormatterFlags.None); StringBuilder builder = new StringBuilder(); if (!remove_comments) { builder.AppendLine($"// DllOffset: 0x{Offset:X}"); builder.AppendLine($"// DllPath {FilePath}"); } if (ComplexTypes.Any()) { if (!remove_comments) { builder.AppendLine("// Complex Types: "); } foreach (var type in ComplexTypes) { builder.AppendLine(formatter.FormatComplexType(type)); } } builder.AppendLine().AppendLine(formatter.FormatRpcServerInterface(Server)); return(builder.ToString()); }
public XsdFile(string filePath) { _rootElement = XElement.Load(filePath); TargetNamespace = _rootElement.Attribute("targetNamespace") != null?_rootElement.Attribute("targetNamespace").Value : string.Empty; SimpleTypes.AddRange(_rootElement.Elements(DEFAULT_NAMESPACE + "simpleType").ToList().Select(simple => new XsdSimpleType(TargetNamespace, simple))); ComplexTypes.AddRange(_rootElement.Elements(DEFAULT_NAMESPACE + "complexType").ToList().Select(complex => new XsdComplexType(TargetNamespace, complex))); }
public ComplexType AddComplexType(string typeName) { var value = new ComplexType { Name = typeName }; ComplexTypes.Add(value); return(value); }
private void Compile() { var listTypes = ComplexTypes.Where(type => type.ListName != null) .Select(type => new { name = type.ListQualifiedName, type = (SDataSchemaType)type }); var types = Types.Select(type => new { name = type.QualifiedName, type }) .Concat(listTypes) .ToDictionary(type => type.name, type => type.type); Compile(types); }
public static void NullCull_ComplexTypeAlreadyHasValue_IsIgnored() { var ct = new ComplexTypes { PrimitiveTypes = new PrimitiveTypes { i = 5 } }; ct.NullCull(); Assert.NotNull(ct.PrimitiveTypes); Assert.That(ct.PrimitiveTypes.i, Is.EqualTo(5)); }
private Type CreateCompexType(ModuleBuilder builder, Random rand, string id) { var name = builder.Assembly.GetName().Name + ".ComplexType" + id; TypeBuilder typeBuilder = builder.DefineType(name, TypeAttributes.Public); // define 1~20 properties on the new complex type typeBuilder.DefineProperties( rand.Next(20) + 1, rand, primitiveTypes.Union(_complexTypes).ToArray()); var result = typeBuilder.CreateType(); ComplexTypes.Add(result); return(result); }
/// <summary> Non-generic version of GetAsObject. You probably wantto use GetAsObject. </summary> /// <param name="type"> the type to get this object as </param> public object GetAsObjectNonGeneric(Type type) { object returnThis = Activator.CreateInstance(type); foreach (var f in ComplexTypes.GetValidFields(type)) { var value = GetNonGeneric(f.FieldType, f.Name, f.GetValue(returnThis)); f.SetValue(returnThis, value); } foreach (var p in ComplexTypes.GetValidProperties(type)) { var value = GetNonGeneric(p.PropertyType, p.Name, p.GetValue(returnThis)); p.SetValue(returnThis, value); } return(returnThis); }
/// <summary> /// Format the RPC server as text. /// </summary> /// <param name="remove_comments">True to remove comments from the output.</param> /// <param name="cpp_format">Formating using C++ pseduo syntax.</param> /// <returns>The formatted RPC server.</returns> public string FormatAsText(bool remove_comments, bool cpp_format) { DefaultNdrFormatterFlags flags = remove_comments ? DefaultNdrFormatterFlags.RemoveComments : DefaultNdrFormatterFlags.None; INdrFormatter formatter = cpp_format ? CppNdrFormatter.Create(flags) : DefaultNdrFormatter.Create(flags); StringBuilder builder = new StringBuilder(); if (!remove_comments) { builder.AppendLine($"// DllOffset: 0x{Offset:X}"); builder.AppendLine($"// DllPath {FilePath}"); if (!string.IsNullOrWhiteSpace(ServiceName)) { builder.AppendLine($"// ServiceName: {ServiceName}"); builder.AppendLine($"// ServiceDisplayName: {ServiceDisplayName}"); } if (EndpointCount > 0) { builder.AppendLine($"// Endpoints: {EndpointCount}"); foreach (var ep in Endpoints) { builder.AppendLine($"// {ep.BindingString}"); } } } if (ComplexTypes.Any()) { if (!remove_comments) { builder.AppendLine("// Complex Types: "); } foreach (var type in ComplexTypes) { builder.AppendLine(formatter.FormatComplexType(type)); } } builder.AppendLine().AppendLine(formatter.FormatRpcServerInterface(Server)); return(builder.ToString()); }
/// <summary> /// Removes all members from the conceptual model. /// </summary> public void Clear() { try { foreach (ModelAssociationSet mas in AssociationSets.ToList()) { mas.Remove(); } foreach (ModelComplexType mct in ComplexTypes.ToList()) { mct.Remove(); } foreach (ModelEntityType met in EntityTypes.ToList()) { met.Remove(); } foreach (ModelEntitySet mes in EntitySets.ToList()) { mes.Remove(); } foreach (ModelFunction mf in FunctionImports.ToList()) { mf.Remove(); } } catch (Exception ex) { try { if (!ex.Data.Contains("EDMXType")) { ex.Data.Add("EDMXType", this.GetType().Name); } if (!ex.Data.Contains("EDMXObjectName")) { ex.Data.Add("EDMXObjectName", this.ContainerName); } } catch { } throw; } }
/// <summary> /// Create a group of types randomly /// </summary> /// <param name="count">number of the types to be created</param> /// <param name="rand">random generator</param> public void CreateTypes(int count, Random rand) { // create a random GUID in the form of 00000000000000000000000000000000 var uniqueName = InstanceCreator.CreateInstanceOf <Guid>(rand).ToString("N"); var assemblyName = new AssemblyName(uniqueName); AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder modelBuilder = assemblyBuilder.DefineDynamicModule( assemblyName.Name, assemblyName.Name + ".dll"); for (int i = 0; i < count; i++) { var choice = rand.Next(10); if (choice < 6) { // Entity type var newType = CreateEntityType(modelBuilder, rand, i.ToString()); CreateClientEntityType(modelBuilder, rand, newType); var controller = CreateControllerType(modelBuilder, newType); _controllerTypes.Add(controller); } else if (choice < 7) { // Enum type var newType = CreateEnumType(modelBuilder, rand, i.ToString()); ComplexTypes.Add(newType); } else { // Complex Type CreateCompexType(modelBuilder, rand, i.ToString()); } } this.Assembly = assemblyBuilder; }
static void Main(string[] args) { var c = new Computer { UnitsInStock = 30 }; var b = new Book { UnitsInStock = 130 }; var gc = new GamingConsole { UnitsInStock = 10 }; var pmc = new ProductManager <Computer>(c); var pmb = new ProductManager <Book>(b); var pmg = new ProductManager <GamingConsole>(gc); pmc.AddToStock(5); pmc.AddToStock(20); pmc.Sell(45); pmc.Sell(16); pmb.AddToStock(8); pmb.Sell(80); pmg.AddToStock(10); pmg.Sell(7); //I am from Mut -> Mutluyum //DRY - Don't repeat yourself //YAGNI - You aren't gonna need it //KISS - Keep it simple & stupid var result = ComplexTypes.SaveStudents(); foreach (var item in result) { Console.WriteLine("{0,8} {1} {2}", item.Number, item.FirstName, item.LastName); } Console.ReadKey(); }
public void complex_noreturn(/*IN*/ ComplexTypes aVal) { }
public void setStruct_attr(ComplexTypes _struct_attr) { _complexTypes = _struct_attr; }
public void complex_oneway( /*IN*/ComplexTypes aVal ) { }
public void complex_noreturn( /*IN*/ComplexTypes aVal ) { }
public ComplexTypes complex_inout( /*INOUT*/ref ComplexTypes aVal ) { return aVal; }
public ComplexTypes complex_in( /*IN*/ComplexTypes aVal ) { return aVal; }
public void setStruct_attr( ComplexTypes _struct_attr ) { _complexTypes = _struct_attr; }
public void setStruct( /*IN*/ComplexTypes c ) { _complexTypes = c; }
public ComplexTypes complex_in(/*IN*/ ComplexTypes aVal) { return(aVal); }
public static void AdvancedConcepts() { ScalarTypes scalarType = Helper.FillObject <ScalarTypes>(); var scalarTypeEncode = Helper.Encode(scalarType); var scalarTypeDecode = Helper.Decode(scalarTypeEncode, ScalarTypes.Parser); Assert.IsTrue(Helper.CompareObjects(scalarType, scalarTypeDecode)); ComplexTypes complexType = Helper.FillObject <ComplexTypes>(); complexType.Maps.Add(1, "Suresh"); complexType.Numbers.Add(10); complexType.Details = Any.Pack(Helper.FillObject <Person>()); var complexTypeEncode = Helper.Encode(complexType); var complexTypeDecode = Helper.Decode(complexTypeEncode, ComplexTypes.Parser); Assert.IsTrue(Helper.CompareObjects(complexType, complexTypeDecode)); if (complexTypeDecode.Details.Is(Person.Descriptor)) { complexTypeDecode.Details.TryUnpack(out Person person); } var oneOfCase = complexTypeDecode.OneofCase; //returns the name of the field that is set NullableTypes nullableType = Helper.FillObject <NullableTypes>(); var nullableTypeEncode = Helper.Encode(nullableType); var nullableTypeDecode = Helper.Decode(nullableTypeEncode, NullableTypes.Parser); Assert.IsTrue(Helper.CompareObjects(nullableType, nullableTypeDecode)); TimeTypes timeType = Helper.FillObject <TimeTypes>(); var timeTypeEncode = Helper.Encode(timeType); var timeTypeDecode = Helper.Decode(timeTypeEncode, TimeTypes.Parser); Assert.IsTrue(Helper.CompareObjects(timeType, timeTypeDecode)); //Write a collections List <ScalarTypes> sts = new List <ScalarTypes>(); sts.Add(Helper.FillObject <ScalarTypes>()); sts.Add(Helper.FillObject <ScalarTypes>()); MemoryStream ipStream = new MemoryStream(); foreach (var st in sts) { st.WriteDelimitedTo(ipStream); } using (var file = File.Create("data.bin")) file.Write(ipStream.ToArray()); ipStream.Close(); List <ScalarTypes> stsDecoded = new List <ScalarTypes>(); using (var stream = File.OpenRead("data.bin")) { while (stream.Position < stream.Length) { var sto = ScalarTypes.Parser.ParseDelimitedFrom(stream); stsDecoded.Add(sto); } } Assert.IsTrue(Helper.CompareObjects(sts, stsDecoded)); }
public ComplexTypes complex_inout(/*INOUT*/ ref ComplexTypes aVal) { return(aVal); }
public void setStruct(/*IN*/ ComplexTypes c) { _complexTypes = c; }
public void complex_oneway(/*IN*/ ComplexTypes aVal) { }