Beispiel #1
0
        public async Task <ActionInfo> GetActionInfoAsync(string actionID)
        {
            actionID.NullTest(nameof(actionID));
            if (!_actionsCache.TryGetValue(actionID, out ActionInfo ai))
            {
                using (var dr = await SysCatDbContext.GetReaderAsync(_sql_actions.ToFormat(actionID, _schemaName)))
                {
                    if (dr.Read())
                    {
                        ai = SetActionAttributes(dr);
                    }
                }
                if (ai != null)
                {
                    using (var dr = await SysCatDbContext.GetReaderAsync(_sql_parameters.ToFormat(ai.IID, _schemaName)))
                    {
                        ParamInfoList pil = ai.InterfaceParameters;
                        for (; dr.Read();)
                        {
                            pil.Add(SetParamAttributes(dr));
                        }
                    }
                }
                else
                {
                    throw new KeyNotFoundException($"Action {actionID} not found");
                }

                _actionsCache.TryAdd(actionID, ai);
            }
            return(ai);
        }
Beispiel #2
0
        private static async Task <JMXSchema> GetSchemaInternalAsync(MdbContext mdb, string areaName, string objectName, int syncState)
        {
            string sortDirrect = syncState == 0 ? "" : "desc";
            string sql         = $@"
				select 
					ID
					,ObjectSchema
					,SyncState 
				from V_SysSchemas 
				where SchemaName = '{areaName}' 
					and (ObjectName = '{objectName}' or DbObjectName = '{objectName}') 
				and SyncState >= {syncState}
				order by SyncState {sortDirrect} limit 1"                ;

            using (var dr = await mdb.GetReaderAsync(sql))
            {
                if (!dr.Read())
                {
                    //object schema not found in database
                    throw new InvalidOperationException(string.Format(Properties.Strings.S031_MetaStack_Core_SysCat_SysCatManager_getSchema_2,
                                                                      $"{areaName}.{objectName}", syncState));
                }
                var schema = JMXSchema.Parse((string)dr["ObjectSchema"]);
                schema.ID        = Convert.ToInt32(dr["ID"]);
                schema.SyncState = (int)dr["SyncState"];
                return(schema);
            }
        }
Beispiel #3
0
 private async Task _getReaderSpeedTestAsync()
 {
     using (FileLog l = new FileLog("MdbContextTest", new FileLogSettings()
     {
         DateFolderMask = "yyyy-MM-dd"
     }))
     {
         DateTime t = DateTime.MinValue;
         //Caching pool
         int i = 0;
         for (i = 0; i < 100; i++)
         {
             using (var ctx = new MdbContext(_cn))
             {
             }
         }
         using (var ctx = new MdbContext(_cn))
         {
             l.Debug("SpeedTestAsync 1 Start ");
             MdbContextOptions.GetOptions().CommandTimeout = 120;
             for (i = 0; i < 1000; i++)
             {
                 using (var dr = await ctx.GetReaderAsync("Select * From Bank..PayDocs Where Handle = @handle",
                                                          new MdbParameter("@handle", 3999758)))
                 {
                     dr.Read();
                 }
             }
             l.Debug($"SpeedTestAsync 1 Finish {i} count result {i}");
             l.Debug("SpeedTestAsync 2 Start ");
             for (i = 0; i < 1000; i++)
             {
                 using (var dr = await ctx.GetReaderAsync("Select * From Bank..PayDocs Where Handle = @handle",
                                                          "@handle", 3999758))
                 {
                     dr.Read();
                 }
             }
             l.Debug($"SpeedTestAsync 2 Finish {i} count result {i}");
         }
     }
 }
