コード例 #1
0
        /// <summary>
        /// Load Data
        /// </summary>
        /// <param name="parameters">
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public object Load(object parameters)
        {
            Logger.Trace("Started Import()");

            string path = this.ReturnFilePath(parameters as string);

            Logger.Debug($"Path: {path}");
            FileSourceOptions result = null;

            if (File.Exists(path))
            {
                Logger.Trace("Path Exists");
                result = ObjectXMLSerializer <FileSourceOptions> .Load(path);
            }
            else
            {
                result = new FileSourceOptions();

                Logger.Trace("Path Doesn't Exist");
            }

            Logger.Trace("Completed Import()");

            return(result);
        }
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EdmxUserControl" /> class.
 /// </summary>
 public EdmxUserControl()
 {
     Logger.Trace("Started EdmxUserControl()");
     this.InitializeComponent();
     this.options = new FileSourceOptions();
     Logger.Trace("Completed EdmxUserControl()");
 }
コード例 #3
0
        /// <summary>
        /// Tests Data Source
        /// </summary>
        /// <param name="parameters">
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Test(object parameters)
        {
            Logger.Trace("Started Test()");

            FileSourceOptions options = parameters as FileSourceOptions;
            bool result = File.Exists(options.Path);

            Logger.Trace("Completed Test()");

            return(result);
        }
コード例 #4
0
        /// <inheritdoc />
        /// <summary>
        ///     The load data.
        /// </summary>
        /// <exception cref="T:System.NotImplementedException">
        /// </exception>
        public void LoadData(object parameters)
        {
            Logger.Trace("Started LoadData()");

            this.options = this.SourceType.Load(parameters) as FileSourceOptions;

            if (this.options != null)
            {
                this.TxtFilePath.Text = this.options.Path;
            }
            else
            {
                this.TxtFilePath.Text = string.Empty;
            }

            Logger.Trace("Completed LoadData()");
        }
コード例 #5
0
        /// <summary>
        /// Saves
        /// </summary>
        /// <param name="parameters">
        /// </param>
        public void Save(object parameters)
        {
            Logger.Trace("Started Save()");

            List <object> saveParameters = parameters as List <object>;
            string        path           = this.ReturnFilePath(saveParameters[0] as string);

            Logger.Debug($"Path: {path}");

            FileSourceOptions options = saveParameters[1] as FileSourceOptions;

            if (options == null)
            {
                options = new FileSourceOptions();
            }

            ObjectXMLSerializer <FileSourceOptions> .Save(options, path, SerializedFormat.Document);

            Logger.Trace("Completed Save()");
        }
コード例 #6
0
 public FileSourceList(IOptions <FileSourceOptions> options, SourceFactory sourceFactory)
 {
     _options       = options.Value;
     _sourceFactory = sourceFactory;
 }
