private static void WriteMetadata(string jsonFilePath, IDataStore store) { var metadatas = store.GetCollection <ElectLogMetadataModel>("metadata"); var metadata = metadatas.AsQueryable().FirstOrDefault(); var fileInfo = new FileInfo(jsonFilePath); var logs = store.GetCollection <LogModel>("logs"); var totalLog = logs.Count; if (metadata == null) { metadata = new ElectLogMetadataModel(); metadata.CreatedTime = metadata.LastUpdatedTime = DateTimeOffset.Now; metadata.FileName = fileInfo.Name; metadata.FileSize = fileInfo.Length.Bytes().Humanize(); metadata.TotalLog = totalLog; metadatas.InsertOne(metadata); } else { metadata.LastUpdatedTime = DateTimeOffset.Now; metadata.FileName = fileInfo.Name; metadata.FileSize = fileInfo.Length.Bytes().Humanize(); metadata.TotalLog = totalLog; metadatas.UpdateOne(x => true, metadata); } }
private static void WriteMetadata(IDataStore store) { var metadatas = store.GetCollection <ElectLogMetadataModel>("metadata"); var metadata = metadatas.AsQueryable().FirstOrDefault(); if (metadata == null) { metadata = new ElectLogMetadataModel(); metadata.CreatedTime = metadata.LastUpdatedTime = DateTimeOffset.UtcNow; metadatas.InsertOne(metadata); } else { metadata.LastUpdatedTime = DateTimeOffset.UtcNow; metadatas.UpdateOne(x => true, metadata); } }