Пример #1
0
        /// <summary>
        /// 添加多个表格
        /// </summary>
        /// <param name="tables"></param>
        public void AddTables(IEnumerable <ITable> tables)
        {
            Tables.AddRange(tables);
            var tableNamesItems = tables.Select(v => ((IObjectClass)v).AliasName).Select(v => new ImageListBoxItem(v, 17)).ToArray();

            imagelistBoxTables.Items.AddRange(tableNamesItems);
        }
        public override void LoadData()
        {
            base.LoadData();
            IEnumerable <Tables> tables = BistroDatabase.Instance.Get <Tables>(DBQuery.GET_TABLES);

            Tables.AddRange(tables);
        }
Пример #3
0
        private async void RetrieveTablesAsync()
        {
            IsBusy             = true;
            BusyMessage        = "Retrieving tables...";
            Tables.IsNotifying = false;
            Tables.Clear();
            _selectedTables.Clear();
            try
            {
                if (SelectedDatabase != null)
                {
                    using (var conn = new SqlConnection(ConnectionString))
                    {
                        await conn.OpenAsync();

                        IEnumerable <Table> tbls = await Task.Run(
                            () => Model.retrieveTables(conn,
                                                       new GenerationOptions(SelectedDatabase,
                                                                             FSharpOption <String> .None,
                                                                             new FSharpOption <string>("Id$"),
                                                                             true)));

                        Tables.AddRange(tbls);
                    }
                }
            }
            finally
            {
                IsBusy             = false;
                BusyMessage        = String.Empty;
                Tables.IsNotifying = true;
                Tables.Refresh();
            }
        }
Пример #4
0
 internal SqlFromClause(
     SelectQuery selectQuery,
     SqlFromClause clone,
     Dictionary <ICloneableElement, ICloneableElement> objectTree,
     Predicate <ICloneableElement> doClone)
     : base(selectQuery)
 {
     Tables.AddRange(clone.Tables.Select(ts => (SqlTableSource)ts.Clone(objectTree, doClone)));
 }
Пример #5
0
        public override void LoadData()
        {
            base.LoadData();
            TableOrderItems = BistroDatabase.Instance.Get <TableOrderItems>(DBQuery.GET_TABLE_ORDER_ITEMS).ToObservableCollection();
            IEnumerable <Tables>    tables     = BistroDatabase.Instance.Get <Tables>(DBQuery.GET_TABLES);
            IEnumerable <OrderItem> orderItems = BistroDatabase.Instance.Get <OrderItem>(DBQuery.GET_ORDER_ITEMS);

            Tables.AddRange(tables);
            OrderItems.AddRange(orderItems);
        }
Пример #6
0
        public DataContext AddTables(IEnumerable <TableSymbol> tables)
        {
            if (tables == null)
            {
                throw new ArgumentNullException(nameof(tables));
            }

            var newTables = Tables.AddRange(tables);

            return(WithTables(newTables));
        }
Пример #7
0
    public GanttData()
    {
        DataTable table = new DataTable("table");

        table.Columns.Add("GanntTask", typeof(string));
        table.Columns.Add("GanntStart", typeof(DateTime));
        table.Columns.Add("GanntEnd", typeof(DateTime));
        table.Columns.Add("GanttPercentageComplete", typeof(Int32));
        table.Columns.Add("GanttOwner", typeof(string));

        Tables.AddRange(new DataTable[] { table });
    }
        public ManualDataSet()
            : base()
        {
            DataTable table = new DataTable("table");

            DataSetName = "ManualDataSet";

            table.Columns.Add("ID", typeof(Int32));
            table.Columns.Add("RtfColumn1", typeof(string));
            table.Columns.Add("RtfColumn2", typeof(string));
            table.Constraints.Add("IDPK", table.Columns["ID"], true);

            Tables.AddRange(new DataTable[] { table });
        }
        public TabletDataSet()
            : base()
        {
            DataTable table = new DataTable("table");

            DataSetName = "ManualDataSet";

            for (int i = 0; i < m_columns; i++)
            {
                table.Columns.Add("Column" + i.ToString(), typeof(Int32));
            }

            Tables.AddRange(new DataTable[] { table });
        }
Пример #10
0
        public SimpleDataSet()
            : base()
        {
            DataTable table = new DataTable("table");

            DataSetName = "ManualDataSet";

            table.Columns.Add("ID", typeof(Int32));
            table.Columns.Add("MyDateTime", typeof(DateTime));
            table.Columns.Add("MyRow", typeof(string));
            table.Columns.Add("MyData", typeof(double));
            table.Constraints.Add("IDPK", table.Columns["ID"], true);

            Tables.AddRange(new DataTable[] { table });
        }
