Esempio n. 1
0
        public int GenerateDataView(IDataSource conn, string tablename, string SchemaName, string Filterparamters)
        {
            //int maxcnt;

            DMEEditor.ErrorObject.Flag = Errors.Ok;
            List <ChildRelation> ds = conn.GetChildTablesList(tablename, SchemaName, Filterparamters);
            //if (DataView.Entities.Count == 0)
            //{


            //    EntityStructure viewheader = new EntityStructure() { Id = NextHearId(), EntityName = DataView.ViewName };
            //    viewheader.DataSourceID = conn.DatasourceName;
            //    viewheader.EntityName = DataView.ViewName.ToUpper();
            //    viewheader.ParentId = 0;
            //    viewheader.ViewID = DataView.ViewID;

            //    DataView.Entities.Add(viewheader);
            //}


            //  maxcnt = DataView.Entities.Max(m => m.Id);
            EntityStructure maintab = new EntityStructure()
            {
                Id = NextHearId(), EntityName = tablename
            };

            maintab.DataSourceID         = conn.DatasourceName;
            maintab.EntityName           = tablename.ToUpper();
            maintab.ViewID               = DataView.ViewID;
            maintab.DatasourceEntityName = tablename;
            maintab.ParentId             = 0;

            DataView.Entities.Add(maintab);
            EntitiesNames.Add(maintab.EntityName);
            if (ds != null && ds.Count > 0)
            {
                // var tb = ds.Tables[0];
                //-------------------------------
                // Create Parent Record First
                //-------------------------------
                if (ds.Count > 0)
                {
                    foreach (ChildRelation r in ds)
                    {
                        EntityStructure a;
                        a = SetupEntityInView(DataView, DataView.Entities, r.child_table, tablename, r.child_column, r.parent_column, maintab.Id, conn.DatasourceName);
                    }
                }
            }

            return(maintab.Id);
        }
