internal void ReturnLargeBuffer(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (!IsLargeBufferMultiple(buffer.Length)) { throw new ArgumentException("buffer did not originate from this memory manager. The size is not a multiple of " + LargeBufferMultiple); } var num = buffer.Length / largeBufferMultiple - 1; if (num < largePools.Length) { if ((largePools[num].Count + 1) * buffer.Length <= MaximumFreeLargePoolBytes || MaximumFreeLargePoolBytes == 0) { largePools[num].Push(buffer); Interlocked.Add(ref largeBufferFreeSize[num], buffer.Length); } else { LargeBufferDiscarded?.Invoke(MemoryStreamDiscardReason.EnoughFree); } } else { num = largeBufferInUseSize.Length - 1; LargeBufferDiscarded?.Invoke(MemoryStreamDiscardReason.TooLarge); } Interlocked.Add(ref largeBufferInUseSize[num], -buffer.Length); UsageReport?.Invoke(smallPoolInUseSize, smallPoolFreeSize, LargePoolInUseSize, LargePoolFreeSize); }
/// <summary> /// Get a list of all folders on the server. Optionally include default system generated folders. /// </summary> /// <param name="includeSystemFolders">Boolean signifying whether to include the system generated folders (currently System and Utilities) if they exist.</param> /// <returns>List of folder names</returns> //public async Task<IEnumerable<string>> GetFolderNames(bool includeSystemFolders = false) //{ // Uri rootFolderEndpoint = new Uri(ServerUrl, "services"); // ServicesResponse response = await GetStringAsync<ServicesResponse>(rootFolderEndpoint); // var folders = (from folderDetail in response.foldersDetail select folderDetail.folderName); // if (!includeSystemFolders) folders = (from folder in folders where folder != "System" && folder != "Utilities" select folder); // return folders; //} public async Task <JObject> AddUsageReport(string usageReport, List <string> services, Options options, long?fromUnix, long?toUnix, string[] metrics) { Uri endpoint = new Uri(ServerUrl, "usagereports/add"); UsageReport r = new UsageReport(); r.reportname = usageReport; r.since = options.Since; if (options.Since == SinceType.CUSTOM) { r.from = fromUnix.Value; r.to = toUnix.Value; } if (options.AggregationInterval.HasValue) { r.aggregationInterval = options.AggregationInterval.Value; } Query q = new Query(); q.metrics = metrics; string[] resourceURIs = services.Select(c => { c = "services/" + c; return(c); }).ToArray(); q.resourceURIs = resourceURIs; r.queries = new Query[] { q }; Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("usagereport", JsonConvert.SerializeObject(r)); var content = new FormUrlEncodedContent(d); return(await PostAsync(endpoint, content, true)); }
internal void ReturnBlocks(ICollection <byte[]> blocks) { if (blocks == null) { throw new ArgumentNullException(nameof(blocks)); } var num = blocks.Count * BlockSize; Interlocked.Add(ref smallPoolInUseSize, -num); foreach (var block in blocks) { if (block == null || block.Length != BlockSize) { throw new ArgumentException("blocks contains buffers that are not BlockSize in length"); } } foreach (byte[] block2 in blocks) { if (MaximumFreeSmallPoolBytes != 0 && SmallPoolFreeSize >= MaximumFreeSmallPoolBytes) { BlockDiscarded?.Invoke(); break; } Interlocked.Add(ref smallPoolFreeSize, BlockSize); smallPool.Push(block2); } UsageReport?.Invoke(smallPoolInUseSize, smallPoolFreeSize, LargePoolInUseSize, LargePoolFreeSize); }
public void VerifyResult() { DownloadCompletionAndUsageReportExample example = new DownloadCompletionAndUsageReportExample(Props.GetInstance()); example.Run(); // Assert correct download of completion report CompletionReport completionReport = example.sdkCompletionReport; Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(completionReport.Senders[0].Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); Assert.IsNotNull(example.csvCompletionReport); Assert.IsNotEmpty(example.csvCompletionReport); // Assert correct download of usage report UsageReport usageReport = example.sdkUsageReport; Assert.Greater(usageReport.SenderUsageReports.Count, 0, "There should be only 1 sender."); Assert.Greater(usageReport.SenderUsageReports[0].CountByUsageReportCategory.Count, 0, "Number of dictionary entries should be greater than 0."); Assert.IsTrue(usageReport.SenderUsageReports[0].CountByUsageReportCategory.ContainsKey(UsageReportCategory.DRAFT), "There should be at a draft key in packages map."); Assert.Greater(usageReport.SenderUsageReports[0].CountByUsageReportCategory[UsageReportCategory.DRAFT], 0, "Number of drafts should be greater than 0."); Assert.IsNotNull(example.csvUsageReport, "Usage report in csv cannot be null."); Assert.IsNotEmpty(example.csvUsageReport, "Usage report in csv cannot be empty."); }
internal void ReportUsageReport( long blockPoolInUseBytes, long blockPoolFreeBytes, long bufferPoolInUseBytes, long bufferPoolFreeBytes) { UsageReport?.Invoke( blockPoolInUseBytes, blockPoolFreeBytes, bufferPoolInUseBytes, bufferPoolFreeBytes); }
public SingleUsageTag(UsageReport report) : base("div") { AddClass("single-command-usage"); var parts = report.Usage.Split(' '); var command = parts.Take(2).Join(" "); var argsAndFlags = parts.Skip(2).Join(" "); Add("em").Text(command); Append(new LiteralTag(argsAndFlags)); }
public void VerifyResult() { lock (lockThis) { DownloadReportExample example = new DownloadReportExample(); example.Run(); // Assert correct download of completion report for a sender CompletionReport completionReportForSender = example.sdkCompletionReportForSenderDraft; SenderCompletionReport senderCompletionReportForSenderId1 = getSenderCompletionReportForSenderId(example.sdkCompletionReportForSenderDraft.Senders, example.senderUID); Assert.AreEqual(completionReportForSender.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId1.Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); AssertCreatedPackageIncludedInCompletionReport(completionReportForSender, example.senderUID, example.PackageId, "DRAFT"); Assert.IsNotNull(example.csvCompletionReportForSenderDraft); Assert.IsNotEmpty(example.csvCompletionReportForSenderDraft); CSVReader reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportForSenderDraft)))); IList <string[]> rows = reader.readAll(); if (senderCompletionReportForSenderId1.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, senderCompletionReportForSenderId1.Packages.Count - 1); Assert.LessOrEqual(rows.Count, senderCompletionReportForSenderId1.Packages.Count + 3); } AssertCreatedPackageIncludedInCSV(rows, example.PackageId, "DRAFT"); SenderCompletionReport senderCompletionReportForSenderId3 = getSenderCompletionReportForSenderId(example.sdkCompletionReportForSenderSent.Senders, example.senderUID); completionReportForSender = example.sdkCompletionReportForSenderSent; Assert.AreEqual(completionReportForSender.Senders.Count, 1, "There should be only 1 sender."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages.Count, 1, "Number of package completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages[0].Documents.Count, 1, "Number of document completion reports should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId3.Packages[0].Signers.Count, 1, "Number of signer completion reports should be greater than 1."); AssertCreatedPackageIncludedInCompletionReport(completionReportForSender, example.senderUID, example.package2Id, "SENT"); Assert.IsNotNull(example.csvCompletionReportForSenderSent); Assert.IsNotEmpty(example.csvCompletionReportForSenderSent); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportForSenderSent)))); rows = reader.readAll(); if (senderCompletionReportForSenderId3.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, senderCompletionReportForSenderId3.Packages.Count - 1); Assert.LessOrEqual(rows.Count, senderCompletionReportForSenderId3.Packages.Count + 3); } AssertCreatedPackageIncludedInCSV(rows, example.package2Id, "SENT"); // Assert correct download of completion report for all senders CompletionReport completionReport = example.sdkCompletionReportDraft; SenderCompletionReport senderCompletionReportForSenderId2 = getSenderCompletionReportForSenderId(completionReport.Senders, example.senderUID); Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "Number of sender should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId2.Packages.Count, 0, "Number of package completion reports should be greater than 0."); AssertCreatedPackageIncludedInCompletionReport(completionReport, example.senderUID, example.PackageId, "DRAFT"); Assert.IsNotNull(example.csvCompletionReportDraft); Assert.IsNotEmpty(example.csvCompletionReportDraft); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportDraft)))); rows = reader.readAll(); if (senderCompletionReportForSenderId2.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, GetCompletionReportCount(completionReport) - 1); Assert.LessOrEqual(rows.Count, GetCompletionReportCount(completionReport) + 3); } AssertCreatedPackageIncludedInCSV(rows, example.PackageId, "DRAFT"); completionReport = example.sdkCompletionReportSent; Assert.GreaterOrEqual(completionReport.Senders.Count, 1, "Number of sender should be greater than 1."); Assert.GreaterOrEqual(senderCompletionReportForSenderId2.Packages.Count, 0, "Number of package completion reports should be greater than 0."); AssertCreatedPackageIncludedInCompletionReport(completionReport, example.senderUID, example.package2Id, "SENT"); Assert.IsNotNull(example.csvCompletionReportSent); Assert.IsNotEmpty(example.csvCompletionReportSent); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvCompletionReportSent)))); rows = reader.readAll(); if (senderCompletionReportForSenderId2.Packages.Count > 0) { Assert.GreaterOrEqual(rows.Count, GetCompletionReportCount(completionReport) - 1); Assert.LessOrEqual(rows.Count, GetCompletionReportCount(completionReport) + 3); } AssertCreatedPackageIncludedInCSV(rows, example.package2Id, "SENT"); // Assert correct download of usage report UsageReport usageReport = example.sdkUsageReport; SenderUsageReport senderUsageReportForSenderId = getSenderUsageReportForSenderId(usageReport.SenderUsageReports, example.senderUID); Assert.Greater(usageReport.SenderUsageReports.Count, 0, "There should be only 1 sender."); Assert.GreaterOrEqual(senderUsageReportForSenderId.CountByUsageReportCategory.Count, 1, "Number of map entries should be greater or equal to 1."); Assert.IsTrue(senderUsageReportForSenderId.CountByUsageReportCategory.ContainsKey(UsageReportCategory.DRAFT), "There should be at a draft key in packages map."); Assert.GreaterOrEqual(senderUsageReportForSenderId.CountByUsageReportCategory[UsageReportCategory.DRAFT], 1, "Number of drafts should be greater or equal to 1."); Assert.IsNotNull(example.csvUsageReport, "Usage report in csv cannot be null."); Assert.IsNotEmpty(example.csvUsageReport, "Usage report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvUsageReport)))); rows = reader.readAll(); if (usageReport.SenderUsageReports.Count > 0) { Assert.GreaterOrEqual(rows.Count, usageReport.SenderUsageReports.Count - 1); Assert.LessOrEqual(rows.Count, usageReport.SenderUsageReports.Count + 3); } // Assert correct download of delegation report DelegationReport delegationReportForAccountWithoutDate = example.sdkDelegationReportForAccountWithoutDate; Assert.GreaterOrEqual(delegationReportForAccountWithoutDate.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForAccountWithoutDate, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForAccountWithoutDate, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForAccountWithoutDate)))); rows = reader.readAll(); if (delegationReportForAccountWithoutDate.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForAccountWithoutDate.DelegationEvents[example.senderUID].Count, rows.Count); } DelegationReport delegationReportForAccount = example.sdkDelegationReportForAccount; Assert.GreaterOrEqual(delegationReportForAccount.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForAccount, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForAccount, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForAccount)))); rows = reader.readAll(); if (delegationReportForAccount.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForAccount.DelegationEvents[example.senderUID].Count, rows.Count); } DelegationReport delegationReportForSender = example.sdkDelegationReportForSender; Assert.GreaterOrEqual(delegationReportForSender.DelegationEvents.Count, 0, "Number of DelegationEventReports should be greater than 0."); Assert.IsNotNull(example.csvDelegationReportForSender, "Delegation report in csv cannot be null."); Assert.IsNotEmpty(example.csvDelegationReportForSender, "Delegation report in csv cannot be empty."); reader = new CSVReader(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(example.csvDelegationReportForSender)))); rows = reader.readAll(); if (delegationReportForSender.DelegationEvents.Count > 0) { rows = GetRowsBySender(rows, example.senderUID); Assert.AreEqual(delegationReportForSender.DelegationEvents[example.senderUID].Count, rows.Count); } } }
internal void ReportUsageReport( long smallPoolInUseBytes, long smallPoolFreeBytes, long largePoolInUseBytes, long largePoolFreeBytes ) => UsageReport?.Invoke(smallPoolInUseBytes, smallPoolFreeBytes, largePoolInUseBytes, largePoolFreeBytes);
public Task SendUsageReportAsync(OwnerMetaData owner, UsageReport report) { UsageReport.Should().BeNull(); UsageReport = report; return(Task.CompletedTask); }
public void MessageReceiver(object sender, SPPMessage e) { BaseMessageParser parser = SPPMessageParserFactory.BuildParser(e); AnyMessageReceived?.Invoke(this, parser); switch (e.Id) { case SPPMessage.MessageIds.MSG_ID_RESET: ResetResponse?.Invoke(this, ((ResetResponseParser)parser).ResultCode); break; case SPPMessage.MessageIds.MSG_ID_FOTA_DEVICE_INFO_SW_VERSION: SwVersionResponse?.Invoke(this, ((SoftwareVersionOTAParser)parser).SoftwareVersion); break; case SPPMessage.MessageIds.MSG_ID_BATTERY_TYPE: BatteryTypeResponse?.Invoke(this, (BatteryTypeParser)parser); break; case SPPMessage.MessageIds.MSG_ID_AMBIENT_MODE_UPDATED: AmbientEnabledUpdateResponse?.Invoke(this, ((AmbientModeUpdateParser)parser).Enabled); break; case SPPMessage.MessageIds.MSG_ID_DEBUG_BUILD_INFO: BuildStringResponse?.Invoke(this, ((DebugBuildInfoParser)parser).BuildString); break; case SPPMessage.MessageIds.MSG_ID_DEBUG_GET_ALL_DATA: GetAllDataResponse?.Invoke(this, (DebugGetAllDataParser)parser); break; case SPPMessage.MessageIds.MSG_ID_DEBUG_SERIAL_NUMBER: SerialNumberResponse?.Invoke(this, (DebugSerialNumberParser)parser); break; case SPPMessage.MessageIds.MSG_ID_EXTENDED_STATUS_UPDATED: ExtendedStatusUpdate?.Invoke(this, (ExtendedStatusUpdateParser)parser); break; case SPPMessage.MessageIds.MSG_ID_FIND_MY_EARBUDS_STOP: FindMyGearStopped?.Invoke(this, null); break; case SPPMessage.MessageIds.MSG_ID_RESP: GenericResponse?.Invoke(this, (GenericResponseParser)parser); break; case SPPMessage.MessageIds.MSG_ID_SELF_TEST: SelfTestResponse?.Invoke(this, (SelfTestParser)parser); break; case SPPMessage.MessageIds.MSG_ID_SET_TOUCHPAD_OTHER_OPTION: OtherOption?.Invoke(this, ((SetOtherOptionParser)parser).OptionType); break; case SPPMessage.MessageIds.MSG_ID_STATUS_UPDATED: StatusUpdate?.Invoke(this, (StatusUpdateParser)parser); break; case SPPMessage.MessageIds.MSG_ID_USAGE_REPORT: UsageReport?.Invoke(this, (UsageReportParser)parser); break; case SPPMessage.MessageIds.MSG_ID_MUTE_EARBUD_STATUS_UPDATED: FindMyGearMuteUpdate?.Invoke(this, (MuteUpdateParser)parser); break; case SPPMessage.MessageIds.MSG_ID_ANC_STATUS_UPDATED: NoiseCancellingUpdated?.Invoke(this, ((NoiseCancellingUpdatedParser)parser).Enabled); break; } }
public void DispatchEvent(BaseMessageParser?parser, SPPMessage.MessageIds?ids = null) { AnyMessageReceived?.Invoke(this, parser); switch (ids ?? parser?.HandledType ?? 0) { case SPPMessage.MessageIds.RESET: ResetResponse?.Invoke(this, (parser as ResetResponseParser)?.ResultCode ?? -1); break; case SPPMessage.MessageIds.FOTA_DEVICE_INFO_SW_VERSION: SwVersionResponse?.Invoke(this, (parser as SoftwareVersionOTAParser)?.SoftwareVersion ?? "null"); break; case SPPMessage.MessageIds.BATTERY_TYPE: BatteryTypeResponse?.Invoke(this, (parser as BatteryTypeParser) !); break; case SPPMessage.MessageIds.AMBIENT_MODE_UPDATED: AmbientEnabledUpdateResponse?.Invoke(this, (parser as AmbientModeUpdateParser)?.Enabled ?? false); break; case SPPMessage.MessageIds.DEBUG_BUILD_INFO: BuildStringResponse?.Invoke(this, (parser as DebugBuildInfoParser)?.BuildString ?? "null"); break; case SPPMessage.MessageIds.DEBUG_GET_ALL_DATA: GetAllDataResponse?.Invoke(this, (parser as DebugGetAllDataParser) !); break; case SPPMessage.MessageIds.DEBUG_SERIAL_NUMBER: SerialNumberResponse?.Invoke(this, (parser as DebugSerialNumberParser) !); break; case SPPMessage.MessageIds.EXTENDED_STATUS_UPDATED: BaseUpdate?.Invoke(this, (parser as IBasicStatusUpdate) !); ExtendedStatusUpdate?.Invoke(this, (parser as ExtendedStatusUpdateParser) !); break; case SPPMessage.MessageIds.FIND_MY_EARBUDS_STOP: FindMyGearStopped?.Invoke(this, EventArgs.Empty); break; case SPPMessage.MessageIds.RESP: GenericResponse?.Invoke(this, (parser as GenericResponseParser) !); break; case SPPMessage.MessageIds.SELF_TEST: SelfTestResponse?.Invoke(this, (parser as SelfTestParser) !); break; case SPPMessage.MessageIds.SET_TOUCHPAD_OTHER_OPTION: OtherOption?.Invoke(this, (parser as SetOtherOptionParser) !.OptionType); break; case SPPMessage.MessageIds.STATUS_UPDATED: StatusUpdate?.Invoke(this, (parser as StatusUpdateParser) !); BaseUpdate?.Invoke(this, (parser as IBasicStatusUpdate) !); break; case SPPMessage.MessageIds.USAGE_REPORT: UsageReport?.Invoke(this, (parser as UsageReportParser) !); break; case SPPMessage.MessageIds.MUTE_EARBUD_STATUS_UPDATED: FindMyGearMuteUpdate?.Invoke(this, (parser as MuteUpdateParser) !); break; case SPPMessage.MessageIds.NOISE_REDUCTION_MODE_UPDATE: AncEnabledUpdateResponse?.Invoke(this, (parser as NoiseReductionModeUpdateParser)?.Enabled ?? false); break; case SPPMessage.MessageIds.NOISE_CONTROLS_UPDATE: NoiseControlUpdateResponse?.Invoke(this, (parser as NoiseControlUpdateParser)?.Mode ?? NoiseControlMode.Off); break; } }
static async Task Main(string[] args) { // Get the app settings var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); var config = builder.Build(); Program.AppSettings = new AppSettingsModel(); config.GetSection("AppSettings").Bind(Program.AppSettings); // Set the output folder if (string.IsNullOrEmpty(AppSettings.OutputFolder)) { Program.AppSettings.OutputFolder = Directory.GetCurrentDirectory(); } else { if (!Directory.Exists(Program.AppSettings.OutputFolder)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Output folder '{Program.AppSettings.OutputFolder}' not found."); } } // Get command Console.WriteLine("Type the command number and click enter"); Console.WriteLine(" Type 1 to export the auditing log"); Console.WriteLine(" Type 2 to export the usage log"); Console.WriteLine(" Type 3 to export all users in the directory"); Console.WriteLine(" Type 4 to get a specific user"); Console.WriteLine(" Type 5 to delete a user"); bool correctInput = false; while (!correctInput) { correctInput = true; string decision = Console.ReadLine(); int iDecision; if (int.TryParse(decision, out iDecision)) { switch (iDecision) { case 1: AuditLog auditLogs = new AuditLog(Program.AppSettings); await auditLogs.Run(); break; case 2: UsageReport usageReport = new UsageReport(Program.AppSettings); await usageReport.Run(); break; case 3: GetUsers getUsers = new GetUsers(Program.AppSettings); await getUsers.Run(); break; case 4: GetUser getUser = new GetUser(Program.AppSettings); await getUser.Run(); break; case 5: DeleteUser deleteUser = new DeleteUser(Program.AppSettings); await deleteUser.Run(); break; } } else { correctInput = false; } } Console.WriteLine("The report is ready!!!"); Console.ReadLine(); }