Пример #11
0
        public OwnersDataSet()
            : base()
        {
            DataTable owners = new DataTable("Owners");
            DataTable pets   = new DataTable("Pets");

            DataSetName = "OwnersAndPets";

            owners.Columns.Add("ownerId", typeof(Int32));
            owners.Columns.Add("yearOfBirth", typeof(Int32));
            owners.Columns.Add("firstName", typeof(string));
            owners.Columns.Add("lastName", typeof(string));

            pets.Columns.Add("ownerId", typeof(Int32));
            pets.Columns.Add("petId", typeof(Int32));
            pets.Columns.Add("name", typeof(string));
            pets.Columns.Add("isNeutured", typeof(bool));
            pets.Columns.Add("type", typeof(PetType));

            Tables.AddRange(new DataTable[] { owners, pets });
            Relations.Add("OwnersPets", owners.Columns["ownerId"], pets.Columns["ownerId"]);

            owners.Rows.Add(new object[] { 1, 1950, "John", "Smith" });
            owners.Rows.Add(new object[] { 2, 1980, "Cathy", "Williams" });
            owners.Rows.Add(new object[] { 3, 1974, "Simon", "Iverson" });
            owners.Rows.Add(new object[] { 4, 1969, "Angie", "Young" });
            owners.Rows.Add(new object[] { 5, 1988, "Charles", "Adam" });
            owners.Rows.Add(new object[] { 6, 1920, "Michelle", "Jonson" });

            pets.Rows.Add(new object[] { 1, 2, "Smyth", true, PetType.Bird });
            pets.Rows.Add(new object[] { 1, 7, "Smyth2", true, PetType.Bird });
            pets.Rows.Add(new object[] { 1, 8, "Jaidan", false, PetType.Cat });

            pets.Rows.Add(new object[] { 2, 1, "Goldie", false, PetType.Fish });
            pets.Rows.Add(new object[] { 2, 3, "Willow", true, PetType.Rodent });

            pets.Rows.Add(new object[] { 3, 4, "Surge", true, PetType.Dog });

            pets.Rows.Add(new object[] { 4, 5, "Jumbo", true, PetType.Cat });
            pets.Rows.Add(new object[] { 4, 10, "Pat", true, PetType.Cat });
            pets.Rows.Add(new object[] { 4, 11, "Mike", false, PetType.Fish });
            pets.Rows.Add(new object[] { 4, 113, "Bill", false, PetType.Fish });

            pets.Rows.Add(new object[] { 5, 12, "Pete", false, PetType.Bird });
            pets.Rows.Add(new object[] { 5, 17, "Rufus", true, PetType.Dog });
        }
Пример #12
0
        private void Initialize(string dataSource, bool canDiscover)
        {
            if (!Exists(dataSource))
            {
                throw new SQLiteDataSourceNotFoundException(dataSource);
            }

            Connection?.Close();
            Connection = new SQLiteConnection($"Data Source={dataSource};Version=3;");
            Connection.OpenAsync();

            DataSource = dataSource;
            if (canDiscover)
            {
                Tables.AddRange(Discover.DataBase(this));
            }
        }
        public SimpleDataSet()
        {
            DataTable table = new DataTable("table");

            table.Columns.Add("ID", typeof(Int32));
            table.Columns.Add("row1", typeof(string));
            table.Columns.Add("row2", typeof(string));
            table.Columns.Add("row3", typeof(string));
            table.Columns.Add("data1", typeof(double));
            table.Columns.Add("data2", typeof(double));
            table.Columns.Add("data3", typeof(double));
            table.Constraints.Add("IDPK", table.Columns["ID"], true);

            Tables.AddRange(new DataTable[] { table });

            CreateData();
        }
Пример #14
0
        public void AnalyzeDatabase()
        {
            using (var engine = new SqlCeEngine(ConnectionString))
            {
                var schema = engine.GetSchemaInformationViews();

                var tables = schema.Tables["INFORMATION_SCHEMA.TABLES"].AsEnumerable().Select(c => c.Field <string>("TABLE_NAME")).ToList();
                if (tables.Count == 0)
                {
                    return;
                }

                var tableList = GetTableInformation(tables, schema);
                Tables.AddRange(tableList.Values);

                FetchPrimaryKeys(schema);
                FetchIndexes(schema);
            }
        }