Esempio n. 2
0
        public int AddEntitytoDataView(EntityStructure maintab)
        {
            DMEEditor.ErrorObject.Flag = Errors.Ok;
            string tablename = maintab.DatasourceEntityName;

            try
            {
                maintab.Id     = NextHearId();
                maintab.ViewID = 0;
                if (maintab.ParentId == -1)
                {
                    maintab.ParentId = 0;
                }

                //--- check entity already exist , if it does change Entity Name
                if (CheckEntityExist(maintab.DatasourceEntityName))
                {
                    int cnt = EntitiesNames.Where(p => p.Equals(maintab.DatasourceEntityName, StringComparison.OrdinalIgnoreCase)).Count() + 1;
                    maintab.EntityName = maintab.DatasourceEntityName + "_" + cnt;
                }

                DataView.Entities.Add(maintab);
                EntitiesNames.Add(maintab.EntityName);
                IDataSource entityds = DMEEditor.GetDataSource(maintab.DataSourceID);
                if (entityds != null && entityds.Category == DatasourceCategory.RDBMS)
                {
                    List <ChildRelation> ds = entityds.GetChildTablesList(maintab.DatasourceEntityName, entityds.Dataconnection.ConnectionProp.SchemaName, null);
                    if (ds != null && ds.Count > 0)
                    {
                        // var tb = ds.Tables[0];
                        //-------------------------------
                        // Create Parent Record First
                        //-------------------------------
                        if (ds.Count > 0)
                        {
                            foreach (ChildRelation r in ds)
                            {
                                EntityStructure a;
                                a = SetupEntityInView(DataView, DataView.Entities, r.child_table, maintab.DatasourceEntityName, r.child_column, r.parent_column, maintab.Id, entityds.DatasourceName);
                            }
                        }
                    }
                }

                return(maintab.Id);
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Esempio n. 3
0
        private void SmartDetect(string filename)
        {
            var detector = new FileHelpers.Detection.SmartFormatDetector();
            var formats  = detector.DetectFileFormat(filename);

            foreach (var format in formats)
            {
                Console.WriteLine("Format Detected, confidence:" + format.Confidence + "%");
                var delimited = format.ClassBuilderAsDelimited;

                Console.WriteLine("    Delimiter:" + delimited.Delimiter);
                Console.WriteLine("    Fields:");
                EntityStructure entityData = new EntityStructure();

                string sheetname;
                sheetname                       = FileName;
                entityData.Viewtype             = ViewType.File;
                entityData.DatabaseType         = DataSourceType.Text;
                entityData.DataSourceID         = FileName;
                entityData.DatasourceEntityName = FileName;
                entityData.Caption              = FileName;
                entityData.EntityName           = FileName;
                List <EntityField> Fields = new List <EntityField>();
                int y = 0;
                foreach (var field in delimited.Fields)
                {
                    Console.WriteLine("        " + field.FieldName + ": " + field.FieldType);


                    EntityField f = new EntityField();


                    //  f.tablename = sheetname;
                    f.fieldname = field.FieldName;
                    f.fieldtype = field.FieldType.ToString();
                    f.ValueRetrievedFromParent = false;
                    f.EntityName = sheetname;
                    f.FieldIndex = y;
                    Fields.Add(f);
                    y += 1;
                }

                entityData.Fields = new List <EntityField>();
                entityData.Fields.AddRange(Fields);
                Entities.Clear();
                EntitiesNames.Clear();
                EntitiesNames.Add(filename);
                Entities.Add(entityData);
            }
        }
Esempio n. 4
0
        public int AddEntityAsChild(IDataSource conn, string tablename, string SchemaName, string Filterparamters, int viewindex, int ParentTableIndex)
        {
            DMEEditor.ErrorObject.Flag = Errors.Ok;

            List <ChildRelation> ds = conn.GetChildTablesList(tablename, SchemaName, Filterparamters);


            EntityStructure maintab = new EntityStructure()
            {
                Id = NextHearId(), EntityName = tablename
            };

            maintab.DataSourceID         = conn.DatasourceName;
            maintab.EntityName           = tablename;
            maintab.ViewID               = DataView.ViewID;
            maintab.ParentId             = ParentTableIndex;
            maintab.DatasourceEntityName = tablename;
            if (CheckEntityExist(maintab.DatasourceEntityName))
            {
                int cnt = EntitiesNames.Where(p => p.Equals(maintab.DatasourceEntityName, StringComparison.OrdinalIgnoreCase)).Count();
                maintab.EntityName = maintab.DatasourceEntityName + "_" + cnt + 1;
            }
            DataView.Entities.Add(maintab);
            EntitiesNames.Add(maintab.EntityName);

            if (ds != null && ds.Count > 0)
            {
                //var tb = ds.Tables[0];
                //-------------------------------
                // Create Parent Record First
                //-------------------------------
                if (ds.Count > 0)
                {
                    foreach (ChildRelation r in ds)
                    {
                        EntityStructure a;
                        a = SetupEntityInView(DataView, DataView.Entities, r.child_table, maintab.DatasourceEntityName, r.child_column, r.parent_column, maintab.Id, conn.DatasourceName);
                    }
                }
            }

            return(maintab.Id);
        }
Esempio n. 5
0
 public List <string> GetEntitesList()
 {
     EntitiesNames.Clear();
     EntitiesNames.Add(DatasourceName);
     return(EntitiesNames);
 }
        public List <string> GetEntitesList()
        {
            try
            {
                //---------------Get Categories---------------- -

                if (Entities.Count == 0)

                {
                    DatasourceEntities f = DMEEditor.ConfigEditor.LoadDataSourceEntitiesValues(DatasourceName);
                    if (f != null)
                    {
                        Entities = f.Entities;
                    }
                }
                if (Entities == null || Entities.Count() == 0)
                {
                    string retval     = GetCategoriesDataAsync("GetCategories", @"/category/?api_key=@apikey&category_id=371").Result;
                    var    data       = JObject.Parse(retval);
                    var    categorytk = data.SelectToken("category");


                    // Category categorys = JsonConvert.DeserializeObject<Category>(categorytk.ToString());

                    int i = 1;
                    //foreach (var item in categorys.childcategories)
                    //{
                    //    EntityStructure x = new EntityStructure();
                    //    x.ParentId = 0;
                    //    x.Id = i;
                    //    i += 1;
                    //    x.EntityName = item.name;
                    //    x.Viewtype = ViewType.Url;
                    //    x.Category = "WEBAPI";
                    //    x.DataSourceID = DatasourceName;
                    //    x.CustomBuildQuery = $"/category/?api_key=7535ABF7E83252CB08E4300380DFA02D&category_id={item.category_id}";
                    //    Entities.Add(x);
                    //    //   retval = GetCategoriesDataAsync("GetCategories", x.CustomBuildQuery).Result;
                    //    var ou = GetCategoriesDataAsync("GetCategories", x.CustomBuildQuery);
                    //    ou.Wait();
                    //    data = JObject.Parse(ou.Result);
                    //    categorytk = data.SelectToken("category");
                    //Category ct = JsonConvert.DeserializeObject<Category>(categorytk.ToString());
                    //foreach (Childcategory cc in ct.childcategories)
                    //{
                    //    createentities(cc, x);
                    //}


                    //}
                }
                EntitiesNames.Clear();
                foreach (EntityStructure item in Entities)
                {
                    item.CustomBuildQuery = item.CustomBuildQuery.Replace("api_key=7535ABF7E83252CB08E4300380DFA02D", "api_key=@apikey");
                    EntitiesNames.Add(item.EntityName);
                }
                DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                    datasourcename = DatasourceName, Entities = Entities
                });
                return(EntitiesNames);
            }
            catch (Exception ex)
            {
                DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                    datasourcename = DatasourceName, Entities = Entities
                });
                return(null);
            }
        }
