Exemplo n.º 1
0
        public void LoadData(WorkEntity workEntity)
        {
            if (TableInformation == null)
                return;

            if (DataHolder.ImportType == ImportType.Append)
            {
                // Retrieve the current data set
                // Merge the new dataset with the current data set.
                // Store in the same storage element.

                int lastUniqueId = Int32.Parse(DataHolder.Data.Tables[0].Rows[DataHolder.Data.Tables[0].Rows.Count - 1]["_UniqueRowId"].ToString());

                DataView storageView = DataHolder.StorageTable.Tables[0].DefaultView;

                foreach (DataRowView drv in storageView)
                {
                    DataRow newRow = DataHolder.Data.Tables[0].NewRow();

                    for (int i=0;i<DataHolder.Data.Tables[0].Columns.Count;i++)
                    {
                        if (DataHolder.StorageTable.Tables[0].Columns.Contains(DataHolder.Data.Tables[0].Columns[i].ColumnName))
                            newRow[DataHolder.Data.Tables[0].Columns[i].ColumnName] =
                                drv[DataHolder.Data.Tables[0].Columns[i].ColumnName];

                    }

                    newRow["_UniqueRowId"] = ++lastUniqueId;
                    DataHolder.Data.Tables[0].Rows.Add(newRow);
                }

                XmlDataDocument xmlDataDocument = new XmlDataDocument(DataHolder.Data);

                TableInformation.Storage = xmlDataDocument;
                UnitOfWork.CurrentSession.SaveOrUpdate(TableInformation);

            }
            else
            {
                // Create unique key.
                DataHolder.StorageTable.Tables[0].Columns.Add("_UniqueRowId");
                int i = 0;
                foreach (DataRow dr in DataHolder.StorageTable.Tables[0].Rows)
                    dr["_UniqueRowId"] = i++;

                XmlDataDocument xmlDataDocument = new XmlDataDocument(DataHolder.StorageTable);

                TableInformation.Storage = xmlDataDocument;
                UnitOfWork.CurrentSession.SaveOrUpdate(TableInformation);
            }

            if (workEntity != null)
                workEntity.Completed = true;
        }
Exemplo n.º 2
0
        public void CreateDataSetSchemaMetaInformation(WorkEntity workEntity)
        {
            if (uowImpl == null)
                uowImpl = UnitOfWork.Start();

            if (workEntity == null)
                return;

            if (DataHolder.ImportType == ImportType.Append)
            {
                TableInfo ti = UnitOfWork.CurrentSession.Get<TableInfo>(DataHolder.ParentTable.Id);

                TableInformation = ti;
                SchemaInformation = ti.Schema;

                DataHolder.Data = new DataSet();
                DataHolder.Data.ReadXml(new XmlNodeReader(ti.Storage));

                for (int i = 0; i< DataHolder.Columns.Count; i++)
                {
                    ImportColumn ic = DataHolder.Columns[i];

                    bool found = false;
                    foreach (SchemaColumn sc in SchemaInformation.Columns.Where(sc => sc.OrigName == ic.OrigName))
                        found = true;

                    if (!found)
                    {
                        SchemaColumn sc = new SchemaColumn();
                        sc.Name = ic.Name;
                        sc.OrigName = ic.OrigName;
                        sc.Schema = SchemaInformation;
                        sc.Type = ic.StorageType;
                        sc.ValidBegin = DateTime.Now;
                        sc.ColOrder = i+1; // The _UniqueRow is already added.
                        if (!String.IsNullOrEmpty(ic.DateFormat))
                            sc.DateFormat = ic.DateFormat;

                        UnitOfWork.CurrentSession.Save(sc);
                        SchemaInformation.Columns.Add(sc);

                        DataHolder.Data.Tables[0].Columns.Add(sc.OrigName);
                    }
                    // Loop though the new added stuff.
                }
            }
            else
            {
                SchemaInfo schema = new SchemaInfo();
                schema.ValidBegin = DateTime.Now;
                //schema.SchemaParent = latestSchema;
                schema.Name = "Import Demo";

                UnitOfWork.CurrentSession.Save(schema);
                UnitOfWork.CurrentSession.Flush();

                for (int i = 0; i < DataHolder.Columns.Count;i++ )
                {
                    ImportColumn ic = DataHolder.Columns[i];

                    SchemaColumn sc = new SchemaColumn();
                    sc.Name = ic.Name;
                    sc.OrigName = ic.OrigName;
                    sc.Schema = schema;
                    sc.Type = ic.StorageType;
                    sc.ValidBegin = DateTime.Now;
                    sc.ColOrder = i;
                    if (!String.IsNullOrEmpty(ic.DateFormat))
                        sc.DateFormat = ic.DateFormat;

                    UnitOfWork.CurrentSession.Save(sc);
                    schema.Columns.Add(sc);
                }

                SchemaInformation = schema;
            }

            workEntity.Completed = true;
        }