Пример #15
0
        public override sealed async Task LoadSchemaAsync()
        {
            StartWork();
            try
            {
                await(Task.Run(() =>
                {
                    DataSource.DatabaseMetadata.PreloadTables();
                    DataSource.DatabaseMetadata.PreloadViews();
                })); //Task-10, we need an async version of this.


                Tables.AddRange(DataSource.DatabaseMetadata.GetTablesAndViews().Where(t => t.IsTable).OrderBy(t => t.Name.Name).Select(t => new SQLiteTableVM(DataSource, t)));
                Views.AddRange(DataSource.DatabaseMetadata.GetTablesAndViews().Where(t => !t.IsTable).OrderBy(t => t.Name.Name).Select(t => new ViewVM(t)));
            }
            finally
            {
                StopWork();
            }
        }
Пример #16
0
 private void UpdateTables()
 {
     Tables.Clear();
     Tables.AddRange(AppServices.DataAccessService.GetCurrentTables(AppServices.MainDataContext.SelectedDepartment.TerminalTableScreenId, CurrentPageNo)
                     .Select(x => new TableScreenItemViewModel(x, AppServices.MainDataContext.SelectedTableScreen)));
     if (SelectedTableScreen != null)
     {
         AlphaButtonValues = !string.IsNullOrEmpty(SelectedTableScreen.AlphaButtonValues) ? SelectedTableScreen.AlphaButtonValues.Split(',') : new string[0];
         NumeratorHeight   = SelectedTableScreen.NumeratorHeight;
     }
     else
     {
         NumeratorHeight   = 0;
         AlphaButtonValues = new string[0];
     }
     RaisePropertyChanged("Tables");
     RaisePropertyChanged("NavigatorHeight");
     RaisePropertyChanged("SelectedTableScreen");
     RaisePropertyChanged("NumeratorHeight");
     RaisePropertyChanged("TableScreenAlignment");
 }
Пример #17
0
        async Task <bool> ExecuteLoadTablesAsync(bool force = false)
        {
            if (IsBusy)
            {
                return(false);
            }
            var realm = App.GetRealm();

            try
            {
                IsBusy        = true;
                NoTablesFound = false;


                var realmCloudTables = realm.All <RealmCloudTable>();
                if (realmCloudTables.Count() > 0 && force == false)
                {
                    Console.WriteLine("Load from local tables");

                    var storageAccounts            = realm.All <StorageAccountExt>().Where(sa => sa.IsStorageAccountOn);
                    List <ASECloudTable> aseTables = new List <ASECloudTable>();
                    if (storageAccounts.Count() > 0)
                    {
                        foreach (var realmCloudTable in realmCloudTables)
                        {
                            StorageAccountsExist = true;
                            var storageAccount = storageAccounts.Where((arg) => arg.Name == realmCloudTable.StorageAccountName).FirstOrDefault();

                            if (storageAccount != null)
                            {
                                var te = new CloudTable(new Uri(realmCloudTable.TableUri),
                                                        new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccount.Name, storageAccount.PrimaryKey));
                                aseTables.Add(new ASECloudTable(te, storageAccount.Name));
                            }
                        }
                        Tables.Clear();
                        Tables.AddRange(aseTables);
                    }
                }
                else
                {
                    var storageAccounts = realm.All <StorageAccountExt>().Where(sa => sa.IsStorageAccountOn);

                    Tables.Clear();
                    foreach (var account in storageAccounts)
                    {
                        string connectionString = Constants.StorageConnectionString;
                        connectionString = connectionString.Replace("<ACCOUNTNAME>", account.Name);
                        connectionString = connectionString.Replace("<ACCOUNTKEY>", account.PrimaryKey);
                        CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString);
                        var tableClient        = sa.CreateCloudTableClient();
                        var tables             = await tableClient.ListTablesAsync();

                        List <ASECloudTable> aseTables = new List <ASECloudTable>();
                        for (int i = 0; i < tables.Count; i++)
                        {
                            aseTables.Add(new ASECloudTable(tables[i]));
                        }

                        aseTables.All(c => { c.StorageAccountName = account.Name; return(true); });
                        Tables.AddRange(aseTables);
                    }
                    if (storageAccounts.Count() > 0)
                    {
                        StorageAccountsExist = true;
                    }
                    else
                    {
                        StorageAccountsExist = false;
                    }

                    await realm.WriteAsync(temprealm =>
                    {
                        temprealm.RemoveAll <RealmCloudTable>();
                        foreach (var table in Tables)
                        {
                            temprealm.Add(new RealmCloudTable(table.TableName, table.StorageAccountName, table.BaseTable.Uri.ToString()));
                        }
                    });

                    realm.All <RealmCloudTable>().SubscribeForNotifications((sender, changes, error) =>
                    {
                        Console.WriteLine("Change to CloudTables");
                    });
                }
                SortTables();
                if (Tables.Count == 0)
                {
                    NoTablesFound = true;
                }
                else
                {
                    NoTablesFound = false;
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteLoadTablesAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
            }
            return(true);
        }