Beispiel #4
0
        private async Task executeTestAsync()
        {
            using (FileLog l = new FileLog("MdbContextTest", new FileLogSettings()
            {
                DateFolderMask = "yyyy-MM-dd"
            }))
            {
                MdbContextOptions.GetOptions().CommandTimeout = 120;
                using (var ctx = new MdbContext(_cn))
                {
                    l.Debug("Test 1 Start ");
                    int    i   = 0;
                    string sql = @"Create Table TestTable(
					ID		uniqueidentifier	not null primary key,
					Name	varchar(128)	not null,
					DateOper	datetime	not null,
					Notes	varchar(256)	null,
					Handle	int				not null)"                                    ;
                    i = await ctx.ExecuteAsync(sql);

                    l.Debug($"Test 1 Finish rows result {i}");

                    l.Debug("Test 2 Start ");
                    sql = @"Insert Into TestTable (ID, Name, DateOper, Handle)
					Values(@ID, @Name, @DateOper, @Handle)"                    ;

                    i = 0;
                    for (; i < 1000; i++)
                    {
                        await ctx.ExecuteAsync(sql,
                                               new MdbParameter("@ID", Guid.NewGuid()),
                                               new MdbParameter("@Name", "Тестовая строка № " + i.ToString()),
                                               new MdbParameter("@DateOper", vbo.Date().AddDays(i - 1000)),
                                               new MdbParameter("@Handle", i) { NullIfEmpty = false });;
                    }
                    l.Debug($"Test 2 Finish rows result {i}");
                    l.Debug("Test 3 Start ");
                    i = 0;
                    using (var dr = await ctx.GetReaderAsync("Select * From TestTable Order By Handle"))
                    {
                        for (; dr.Read(); i++)
                        {
                            l.Debug(dr.GetRowJSON());
                        }
                    }
                    l.Debug($"Test 3 Finish rows result {i}");
                    l.Debug("Test 4 Start ");
                    sql = "Drop Table TestTable";
                    i   = await ctx.ExecuteAsync(sql);

                    l.Debug($"Test 4 Finish rows result {i}");
                }
            }
        }
Beispiel #5
0
        static async Task selectTestTableAsync(MdbContext ctx, FileLogger l)
        {
            l.Debug("Select Test Table Start");
            int i = 0;

            using (var dr = await ctx.GetReaderAsync("Select * From TestTable Order By Handle"))
            {
                for (; dr.Read(); i++)
                {
                    l.Debug(dr.GetRowJSON());
                }
            }
            l.Debug($"Select Test Table Finish rows result {i}");
        }
        public async Task <string> GetSettings(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("Invalid argument for get settings", nameof(path));
            }

            string[] items    = path.Split('.', StringSplitOptions.RemoveEmptyEntries);
            bool     needJson = items.Length > 1;

            JsonWriter w        = new JsonWriter(Formatting.None);
            JsonValue  settings = null;

            if (!_cache.TryGetValue(items[0], out string s))
            {
                using (MdbContext mdb = _mdbFactory.GetContext(Properties.Strings.DefaultConnection))
                    using (var dr = await mdb.GetReaderAsync(_sql_get_settings,
                                                             new MdbParameter("@identifier", items[0])))
                    {
                        if (!dr.Read())
                        {
                            throw new KeyNotFoundException($"No found setting with Identifier = '{items[0]}'");
                        }

                        w.WriteStartObject();
                        for (int i = 0; i < dr.FieldCount; i++)
                        {
                            string name = dr.GetName(i);
                            if (name == "ValueString")
                            {
                                string source = (string)dr.GetValue(i);
                                if (needJson && !JsonValue.TryParse(source, out settings))
                                {
                                    throw new KeyNotFoundException($"No found setting with path = '{path}' Or ValueString is not json format");
                                }

                                w.WritePropertyName("Settings");
                                if (needJson || JsonValue.Test(source))
                                {
                                    w.WriteRaw(source);
                                }
                                else
                                {
                                    w.WriteValue(source);
                                }
                            }
                            else
                            {
                                w.WriteProperty(name, dr.GetValue(i));
                            }
                        }
                        w.WriteEndObject();
                        s = w.ToString();
                        _cache.TryAdd(items[0], s);
                    }
            }
            else if (needJson)
            {
                settings = new JsonReader(s).Read()["Settings"];
            }

            if (!needJson)
            {
                return(s);
            }
            else if (settings == null)
            {
                throw new InvalidCastException($"ValueString has not valid json format");
            }

            var result = settings[items[1]];

            for (int i = 2; i < items.Length; i++)
            {
                result = result[items[i]];
            }
            return(result.ToString());
        }