public CKSSubjects(string cksResponse) : base(cksResponse) { if (Status == CKSOperationStatus.ok) { var xsubjs = Source.Element("clients"); foreach (var client in xsubjs.Elements()) { _subjects.Add(client.Attribute("id").Value.ToLongOrDefault(), new CKSSubject(client)); } } }
internal static IValue ObjectShort(ListNode list, Scope scope) { var mapList = ((ListNode)list.Children[1]).Children; MapTable map = new MapTable(); for (int i = 0; i < mapList.Count; ++i) { var key = (IdentifierNode)mapList[i]; var val = key.EvalOnce(scope); map.Add(key, val); } return(map); }
internal static IValue Object(ListNode list, Scope scope) { var mapList = ((ListNode)list.Children[1]).Children; if (mapList.Count % 2 != 0) { throw new Exception("Unable to create map, missing key"); } MapTable map = new MapTable(); for (int i = 0; i < mapList.Count - 1; i += 2) { var key = (IdentifierNode)mapList[i]; var val = mapList[i + 1].EvalOnce(scope); map.Add(key, val); } return(map); }
internal static IValue Dictionary(List <IValue> list, Scope scope) { var mapList = ((ListTable)list[0]).AsList(); if (mapList.Count % 2 != 0) { throw new Exception("Unable to create map, missing key"); } MapTable map = new MapTable(); for (int i = 0; i < mapList.Count - 1; i += 2) { var key = mapList[i]; var val = mapList[i + 1]; map.Add(key, val); } return(map); }
private static async Task <string> GetSqlVersion(MdbContext mdb) { int mdbHash = mdb.MdbHash(); if (!_versions.TryGetValue(mdbHash, out string sqlVersion)) { sqlVersion = await mdb.ExecuteAsync <string>(SqlServer.SQLVersion); if (sqlVersion.IsEmpty()) { sqlVersion = "10"; } else { sqlVersion = sqlVersion.GetToken(0, "."); } _versions.Add(mdbHash, sqlVersion); } return(sqlVersion); }
/// <summary> /// Create <see cref="DataPackage"/> from full json format /// </summary> /// <param name="source">json string whit Headers, Columns and Data rows </param> /// <param name="jsonFormat"><see cref="TsJsonFormat"/></param> /// <param name="headerSpaceSize">For no headers package set headerSpaceSize = 8</param> internal DataPackage(JsonValue source, TsJsonFormat jsonFormat = TsJsonFormat.Full, int headerSpaceSize = 0) : base(source) { if (jsonFormat != TsJsonFormat.Simple) { var j = source as JsonObject; if (headerSpaceSize == 0) { headerSpaceSize = (int)j.GetIntOrDefault("HeaderSize", header_space_size_default); } JsonArray columns = j.GetArray("Columns"); JsonArray rows = j.GetArray("Rows"); _b = new BinaryDataBuffer(headerSpaceSize * 2); _bw = new BinaryDataWriter(_b); _br = new BinaryDataReader(_b); _colCount = columns.Count; bool hasValues = rows != null; //headers _headerSpaceSize = headerSpaceSize; _headers = new MapTable <string, object>(StringComparer.Ordinal); JsonObject headers = (JsonObject)j["Headers"]; foreach (var pair in headers) { _headers.Add(pair.Key, pair.Value?.GetValue()); } //Create col info _indexes = new string[_colCount]; _colInfo = new ColumnInfo[_colCount]; for (int i = 0; i < _colCount; i++) { var c = columns[i]; _indexes[i] = (string)c["Name"]; _colInfo[i] = new ColumnInfo() { DataType = MdbTypeMap.GetType((string)c["Type"], typeof(string)), ColumnSize = (int)c["Size"], AllowDBNull = (bool)c["AllowNull"] }; } WritePackageHeader(); //values if (hasValues) { if (jsonFormat == TsJsonFormat.Full) { foreach (JsonObject r in rows) { AddNew(); foreach (var o in r) { SetValue(o.Key, o.Value?.GetValue()); } Update(); } } else { //!!! Not tested foreach (JsonArray a in rows) { AddNew(); foreach (var o in a) { for (int i = 0; i < _colCount; i++) { SetValue(_indexes[i], o?.GetValue()); } } Update(); } } } } else //simple { if (headerSpaceSize == 0) { headerSpaceSize = header_space_size_default; } _b = new BinaryDataBuffer(headerSpaceSize * 2); _bw = new BinaryDataWriter(_b); _br = new BinaryDataReader(_b); JsonObject dataRow; bool isArray = false; if (source is JsonObject j) { dataRow = j; } else if (source is JsonArray a) { if (a.Count == 0) { throw new ArgumentException("Parameter array cannot be empty"); } dataRow = (JsonObject)a[0]; isArray = true; } else { throw new ArgumentException("The constructor of DataPackage requires JsonObject or JsonArray parameter type."); } _headerSpaceSize = headerSpaceSize; _headers = new MapTable <string, object>(StringComparer.Ordinal); _colCount = dataRow.Count; _indexes = new string[_colCount]; _colInfo = new ColumnInfo[_colCount]; int i = 0; foreach (var kvp in dataRow) { _indexes[i] = kvp.Key; _colInfo[i] = ColumnInfo.FromValue(kvp.Value?.GetValue()); i++; } WritePackageHeader(); if (isArray) { foreach (var r in (source as JsonArray)) { AddNew(); foreach (var o in (JsonObject)r) { SetValue(o.Key, o.Value?.GetValue()); } Update(); } } else { AddNew(); foreach (var o in dataRow) { SetValue(o.Key, o.Value?.GetValue()); } Update(); } } GoDataTop(); }
private void MapTableTests() { using (FileLog l = new FileLog("MapTableTest", new FileLogSettings() { DateFolderMask = "yyyy-MM-dd" })) { const int loop_count = 100_000; int[] test_data = new int[] { 32, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 65536, 131072, 524288, 1048576 /*, 2097152, 4194304*/ }; foreach (int item_size in test_data) { string key = fixed_key_part + (item_size / 2).ToString(); DateTime start = DateTime.Now; MapTable <string, int> d = new MapTable <string, int>(StringComparer.Ordinal); for (int i = 1; i < item_size; i++) { d.Add(fixed_key_part + i.ToString(), i); } //Parallel.For(0, item_size, i => // d.Add(fixed_key_part + i.ToString(), i)); //MapTable<string, int> d = new MapTable<string, int>( // Enumerable.Range(0, item_size) // .Select(i => new KeyValuePair<string, int>(fixed_key_part + i.ToString(), i)).ToList(), // EqualityComparer<string>.Default); DateTime stop = DateTime.Now; l.Debug($"Create MapTable with {item_size} with colissions = {d.Collisions} elements. Time = {(stop - start).TotalMilliseconds} ms"); Dictionary <string, int> d1 = new Dictionary <string, int>(); object o = new object(); start = DateTime.Now; //Parallel.For(0, item_size, i => //{ // lock (o) // d1.Add(fixed_key_part + i.ToString(), i); //}); for (int i = 1; i < item_size; i++) { lock (o) d1.Add(fixed_key_part + i.ToString(), i); } stop = DateTime.Now; l.Debug($"Create Dictionary with {item_size} elements. Time = {(stop - start).TotalMilliseconds} ms"); start = DateTime.Now; ReadOnlyCache <string, int> d2 = new ReadOnlyCache <string, int>(StringComparer.Ordinal, Enumerable.Range(0, item_size) //.Select(i => new KeyValuePair<string, int>(fixed_key_part + i.ToString(), i)) .Select(i => (fixed_key_part + i.ToString(), i)) .ToArray()); stop = DateTime.Now; l.Debug($"Create ReadOnlyCache with {item_size} elements. Time = {(stop - start).TotalMilliseconds} ms"); start = DateTime.Now; int k = 0; for (int i = 0; i < loop_count; i++) { k = d[key]; } stop = DateTime.Now; l.Debug($"MapTable TryGetValue with {loop_count} runs index of = {k} whith fragmentation = {d.Fragmentation} total time = {(stop - start).TotalMilliseconds} ms"); start = DateTime.Now; for (int i = 0; i < loop_count; i++) { lock (o) k = d1[key]; } stop = DateTime.Now; int fragmentation = (d1.GetType().GetField("_buckets", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(d1) as int[]).Count(p => p == -1); l.Debug($"Dictionary TryGetValue with {loop_count} runs index of = {k} whith fragmentation = {fragmentation} total time = {(stop - start).TotalMilliseconds} ms"); start = DateTime.Now; for (int i = 0; i < loop_count; i++) { lock (o) k = d2[key]; } stop = DateTime.Now; l.Debug($"ReadOnlyCache TryGetValue with {loop_count} runs index of = {k} total time = {(stop - start).TotalMilliseconds} ms"); } //ConcurrentDictionary<string, int> d2 = new ConcurrentDictionary<string, int>(); //start = DateTime.Now; //System.Threading.Tasks.Parallel.For(0, loop_count, i => // d2.TryAdd(fixed_key_part + i.ToString(), i)); //stop = DateTime.Now; //l.Debug($"Create ConcurrentDictionary with {loop_count} elements. Time = {(stop - start).TotalMilliseconds} ms"); //start = DateTime.Now; //for (int i = 0; i < loop_count; i++) // d2.TryGetValue(fixed_key_part + "500011", out k); //stop = DateTime.Now; //l.Debug($"ConcurrentDictionary TryGetValue with {loop_count} runs index of = {k} whith fragmentation = {0} total time = {(stop - start).TotalMilliseconds} ms"); } }
public static MapTable <string, ActionInfo> CreateActionsList() { MapTable <string, ActionInfo> actions = ActionInfoCache.Instance; #region Sys.LoginRequest ActionInfo ai = new ActionInfo() { ActionID = "Sys.LoginRequest", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = false, AuthenticationRequired = false, AuthorizationRequired = false, ClassName = typeof(SysLoginRequest).FullName, Description = "Запрос на логин (принимает Имя пользователя и открытый ключ клиента, возвращает ИД сессии + открытый ключ сервера)", EMailOnError = false, LogOnError = true, MultipleRowsParams = false, MultipleRowsResult = false, TransactionSupport = TransactionActionSupport.None, Name = "Запрос на логин", WebAuthentication = ActionWebAuthenticationType.None, IsStatic = true }; ParamInfo pi = new ParamInfo() { AttribName = "UserName", FieldName = "UserName", ParameterID = "UserName", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Имя пользователя", Position = 1, PresentationType = "TextBox", Visible = true, Width = 30, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "PublicKey", FieldName = "PublicKey", ParameterID = "PublicKey", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Открытый ключ клиента", Position = 2, PresentationType = "TextBox", Visible = true, Width = 256, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "LoginInfo", FieldName = "LoginInfo", ParameterID = "LoginInfo", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Login Info", Position = 3, PresentationType = "TextBox", Visible = true, Width = 256, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion Sys.LoginRequest #region Sys.Logon ai = new ActionInfo() { ActionID = "Sys.Logon", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = false, AuthenticationRequired = false, AuthorizationRequired = false, ClassName = typeof(SysLogon).FullName, Description = "Аутентификация пользователя (принимает Имя пользователя, ИД сессии, зашифрованный открытым ключем сервера пароль, возвращает зашифрованный открытым ключем клиента симметричный ключ)", EMailOnError = false, LogOnError = true, MultipleRowsParams = false, MultipleRowsResult = false, TransactionSupport = TransactionActionSupport.None, Name = "Аутентификация пользователя", WebAuthentication = ActionWebAuthenticationType.None, IsStatic = true }; pi = new ParamInfo() { AttribName = "UserName", FieldName = "UserName", ParameterID = "UserName", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Имя пользователя", Position = 1, PresentationType = "TextBox", Visible = true, Width = 30, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "SessionID", FieldName = "SessionID", ParameterID = "SessionID", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "ИД сессии", Position = 2, PresentationType = "TextBox", Visible = true, Width = 34, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "EncryptedKey", FieldName = "EncryptedKey", ParameterID = "EncryptedKey", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Зашифрованный пароль", Position = 3, PresentationType = "TextBox", Visible = true, Width = 256, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "Ticket", FieldName = "Ticket", ParameterID = "Ticket", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Зашифрованный токен аутентификации", Position = 4, PresentationType = "TextBox", Visible = true, Width = 256, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion Sys.Logon #region Sys.Select ai = new ActionInfo() { ActionID = "Sys.Select", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = true, AuthenticationRequired = true, AuthorizationRequired = true, ClassName = typeof(SysSelect).FullName, Description = "Выборка данных из источника", EMailOnError = false, LogOnError = true, MultipleRowsParams = true, MultipleRowsResult = true, TransactionSupport = TransactionActionSupport.None, Name = "Выборка данных из источника", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; pi = new ParamInfo() { AttribName = "ParamName", FieldName = "ParamName", ParameterID = "ParamName", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Наименование параметра", Position = 1, PresentationType = "TextBox", Visible = true, Width = 30, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "ParamValue", FieldName = "ParamValue", ParameterID = "ParamValue", DataType = "object", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Значение параметра", Position = 2, PresentationType = "TextBox", Visible = true, Width = 1024, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion #region Sys.Getschema ai = new ActionInfo() { ActionID = "Sys.GetSchema", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = true, AuthenticationRequired = true, AuthorizationRequired = false, ClassName = typeof(SysGetSchema).FullName, Description = "Получить схему объекта", EMailOnError = false, LogOnError = true, MultipleRowsParams = true, MultipleRowsResult = true, TransactionSupport = TransactionActionSupport.None, Name = "Получить схему объекта", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; pi = new ParamInfo() { AttribName = "ObjectName", FieldName = "ObjectName", ParameterID = "ObjectName", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Наименование объекта", Position = 1, PresentationType = "TextBox", Visible = true, Width = 60, Required = true, IsObjectName = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "ObjectSchema", FieldName = "ObjectSchema", ParameterID = "ObjectSchema", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Схема объекта", Position = 2, PresentationType = "TextBox", Visible = true, Width = 1024 * 256, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion #region Sys.Logout ai = new ActionInfo() { ActionID = "Sys.Logout", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = false, AuthenticationRequired = false, AuthorizationRequired = false, ClassName = typeof(SysLogout).FullName, Description = "Закрыть сессию", EMailOnError = false, LogOnError = true, MultipleRowsParams = false, MultipleRowsResult = false, TransactionSupport = TransactionActionSupport.None, Name = "Получить схему объекта", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; actions.Add(ai.ActionID, ai); #endregion #region Sys.SaveSchema ai = new ActionInfo() { ActionID = "Sys.SaveSchema", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = true, AuthenticationRequired = true, AuthorizationRequired = true, ClassName = typeof(SysSaveSchema).FullName, Description = "Сохранить схему объекта", EMailOnError = false, LogOnError = true, MultipleRowsParams = true, MultipleRowsResult = true, TransactionSupport = TransactionActionSupport.Support, Name = "Сохранить схему объекта", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; pi = new ParamInfo() { AttribName = "ObjectSchema", FieldName = "ObjectSchema", ParameterID = "ObjectSchema", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Схема объекта", Position = 1, PresentationType = "TextBox", Visible = true, Width = 1024 * 256, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "ObjectSchemaResult", FieldName = "ObjectSchema", ParameterID = "ObjectSchemaResult", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Схема объекта", Position = 2, PresentationType = "TextBox", Visible = true, Width = 1024 * 256, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion #region Sys.GetActionInfo ai = new ActionInfo() { ActionID = "Sys.GetActionInfo", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = true, AuthenticationRequired = true, AuthorizationRequired = true, ClassName = typeof(SysGetActionInfo).FullName, Description = "Получить описание операции", EMailOnError = false, LogOnError = true, MultipleRowsParams = true, MultipleRowsResult = true, TransactionSupport = TransactionActionSupport.None, Name = "Получить описание операции", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; pi = new ParamInfo() { AttribName = "ActionID", FieldName = "ActionID", ParameterID = "ActionID", DataType = "string", Dirrect = ParamDirrect.Input, Enabled = true, Name = "Наименование операции", Position = 1, PresentationType = "TextBox", Visible = true, Width = 60, Required = true }; ai.InterfaceParameters.Add(pi); pi = new ParamInfo() { AttribName = "ActionInfo", FieldName = "ActionInfo", ParameterID = "ActionInfo", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Схема операции", Position = 2, PresentationType = "TextBox", Visible = true, Width = 1024 * 256, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion #region Sys.PipeRead ai = new ActionInfo() { ActionID = "Sys.PipeRead", AssemblyID = typeof(ActionsListInternal).Assembly.GetWorkName(), AsyncMode = false, AuthenticationRequired = true, AuthorizationRequired = true, ClassName = typeof(SysPipeRead).FullName, Description = "Запустить канал вывода информации для текущей сессии", EMailOnError = false, LogOnError = true, MultipleRowsParams = true, MultipleRowsResult = true, TransactionSupport = TransactionActionSupport.None, Name = "Запустить канал вывода информации для текущей сессии", WebAuthentication = ActionWebAuthenticationType.Basic, IsStatic = true }; pi = new ParamInfo() { AttribName = "Result", FieldName = "Result", ParameterID = "Result", DataType = "string", Dirrect = ParamDirrect.Output, Enabled = true, Name = "Результат операции", Position = 1, PresentationType = "TextBox", Visible = true, Width = 60, Required = true }; ai.InterfaceParameters.Add(pi); actions.Add(ai.ActionID, ai); #endregion return(actions); }