Пример #18
0
 public void JoinOn(List <Table> tables)
 {
     Tables.AddRange(tables);
 }
Пример #19
0
        private void FromCurrentFormat(byte[] bytes, int offset = 0)
        {
            Signature = bytes.GetString(0, 2);
            Version   = bytes.ToByte(2);
            Length    = bytes.Length;

            offset += 3;
            int parts = 1;

            this.parentClass?.PassMessage(parts, $"PRG Header 1 - Offset {offset}");


            //Get all inputs
            Inputs.AddRange(GetArray(bytes,
                                     InputPoint.GetCount(FileVersion),
                                     InputPoint.GetSize(FileVersion), ref offset)
                            .Select(i => new InputPoint(i, 0, FileVersion)));

            parts += Inputs.Count;
            this.parentClass?.PassMessage(parts, $"InputPoints {Inputs.Count} - Offset {offset}");


            //Get all outputs
            Outputs.AddRange(GetArray(bytes,
                                      OutputPoint.GetCount(FileVersion),
                                      OutputPoint.GetSize(FileVersion), ref offset)
                             .Select(i => new OutputPoint(i, 0, FileVersion)));

            parts += Outputs.Count;
            this.parentClass?.PassMessage(parts, $"OutputPoints {Outputs.Count} - Offset {offset}");


            //Get all variables
            Variables.AddRange(GetArray(bytes,
                                        VariablePoint.GetCount(FileVersion),
                                        VariablePoint.GetSize(FileVersion), ref offset)
                               .Select(i => new VariablePoint(i, 0, FileVersion)));
            parts += Variables.Count;
            this.parentClass?.PassMessage(parts, $"VariablePoints {Variables.Count} - Offset {offset}");

            //Get all programs
            Programs.AddRange(GetArray(bytes,
                                       ProgramPoint.GetCount(FileVersion),
                                       ProgramPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new ProgramPoint(i, 0, FileVersion)));

            parts += Programs.Count;
            this.parentClass?.PassMessage(parts, $"ProgramPoints {Programs.Count} - Offset {offset}");

            //Get all controllers
            Controllers.AddRange(GetArray(bytes,
                                          ControllerPoint.GetCount(FileVersion),
                                          ControllerPoint.GetSize(FileVersion), ref offset)
                                 .Select(i => new ControllerPoint(i, 0, FileVersion)));

            parts += Controllers.Count;
            this.parentClass?.PassMessage(parts, $"ControllerPoints {Controllers.Count} - Offset {offset}");

            //Get all screens
            Screens.AddRange(GetArray(bytes,
                                      ScreenPoint.GetCount(FileVersion),
                                      ScreenPoint.GetSize(FileVersion), ref offset)
                             .Select(i => new ScreenPoint(i, 0, FileVersion)));

            parts += Screens.Count;
            this.parentClass?.PassMessage(parts, $"ScreenPoints {Screens.Count} - Offset {offset}");

            //Get all graphics

            //TODO: NOT MINE: Constants to object static Size(FileVersion) Count(FileVersion)

            Graphics.AddRange(GetArray(bytes,
                                       GraphicPoint.GetCount(FileVersion),
                                       GraphicPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new GraphicPoint(i, 0, FileVersion)));

            parts += Graphics.Count;
            this.parentClass?.PassMessage(parts, $"GraphicPoints {Graphics.Count} - Offset {offset}");

            Users.AddRange(GetArray(bytes,
                                    UserPoint.GetCount(FileVersion),
                                    UserPoint.GetSize(FileVersion), ref offset)
                           .Select(i => new UserPoint(i, 0, FileVersion)));

            parts += Users.Count;
            this.parentClass?.PassMessage(parts, $"UserPoints {Users.Count} - Offset {offset}");

            CustomUnits.Digital.AddRange(GetArray(bytes,
                                                  CustomDigitalUnitsPoint.GetCount(FileVersion),
                                                  CustomDigitalUnitsPoint.GetSize(FileVersion), ref offset)
                                         .Select(i => new CustomDigitalUnitsPoint(i, 0, FileVersion)));

            parts += CustomUnits.Digital.Count;
            this.parentClass?.PassMessage(parts, $"CustomUnits.DigitalPoints {CustomUnits.Digital.Count} - Offset {offset}");

            Tables.AddRange(GetArray(bytes,
                                     TablePoint.GetCount(FileVersion),
                                     TablePoint.GetSize(FileVersion), ref offset)
                            .Select(i => new TablePoint(i, 0, FileVersion)));

            parts += Tables.Count;
            this.parentClass?.PassMessage(parts, $"TablePoints {Tables.Count} - Offset {offset}");

            Settings = new Settings(
                GetObject(bytes, Settings.GetSize(FileVersion), ref offset), 0, FileVersion);

            parts += 1;
            this.parentClass?.PassMessage(parts, $"Settings 1 - Offset {offset}");

            Schedules.AddRange(GetArray(bytes,
                                        SchedulePoint.GetCount(FileVersion),
                                        SchedulePoint.GetSize(FileVersion), ref offset)
                               .Select(i => new SchedulePoint(i, 0, FileVersion)));

            parts += Schedules.Count;
            this.parentClass?.PassMessage(parts, $"SchedulePoints {Schedules.Count} - Offset {offset}");

            Holidays.AddRange(GetArray(bytes,
                                       HolidayPoint.GetCount(FileVersion),
                                       HolidayPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new HolidayPoint(i, 0, FileVersion)));

            parts += Holidays.Count;
            this.parentClass?.PassMessage(parts, $"HolidayPoints {Holidays.Count} - Offset {offset}");

            Monitors.AddRange(GetArray(bytes,
                                       MonitorPoint.GetCount(FileVersion),
                                       MonitorPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new MonitorPoint(i, 0, FileVersion)));

            parts += Monitors.Count;
            this.parentClass?.PassMessage(parts, $"MonitorPoints {Monitors.Count} - Offset {offset}");

            ScheduleCodes.AddRange(GetArray(bytes,
                                            ScheduleCode.GetCount(FileVersion),
                                            ScheduleCode.GetSize(FileVersion), ref offset)
                                   .Select(i => new ScheduleCode(i, 0, FileVersion)));

            parts += ScheduleCodes.Count;
            this.parentClass?.PassMessage(parts, $"ScheduleCodes {ScheduleCodes.Count} - Offset {offset}");

            HolidayCodes.AddRange(GetArray(bytes,
                                           HolidayCode.GetCount(FileVersion),
                                           HolidayCode.GetSize(FileVersion), ref offset)
                                  .Select(i => new HolidayCode(i, 0, FileVersion)));

            parts += HolidayCodes.Count;
            this.parentClass?.PassMessage(parts, $"HolidayCodes {HolidayCodes.Count} - Offset {offset}");


            int pcode_offset     = offset;
            var ProgramCodeBytes = bytes.ToBytes(offset, ProgramCode.GetSize(FileVersion));

            ProgramCodes.AddRange(GetArray(bytes,
                                           ProgramCode.GetCount(FileVersion),
                                           ProgramCode.GetSize(FileVersion), ref offset)
                                  //.Select(i => new ProgramCode(i, this, 0, FileVersion)));
                                  .Select(i => new ProgramCode()));

            ProgramCodes[0] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion);

            parts += 1;
            this.parentClass?.PassMessage(parts, $"ProgramCodes 1 - Offset {pcode_offset+2000}");


            for (int i = 1; i < ProgramCode.GetCount(FileVersion); i++)
            {
                pcode_offset    += ProgramCode.GetSize(FileVersion);
                ProgramCodeBytes = bytes.ToBytes(pcode_offset, ProgramCode.GetSize(FileVersion));
                ProgramCodes[i]  = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion);

                parts += 1;
                this.parentClass?.PassMessage(parts, $"ProgramCodes {i+1} - Offset {pcode_offset+2000}");

                //Debug.WriteLine($"Leído ProgramCode[{i}]");
            }



            CustomUnits.Analog.AddRange(GetArray(bytes,
                                                 CustomAnalogUnitsPoint.GetCount(FileVersion),
                                                 CustomAnalogUnitsPoint.GetSize(FileVersion), ref offset)
                                        .Select(i => new CustomAnalogUnitsPoint(i, 0, FileVersion)));

            parts += CustomUnits.Analog.Count;
            this.parentClass?.PassMessage(parts, $"CustomUnits.AnalogPoints {CustomUnits.Analog.Count} - Offset {offset}");

            CheckOffset(offset, Length);

            UpdateCustomUnits();
        }
