private async Task InsertElasticDataAsync() { try { var transactionID = Guid.NewGuid().ToString(); var elasticTableName = "stagingSchema" + ToTimeStamp(DateTime.UtcNow); await table.CreateTableAsync(elasticTableName); Console.WriteLine($"Inserting data into table: {elasticTableName}"); List <ElasticTableEntity> items = new List <ElasticTableEntity>(); for (int i = 0; i < 10; i++) { dynamic item = new ElasticTableEntity(); item.PartitionKey = transactionID; item.RowKey = Guid.NewGuid().ToString(); for (int j = 0; j < 20; j++) { item[$"property{j}"] = $"value{j}"; } items.Add(item); } await table.InsertBulkElasticAsync(elasticTableName, items); } catch (Exception ex) { Console.WriteLine($"Error in InsertElasticDataAsync : {ex.Message}"); } }
private TableBatchOperation ComposeBatch(IEnumerable<LogEvent> events) { var batch = new TableBatchOperation(); foreach (LogEvent e in events) { var row = new ElasticTableEntity { PartitionKey = e.EventTime.ToString("yy-MM-dd"), RowKey = e.EventTime.ToString("HH-mm-ss-fff") }; row.Add("source", e.SourceName); row.Add("severity", e.Severity); row.Add("message", e.FormattedMessage); row.Add("error", e.ErrorException == null ? string.Empty : e.ErrorException.ToString()); if (e.Properties != null) { foreach (var p in e.Properties) { if (p.Key == LogEvent.ErrorPropertyName) continue; row.Add(p.Key, p.Value); } } batch.Insert(row); } return batch.Count > 0 ? batch : null; }
private void LogUsage(string cmdInfo) { // cmdInfo: [0]Mac;[1]Software;[2]" "; // cmdInfo: [3]Component;[4]Command;[5]Parameters;[6]Note;[7]Username;[8]Version var infos = cmdInfo.Split(';'); ElasticTableEntity entity = new ElasticTableEntity(); entity.PartitionKey = nowEST.ToString("yyyyMMMdd", ci); entity.RowKey = nowEST.ToString("HH:mm:ss.f", ci); entity["Component"] = infos[3]; entity["Command"] = infos[4]; entity["Parameters"] = infos[5]; entity["Note"] = infos[6]; entity["Mac"] = infos[0]; entity["Username"] = infos[7]; entity["Version"] = infos[8]; switch (infos[1].Replace(" ", "") + "Log") { case DieLog: tableDieLog.Execute(TableOperation.Insert(entity)); break; case MoldLog: tableMoldLog.Execute(TableOperation.Insert(entity)); break; } }
private void LogInfo(string command, string license, string userInfo, string result) { dynamic entity = new ElasticTableEntity(); entity.PartitionKey = nowEST.ToString("yyyyMMM", ci); entity.RowKey = nowEST.ToString("dd HH:mm:ss.f", ci); //(DateTime.MaxValue.Ticks - DateTime.Now.Ticks).ToString(); entity["Command"] = command; entity["License"] = license; entity["UserInfo"] = userInfo; entity["Result"] = result; // Insert the entity we created dynamically tableLog.Execute(TableOperation.Insert(entity)); }
private void ToolsLog(string cmdInfo) { // cmdInfo: [0]Mac;[1]Software;[2]Version; // cmdInfo: [3]DomainName;[4]UserName;[5]MachineName;[6]OSVersion;//v1.2.2[7]Command var infos = cmdInfo.Split(';'); ElasticTableEntity entity = new ElasticTableEntity(); entity.PartitionKey = nowEST.ToString("yyyyMMMdd", ci); entity.RowKey = nowEST.ToString("HH:mm:ss.f", ci); entity["Software"] = infos[1]; entity["Version"] = infos[2]; entity["DomainName"] = infos[3]; entity["UserName"] = infos[4]; entity["MachineName"] = infos[5]; entity["OSVersion"] = infos[6]; entity["Mac"] = infos[0]; if (infos.Length > 7) { entity["Command"] = infos[7]; } tableToolsLog.Execute(TableOperation.Insert(entity)); }
private string ModifyLicense(string lic) { string result = CommandResult.OK; // lic: [0]SerialID;[1]Software;[2]MacHash; // lic: [3]VariableName=Value;[4]VariableName=Value;[5]VariableName=Value;.... var lics = lic.Split(';'); if (lics.Length < 4) { result = CommandResult.InvalidCommand; return(result); } // Query the table and retrieve a collection of entities. var query = new TableQuery <ElasticTableEntity>(); IEnumerable <ElasticTableEntity> entities = null; IEnumerable <ElasticTableEntity> q = null; q = table.ExecuteQuery(query).Where(e => e.Value("PartitionKey").StartsWith(lics[1])).Select(e => e); entities = q.ToList(); var md5Hash = MD5.Create(); //string userHash = GetMd5Hash(md5Hash, lics[2]); ElasticTableEntity iEntity = null; foreach (ElasticTableEntity entity in entities) { string iHash = GetMd5Hash(md5Hash, entity.RowKey); if (iHash == lics[2]) { iEntity = entity; break; } } if (iEntity == null) { result = CommandResult.NotFound; return(result); } for (int i = 3; i < lics.Length; ++i) { var nv = lics[i].Split('='); if (nv.Length == 2) { if (nv[0].Contains("Date") && iEntity.Properties.ContainsKey(nv[0])) { iEntity[nv[0]] = new DateTime(Int32.Parse(nv[1].Substring(0, 4)), Int32.Parse(nv[1].Substring(4, 2)), Int32.Parse(nv[1].Substring(6, 2)));; } } } table.Execute(TableOperation.Merge(iEntity)); return(result); /* * LicenseInfo licInfo = RetrieveEntityUsingPointQuery(table, lics[1], lics[0]); * * if (licInfo == null) * { * result = CommandResult.NotFound; * return result; * } * * for (int i = 4; i < lics.Length; ++i) * { * var nv = lics[i].Split('='); * if (nv.Length == 2) * { * switch (nv[0]) * { * case nameof(licInfo.Contact): * licInfo.Contact = nv[1]; * break; * * case nameof(licInfo.Customer): * licInfo.Customer = nv[1]; * break; * * case nameof(licInfo.Email): * licInfo.Email = nv[1]; * break; * * case nameof(licInfo.ExpireDate): * licInfo.ExpireDate = new DateTime(Int32.Parse(nv[1].Substring(0, 4)), Int32.Parse(nv[1].Substring(4, 2)), Int32.Parse(nv[1].Substring(6, 2))); * break; * * case nameof(licInfo.IssueDate): * licInfo.IssueDate = new DateTime(Int32.Parse(nv[1].Substring(0, 4)), Int32.Parse(nv[1].Substring(4, 2)), Int32.Parse(nv[1].Substring(6, 2))); * break; * * case nameof(licInfo.MaintenanceDate): * licInfo.MaintenanceDate = new DateTime(Int32.Parse(nv[1].Substring(0, 4)), Int32.Parse(nv[1].Substring(4, 2)), Int32.Parse(nv[1].Substring(6, 2))); * break; * * case nameof(licInfo.Phone): * licInfo.Phone = nv[1]; * break; * * case nameof(licInfo.SoftVersion): * licInfo.SoftVersion = nv[1]; * break; * * case nameof(licInfo.Keys): * licInfo.Keys = Int32.Parse(nv[1]); * break; * * default: * //result = CommandResult.NotFound; * break; * } * * } * } * * try * { * // https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ * TableOperation mergeOperation = TableOperation.Merge(licInfo); * table.Execute(mergeOperation); * } * catch (StorageException) * { * } */ }