コード例 #7
0
        /// <summary>
        /// Import data structure.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="DatabaseModel"/>.
        /// </returns>
        public DatabaseModel Import(object options)
        {
            Logger.Trace("Started Import()");

            DatabaseModel     result     = new DatabaseModel();
            FileSourceOptions fileOption = options as FileSourceOptions;
            var edmx             = TiraggoEdmx_v3.Edmx.Load(fileOption.Path);
            var entityTableNames = new HashSet <string>(
                edmx.Runtime.ConceptualModels.Schema.EntityTypes.Select(tbl => tbl.Name.ToUpper()));

            result.Tables = edmx.Runtime.ConceptualModels.Schema.EntityTypes.Select(
                tbl => new Table
            {
                TableName = tbl.Name,
                Columns   =
                    tbl.Properties.Select(
                        col => new Column
                {
                    ColumnName     = col.Name,
                    CSharpDataType =
                        this.MapDatabaseTypeToCSharp(col.Type),
                    IsRequired  = col.Nullable,
                    ColumnOrder =
                        tbl.Properties.ToList().IndexOf(col) + 1,
                    Precision =
                        (col.Precision > 0 && col.Scale > 0)
                                                              ? col.Precision
                                                              : 0,
                    Scale =
                        (col.Precision > 0 && col.Scale > 0)
                                                              ? col.Scale
                                                              : 0,
                    Length =
                        string.IsNullOrEmpty(col.MaxLength)
                                                              ? 0
                                                              : Convert.ToInt32(col.MaxLength),
                    IsPrimaryKey = tbl.Key.Any(pk => pk.Name == col.Name)
                }).ToList(),
                RelationShips = edmx.Runtime.StorageModels.Schema.Associations
                                .Where(
                    ass =>
                    (ass.ReferentialConstraint.Dependent.Role == tbl.Name ||
                     ass.ReferentialConstraint.Principal.Role == tbl.Name) &&
                    (entityTableNames.Contains(
                         ass.ReferentialConstraint.Dependent.Role.ToUpper()) &&
                     entityTableNames.Contains(
                         ass.ReferentialConstraint.Principal.Role.ToUpper()))).Select(
                    rel => new Relationship
                {
                    TableName =
                        (rel.ReferentialConstraint.Dependent.Role
                         == tbl.Name)
                                                              ? rel.ReferentialConstraint.Principal
                        .Role
                                                              : rel.ReferentialConstraint.Dependent
                        .Role,
                    ColumnName =
                        (rel.ReferentialConstraint.Dependent.Role
                         == tbl.Name)
                                                              ? rel.ReferentialConstraint.Dependent
                        .PropertyRef.Name
                                                              : rel.ReferentialConstraint.Principal
                        .PropertyRef.Name,
                    ForeignColumnName =
                        (rel.ReferentialConstraint.Principal.Role
                         == tbl.Name)
                                                              ? rel.ReferentialConstraint.Dependent
                        .PropertyRef.Name
                                                              : rel.ReferentialConstraint.Principal
                        .PropertyRef.Name,
                    DependencyRelationShip =
                        (rel.ReferentialConstraint.Dependent.Role
                         == tbl.Name)
                                                              ? RelationshipType.ForeignKey
                                                              : RelationshipType.ForeignKeyChild
                }).ToList()
            }).ToList();

            Logger.Trace("Completed Import()");
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Import data structure.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="DatabaseModel"/>.
        /// </returns>
        public DatabaseModel Import(object options)
        {
            Logger.Trace("Started Import()");

            DatabaseModel     result     = new DatabaseModel();
            FileSourceOptions fileOption = options as FileSourceOptions;

            var edmx             = Edmx.Load(fileOption.Path);
            var entityTableNames = new HashSet <string>(
                edmx.Runtime.ConceptualModels.Schema.EntityTypes.Select(tbl => tbl.Name.ToUpper()));

            foreach (var table in edmx.Runtime.ConceptualModels.Schema.EntityTypes)
            {
                var tbl = new Table
                {
                    TableName  = table.Name,
                    SchemaName = new TiraggoEntityInfo(
                        edmx,
                        $"{edmx.Runtime.ConceptualModels.Schema.Namespace}.{table.Name}")
                                 .StorageInfo.Schema
                };

                result.Tables.Add(tbl);

                foreach (var col in table.Properties)
                {
                    var column = new Column
                    {
                        ColumnName     = col.Name,
                        DomainDataType = this.MapDatabaseType(col.Type, null),
                        IsPrimaryKey   = table.Key.Any(pk => pk.Name == col.Name),
                        IsRequired     =
                            (col.NullableSpecified && !col.Nullable) ||
                            table.Key.Any(pk => pk.Name == col.Name),
                        ColumnOrder = table.Properties.ToList().IndexOf(col) + 1,
                        Precision   = (col.Precision > 0 && col.Scale > 0) ? col.Precision : 0,
                        Scale       = (col.Precision > 0 && col.Scale > 0) ? col.Scale : 0,
                        Length      = string.IsNullOrEmpty(col.MaxLength)
                                                      ? 0
                                                      : Convert.ToInt32(col.MaxLength)
                    };

                    if (column.IsPrimaryKey)
                    {
                        tbl.DatabaseGeneratedKeyType = this.MapDatabaseGeneratedKey(col.StoreGeneratedPattern);
                    }

                    tbl.Columns.Add(column);
                }

                // var relationships = edmx.Runtime.StorageModels.Schemas.Associations.Where(ass => (ass.ReferentialConstraint.Dependent.Role == table.Name || ass.ReferentialConstraint.Principal.Role == table.Name) &&
                // (entityTableNames.Contains(ass.ReferentialConstraint.Dependent.Role.ToUpper()) &&
                // entityTableNames.Contains(ass.ReferentialConstraint.Principal.Role.ToUpper())));

                // Todo: Work in progress
                var relationships = edmx.Runtime.StorageModels.Schema.Associations.Where(
                    ass => (ass.ReferentialConstraint.Dependent.Role == table.Name ||
                            ass.ReferentialConstraint.Principal.Role == table.Name) &&
                    entityTableNames.Contains(ass.ReferentialConstraint.Principal.Role.ToUpper()));

                foreach (var rel in relationships)
                {
                    var ass = new Relationship
                    {
                        ReferencedTableName =
                            (rel.ReferentialConstraint.Dependent.Role == table.Name)
                                              ? rel.ReferentialConstraint.Principal.Role
                                              : rel.ReferentialConstraint.Dependent.Role,
                        ColumnName =
                            (rel.ReferentialConstraint.Dependent.Role == table.Name)
                                              ? rel.ReferentialConstraint.Dependent.PropertyRef.Name
                                              : rel.ReferentialConstraint.Principal.PropertyRef.Name,
                        ReferencedColumnName =
                            (rel.ReferentialConstraint.Principal.Role == table.Name)
                                              ? rel.ReferentialConstraint.Dependent.PropertyRef.Name
                                              : rel.ReferentialConstraint.Principal.PropertyRef.Name,
                        DependencyRelationShip =
                            (rel.ReferentialConstraint.Dependent.Role == table.Name)
                                              ? RelationshipType.ForeignKey
                                              : RelationshipType.ForeignKeyChild,
                        RelationshipName = rel.Name,

                        SchemaName = new TiraggoEntityInfo(
                            edmx,
                            $"{edmx.Runtime.ConceptualModels.Schema.Namespace}.{table.Name}")
                                     .StorageInfo.Schema
                    };

                    if (rel.Ends.Count() != 2)
                    {
                        throw new Exception("Error in association multiplicity");
                    }

                    var tblMp    = rel.Ends.First(o => o.Role == table.Name);
                    var refTblMp = rel.Ends.First(o => o.Role == ass.ReferencedTableName);

                    ass.Multiplicity           = this.MapMultiplicity(tblMp.Multiplicity);
                    ass.ReferencedMultiplicity = this.MapMultiplicity(refTblMp.Multiplicity);


                    // check For Recursive Reference:
                    var  checker   = rel.Ends.First().Type;
                    bool isSelfRef = true;

                    foreach (var item in rel.Ends)
                    {
                        if (checker != item.Type)
                        {
                            isSelfRef = false;
                        }
                    }

                    Relationship assClone = null;
                    if (isSelfRef)
                    {
                        ass.RelatedTable        = tbl;
                        ass.ReferencedTableName = table.Name;
                        ass.Table             = tbl;
                        ass.RelationshipAlias = table.Name + "_1";

                        assClone = ass.Clone() as Relationship;
                        assClone.RelationshipAlias      = table.Name + "_2";
                        assClone.ColumnName             = ass.ReferencedColumnName;
                        assClone.ReferencedColumnName   = ass.ColumnName;
                        assClone.DependencyRelationShip = RelationshipType.ForeignKey;
                        assClone.Multiplicity           = ass.ReferencedMultiplicity;
                        assClone.ReferencedMultiplicity = ass.Multiplicity;
                    }


                    tbl.Relationships.Add(ass);
                    if (assClone != null)
                    {
                        tbl.Relationships.Add(assClone);
                    }
                }

                FormatNavigationPropertiesToBeUnique(tbl);
            }



            this.Fix(result);

            Logger.Trace("Completed Import()");
            return(result);
        }