Пример #20
0
        public override sealed async Task LoadSchemaAsync()
        {
            StartWork();
            try
            {
                await(Task.Run(() =>
                {
                    DataSource.DatabaseMetadata.PreloadTables();
                    DataSource.DatabaseMetadata.PreloadViews();
                })); //Task-10, we need an async version of this.


                Tables.AddRange(DataSource.DatabaseMetadata.GetTablesAndViews().Where(t => t.IsTable).OrderBy(t => t.Name.Schema).ThenBy(t => t.Name.Name).Select(t => new SqlServerTableVM(DataSource, (SqlServerTableOrViewMetadata <SqlDbType>)t)));
                Views.AddRange(DataSource.DatabaseMetadata.GetTablesAndViews().Where(t => !t.IsTable).OrderBy(t => t.Name.Schema).ThenBy(t => t.Name.Name).Select(t => new ViewVM(t)));

                const string tableDescriptionsSql = @"SELECT s.name AS SchemaName, t.name AS TableName, ep.value FROM sys.extended_properties ep
INNER JOIN sys.tables t ON ep.major_id = t.object_id AND ep.minor_id = 0
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
AND ep.name = 'MS_Description';";

                var tableDescriptions = await DataSource.Sql(tableDescriptionsSql).ToTable().ExecuteAsync();

                foreach (var item in tableDescriptions.Rows)
                {
                    var table = Tables.Single(t => t.Table.Name.Schema == (string)item["SchemaName"] && t.Table.Name.Name == (string)item["TableName"]);
                    table.Description = (string)item["value"];
                }

                const string columnDescriptionsSql = @"SELECT s.name AS SchemaName, t.name AS TableName, c.name AS ColumnName, ep.value FROM sys.extended_properties ep
INNER JOIN sys.tables t ON ep.major_id = t.object_id 
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN sys.columns c ON c.object_id = ep.major_id AND c.column_id = ep.minor_id
AND ep.name = 'MS_Description'";


                var columnDescriptions = await DataSource.Sql(columnDescriptionsSql).ToTable().ExecuteAsync();

                foreach (var item in columnDescriptions.Rows)
                {
                    var table  = Tables.Single(t => t.Table.Name.Schema == (string)item["SchemaName"] && t.Table.Name.Name == (string)item["TableName"]);
                    var column = (SqlServerColumnModel)table.Columns.Single(c => c.Name == (string)item["ColumnName"]);
                    column.Description = (string)item["value"];
                }

                const string sparseColumnsSql = @"SELECT s.name AS SchemaName, t.name AS TableName, c.name AS ColumnName, c.is_sparse 
FROM sys.tables t 
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN sys.columns c ON c.object_id = t.object_id";
                var          sparseColumns    = await DataSource.Sql(sparseColumnsSql).ToTable().ExecuteAsync();

                foreach (var item in sparseColumns.Rows)
                {
                    var table  = Tables.Single(t => t.Table.Name.Schema == (string)item["SchemaName"] && t.Table.Name.Name == (string)item["TableName"]);
                    var column = (SqlServerColumnModel)table.Columns.Single(c => c.Name == (string)item["ColumnName"]);
                    column.IsSparse = (bool)item["is_sparse"];
                }

                const string relatedTablesSql = @"SELECT s.name AS SchemaName, t.name AS TableName, s2.name AS ReferencedSchemaName, t2.name AS ReferencedTableName
FROM sys.foreign_key_columns fkc
    INNER JOIN sys.tables t
        ON fkc.parent_object_id = t.object_id
    INNER JOIN sys.columns c
        ON c.column_id = fkc.parent_column_id
           AND c.object_id = fkc.parent_object_id
    INNER JOIN sys.schemas s
        ON s.schema_id = t.schema_id
    INNER JOIN sys.tables t2
        ON fkc.referenced_object_id = t2.object_id
    INNER JOIN sys.columns c2
        ON c2.column_id = fkc.referenced_column_id
           AND c2.object_id = fkc.referenced_object_id
    INNER JOIN sys.schemas s2
        ON s2.schema_id = t2.schema_id
    INNER JOIN sys.foreign_keys fk
        ON fk.object_id = fkc.constraint_object_id";

                var relatedTables = await DataSource.Sql(relatedTablesSql).ToTable().ExecuteAsync();

                foreach (var item in relatedTables.Rows)
                {
                    var table        = Tables.Single(t => t.Table.Name.Schema == (string)item["SchemaName"] && t.Table.Name.Name == (string)item["TableName"]);
                    var relatedTable = Tables.Single(t => t.Table.Name.Schema == (string)item["ReferencedSchemaName"] && t.Table.Name.Name == (string)item["ReferencedTableName"]);

                    if (!table.ReferencedTables.Contains(relatedTable))
                    {
                        table.ReferencedTables.Add(relatedTable);
                    }
                    if (!relatedTable.ReferencedByTables.Contains(table))
                    {
                        relatedTable.ReferencedByTables.Add(table);
                    }
                }
            }
            finally
            {
                StopWork();
            }
        }
