Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 public List <string> GetEntitesList()
 {
     EntitiesNames.Clear();
     EntitiesNames.Add(DatasourceName);
     return(EntitiesNames);
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        public List <string> GetEntitesList()
        {
            try
            {
                if (!string.IsNullOrEmpty(Dataconnection.ConnectionProp.ApiKey))
                {
                    if (Entities.Count == 0)

                    {
                        DatasourceEntities f = DMEEditor.ConfigEditor.LoadDataSourceEntitiesValues(DatasourceName);
                        if (f != null)
                        {
                            Entities = f.Entities;
                        }
                    }
                    DMEEditor.AddLogMessage("Log Time", $"started International Energy Data {DateTime.Now}", DateTime.Now, 2134384, "International Energy Data", Errors.Ok);

                    if (!Entities.Where(o => o.EntityName.Equals("International Energy Data", StringComparison.OrdinalIgnoreCase)).Any())
                    {
                        CreateCategories(2134384, "International Energy Data", 0);
                    }
                    DMEEditor.AddLogMessage("Log Time", $"started Petroleum {DateTime.Now}", DateTime.Now, 2134384, "Petroleum", Errors.Ok);
                    DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                        datasourcename = DatasourceName, Entities = Entities
                    });
                    if (!Entities.Where(o => o.EntityName.Equals("Petroleum", StringComparison.OrdinalIgnoreCase)).Any())
                    {
                        CreateCategories(714755, "Petroleum", 0);
                    }
                    DMEEditor.AddLogMessage("Log Time", $"started  Crude Oil Imports {DateTime.Now}", DateTime.Now, 2134384, "Crude Oil Imports", Errors.Ok);
                    DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                        datasourcename = DatasourceName, Entities = Entities
                    });
                    if (!Entities.Where(o => o.EntityName.Equals("Crude Oil Imports", StringComparison.OrdinalIgnoreCase)).Any())
                    {
                        CreateCategories(1292190, "Crude Oil Imports", 0);
                    }
                    DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                        datasourcename = DatasourceName, Entities = Entities
                    });



                    //string retval = GetCategoriesDataAsync("GetCategories", $"/category/?api_key={Dataconnection.ConnectionProp.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 (Childcategory item in categorys.childcategories)
                    //    {
                    //        if (!Entities.Where(o => o.EntityName.Equals(item.name, StringComparison.OrdinalIgnoreCase)).Any())
                    //        {
                    //            EntityStructure x = new EntityStructure();
                    //            x.ParentId = 0;
                    //            x.Id = i;
                    //            i += 1;
                    //            x.EntityName = item.name;
                    //            x.Viewtype = ViewType.Url;

                    //            x.DataSourceID = DatasourceName;
                    //            x.Category = "Category";
                    //            x.CustomBuildQuery = $"/category/?api_key={Dataconnection.ConnectionProp.ApiKey}&category_id={item.category_id}";
                    //            Entities.Add(x);
                    //            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)
                    //            {
                    //                CreateChildCategories(cc, x);
                    //            }

                    //            DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities { datasourcename = DatasourceName, Entities = Entities });
                    //        }

                    //    }

                    //}
                    EntitiesNames.Clear();
                    EntitiesNames = Entities.Select(p => p.EntityName).ToList();


                    DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                        datasourcename = DatasourceName, Entities = Entities
                    });
                }
                //---------------Get Categories---------------- -
                if (!string.IsNullOrEmpty(Dataconnection.ConnectionProp.ApiKey))
                {
                }
                return(EntitiesNames);
            }
            catch (Exception)
            {
                DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                    datasourcename = DatasourceName, Entities = Entities
                });
                return(null);
            }
        }