private HttpContext GetContext(ClusterInfo cluster, int selectedDestination, IProxyErrorFeature error) { var context = new DefaultHttpContext(); context.Features.Set(GetProxyFeature(cluster.Config, cluster.DynamicState.AllDestinations[selectedDestination])); context.Features.Set(error); context.SetEndpoint(GetEndpoint(cluster)); return(context); }
public void Handle(SystemMessage.SystemInit message) { if (_state != GossipState.Startup) { return; } _cluster = new ClusterInfo(GetInitialMe()); Handle(new GossipMessage.RetrieveGossipSeedSources()); }
internal void ProcessLoginGetListReply(LoginGetListReplyPacket loginGetListReplyPacket, LoginGetListPacket loginGetListPacket) { QQEventArgs <LoginGetListReplyPacket, LoginGetListPacket> e = new QQEventArgs <LoginGetListReplyPacket, LoginGetListPacket>(QQClient, loginGetListReplyPacket, loginGetListPacket); foreach (QQ.Entities.QQBasicInfo qq in loginGetListReplyPacket.QQList) { if (!QQClient.QQUser.QQList.ContainsKey(qq.QQ)) { QQClient.QQUser.QQList.Add(qq.QQ, qq); } } StringBuilder sb = new StringBuilder(); sb.AppendLine("本次得到QQ " + loginGetListReplyPacket.QQList.Count + " 个。"); #if DEBUG foreach (QQ.Entities.QQBasicInfo qq in loginGetListReplyPacket.QQList) { sb.AppendLine(string.Format("\t\tQQ:{0} type:{1} group: {2} ", qq.QQ, qq.Type, qq.GroupId)); } #endif QQClient.LogManager.Log(sb.ToString()); //应该将QQ好友,QQ群存入存入QQuser对象 if (!e.InPacket.Finished)//好友没有下载完,继续下载 { //LoginGetList(e.InPacket.NextPos); LoginGetList(++lisPackets); } else //好友下载完毕 触发事件 { QQClient.LogManager.Log("获取全部好友完成!"); //分到各自的列表组 foreach (QQBasicInfo qq in QQClient.QQUser.QQList.Values) { switch (qq.Type) { case QQType.Cluster: ClusterInfo ClusterInfo = new ClusterInfo(); ClusterInfo.QQBasicInfo = qq; QQClient.QQUser.ClusterList.Add(qq.QQ, ClusterInfo); break; case QQType.QQ: QQFriend QQFriend = new QQFriend(); QQFriend.QQBasicInfo = qq; QQClient.QQUser.Friends.Add(qq.QQ, QQFriend); break; default: QQClient.LogManager.Log("unknown QQ.Type: 0x" + qq.Type.ToString("X") + " qq=" + qq.QQ.ToString() + " gid=0x" + qq.GroupId.ToString("X2")); break; } } OutPacket outPacket = new LoginSendInfoPacket(this.QQClient); QQClient.PacketManager.SendPacketAnyway(outPacket, QQPort.Main.Name); } }
public IList <P> RunCluster() { // Skip points outside the grid, not visible to user then skip those IList <P> filtered = ClusterInfo.DoFilterData(this._jsonReceive.Zoomlevel) ? FilterUtil.FilterDataByViewport(this.points, Grid) : this.points; // Put points in buckets foreach (var p in filtered) { var idxy = GetPointMappedIds(p, Grid, DeltaX, DeltaY); var idx = idxy[0]; var idy = idxy[1]; // Bucket id var id = GetId(idx, idy); // Bucket exists, add point if (BucketsLookup.ContainsKey(id)) { BucketsLookup[id].Points.Add(p); } // New bucket, create and add point else { var bucket = new Bucket(idx, idy, id); bucket.Points.Add(p); BucketsLookup.Add(id, bucket); } } // Calculate centroid for all buckets SetCentroidForAllBuckets(BucketsLookup.Values); // Merge if gridpoint is to close if (GmcSettings.Get.DoMergeGridIfCentroidsAreCloseToEachOther) { MergeClustersGrid(); } if (GmcSettings.Get.DoUpdateAllCentroidsToNearestContainingPoint) { UpdateAllCentroidsToNearestContainingPoint(); } // Check again // Merge if gridpoint is to close if (GmcSettings.Get.DoMergeGridIfCentroidsAreCloseToEachOther && GmcSettings.Get.DoUpdateAllCentroidsToNearestContainingPoint) { MergeClustersGrid(); // And again set centroid to closest point in bucket UpdateAllCentroidsToNearestContainingPoint(); } return(GetClusterResult(Grid)); }
private IReverseProxyFeature GetProxyFeature(ClusterInfo clusterInfo, DestinationInfo destination) { return(new ReverseProxyFeature() { ProxiedDestination = destination, ClusterSnapshot = clusterInfo.Config, RouteSnapshot = new RouteConfig(new ProxyRoute(), clusterInfo, HttpTransformer.Default), }); }
public void OnClusterAdded(ClusterInfo cluster) { var activeHealthCheckOptions = cluster.Config.Options.HealthCheck?.Active; if ((activeHealthCheckOptions?.Enabled).GetValueOrDefault()) { _scheduler.ScheduleEntity(cluster, activeHealthCheckOptions.Interval ?? _monitorOptions.DefaultInterval); } }
public static ClusterInfo UpdateCluster(ClusterInfo cluster, Func <MemberInfo, MemberInfo> update, ITimeProvider timeProvider, TimeSpan deadMemberRemovalTimeout) { // update members and remove dead timed-out members, if there are any var newMembers = cluster.Members.Select(update) .Where(x => x.IsAlive || timeProvider.UtcNow - x.TimeStamp < deadMemberRemovalTimeout); return(new ClusterInfo(newMembers)); }
public async Task Invoke_SetsFeatures() { var proxyHttpClientFactoryMock = new Mock <IProxyHttpClientFactory>(); var cluster1 = new ClusterInfo( clusterId: "cluster1", destinationManager: new DestinationManager(), proxyHttpClientFactory: proxyHttpClientFactoryMock.Object); cluster1.Config.Value = new ClusterConfig(default, default, default);
public void SetActive(ClusterInfo cluster, IEnumerable <NewActiveDestinationHealth> newHealthStates) { foreach (var newHealthState in newHealthStates) { newHealthState.Destination.Health.Active = newHealthState.NewActiveHealth; } cluster.UpdateDynamicState(); }
public async Task Invoke_Works() { var proxyHttpClientFactoryMock = new Mock <IProxyHttpClientFactory>(); var cluster1 = new ClusterInfo( clusterId: "cluster1", destinationManager: new DestinationManager(), proxyHttpClientFactory: proxyHttpClientFactoryMock.Object); cluster1.Config.Value = new ClusterConfig(default, new ClusterConfig.ClusterLoadBalancingOptions(LoadBalancingMode.RoundRobin), default);
public async Task NoDestinations_503() { var httpContext = new DefaultHttpContext(); httpContext.Request.Method = "GET"; httpContext.Request.Scheme = "https"; httpContext.Request.Host = new HostString("example.com"); var httpClient = new HttpMessageInvoker(new Mock <HttpMessageHandler>().Object); var cluster1 = new ClusterInfo( clusterId: "cluster1", destinationManager: new DestinationManager()); var clusterConfig = new ClusterConfig(new Cluster(), httpClient); httpContext.Features.Set <IReverseProxyFeature>( new ReverseProxyFeature() { AvailableDestinations = Array.Empty <DestinationInfo>(), ClusterConfig = clusterConfig }); httpContext.Features.Set(cluster1); var aspNetCoreEndpoints = new List <Endpoint>(); var routeConfig = new RouteConfig( route: new RouteInfo("route1"), proxyRoute: new ProxyRoute(), cluster: cluster1, transformer: null); var aspNetCoreEndpoint = CreateAspNetCoreEndpoint(routeConfig); aspNetCoreEndpoints.Add(aspNetCoreEndpoint); httpContext.SetEndpoint(aspNetCoreEndpoint); Mock <IHttpProxy>() .Setup(h => h.ProxyAsync( httpContext, It.IsAny <string>(), httpClient, It.IsAny <RequestProxyOptions>(), It.IsAny <HttpTransformer>())) .Returns(() => throw new NotImplementedException()); var sut = Create <ProxyInvokerMiddleware>(); Assert.Equal(0, cluster1.ConcurrencyCounter.Value); await sut.Invoke(httpContext); Assert.Equal(0, cluster1.ConcurrencyCounter.Value); Mock <IHttpProxy>().Verify(); Assert.Equal(StatusCodes.Status503ServiceUnavailable, httpContext.Response.StatusCode); var errorFeature = httpContext.Features.Get <IProxyErrorFeature>(); Assert.Equal(ProxyError.NoAvailableDestinations, errorFeature?.Error); Assert.Null(errorFeature.Exception); }
public void CanCreateUpdateDeleteExtensionInstanceWithoutIdentity() { ClusterInfo cluster = new ClusterInfo( name: "arc-cluster", type: ClusterInfo.ClusterType.connectedClusters, location: "eastus2euap", resourceGroup: "dotnet-sdk-tests" ); Extension extensionInstance = new Extension( name: "dapr", type: ExtensionTestBase.ConfigurationType, extensionType: "microsoft.dapr", autoUpgradeMinorVersion: false, releaseTrain: "stable", version: "1.6.0", scope: new Scope( cluster: new ScopeCluster( releaseNamespace: "dapr-system" ) ) ); using (var context = MockContext.Start(this.GetType())) { using (var testFixture = new ExtensionTestBase(context)) { testFixture.Cluster = cluster; testFixture.Extension = extensionInstance; // List configurations and get count var extensions = testFixture.ListExtensions(); int extensionCount = extensions.Count(); // Create a configuration var newExtension = testFixture.CreateExtension(); Assert.NotNull(newExtension); // Get the configuration and verify var ext = testFixture.GetExtension(); Assert.Equal(extensionInstance.Name, ext.Name); Assert.True((ext.ProvisioningState.ToString() == "Creating") || (ext.ProvisioningState.ToString() == "Succeeded")); // List configurations and get count to confirm it is up by one extensions = testFixture.ListExtensions(); Assert.True(extensions.Count() == extensionCount + 1); // Delete the configuration created testFixture.DeleteExtension(); // List configurations and get count to confirm it is what we started with extensions = testFixture.ListExtensions(); Assert.True(extensions.Count() == extensionCount); } } }
public async Task Invoke_NoHealthyEndpoints_CallsNext() { var httpClient = new HttpMessageInvoker(new Mock <HttpMessageHandler>().Object); var cluster1 = new ClusterInfo(clusterId: "cluster1"); cluster1.Config = new ClusterConfig( new Cluster() { HealthCheck = new HealthCheckOptions { Active = new ActiveHealthCheckOptions { Enabled = true, Timeout = Timeout.InfiniteTimeSpan, Interval = Timeout.InfiniteTimeSpan, Policy = "Any5xxResponse", } } }, httpClient); var destination1 = cluster1.Destinations.GetOrAdd( "destination1", id => new DestinationInfo(id) { Config = new DestinationConfig(new Destination { Address = "https://localhost:123/a/b/" }), Health = { Active = DestinationHealth.Unhealthy }, }); cluster1.ProcessDestinationChanges(); var aspNetCoreEndpoints = new List <Endpoint>(); var routeConfig = new RouteConfig( proxyRoute: new ProxyRoute(), cluster: cluster1, transformer: null); var aspNetCoreEndpoint = CreateAspNetCoreEndpoint(routeConfig); aspNetCoreEndpoints.Add(aspNetCoreEndpoint); var httpContext = new DefaultHttpContext(); httpContext.SetEndpoint(aspNetCoreEndpoint); var sut = Create <DestinationInitializerMiddleware>(); await sut.Invoke(httpContext); var feature = httpContext.Features.Get <IReverseProxyFeature>(); Assert.NotNull(feature); Assert.Single(feature.AllDestinations); Assert.Empty(feature.AvailableDestinations); Assert.Equal(StatusCodes.Status418ImATeapot, httpContext.Response.StatusCode); }
private static void CheckLxc(ClusterInfo clusterInfo, List <DiagnosticResult> result, IEnumerable <dynamic> validResource, Settings settings) { foreach (var vm in validResource.Where(a => a.type == "lxc" && a.template != 1)) { CheckCommonVm(clusterInfo, result, settings, vm, DiagnosticResultContext.Lxc); } }
public IEnumerable <BlockEnhancedInfo> Get(string dummy, long clusterID, int projectID) { // WARNING : This is extremely inefficient. Find another way of getting it ClusterInfo cluster = DB.Clusters.GetCluster(clusterID); List <BlockEnhancedInfo> blocks = new List <BlockEnhancedInfo>(); blocks = DB.GetBlocksEnhanced(projectID).FindAll(i => i.ClusterID == clusterID); return(blocks); }
private ElectionMessage.PrepareOk CreatePrepareOk(int view) { var ownInfo = GetOwnInfo(); var clusterInfo = new ClusterInfo(_servers); return(new ElectionMessage.PrepareOk(view, ownInfo.InstanceId, ownInfo.HttpEndPoint, ownInfo.EpochNumber, ownInfo.EpochPosition, ownInfo.EpochId, ownInfo.EpochLeaderInstanceId, ownInfo.LastCommitPosition, ownInfo.WriterCheckpoint, ownInfo.ChaserCheckpoint, ownInfo.NodePriority, clusterInfo)); }
public void SetDistributionStrategy(string cluster, string database, string collection, IDistributionStrategy distribution) { ClusterInfo clusterInfo = (ClusterInfo)_clusterMetaData[cluster]; if (clusterInfo.Databases != null) { clusterInfo.GetDatabase(database).GetCollection(collection).DistributionStrategy = distribution; _configurationStore.InsertOrUpdateDistributionStrategy(clusterInfo, database, collection); } }
public IDistribution GetDistribution(string cluster, string database, string collection) { ClusterInfo clusterInfo = (ClusterInfo)_clusterMetaData[cluster]; if (clusterInfo.Databases != null) { return clusterInfo.GetDatabase(database).GetCollection(collection).DataDistribution; } return null; }
public IntegratorResource(ClusterInfo info) { Nodes = info.Node.Select(n => new IntegratorNode(info.Name, n)).ToArray(); Parameters[NetworkDegradation.LCN] = info.LatencyClusterNode.ToString(); //LatencyPlannerCluster = info.LatencyPlannerCluster; Name = info.Name; /*ThroughputClusterNode = info.ThroughputClusterNode; * ThroughputPlannerCluster = info.ThroughputPlannerCluster;*/ }
public Chromosome(List <Spot> _spots) //初始產生染色體以Random的方式增加變異性 { spots.Clear(); for (int i = 0; i < _spots.Count; i++) { spots.Add(new Spot(_spots[i])); spots[i].RandomCenter(); } clusterInfo = new ClusterInfo(spots); }
public static ClusterInfo MergeClusters(ClusterInfo myCluster, ClusterInfo othersCluster, EndPoint peerEndPoint, Func <MemberInfo, MemberInfo> update, DateTime utcNow, MemberInfo me, Guid?currentLeaderInstanceId, TimeSpan allowedTimeDifference, TimeSpan deadMemberRemovalTimeout) { var members = myCluster.Members.ToDictionary(member => member.HttpEndPoint, new EndPointEqualityComparer()); foreach (var member in othersCluster.Members) { if (member.InstanceId == me.InstanceId || member.Is(me.HttpEndPoint) ) // we know about ourselves better { continue; } if (peerEndPoint != null && member.Is(peerEndPoint)) // peer knows about itself better { if ((utcNow - member.TimeStamp).Duration() > allowedTimeDifference) { Log.Error("Time difference between us and [{peerEndPoint}] is too great! " + "UTC now: {dateTime:yyyy-MM-dd HH:mm:ss.fff}, peer's time stamp: {peerTimestamp:yyyy-MM-dd HH:mm:ss.fff}.", peerEndPoint, utcNow, member.TimeStamp); } members[member.HttpEndPoint] = member; } else { MemberInfo existingMem; // if there is no data about this member or data is stale -- update if (!members.TryGetValue(member.HttpEndPoint, out existingMem) || IsMoreUpToDate(member, existingMem)) { // we do not trust leader's alive status and state to come from outside if (currentLeaderInstanceId != null && existingMem != null && member.InstanceId == currentLeaderInstanceId) { members[member.HttpEndPoint] = member.Updated(utcNow: utcNow, isAlive: existingMem.IsAlive, state: existingMem.State); } else { members[member.HttpEndPoint] = member; } } } } // update members and remove dead timed-out members, if there are any var newMembers = members.Values.Select(update) .Where(x => x.IsAlive || utcNow - x.TimeStamp < deadMemberRemovalTimeout); return(new ClusterInfo(newMembers)); }
public IPoints RunClusterAlgo(ClusterInfo clusterInfo) { // Skip points outside the grid IPoints filtered = clusterInfo.IsFilterData ? FilterDataset(Dataset, Grid) : Dataset; // Put points in buckets foreach (var p in filtered.Data) { var idxy = GetPointMappedIds(p, Grid, DeltaX, DeltaY); var idx = idxy[0]; var idy = idxy[1]; // Bucket id var id = GetId(idx, idy); // Bucket exists, add point if (BucketsLookup.ContainsKey(id)) { BucketsLookup[id].Points.Add(p); } // New bucket, create and add point else { var bucket = new Bucket(idx, idy, id); bucket.Points.Add(p); BucketsLookup.Add(id, bucket); } } // Calculate centroid for all buckets SetCentroidForAllBuckets(BucketsLookup.Values); // Merge if gridpoint is to close if (AlgoConfig.DoMergeGridIfCentroidsAreCloseToEachOther) { MergeClustersGrid(); } if (AlgoConfig.DoUpdateAllCentroidsToNearestContainingPoint) { UpdateAllCentroidsToNearestContainingPoint(); } // Check again // Merge if gridpoint is to close if (AlgoConfig.DoMergeGridIfCentroidsAreCloseToEachOther && AlgoConfig.DoUpdateAllCentroidsToNearestContainingPoint) { MergeClustersGrid(); // And again set centroid to closest point in bucket UpdateAllCentroidsToNearestContainingPoint(); } return(GetClusterResult(Grid)); }
public ClusterInfo[] GetAllClusterInfo() { if (_clusterMetaData != null && _clusterMetaData.Values.Count > 0) { ClusterInfo[] clusterInfo = new ClusterInfo[_clusterMetaData.Values.Count]; _clusterMetaData.Values.CopyTo(clusterInfo, 0); return clusterInfo; } return null; }
public void Handle(SystemMessage.VNodeConnectionEstablished message) { var oldCluster = _cluster; _cluster = UpdateCluster(_cluster, x => x.Is(message.VNodeEndPoint) ? x.Updated(isAlive: true) : x); if (_cluster.HasChangedSince(oldCluster)) { LogClusterChange(oldCluster, _cluster, string.Format("TCP connection established to [{0}]", message.VNodeEndPoint)); } _bus.Publish(new GossipMessage.GossipUpdated(_cluster)); }
private RouteConfig BuildRouteConfig(ProxyRoute source, ClusterInfo cluster) { var transforms = _transformBuilder.Build(source, cluster?.Config?.Options); var newRouteConfig = new RouteConfig( source, cluster, transforms); return(newRouteConfig); }
public void Handle(SystemMessage.StateChangeMessage message) { CurrentRole = message.State; var replicaState = message as SystemMessage.ReplicaStateMessage; CurrentLeader = replicaState == null ? null : replicaState.Leader; _cluster = UpdateCluster(_cluster, x => x.InstanceId == NodeInfo.InstanceId ? GetUpdatedMe(x) : x, _timeProvider, DeadMemberRemovalPeriod); _bus.Publish(new GossipMessage.GossipUpdated(_cluster)); }
public void CanCreateUpdateDeleteSourceControlConfiguration() { ClusterInfo cluster = new ClusterInfo( name: "azure-arc5", type: ClusterInfo.ClusterType.connectedClusters, location: "eastus2euap", resourceGroup: "haikudevtesting" ); SourceControlConfiguration configuration = new SourceControlConfiguration( name: "netsdktestconfig01a", type: SourceControlConfigurationTestBase.ConfigurationType, repositoryUrl: "git://github.com/anubhav929/flux-get-started", operatorNamespace: "netsdktestconfig01a-opns", operatorInstanceName: "netsdktestconfig01a-opin", operatorParams: "--git-readonly", operatorScope: "namespace", enableHelmOperator: "true" ); using (var context = MockContext.Start(this.GetType())) { using (var testFixture = new SourceControlConfigurationTestBase(context)) { testFixture.Cluster = cluster; testFixture.SourceControlConfiguration = configuration; // List configurations and get count var configurations = testFixture.ListSourceControlConfigurations(); int configCount = configurations.Count(); // Create a configuration var newConfig = testFixture.CreateSourceControlConfiguration(); Assert.NotNull(newConfig); // Get the configuration and verify var config = testFixture.GetSourceControlConfiguration(); Assert.Equal(configuration.Name, config.Name); Assert.True((config.ComplianceStatus.ComplianceState.ToString() == "Pending") || (config.ComplianceStatus.ComplianceState.ToString() == "Installed")); // List configurations and get count to confirm it is up by one configurations = testFixture.ListSourceControlConfigurations(); Assert.True(configurations.Count() == configCount + 1); // Delete the configuration created testFixture.DeleteSourceControlConfiguration(); // List configurations and get count to confirm it is what we started with configurations = testFixture.ListSourceControlConfigurations(); Assert.True(configurations.Count() == configCount); } } }
private RouteConfig BuildRouteConfig(ProxyRoute source, ClusterInfo cluster, RouteInfo runtimeRoute) { var transforms = _transformBuilder.Build(source.Transforms); var newRouteConfig = new RouteConfig( runtimeRoute, source, cluster, transforms); return(newRouteConfig); }
public void LogExecute(ClusterInfo info, IHaveClusterKeyItem item, ExecutionInfo executionInfo) { lock (syncObj) { counter++; LstDequeue.Add(new EnqueueDequeResult(info, item, executionInfo, DateTime.Now)); if (counter == itemNumber) { autoResetEvent.Set(); } } }
public void Handle(SystemMessage.StateChangeMessage message) { CurrentRole = message.State; var replicaState = message as SystemMessage.ReplicaStateMessage; CurrentMaster = replicaState == null ? null : replicaState.Master; _cluster = UpdateCluster(_cluster, x => x.InstanceId == NodeInfo.InstanceId ? GetUpdatedMe(x) : x); //if (_cluster.HasChangedSince(oldCluster)) //LogClusterChange(oldCluster, _cluster, _nodeInfo.InternalHttp); _bus.Publish(new GossipMessage.GossipUpdated(_cluster)); }
static void Main(string[] args) { Console.WriteLine( "Press enter to start the processing units and press enter again to stop the processing units"); Console.ReadLine(); var primaryClusterInfo = new ClusterInfo("partitioned-sync2backup", 1, null, 1, 1); var backupClusterInfo = new ClusterInfo("partitioned-sync2backup", 1, 1, 1, 1); var deployPath = Path.GetFullPath(@"..\"); var primaryProcessorContainerHost = new ProcessingUnitContainerHost(Path.Combine(deployPath, "processor"), primaryClusterInfo, null); var backupProcessorContainerHost = new ProcessingUnitContainerHost(Path.Combine(deployPath, "processor"), backupClusterInfo, null); var feederContainerHost = new ProcessingUnitContainerHost(Path.Combine(deployPath, "feeder"), null, null); Console.ReadLine(); feederContainerHost.Dispose(); backupProcessorContainerHost.Dispose(); primaryProcessorContainerHost.Dispose(); }
private ClusterInfo getClusterInfo(int cluster, List<ProteinTableForm.ProteinGroupRow> proteinList, Dictionary<string, HashSet<int>> proteinAccessionToPeptideList, List<PeptideTableForm.DistinctPeptideRow> peptideList) { var ci = new ClusterInfo { peptideCount = 0, spectraCount = 0, clusterID = cluster }; var allTables = new List<List<List<string>>>(); var sequence2Data = new Dictionary<string, List<string>>(); var sequence2Group = new Dictionary<string, List<int>>(); var group2Sequences = new Dictionary<string, List<string>>(); var peptideGroupList = new List<string>(); var proteinTable = new List<List<string>> { new List<string> { "Group", "Accession", "Peptides", "Spectra", "Description" } }; ci.proteinGroupCount = proteinList.Count; for (int x = 0; x < proteinList.Count; x++) { var proteinGroup = proteinList[x]; proteinTable.Add(new List<string> { TableExporter.IntToColumn(x + 1), proteinGroup.Proteins, proteinGroup.DistinctPeptides.ToString(), proteinGroup.Spectra.ToString(), proteinGroup.FirstProtein.Description }); //get peptides in protein var usedPeptides = new HashSet<PeptideTableForm.DistinctPeptideRow>(); var allGroupedProteins = proteinGroup.Proteins.Split(",".ToCharArray()); foreach (var protein in allGroupedProteins) foreach (var peptideIndex in proteinAccessionToPeptideList[protein]) usedPeptides.Add(peptideList[peptideIndex]); foreach (var peptide in usedPeptides) { if (sequence2Data.ContainsKey(peptide.Peptide.Sequence)) sequence2Group[peptide.Peptide.Sequence].Add(x); else { sequence2Data.Add(peptide.Peptide.Sequence, new List<string> { peptide.Spectra.ToString(), Math.Round(peptide.Peptide.MonoisotopicMass, 4).ToString(), Math.Round(peptide.Peptide.Matches.Min(n => n.QValue), 4).ToString() }); sequence2Group.Add(peptide.Peptide.Sequence, new List<int> { x }); ci.spectraCount += peptide.Spectra; ci.peptideCount++; } } } allTables.Add(proteinTable); foreach (var kvp in sequence2Group) { kvp.Value.Sort(); var value = new List<string>(); foreach (var group in kvp.Value) value.Add(group.ToString()); var groupName = string.Join(",", value.ToArray()); if (group2Sequences.ContainsKey(groupName)) group2Sequences[groupName].Add(kvp.Key); else { group2Sequences.Add(groupName, new List<string> { kvp.Key }); peptideGroupList.Add(groupName); } } peptideGroupList.Sort(); var peptideTable = new List<List<string>> { new List<string> { "PeptideGroup", "Unique", "Sequence", "Spectra", "Mass", "Best Q-Value" } }; for (var x = 0; x < peptideGroupList.Count; x++) { var first = true; var unique = peptideGroupList[x].Length == 1; foreach (var peptide in group2Sequences[peptideGroupList[x]]) { peptideTable.Add(new List<string> { first ? (x + 1).ToString() : string.Empty, unique ? "*" : string.Empty, peptide, sequence2Data[peptide][0], sequence2Data[peptide][1], sequence2Data[peptide][2] }); first = false; } } allTables.Add(peptideTable); var associationTable = new List<List<string>>(); //first row var tempList = new List<string> { string.Empty }; for (var x = 1; x <= peptideGroupList.Count; x++) tempList.Add(x.ToString()); associationTable.Add(tempList); //second row tempList = new List<string>() { "Peptides" }; for (var x = 0; x < peptideGroupList.Count; x++) tempList.Add(group2Sequences[peptideGroupList[x]].Count.ToString()); associationTable.Add(tempList); //third row tempList = new List<string>() { "Spectra" }; for (var x = 0; x < peptideGroupList.Count; x++) { var spectraCount = 0; foreach (var sequence in group2Sequences[peptideGroupList[x]]) { int peptideSpectra; int.TryParse(sequence2Data[sequence][0], out peptideSpectra); spectraCount += peptideSpectra; } tempList.Add(spectraCount.ToString()); } associationTable.Add(tempList); //protein rows for (var x = 0; x < proteinList.Count; x++) { tempList = new List<string> { TableExporter.IntToColumn(x + 1) }; for (var y = 0; y < peptideGroupList.Count; y++) { var containedProGroups = peptideGroupList[y].Split(",".ToCharArray()); var containNumbers = containedProGroups.Select(item => int.Parse(item)); tempList.Add(containNumbers.Contains(x) ? "x" : string.Empty); } associationTable.Add(tempList); } allTables.Add(associationTable); ci.clusterTables = allTables; return ci; }
private void HandlePacket(byte[] packet) { // jedes Kugelmatik V3 Paket ist mindestens HeaderSize Bytes lang und fangen mit "KKS" an if (packet.Length < HeaderSize || packet[0] != 'K' || packet[1] != 'K' || packet[2] != 'S') return; bool isGuaranteed = packet[3] > 0; PacketType type = (PacketType)packet[4]; using (MemoryStream stream = new MemoryStream(packet)) using (BinaryReader reader = new BinaryReader(stream)) { stream.Position = HeaderSize - 4; // 4 Bytes für die Revision int revision = reader.ReadInt32(); if (Kugelmatik.Config.VerbosePacketReceive && type != PacketType.Ack && (type != PacketType.Ping || Kugelmatik.Config.LogPingPacket)) Log.Verbose("[{0}, {1}] Received: [{2}] {3}, size: {4} bytes", X, Y, revision, type, packet.Length); switch (type) { case PacketType.Ping: bool wasNotConnected = !CheckConnection(); lastPing = Environment.TickCount; long time = reader.ReadInt64(); // time ist der Wert von stopwatch zum Zeitpunkt des Absenden des Pakets Ping = (int)(stopwatch.ElapsedMilliseconds - time); RemovePacketToAcknowlegde(revision); if (wasNotConnected && OnConnected != null) OnConnected(this, EventArgs.Empty); break; case PacketType.Ack: IPacket acknowlegdedPacket; if (!packetsToAcknowledge.TryGetValue(revision, out acknowlegdedPacket)) { if (Kugelmatik.Config.VerbosePacketReceive) Log.Verbose("[{0}, {1}] Unknown acknowlegde: [{2}]", X, Y, revision); break; } if (Kugelmatik.Config.VerbosePacketReceive) Log.Verbose("[{0}, {1}] Acknowlegde: [{2}] {3}", X, Y, revision, acknowlegdedPacket.Type); RemovePacketToAcknowlegde(revision); break; case PacketType.GetData: for (int x = 0; x < Width; x++) // for-Schleife muss mit Firmware übereinstimmen for (int y = 0; y < Height; y++) { Stepper stepper = GetStepperByPosition(x, y); ushort height = reader.ReadUInt16(); if (height > Kugelmatik.ClusterConfig.MaxSteps) continue; // Höhe ignorieren byte waitTime = reader.ReadByte(); stepper.Height = height; stepper.WaitTime = waitTime; stepper.OnDataSent(); } RemovePacketToAcknowlegde(revision); break; case PacketType.Info: byte buildVersion = reader.ReadByte(); BusyCommand currentBusyCommand = BusyCommand.None; if (buildVersion >= 11) currentBusyCommand = (BusyCommand)reader.ReadByte(); else if (buildVersion >= 8) currentBusyCommand = reader.ReadByte() > 0 ? BusyCommand.Unknown : BusyCommand.None; int highestRevision = 0; if (buildVersion >= 9) highestRevision = reader.ReadInt32(); ClusterConfig config = new ClusterConfig(); if (buildVersion < 15) { byte stepMode = reader.ReadByte(); if (!Enum.IsDefined(typeof(StepMode), stepMode)) throw new InvalidDataException("Unknown step mode"); int delayTime = reader.ReadInt32(); bool useBreak = false; if (buildVersion >= 6) useBreak = reader.ReadByte() > 0; config = ClusterConfig.GetCompatibility((StepMode)stepMode, delayTime, useBreak); } ErrorCode lastError = ErrorCode.None; if (buildVersion >= 12) { int error = reader.ReadByte(); if (!Enum.IsDefined(typeof(ErrorCode), error)) lastError = ErrorCode.UnknownError; else lastError = (ErrorCode)error; } ErrorCode lastSavedError = Info == null ? ErrorCode.None : info.LastError; if (lastSavedError != lastError && lastError != ErrorCode.None) Log.Error("[{0}, {1}] Error changed from {2} to {3}", X, Y, lastSavedError, lastError); int freeRam = -1; if (buildVersion >= 14) freeRam = reader.ReadInt16(); if (buildVersion >= 15) { ushort configSize = reader.ReadUInt16(); if (configSize != ClusterConfig.Size) { config = new ClusterConfig(); Log.Error("[{0}, {1}] Packet config size does not match config structure size (firmware: {2}, size: {3} != {4})", X, Y, buildVersion, configSize, ClusterConfig.Size); } else config = ClusterConfig.Read(reader); } byte mcpStatus = 0; int loopTime = 0; int networkTime = 0; int maxNetworkTime = 0; int stepperTime = 0; int upTime = 0; if (buildVersion >= 17) { mcpStatus = reader.ReadByte(); loopTime = reader.ReadInt32(); networkTime = reader.ReadInt32(); maxNetworkTime = reader.ReadInt32(); stepperTime = reader.ReadInt32(); upTime = reader.ReadInt32(); } Info = new ClusterInfo(buildVersion, currentBusyCommand, highestRevision, config, lastError, freeRam, mcpStatus, loopTime, networkTime, maxNetworkTime, stepperTime, upTime); RemovePacketToAcknowlegde(revision); break; default: throw new InvalidDataException("Invalid packet type sent by cluster."); } } }
public IntegratorResource(ClusterInfo info) { Nodes = info.Node.Select(n => new IntegratorNode(info.Name, n)).ToArray(); Parameters[NetworkDegradation.LCN] = info.LatencyClusterNode.ToString(); //LatencyPlannerCluster = info.LatencyPlannerCluster; Name = info.Name; /*ThroughputClusterNode = info.ThroughputClusterNode; ThroughputPlannerCluster = info.ThroughputPlannerCluster;*/ }
internal static string GetValue(string parameterId, ClusterInfo cluster, LaunchDestination destination) { return GetValue(parameterId, new IntegratorResource(cluster), destination); }
private void UpdateClusterBoxInternal(int ping, ClusterInfo info) { try { if (info == null) clusterInfoGrid.SelectedObject = new object(); else if (!info.Equals(clusterInfoGrid.SelectedObject)) clusterInfoGrid.SelectedObject = info; } catch(NullReferenceException) { // komische PropertyGrid Exception ignorieren } clusterBox.Text = ClusterControl.FormatClusterText(CurrentCluster); ClusterControl.SetClusterBoxColor(clusterBox, ping, info); }