Пример #21
0
        private void FromCurrentFormat(byte[] bytes, int offset = 0)
        {
            Signature = bytes.GetString(0, 2);
            Version   = bytes.ToByte(2);
            Length    = bytes.Length;

            offset += 3;

            //Get all inputs
            Inputs.AddRange(GetArray(bytes,
                                     InputPoint.GetCount(FileVersion),
                                     InputPoint.GetSize(FileVersion), ref offset)
                            .Select(i => new InputPoint(i, 0, FileVersion)));

            //Get all outputs
            Outputs.AddRange(GetArray(bytes,
                                      OutputPoint.GetCount(FileVersion),
                                      OutputPoint.GetSize(FileVersion), ref offset)
                             .Select(i => new OutputPoint(i, 0, FileVersion)));

            //Get all variables
            Variables.AddRange(GetArray(bytes,
                                        VariablePoint.GetCount(FileVersion),
                                        VariablePoint.GetSize(FileVersion), ref offset)
                               .Select(i => new VariablePoint(i, 0, FileVersion)));

            //Get all programs
            Programs.AddRange(GetArray(bytes,
                                       ProgramPoint.GetCount(FileVersion),
                                       ProgramPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new ProgramPoint(i, 0, FileVersion)));

            //Get all controllers
            Controllers.AddRange(GetArray(bytes,
                                          ControllerPoint.GetCount(FileVersion),
                                          ControllerPoint.GetSize(FileVersion), ref offset)
                                 .Select(i => new ControllerPoint(i, 0, FileVersion)));

            //Get all screens
            Screens.AddRange(GetArray(bytes,
                                      ScreenPoint.GetCount(FileVersion),
                                      ScreenPoint.GetSize(FileVersion), ref offset)
                             .Select(i => new ScreenPoint(i, 0, FileVersion)));

            //Get all graphics

            //TODO: Constants to object static Size(FileVersion) Count(FileVersion)

            Graphics.AddRange(GetArray(bytes,
                                       GraphicPoint.GetCount(FileVersion),
                                       GraphicPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new GraphicPoint(i, 0, FileVersion)));

            Users.AddRange(GetArray(bytes,
                                    UserPoint.GetCount(FileVersion),
                                    UserPoint.GetSize(FileVersion), ref offset)
                           .Select(i => new UserPoint(i, 0, FileVersion)));

            CustomUnits.Digital.AddRange(GetArray(bytes,
                                                  CustomDigitalUnitsPoint.GetCount(FileVersion),
                                                  CustomDigitalUnitsPoint.GetSize(FileVersion), ref offset)
                                         .Select(i => new CustomDigitalUnitsPoint(i, 0, FileVersion)));

            Tables.AddRange(GetArray(bytes,
                                     TablePoint.GetCount(FileVersion),
                                     TablePoint.GetSize(FileVersion), ref offset)
                            .Select(i => new TablePoint(i, 0, FileVersion)));

            Settings = new Settings(
                GetObject(bytes, Settings.GetSize(FileVersion), ref offset), 0, FileVersion);

            Schedules.AddRange(GetArray(bytes,
                                        SchedulePoint.GetCount(FileVersion),
                                        SchedulePoint.GetSize(FileVersion), ref offset)
                               .Select(i => new SchedulePoint(i, 0, FileVersion)));

            Holidays.AddRange(GetArray(bytes,
                                       HolidayPoint.GetCount(FileVersion),
                                       HolidayPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new HolidayPoint(i, 0, FileVersion)));

            Monitors.AddRange(GetArray(bytes,
                                       MonitorPoint.GetCount(FileVersion),
                                       MonitorPoint.GetSize(FileVersion), ref offset)
                              .Select(i => new MonitorPoint(i, 0, FileVersion)));

            ScheduleCodes.AddRange(GetArray(bytes,
                                            ScheduleCode.GetCount(FileVersion),
                                            ScheduleCode.GetSize(FileVersion), ref offset)
                                   .Select(i => new ScheduleCode(i, 0, FileVersion)));

            HolidayCodes.AddRange(GetArray(bytes,
                                           HolidayCode.GetCount(FileVersion),
                                           HolidayCode.GetSize(FileVersion), ref offset)
                                  .Select(i => new HolidayCode(i, 0, FileVersion)));


            int pcode_offset     = offset;
            var ProgramCodeBytes = bytes.ToBytes(offset, ProgramCode.GetSize(FileVersion));

            ProgramCodes.AddRange(GetArray(bytes,
                                           ProgramCode.GetCount(FileVersion),
                                           ProgramCode.GetSize(FileVersion), ref offset)
                                  //.Select(i => new ProgramCode(i, this, 0, FileVersion)));
                                  .Select(i => new ProgramCode()));

            ProgramCodes[0] = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion);


            for (int i = 1; i < ProgramCode.GetCount(FileVersion); i++)
            {
                pcode_offset    += ProgramCode.GetSize(FileVersion);
                ProgramCodeBytes = bytes.ToBytes(pcode_offset, ProgramCode.GetSize(FileVersion));
                ProgramCodes[i]  = new ProgramCode(ProgramCodeBytes, this, 0, FileVersion);
                Debug.WriteLine($"Leído ProgramCode[{i}]");
            }



            CustomUnits.Analog.AddRange(GetArray(bytes,
                                                 CustomAnalogUnitsPoint.GetCount(FileVersion),
                                                 CustomAnalogUnitsPoint.GetSize(FileVersion), ref offset)
                                        .Select(i => new CustomAnalogUnitsPoint(i, 0, FileVersion)));

            CheckOffset(offset, Length);

            UpdateCustomUnits();
        }
