/// <summary> /// Select Seconds Of Type /// </summary> /// <param name="seconds">Seconds</param> /// <returns>Throughput</returns> public Throughput SelectSecondsOf(int seconds) { Contract.Requires <ArgumentOutOfRangeException>(0 < seconds); ////Don't Perf; too much logging var time = DateTime.UtcNow.AddSeconds(-1 * seconds); Throughput metrics = null; try { var results = from data in this.generalMetricTable.QueryByPartition(GeneralMetricRow.Partition()) where data.Time >= time select data; var list = results.ToList(); metrics = new Throughput() { ServerStatistics = list.Sum(m => m.ServerStatisticsCount), Messages = list.Sum(m => m.MessageCount), EventLog = list.Sum(m => m.EventLogCount), Exceptions = list.Sum(m => m.ErrorCount), Performance = list.Sum(m => m.PerformanceCount), }; } catch { ////Don't log, table misses are frequent } return(metrics ?? new Throughput()); }
private Throughput() { if (instance == null) { instance = new Throughput(); } }
private static Throughput CalculateThroughput(Device device, Bandwidth[] counters) { var throughput = new Throughput { Id = Guid.NewGuid(), DeviceIPAddress = device.IPAddress, Site = device.Site, Timestamp = counters[0].Timestamp, }; var time = (counters[0].Timestamp.Ticks - counters[1].Timestamp.Ticks) / 10000000; //dt var x0ingress = (counters[0].X0Ingress - counters[1].X0Ingress) * 8; //Octets to bits var x1ingress = (counters[0].X1Ingress - counters[1].X1Ingress) * 8; //Octets to bits var x2ingress = (counters[0].X2Ingress - counters[1].X2Ingress) * 8; //Octets to bits var x0egress = (counters[0].X0Egress - counters[1].X0Egress) * 8; //Octets to bits var x1egress = (counters[0].X1Egress - counters[1].X1Egress) * 8; //Octets to bits var x2egress = (counters[0].X2Egress - counters[1].X2Egress) * 8; //Octets to bits throughput.X0IngressThroughput = x0ingress / time; //bits / sec throughput.X1IngressThroughput = x1ingress / time; //bits / sec throughput.X2IngressThroughput = x2ingress / time; //bits / sec throughput.X0EgressThroughput = x0egress / time; //bits / sec throughput.X1EgressThroughput = x1egress / time; //bits / sec throughput.X2EgressThroughput = x2egress / time; //bits / sec return(throughput); }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = resourceIdentifier.ResourceName; } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } MongoDBDatabaseCreateUpdateParameters mongoDBDatabaseCreateUpdateParameters = new MongoDBDatabaseCreateUpdateParameters { Resource = new MongoDBDatabaseResource { Id = Name }, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB MongoDB Database")) { MongoDBDatabaseGetResults mongoDBDatabaseGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, mongoDBDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSMongoDBDatabaseGetResults(mongoDBDatabaseGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = resourceIdentifier.ResourceName; } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } TableCreateUpdateParameters tableCreateUpdateParameters = new TableCreateUpdateParameters { Resource = new TableResource { Id = Name }, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB Table")) { TableGetResults tableGetResults = CosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, tableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSTableGetResults(tableGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; KeyspaceName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } CassandraTableGetResults readCassandraTableGetResults = null; try { readCassandraTableGetResults = CosmosDBManagementClient.CassandraResources.GetCassandraTable(ResourceGroupName, AccountName, KeyspaceName, Name); } catch (CloudException e) { if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } if (readCassandraTableGetResults != null) { throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name)); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } CassandraTableResource cassandraTableResource = new CassandraTableResource { Id = Name, DefaultTtl = TtlInSeconds }; cassandraTableResource.Schema = PSCassandraSchema.ToSDKModel(Schema); CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters { Resource = cassandraTableResource, Options = options }; if (ShouldProcess(Name, "Creating a new CosmosDB Cassandra Table")) { CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults)); } return; }
// // public Packet(byte[] raw):(byte[] raw, DateTime time // { // Packet(raw, DateTime.Now); // } public Packet(byte[] raw, DateTime time) { if (raw == null) { throw new ArgumentNullException(); } if (raw.Length < 20) { throw new ArgumentException(); } this.m_Raw = raw; this.m_Time = time; this.m_HeaderLength = (raw[0] & 0xF) * 4; if ((raw[0] & 0xF) < 5) { throw new ArgumentException(); } this.m_Precedence = (Precedence)((raw[1] & 0xE0) >> 5); this.m_Delay = (Delay)((raw[1] & 0x10) >> 4); this.m_Throughput = (Throughput)((raw[1] & 0x8) >> 3); this.m_Reliability = (Reliability)((raw[1] & 0x4) >> 2); this.m_TotalLength = raw[2] * 256 + raw[3]; if (!(this.m_TotalLength == raw.Length)) { throw new ArgumentException(); } // invalid size of packet; this.m_Identification = raw[4] * 256 + raw[5]; this.m_TimeToLive = raw[8]; m_Protocol = (InternetProtocol)raw[9]; m_Checksum = new byte[2]; m_Checksum[0] = raw[11]; m_Checksum[1] = raw[10]; try { m_SourceAddress = GetIPAddress(raw, 12); m_DestinationAddress = GetIPAddress(raw, 16); } catch (Exception e) { throw; } if (m_Protocol == InternetProtocol.Tcp || m_Protocol == InternetProtocol.Udp) { m_SourcePort = raw[m_HeaderLength] * 256 + raw[m_HeaderLength + 1]; m_DestinationPort = raw[m_HeaderLength + 2] * 256 + raw[m_HeaderLength + 3]; } else { m_SourcePort = -1; m_DestinationPort = -1; } }
/// <summary> /// Update Throughput /// </summary> /// <param name="obj">Data</param> private static void UpdateThroughput(object obj) { const int Frequency = 1; if (lastRequest > DateTime.UtcNow.AddSeconds(-30)) { throughput = Logging.SelectSecondsOf(Frequency); } }
public void Performance() { var random = new Random(); var data = new Throughput(); var expected = random.Next(); data.Performance = expected; Assert.AreEqual <int>(expected, data.Performance); }
public void EventLog() { var random = new Random(); var data = new Throughput(); var expected = random.Next(); data.EventLog = expected; Assert.AreEqual <int>(expected, data.EventLog); }
public void Messages() { var random = new Random(); var data = new Throughput(); var expected = random.Next(); data.Messages = expected; Assert.AreEqual <int>(expected, data.Messages); }
public void ServerStatistics() { var random = new Random(); var data = new Throughput(); var expected = random.Next(); data.ServerStatistics = expected; Assert.AreEqual <int>(expected, data.ServerStatistics); }
public void Exceptions() { var random = new Random(); var data = new Throughput(); var expected = random.Next(); data.Exceptions = expected; Assert.AreEqual <int>(expected, data.Exceptions); }
public void ReturnWindowParams() { //GUIWindow.PrintLog(Throughput.GetItemText(this.Throughput.SelectedItem)); if (!Int32.TryParse(Throughput.GetItemText(this.Throughput.SelectedItem).Trim(), out requestedBandwidth)) { //GUIWindow.PrintLog("formatowanie blad"); } receiver = Destination.Text; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } MongoDBCollectionResource mongoDBCollectionResource = new MongoDBCollectionResource { Id = Name }; if (Shard != null) { mongoDBCollectionResource.ShardKey = new Dictionary <string, string> { { Shard, "Hash" } }; } if (Index != null) { List <MongoIndex> Indexes = new List <MongoIndex>(); foreach (PSMongoIndex psMongoIndex in Index) { Indexes.Add(PSMongoIndex.ConvertPSMongoIndexToMongoIndex(psMongoIndex)); } mongoDBCollectionResource.Indexes = Indexes; } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters { Resource = mongoDBCollectionResource, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB MongoDB Collection")) { MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = resourceIdentifier.ResourceName; } else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); Name = resourceIdentifier.ResourceName; } TableGetResults readTableGetResults = null; try { readTableGetResults = CosmosDBManagementClient.TableResources.GetTable(ResourceGroupName, AccountName, Name); } catch (CloudException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e); } } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } TableCreateUpdateParameters tableCreateUpdateParameters = new TableCreateUpdateParameters { Resource = new TableResource { Id = Name }, Options = options }; if (ShouldProcess(Name, "Updating an existing CosmosDB Table")) { TableGetResults tableGetResults = CosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, tableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSTableGetResults(tableGetResults)); } return; }
public Packet(byte[] raw, DateTime time) { if (raw == null) { throw new ArgumentNullException(); } if (raw.Length < 20) { throw new ArgumentException(); // invalid IP packet } m_Raw = raw; m_Time = time; m_Version = (raw[0] & 0xF0) >> 4; m_HeaderLength = (raw[0] & 0x0F) * 4 /* sizeof(int) */; if ((raw[0] & 0x0F) < 5) { throw new ArgumentException(); // invalid header of packet } m_Precedence = (Precedence)((raw[1] & 0xE0) >> 5); m_Delay = (Delay)((raw[1] & 0x10) >> 4); m_Throughput = (Throughput)((raw[1] & 0x8) >> 3); m_Reliability = (Reliability)((raw[1] & 0x4) >> 2); m_TotalLength = raw[2] * 256 + raw[3]; if (m_TotalLength != raw.Length) { throw new ArgumentException(); // invalid size of packet } m_Identification = raw[4] * 256 + raw[5]; m_TimeToLive = raw[8]; if (Enum.IsDefined(typeof(Protocol), (int)raw[9])) { m_Protocol = (Protocol)raw[9]; } else { m_Protocol = Protocol.Other; } m_Checksum = new byte[2]; m_Checksum[0] = raw[11]; m_Checksum[1] = raw[10]; m_SourceAddress = new IPAddress(BitConverter.ToUInt32(raw, 12)); m_DestinationAddress = new IPAddress(BitConverter.ToUInt32(raw, 16)); if (m_Protocol == Protocol.Tcp || m_Protocol == Protocol.Udp) { m_SourcePort = raw[m_HeaderLength] * 256 + raw[m_HeaderLength + 1]; m_DestinationPort = raw[m_HeaderLength + 2] * 256 + raw[m_HeaderLength + 3]; } else { m_SourcePort = -1; m_DestinationPort = -1; } }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = resourceIdentifier.ResourceName; } GremlinDatabaseGetResults readGremlinDatabaseGetResults = null; try { readGremlinDatabaseGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinDatabase(ResourceGroupName, AccountName, Name); } catch (CloudException e) { if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } if (readGremlinDatabaseGetResults != null) { throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name)); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters { Resource = new GremlinDatabaseResource { Id = Name }, Options = options }; if (ShouldProcess(Name, "Creating a new CosmosDB Gremlin Database")) { GremlinDatabaseGetResults gremlinDatabaseGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSGremlinDatabaseGetResults(gremlinDatabaseGetResults)); } return; }
public void RegisterMetrics(MetricFactory metrics) { if (!_threadPoolInfo.Enabled && !_runtimeCounters.Enabled) { return; } NumThreads = metrics.CreateGauge("dotnet_threadpool_num_threads", "The number of active threads in the thread pool"); _runtimeCounters.Events.ThreadPoolThreadCount += e => NumThreads.Set(e.Mean); Throughput = metrics.CreateCounter("dotnet_threadpool_throughput_total", "The total number of work items that have finished execution in the thread pool"); _runtimeCounters.Events.ThreadPoolCompletedItemsCount += e => Throughput.Inc(e.IncrementedBy); QueueLength = metrics.CreateHistogram("dotnet_threadpool_queue_length", "Measures the queue length of the thread pool. Values greater than 0 indicate a backlog of work for the threadpool to process.", new HistogramConfiguration { Buckets = _options.QueueLengthHistogramBuckets } ); _runtimeCounters.Events.ThreadPoolQueueLength += e => QueueLength.Observe(e.Mean); NumTimers = metrics.CreateGauge("dotnet_threadpool_timer_count", "The number of timers active"); _runtimeCounters.Events.ActiveTimerCount += e => NumTimers.Set(e.Mean); if (_threadPoolInfo.Enabled) { AdjustmentsTotal = metrics.CreateCounter( "dotnet_threadpool_adjustments_total", "The total number of changes made to the size of the thread pool, labeled by the reason for change", "adjustment_reason"); _threadPoolInfo.Events.ThreadPoolAdjusted += e => { AdjustmentsTotal.Labels(_adjustmentReasonToLabel[e.AdjustmentReason]).Inc(); }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // IO threadpool only exists on windows NumIocThreads = metrics.CreateGauge("dotnet_threadpool_io_num_threads", "The number of active threads in the IO thread pool"); _threadPoolInfo.Events.IoThreadPoolAdjusted += e => NumIocThreads.Set(e.NumThreads); } } }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = resourceIdentifier.ResourceName; } else if (ParameterSetName.Equals(ObjectParameterSet)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); Name = resourceIdentifier.ResourceName; } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters { Resource = new GremlinDatabaseResource { Id = Name }, Options = options }; if (ShouldProcess(Name, "Updating CosmosDB Gremlin Database")) { GremlinDatabaseGetResults gremlinDatabaseGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(ResourceGroupName, AccountName, Name, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSGremlinDatabaseGetResults(gremlinDatabaseGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; KeyspaceName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } CassandraTableResource cassandraTableResource = new CassandraTableResource { Id = Name, DefaultTtl = TtlInSeconds }; cassandraTableResource.Schema = PSCassandraSchema.ConvertPSCassandraSchemaToCassandraSchema(Schema); CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters { Resource = cassandraTableResource, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB Cassandra Table")) { CassandraTableGetResults cassandraTableGetResults = CosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSCassandraTableGetResults(cassandraTableGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } SqlContainerResource sqlContainerResource = new SqlContainerResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); foreach (PSSqlUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKey) { UniqueKey key = new UniqueKey(uniqueKey.Path); uniqueKeyPolicy.UniqueKeys.Add(key); } sqlContainerResource.UniqueKeyPolicy = uniqueKeyPolicy; } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicy.Type }; if (ConflictResolutionPolicy.Type.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicy.Path; } else if (ConflictResolutionPolicy.Type.Equals("Custom", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { IList <IncludedPath> includedPaths = new List <IncludedPath>(); IList <ExcludedPath> excludedPaths = new List <ExcludedPath>(); foreach (string path in IndexingPolicy.IncludedPaths) { includedPaths.Add(new IncludedPath(path: path)); } foreach (string path in IndexingPolicy.ExcludedPaths) { excludedPaths.Add(new ExcludedPath(path: path)); } IndexingPolicy indexingPolicy = new IndexingPolicy { Automatic = IndexingPolicy.Automatic, IndexingMode = IndexingPolicy.IndexingMode, IncludedPaths = includedPaths, ExcludedPaths = excludedPaths }; sqlContainerResource.IndexingPolicy = indexingPolicy; } IDictionary <string, string> options = new Dictionary <string, string>(); if (Throughput != null) { options.Add("Throughput", Throughput.ToString()); } SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Creating or Updating CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } else if (ParameterSetName.Equals(ObjectParameterSet)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = ResourceIdentifierExtensions.GetGremlinDatabaseName(resourceIdentifier); AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); Name = resourceIdentifier.ResourceName; } GremlinGraphGetResults readGremlinGraphGetResults = null; try { readGremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.GetGremlinGraph(ResourceGroupName, AccountName, DatabaseName, Name); } catch (CloudException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e); } } GremlinGraphResource gremlinGraphResource = UpdateAzCosmosDBGremlinGraph.PopulateGremlinGraphResourceResource(readGremlinGraphGetResults.Resource); if (PartitionKeyPath != null) { List <string> Paths = new List <string>(PartitionKeyPath); gremlinGraphResource.PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion }; } if (UniqueKeyPolicy != null) { gremlinGraphResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ToSDKModel(UniqueKeyPolicy); } if (TtlInSeconds != null) { gremlinGraphResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { gremlinGraphResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ToSDKModel(ConflictResolutionPolicy); } if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.LastWriterWins, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.Custom, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } gremlinGraphResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { gremlinGraphResource.IndexingPolicy = PSIndexingPolicy.ToSDKModel(IndexingPolicy); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters { Resource = gremlinGraphResource, Options = options }; if (ShouldProcess(Name, "Updating CosmosDB Gremlin Graph")) { GremlinGraphGetResults gremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSGremlinGraphGetResults(gremlinGraphGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; Name = resourceIdentifier.ResourceName; DatabaseName = ResourceIdentifierExtensions.GetMongoDBDatabaseName(resourceIdentifier); AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } MongoDBCollectionGetResults readMongoDBCollectionGetResults = null; try { readMongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.GetMongoDBCollection(ResourceGroupName, AccountName, DatabaseName, Name); } catch (CloudException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e); } } MongoDBCollectionResource mongoDBCollectionResource = PopulateMongoDBResource(readMongoDBCollectionGetResults.Resource); if (Shard != null) { mongoDBCollectionResource.ShardKey = new Dictionary <string, string> { { Shard, "Hash" } }; } if (Index != null) { List <MongoIndex> Indexes = new List <MongoIndex>(); foreach (PSMongoIndex psMongoIndex in Index) { Indexes.Add(PSMongoIndex.ConvertPSMongoIndexToMongoIndex(psMongoIndex)); } mongoDBCollectionResource.Indexes = Indexes; } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters { Resource = mongoDBCollectionResource, Options = options }; if (ShouldProcess(Name, "Updating an existing CosmosDB MongoDB Collection")) { MongoDBCollectionGetResults mongoDBCollectionGetResults = CosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSMongoDBCollectionGetResults(mongoDBCollectionGetResults)); } return; }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } SqlContainerGetResults readSqlContainerGetResults = null; try { readSqlContainerGetResults = CosmosDBManagementClient.SqlResources.GetSqlContainer(ResourceGroupName, AccountName, DatabaseName, Name); } catch (CloudException e) { if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } if (readSqlContainerGetResults != null) { throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name)); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } SqlContainerResource sqlContainerResource = new SqlContainerResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { sqlContainerResource.UniqueKeyPolicy = PSUniqueKeyPolicy.ConvertPSUniqueKeyPolicyToUniqueKeyPolicy(UniqueKeyPolicy); } if (TtlInSeconds != null) { sqlContainerResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { sqlContainerResource.ConflictResolutionPolicy = PSConflictResolutionPolicy.ConvertPSConflictResolutionPolicyToConflictResolutionPolicy(ConflictResolutionPolicy); } if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.LastWriterWins, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals(ConflictResolutionMode.Custom, StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } sqlContainerResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { sqlContainerResource.IndexingPolicy = PSIndexingPolicy.ConvertPSIndexingToIndexingPolicy(IndexingPolicy); } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters { Resource = sqlContainerResource, Options = options }; if (ShouldProcess(Name, "Creating a new CosmosDB Sql Container")) { SqlContainerGetResults sqlContainerGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSSqlContainerGetResults(sqlContainerGetResults)); } return; }
public static void Save() { if (instance == null) { instance = new SaveClickData(); } string output = ""; var sample = Variables.SampleNumber; Variables.SampleNumber++; var unixTIme = Variables.GetCurrentUnixTimestampMillis(); var SubjectID = Variables.UserId; var TargetNo = Variables.ButtonNames[Variables.NextIndex]; var CurrentHandGameObject = instance._objects.HandController.GetComponent <GetHandMovement>().GetCurrentHand().name; var displacement = CurrentHandGameObject.Split('_')[3]; var texture = CurrentHandGameObject.Split('_')[4]; var amplitude = Variables.Amplitude; var buttonWidth = Variables.ButtonWidthModifier; var ID = Mathf.Log(amplitude / (buttonWidth) + 0.5f, 2); bool Hit = !Variables.ButtonMissedFlag; if (Hit) { if (_repetitionDict.ContainsKey(ID)) { _repetitionDict[ID]++; } else { _repetitionDict.Add(ID, 1); } } var Repetition = (int)(_repetitionDict[ID] / 16) + 1; var duration = Hit ? Variables.Duration: Variables.MissedTimeSinceLastHit; var throughput = Throughput.CalculateTp(ID, Variables.DurationArray.ToArray()); var posTargetX = TargetNo.transform.localPosition.x; var posTargetZ = TargetNo.transform.localPosition.z; var posFingerX = Variables.ClickPositionX; var posFingerZ = Variables.ClickPositionY; var distance = Mathf.Sqrt(Mathf.Pow(posTargetX - posFingerX, 2) + Mathf.Pow(posTargetZ - posFingerZ, 2)); output += sample + CSV_SEPARATOR + unixTIme + CSV_SEPARATOR + SubjectID + CSV_SEPARATOR + CurrentHandGameObject + CSV_SEPARATOR + texture + CSV_SEPARATOR + displacement + CSV_SEPARATOR + ID + CSV_SEPARATOR + buttonWidth + CSV_SEPARATOR + amplitude + CSV_SEPARATOR + duration + CSV_SEPARATOR + TargetNo.name + CSV_SEPARATOR + Hit + CSV_SEPARATOR + Repetition + CSV_SEPARATOR + throughput + CSV_SEPARATOR + posTargetX + CSV_SEPARATOR + posTargetZ + CSV_SEPARATOR + posFingerX + CSV_SEPARATOR + posFingerZ + CSV_SEPARATOR + distance + CSV_SEPARATOR + Variables.LastRoundFailed; instance.sw.Write(output + "\r\n"); instance.sw.Flush(); }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id); ResourceGroupName = resourceIdentifier.ResourceGroupName; DatabaseName = resourceIdentifier.ResourceName; AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier); } List <string> Paths = new List <string>(); foreach (string path in PartitionKeyPath) { Paths.Add(path); } GremlinGraphResource gremlinGraphResource = new GremlinGraphResource { Id = Name, PartitionKey = new ContainerPartitionKey { Kind = PartitionKeyKind, Paths = Paths, Version = PartitionKeyVersion } }; if (UniqueKeyPolicy != null) { UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy { UniqueKeys = new List <UniqueKey>() }; foreach (PSUniqueKey uniqueKey in UniqueKeyPolicy.UniqueKeys) { UniqueKey key = new UniqueKey { Paths = new List <string>() }; foreach (string path in uniqueKey.Paths) { key.Paths.Add(path); } uniqueKeyPolicy.UniqueKeys.Add(key); } gremlinGraphResource.UniqueKeyPolicy = uniqueKeyPolicy; } if (TtlInSeconds != null) { gremlinGraphResource.DefaultTtl = TtlInSeconds; } if (ConflictResolutionPolicy != null) { ConflictResolutionPolicyMode = ConflictResolutionPolicy.Mode; if (ConflictResolutionPolicy.ConflictResolutionPath != null) { ConflictResolutionPolicyPath = ConflictResolutionPolicy.ConflictResolutionPath; } if (ConflictResolutionPolicy.ConflictResolutionProcedure != null) { ConflictResolutionPolicyProcedure = ConflictResolutionPolicy.ConflictResolutionProcedure; } } if (ConflictResolutionPolicyMode != null) { ConflictResolutionPolicy conflictResolutionPolicy = new ConflictResolutionPolicy { Mode = ConflictResolutionPolicyMode }; if (ConflictResolutionPolicyMode.Equals("LastWriterWins", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionPath = ConflictResolutionPolicyPath; } else if (ConflictResolutionPolicyMode.Equals("Custom", StringComparison.OrdinalIgnoreCase)) { conflictResolutionPolicy.ConflictResolutionProcedure = ConflictResolutionPolicyProcedure; } gremlinGraphResource.ConflictResolutionPolicy = conflictResolutionPolicy; } if (IndexingPolicy != null) { IndexingPolicy indexingPolicy = new IndexingPolicy { Automatic = IndexingPolicy.Automatic, IndexingMode = IndexingPolicy.IndexingMode, }; if (IndexingPolicy.IncludedPaths != null) { IList <IncludedPath> includedPaths = new List <IncludedPath>(); foreach (PSIncludedPath pSIncludedPath in IndexingPolicy.IncludedPaths) { includedPaths.Add(new IncludedPath { Path = pSIncludedPath.Path, Indexes = PSIncludedPath.ConvertPSIndexesToIndexes(pSIncludedPath.Indexes) }); } indexingPolicy.IncludedPaths = new List <IncludedPath>(includedPaths); } if (IndexingPolicy.ExcludedPaths != null && IndexingPolicy.ExcludedPaths.Count > 0) { IList <ExcludedPath> excludedPaths = new List <ExcludedPath>(); foreach (PSExcludedPath pSExcludedPath in IndexingPolicy.ExcludedPaths) { excludedPaths.Add(new ExcludedPath { Path = pSExcludedPath.Path }); } indexingPolicy.ExcludedPaths = new List <ExcludedPath>(excludedPaths); } if (IndexingPolicy.CompositeIndexes != null) { IList <IList <CompositePath> > compositeIndexes = new List <IList <CompositePath> >(); foreach (IList <PSCompositePath> pSCompositePathList in IndexingPolicy.CompositeIndexes) { IList <CompositePath> compositePathList = new List <CompositePath>(); foreach (PSCompositePath pSCompositePath in pSCompositePathList) { compositePathList.Add(new CompositePath { Order = pSCompositePath.Order, Path = pSCompositePath.Path }); } compositeIndexes.Add(compositePathList); } indexingPolicy.CompositeIndexes = new List <IList <CompositePath> >(compositeIndexes); } if (IndexingPolicy.SpatialIndexes != null && IndexingPolicy.SpatialIndexes.Count > 0) { IList <SpatialSpec> spatialIndexes = new List <SpatialSpec>(); foreach (PSSpatialSpec pSSpatialSpec in IndexingPolicy.SpatialIndexes) { spatialIndexes.Add(new SpatialSpec { Path = pSSpatialSpec.Path, Types = pSSpatialSpec.Types }); } indexingPolicy.SpatialIndexes = new List <SpatialSpec>(spatialIndexes); } gremlinGraphResource.IndexingPolicy = indexingPolicy; } CreateUpdateOptions options = new CreateUpdateOptions(); if (Throughput != null) { options.Throughput = Throughput.ToString(); } GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters { Resource = gremlinGraphResource, Options = options }; if (ShouldProcess(Name, "Setting CosmosDB Gremlin Graph")) { GremlinGraphGetResults gremlinGraphGetResults = CosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body; WriteObject(new PSGremlinGraphGetResults(gremlinGraphGetResults)); } return; }
public void ComputeResults() { this.computedResults = new Throughput(this); }
public Packet(byte[] raw, DateTime time) { if (raw != null) { if ((int)raw.Length >= 20) { this.m_Raw = raw; this.m_Time = time; this.m_HeaderLength = (raw[0] & 15) * 4; if ((raw[0] & 15) >= 5) { this.m_Precedence = (Precedence)((raw[1] & 224) >> 5); this.m_Delay = (Delay)((raw[1] & 16) >> 4); this.m_Throughput = (Throughput)((raw[1] & 8) >> 3); this.m_Reliability = (Reliability)((raw[1] & 4) >> 2); this.m_TotalLength = raw[2] * 0x100 + raw[3]; if (this.m_TotalLength == (int)raw.Length) { this.m_Identification = raw[4] * 0x100 + raw[5]; this.m_TimeToLive = raw[8]; this.m_Protocol = (Protocol)raw[9]; this.m_Checksum = new byte[2]; this.m_Checksum[0] = raw[11]; this.m_Checksum[1] = raw[10]; try { this.m_SourceAddress = this.GetIPAddress(raw, 12); this.m_DestinationAddress = this.GetIPAddress(raw, 16); } catch { throw; } if (this.m_Protocol == Protocol.Tcp || this.m_Protocol == Protocol.Udp) { this.m_SourcePort = raw[this.m_HeaderLength] * 0x100 + raw[this.m_HeaderLength + 1]; this.m_DestinationPort = raw[this.m_HeaderLength + 2] * 0x100 + raw[this.m_HeaderLength + 3]; return; } else { this.m_SourcePort = -1; this.m_DestinationPort = -1; return; } } else { throw new ArgumentException(); } } else { throw new ArgumentException(); } } else { throw new ArgumentException(); } } else { throw new ArgumentNullException(); } }
public Packet(byte[] raw, DateTime time) { if (raw == null) throw new ArgumentNullException(); if (raw.Length < 20) throw new ArgumentException(); // invalid IP packet m_Raw = raw; m_Time = time; m_Version = (raw[0] & 0xF0) >> 4; m_HeaderLength = (raw[0] & 0x0F) * 4 /* sizeof(int) */; if ((raw[0] & 0x0F) < 5) throw new ArgumentException(); // invalid header of packet m_Precedence = (Precedence)((raw[1] & 0xE0) >> 5); m_Delay = (Delay)((raw[1] & 0x10) >> 4); m_Throughput = (Throughput)((raw[1] & 0x8) >> 3); m_Reliability = (Reliability)((raw[1] & 0x4) >> 2); m_TotalLength = raw[2] * 256 + raw[3]; if (m_TotalLength != raw.Length) throw new ArgumentException(); // invalid size of packet m_Identification = raw[4] * 256 + raw[5]; m_TimeToLive = raw[8]; if (Enum.IsDefined(typeof(Protocol), (int)raw[9])) m_Protocol = (Protocol)raw[9]; else m_Protocol = Protocol.Other; m_Checksum = new byte[2]; m_Checksum[0] = raw[11]; m_Checksum[1] = raw[10]; m_SourceAddress = new IPAddress(BitConverter.ToUInt32(raw, 12)); m_DestinationAddress = new IPAddress(BitConverter.ToUInt32(raw, 16)); if (m_Protocol == Protocol.Tcp || m_Protocol == Protocol.Udp) { m_SourcePort = raw[m_HeaderLength] * 256 + raw[m_HeaderLength + 1]; m_DestinationPort = raw[m_HeaderLength + 2] * 256 + raw[m_HeaderLength + 3]; } else { m_SourcePort = -1; m_DestinationPort = -1; } }