예제 #1
0
        public static Table ExtractionToTable(Extraction ext, bool landing = false)
        {
            Table table = new Table();

            Metadata metadata = new Metadata();

            metadata.createDate   = DateTime.Now;
            metadata.modifiedDate = DateTime.Now;
            metadata.folder       = ext.metadata.folder;
            metadata.user         = ext.metadata.user;
            metadata.name         = ext.metadata.name.Split('.').FirstOrDefault() ?? "name";
            metadata.extraction   = ext._id;

            List <TableColumn> columns = new List <TableColumn>();

            foreach (Column column in ext.Columns)
            {
                if (!landing)
                {
                    columns.Add(new TableColumn(column));
                }
                else
                {
                    columns.Add(new TableColumn(column.name, column.position, column.maxLength));
                }
            }

            table.columns  = columns;
            table.metadata = metadata;

            return(table);
        }
예제 #2
0
        public static Extraction extraction(Metadata metadata, List <Column> columns)
        {
            Extraction extraction = new Extraction
            {
                metadata = metadata,
                Columns  = columns
            };

            return(extraction);
        }
예제 #3
0
        public static List <Extraction> GetAllDocuments(int user = 1)
        {
            var conString  = "mongodb://localhost:27017";
            var Client     = new MongoClient(conString);
            var DB         = Client.GetDatabase("EASYBI");
            var collection = DB.GetCollection <BsonDocument>("EXTRACTION");
            var builder    = Builders <BsonDocument> .Filter;
            var filter     = new BsonDocument("metadata.user", user);

            var list = collection.Find(filter).ToList();
            List <Extraction> extractions = new List <Extraction>();

            foreach (var doc in list)
            {
                Extraction extract = BsonSerializer.Deserialize <Extraction>(doc);
                extractions.Add(extract);
            }

            return(extractions);
        }
예제 #4
0
        public static Extraction GetExtractionCSV(string filename, String delimiter, bool lineWithHeaders, int folder)
        {
            Metadata metadata = new Metadata();

            metadata.createDate   = DateTime.UtcNow;
            metadata.modifiedDate = DateTime.UtcNow;
            metadata.name         = filename.Split('\\').LastOrDefault();
            metadata.user         = Users.GetUserID(Environment.UserName);
            metadata.folder       = folder;

            int           count   = 0;
            List <Column> columns = null;

            using (var reader = new StreamReader(filename))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (count == 0)
                    {
                        columns = GetColumns(line, delimiter, lineWithHeaders);
                    }
                    else
                    {
                        int columnCount = 0;
                        foreach (string field in GetFields(line, delimiter))
                        {
                            Column aux = null;
                            try
                            {
                                if (columnCount >= columns.Count)
                                {
                                    continue;
                                }

                                aux = columns[columnCount];
                                columns[columnCount] = GetColumn(aux, field);
                            }
                            catch (Exception exception)
                            {
                                //throw;
                            }

                            columnCount++;
                        }
                    }

                    count++;
                }

                metadata.registers = count;
            }


            Extraction extraction = new Extraction()
            {
                metadata = metadata,
                Columns  = columns
            };

            UploadExtraction(extraction);

            return(extraction);
        }
예제 #5
0
        public static bool UploadExtraction(Extraction extraction)
        {
            DAL.DBOMongo.InsertAsync(extraction, Constantes.mongoExtractionCollection, Constantes.mongoConnectionString, Constantes.mongoDataBase);

            return(true);
        }