Esempio n. 7
0
        public int AddEntitytoDataView(IDataSource conn, string tablename, string SchemaName, string Filterparamters)
        {
            DMEEditor.ErrorObject.Flag = Errors.Ok;

            EntityStructure maintab;

            try
            {
                List <ChildRelation> ds = conn.GetChildTablesList(tablename, SchemaName, Filterparamters);
                maintab = new EntityStructure()
                {
                    Id = NextHearId(), EntityName = tablename
                };
                maintab.DataSourceID         = conn.DatasourceName;
                maintab.EntityName           = tablename.ToUpper();
                maintab.ViewID               = 0;
                maintab.ParentId             = 0;
                maintab.DatabaseType         = conn.DatasourceType;
                maintab.DatasourceEntityName = tablename;
                if (CheckEntityExist(maintab.DatasourceEntityName))
                {
                    int cnt = EntitiesNames.Where(p => p.Equals(maintab.DatasourceEntityName, StringComparison.OrdinalIgnoreCase)).Count();
                    maintab.EntityName = maintab.DatasourceEntityName + "_" + cnt + 1;
                }
                switch (maintab.DatabaseType)
                {
                case DataSourceType.Oracle:

                case DataSourceType.SqlServer:

                case DataSourceType.Mysql:

                case DataSourceType.SqlCompact:
                case DataSourceType.Postgre:

                case DataSourceType.Firebase:

                case DataSourceType.FireBird:

                case DataSourceType.Couchbase:

                case DataSourceType.RavenDB:

                case DataSourceType.MongoDB:

                case DataSourceType.CouchDB:

                case DataSourceType.VistaDB:

                case DataSourceType.DB2:

                case DataSourceType.SqlLite:
                    maintab.Viewtype = ViewType.Table;
                    break;

                case DataSourceType.Text:

                case DataSourceType.CSV:

                case DataSourceType.Xls:
                case DataSourceType.Json:

                case DataSourceType.xml:
                    maintab.Viewtype = ViewType.File;
                    break;

                case DataSourceType.WebService:

                case DataSourceType.OPC:
                    maintab.Viewtype = ViewType.Url;
                    break;

                default:
                    break;
                }

                DataView.Entities.Add(maintab);
                EntitiesNames.Add(maintab.EntityName);
                if (ds != null && ds.Count > 0)
                {
                    // var tb = ds.Tables[0];
                    //-------------------------------
                    // Create Parent Record First
                    //-------------------------------
                    if (ds.Count > 0)
                    {
                        foreach (ChildRelation r in ds)
                        {
                            EntityStructure a;
                            a = SetupEntityInView(DataView, DataView.Entities, r.child_table, tablename, r.child_column, r.parent_column, maintab.Id, conn.DatasourceName);
                        }
                    }
                }

                return(maintab.Id);
            }
            catch (Exception)
            {
                return(-1);
            }
        }