Exemplo n.º 3
0
        public void FinalizeWorkFlow(WorkEntity workEntity)
        {
            UnitOfWork.CurrentSession.Transaction.Commit();

            if (workEntity != null)
                workEntity.Completed = true;

            uowImpl.Dispose();
        }
Exemplo n.º 4
0
        public void CreateTemporalSupportData(WorkEntity workEntity)
        {
            if (SchemaInformation == null)
                return;

            if (TableInformation == null)
                return;

            if (DataHolder.ImportType == ImportType.Append)
            {
                UnitOfWork.CurrentSession.CreateSQLQuery("DELETE FROM TemporalPoint WHERE TableId = " + TableInformation.Id).ExecuteUpdate();
                UnitOfWork.CurrentSession.CreateSQLQuery("DELETE FROM TemporalLength WHERE TableId = " + TableInformation.Id).ExecuteUpdate();
                UnitOfWork.CurrentSession.CreateSQLQuery("DELETE FROM TemporalInterval WHERE TableId = " + TableInformation.Id).ExecuteUpdate();

            }

            Dictionary<int, TemporalColumnStructure> temporalStructures = GetTemporalStructures();

            if (temporalStructures == null)
                return;

            CultureInfo provider = CultureInfo.InvariantCulture;

            foreach (TemporalColumnStructure c in temporalStructures.Values)
            {
                int i = 0;
                DataSet ds = DataHolder.StorageTable;
                if (DataHolder.ImportType == ImportType.Append)
                    ds = DataHolder.Data;
                foreach (DataRowView dr in ds.Tables[0].AsDataView())
                {
                    //if (i > 1000)
                    //    break;

                    TemporalBase tb = TemporalFactory.GetNewTemporal(c.TimeType);
                    tb.Table = TableInformation;
                    tb.RowNr = i++;
                    tb.TemporalGroup = c.GroupId;

                    DateTime begin;
                    bool parsed = false;
                    if (String.IsNullOrEmpty(c.DateFormat))
                        parsed = DateTime.TryParse(dr[c.TimeBeginCol].ToString(), null, DateTimeStyles.None, out begin);
                    else
                        parsed = DateTime.TryParseExact(dr[c.TimeBeginCol].ToString(), c.DateFormat, provider, DateTimeStyles.None, out begin);

                    if (parsed)
                    {
                        switch (c.TimeType)
                        {
                            case TimeTypes.Point:

                                ((TemporalPoint)tb).Point = begin;
                                break;
                            case TimeTypes.Interval:
                                ((TemporalInterval)tb).TimeBegin = begin;
                                ((TemporalInterval)tb).TimeEnd =
                                    String.IsNullOrEmpty(c.DateFormat) ?
                                        Convert.ToDateTime(dr[c.TimeEndCol], null) :
                                        DateTime.ParseExact(dr[c.TimeEndCol].ToString(), c.DateFormat, provider);
                                break;
                            case TimeTypes.Length:
                                ((TemporalLength)tb).Length = begin;
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                        UnitOfWork.CurrentSession.Save(tb);
                    }

                }

                if (c.GroupId == 0)
                {
                    UnitOfWork.CurrentSession.Flush();

                    if (c.TimeType == TimeTypes.Point)
                    {
                        var o = UnitOfWork.CurrentSession.CreateSQLQuery("SELECT MIN(TimePoint) as Minimum, MAX(TimePoint) as Maximum FROM TemporalPoint WHERE tableId = " +
                                                                    TableInformation.Id + " AND TemporalGroup = 0")
                                                                    .AddScalar("Minimum", NHibernateUtil.DateTime2)
                                                                    .AddScalar("Maximum", NHibernateUtil.DateTime2).UniqueResult<object[]>();

                        TableInformation.ValidBegin = (DateTime)o[0]; ;
                        TableInformation.ValidEnd = (DateTime)o[1]; ;
                        UnitOfWork.CurrentSession.Update(TableInformation);
                    }
                    else if (c.TimeType == TimeTypes.Interval)
                    {
                        var o = UnitOfWork.CurrentSession.CreateSQLQuery("SELECT MIN(TimeBegin) as Minimum, MAX(TimeEnd) as Maximum FROM TemporalPoint WHERE tableId = " +
                                                                    TableInformation.Id + " AND TemporalGroup = 0")
                                                                    .AddScalar("Minimum", NHibernateUtil.DateTime2)
                                                                    .AddScalar("Maximum", NHibernateUtil.DateTime2).UniqueResult<object[]>();

                        TableInformation.ValidBegin = (DateTime)o[0]; ;
                        TableInformation.ValidEnd = (DateTime)o[1]; ;
                        UnitOfWork.CurrentSession.Update(TableInformation);
                    }
                }
            }

            if (workEntity != null)
                workEntity.Completed = true;
        }
Exemplo n.º 5
0
        public void CreateSpatialSupportData(WorkEntity workEntity)
        {
            if (SchemaInformation == null)
                return;

            if (TableInformation == null)
                return;

            Dictionary<int, SpatialColumnStructure> spatialStructures = GetSpatialStructures();

            if (spatialStructures == null)
                return;

            if (DataHolder.ImportType == ImportType.Append)
            {

            } else
            {
                foreach (SpatialColumnStructure c in spatialStructures.Values)
                {
                    int i = 0;
                    foreach (DataRowView dr in DataHolder.StorageTable.Tables[0].AsDataView())
                    {
                        SpatialInfo si = new SpatialInfo
                        {
                            Table = TableInformation,
                            RowNr = i++,
                            SpatialGroup = c.GroupId
                        };

                        Double latitude, longtitude;
                        if (Double.TryParse(dr[c.LatitudeCol].ToString(), out latitude) && Double.TryParse(dr[c.LongtitudeCol].ToString(), out longtitude))
                        {
                            if ((latitude >= -90 && latitude <= 90) || (longtitude >= -90 && longtitude <= 90))
                            {
                                si.Location = new Point(latitude, longtitude) { SRID = 4326 }; // WGS format.
                                UnitOfWork.CurrentSession.Save(si);
                            }
                            else
                            {
                                workEntity.Errors.Add(string.Format("Could not store geographic location. Lat: {0} Long: {1}. Coordinates too small or large. Must be within -90 and 90 degrees.", dr[c.LatitudeCol], dr[c.LongtitudeCol]));
                            }
                        }
                        else
                        {
                            workEntity.Errors.Add("Could not store geographic location. Lat: " + dr[c.LatitudeCol] + " Long: " + dr[c.LongtitudeCol]);
                        }
                    }
                }
            }

            if (workEntity != null)
                workEntity.Completed = true;
        }
Exemplo n.º 6
0
        public void CreateDataSetTableMetaInformation(WorkEntity workEntity)
        {
            if (uowImpl == null)
                uowImpl = UnitOfWork.Start();

            if (SchemaInformation == null)
                return;

            if (DataHolder.ImportType != ImportType.Append)
            {
                TableInfo ti = new TableInfo();

                ti.TableDescription = DataHolder.TableDescription;
                ti.ValidBegin = DateTime.Now;
                ti.Schema = SchemaInformation;
                ti.Dataset = workEntity.WorkingDataset;

                if (DataHolder.ParentTable != null)
                    ti.Parents.Add(DataHolder.ParentTable);

                UnitOfWork.CurrentSession.Save(ti);
                TableInformation = ti;
            }

            if (workEntity != null)
                workEntity.Completed = true;
        }
Exemplo n.º 7
0
        public List<WorkEntity> LoadDataset()
        {
            RepositoryManager rm = new RepositoryManager(Data);

            // Initialize working structure
            WorkEntities = new List<WorkEntity>();

            // Create meta data for schema of table
            WorkEntity workEntity = new WorkEntity();
            workEntity.Name = "Creating meta information for dataset schema";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.CreateDataSetSchemaMetaInformation);
            WorkEntities.Add(workEntity);

            // Create meta data for table
            workEntity = new WorkEntity();
            workEntity.Name = "Creating meta information for dataset.";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.CreateDataSetTableMetaInformation);
            WorkEntities.Add(workEntity);

            // Load the data into the database
            workEntity = new WorkEntity();
            workEntity.Name = "Loading dataset into database";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.LoadData);
            WorkEntities.Add(workEntity);

            // Load the spatial data into the database
            workEntity = new WorkEntity();
            workEntity.Name = "Loading spatial columns into database";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.CreateSpatialSupportData);
            WorkEntities.Add(workEntity);

            // Load the temporal data into the database
            workEntity = new WorkEntity();
            workEntity.Name = "Loading temporal columns into database";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.CreateTemporalSupportData);
            WorkEntities.Add(workEntity);

            // Do any clean up and commit
            workEntity = new WorkEntity();
            workEntity.Name = "Commit changes to database.";
            workEntity.WorkingDataset = WorkingDataset;
            workEntity.Execute += new WorkEntity.DynamicFunc(rm.FinalizeWorkFlow);
            workEntity.CommitEntity = true;
            WorkEntities.Add(workEntity);

            // Write any history information
            //workEntity = new WorkEntity();
            //workEntity.Name = "Store history and provenance information";
            //workEntity.Execute += new WorkEntity.DynamicFunc(rm.CreateDataSetTableMetaInformation);

            return WorkEntities;
        }