Exemplo n.º 1
0
        public OutputCls DesignSchema(dynamic Entity,List<dynamic> Rows)
        {
            ISchemaContext ctx = new SchemaDb();
            var Fields = new List<IDField>();
            OutputCls res = new OutputCls() { Result = false, Comment = "Schema invalid." };
            foreach(dynamic item in Rows)
            {   
                var Field = new IDField();
                Field.Name = item.field_name;
                Field.IsMandatory = (bool)item.field_mandatory;
                Field.FieldType = FieldTypes.SingleField;
                switch ((string)item.field_type)
                {
                    case "string":
                        Field.NativeType = typeof(string);
                        break;
                    case "integer":
                        Field.NativeType = typeof(Int64);
                        break;
                    case "double":
                        Field.NativeType = typeof(double);
                        break;
                    case "datetime":
                        Field.NativeType = typeof(DateTime);
                        break;
                    case "boolean":
                        Field.NativeType = typeof(bool);
                        break;
                    case "character":
                        Field.NativeType = typeof(char);
                        break;
                    default:
                        Field.NativeType = typeof(string);
                        break;                  
                }
                Field.RegexValidation = item.field_regex;
                Field.Desc = item.field_description;
                Fields.Add(Field);
            }
            string SchemaName = Entity.SchemaName;
            SchemaEntity newEntity = SchemaConverter.DesignToSchema(Fields, SchemaName);
            newEntity.GroupName = Entity.GroupName;
            newEntity.SchemaType = (SchemaTypes)Entity.SchemaType;
            newEntity.Description = Entity.Description;
            newEntity.AccessType = (AccessTypes)Entity.AccessType;
            newEntity.CreatedBy = Entity.UserName;
            newEntity.Id = ctx.GetSequence<SchemaEntity>();
            ctx.InsertData<SchemaEntity>(newEntity);
            res.Result = true;
            res.Comment = "ok";

            //khusus columnar (casandra)
            if ((SchemaTypes)Entity.SchemaType == SchemaTypes.HistoricalData)
            {
                SetDatabaseName();
                var dx = container.Get<ColumnarDb>();
                dx.SetupKeyspaceAndTable(SchemaName, newEntity.Fields);
            }
            return res;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {

            ISchemaContext ctx = new SchemaDb();
            dynamic contacts = new System.Dynamic.ExpandoObject();
            (contacts as IDictionary<string, object>).Add("Usia", 40);
            contacts.Name = "Patrick Hines";
            contacts.Phone = "206-555-0144";
            (contacts as IDictionary<string, object>).Add("House", new List<dynamic>());
            contacts.House.Add(new System.Dynamic.ExpandoObject());
            contacts.House[0].Address = "Jln. Klumeten";
            contacts.House[0].POBox = "7658";

            dynamic contacts2 = new ExpandoObject();
            (contacts2 as IDictionary<string, object>).Add("Usia", 39);
            contacts2.Name = "Ellen Adams";
            contacts2.Phone = "206-555-0155";
            contacts2.House = new List<dynamic>();
            contacts2.House.Add(new ExpandoObject());
            contacts2.House[0].Address = "Jln. Klumet";
            contacts2.House[0].POBox = "23456";
           
            Console.WriteLine(SchemaConverter.AreExpandoStructureEquals(contacts, contacts2));
            //GetData();
            //dtx.InsertData<dynamic>(contacts, "contacts");
            SchemaEntity item = SchemaConverter.ExpandoToSchema(contacts, nameof(contacts));
            item.Id = ctx.GetSequence<SchemaEntity>();
            ctx.InsertData<SchemaEntity>(item);
            /*
            var data = ctx.GetAllData<SchemaEntity>();
            foreach(var item in data)
            {
                dynamic obj = SchemaConverter.JsonToExpando(item.JsonStructure);
                if (obj is ExpandoObject)
                {
                    foreach (var property in (IDictionary<String, Object>)obj)
                    {
                        if (property.Value is ExpandoObject)
                        {
                            //do nothing

                        }
                        else if (property.Value is List<dynamic>)
                        {
                            foreach (var element in (List<dynamic>)property.Value)
                            {
                                if (element is ExpandoObject)
                                {
                                    foreach (var pr in (IDictionary<String, Object>)element)
                                    {
                                        Console.WriteLine($"{pr.Key} as {pr.Value.GetType().ToString()} = {pr.Value}");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine($"{property.Key} as {property.Value.GetType().ToString()} = {property.Value}");
                        }

                    }
                }
                
            }*/
            Console.ReadLine();
        }