Пример #22
0
 internal SqlFromClause(IEnumerable <SqlTableSource> tables)
     : base(null)
 {
     Tables.AddRange(tables);
 }
Пример #23
0
 public DataSourceView(string name, Table[] tables) : base(name)
 {
     Tables.AddRange(tables);
 }
Пример #24
0
        internal void ValidateAndAdjust()
        {
            // Connection string
            if (ConnectionString == null)
            {
                // ReSharper disable once NotResolvedInText
                throw new ArgumentNullException("SqlDependencyProvider.Parameters.ConnectionString");
            }

            // Tables
            var tableInfos = new List <SqlDependencyQualifiedObjectName>(Tables);

            tableInfos = tableInfos
                         .Where(p => p?.Name != null)
                         .Distinct()
                         .ToList();
            if (tableInfos.Count == 0)
            {
                // ReSharper disable once NotResolvedInText
                throw new ArgumentNullException("SqlDependencyProvider.Parameters.Tables");
            }
            Tables.Clear();
            Tables.AddRange(tableInfos.OrderBy(p => p.Schema, StringComparer.OrdinalIgnoreCase)
                            .ThenBy(p => p.Name, StringComparer.OrdinalIgnoreCase));

            // Monitored changes
            if (MonitoredChanges == SqlDependencyMonitoredChanges.None)
            {
                // ReSharper disable once NotResolvedInText
                throw new ArgumentNullException("SqlDependencyProvider.Parameters.MonitoredChanges");
            }

            // Check all monitored tables exist
            using (var conn = new SqlConnection(ConnectionString))
            {
                // Ensure open
                Helper.EnsureOpenConnection(conn);

                // Check
                var nonExistingTableNames = new List <string>();
                if (!Tables.Any(t =>
                {
                    if (!Helper.TableExists(conn, null, t))
                    {
                        nonExistingTableNames.Add(t.ToString());
                        return(false);
                    }
                    return(true);
                }))
                {
#if USETRANSLATIONS
                    throw new InvalidOperationException(
                              Translations.Default["SText_SqlDependencyOneOrMoreMonitoredTablesDoNotExist_Names",
                                                   string.Join(", ", nonExistingTableNames)]);
#else
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      Resources.SText_SqlDependencyOneOrMoreMonitoredTablesDoNotExist_Names,
                                                                      string.Join(", ", nonExistingTableNames)));
#endif
                }
            }
        }