/// <summary> /// <para>Determines whether any asteroids need to be removed. This method is called /// automatically by <see cref="AbstractSpawner"/> and should not be called explicitly from /// its subclasses.</para> /// /// <para>The default implementation searches the current game for untracked asteroids /// whose signal strength has reached zero. This is the same approach used by the stock /// spawner and should be adequate for most spawner implementations.</para> /// /// <para>This method must not throw exceptions.</para> /// </summary> protected virtual void checkDespawn() { if (FlightGlobals.Vessels != null) { // C# iterators don't support concurrent modification List <Vessel> toDelete = new List <Vessel> (); foreach (Vessel v in FlightGlobals.Vessels) { DiscoveryInfo trackState = v.DiscoveryInfo; // This test will fail if and only if v is an unvisited, untracked asteroid // It does not matter whether or not it was tracked in the past if (trackState != null && !trackState.HaveKnowledgeAbout(DiscoveryLevels.StateVectors)) { // Untracked asteroid; how old is it? if (v.DiscoveryInfo.GetSignalLife(Planetarium.GetUniversalTime()) <= 0) { toDelete.Add(v); } } } foreach (Vessel oldAsteroid in toDelete) { Debug.Log("[CustomAsteroids]: " + Localizer.Format("#autoLOC_CustomAsteroids_LogUnspawn", oldAsteroid.GetName())); oldAsteroid.Die(); } } }
/// <summary> /// Adds the tags. /// </summary> /// <param name="info">The information.</param> /// <param name="classAttributes">The class attributes.</param> /// <param name="methodAttributes">The method attributes.</param> internal static void AddTags(DiscoveryInfo info, IEnumerable <TagAttribute> classAttributes, IEnumerable <TagAttribute> methodAttributes) { if (info == null) { return; } if (classAttributes != null) { foreach (TagAttribute tag in classAttributes) { if (!info.Tags.Contains(tag.Tag)) { info.Tags.Add(tag.Tag); } } } if (methodAttributes == null) { return; } foreach (TagAttribute methodAttribute in methodAttributes) { if (!info.Tags.Contains(methodAttribute.Tag)) { info.Tags.Add(methodAttribute.Tag); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Window.RequestFeature(WindowFeatures.NoTitle); // Hide the title Bar. // Set view from the layout resource SetContentView(Resource.Layout.Monitor); Bundle bundle = Intent.GetBundleExtra("bundle"); if (savedInstanceState != null) { path = savedInstanceState.GetString("path"); } ParcelableDiscoverInfo parcel = bundle.GetParcelable("info") as ParcelableDiscoverInfo; if (parcel == null) { return; } robinInfo = parcel.info; Button btnConnect = FindViewById <Button>(Resource.Id.btnConnect); btnConnect.Click += BtnConnect_Click; BtnConnect_Click(btnConnect, EventArgs.Empty); FragmentTransaction fragmentTransaction = FragmentManager.BeginTransaction(); MonitorTreeFragment myFrag = new MonitorTreeFragment(); activeFragment = myFrag; // work here to change Activity fragments (add, remove, etc.). Example here of adding. fragmentTransaction.Replace(Resource.Id.fragment_container, activeFragment); fragmentTransaction.SetTransition(FragmentTransit.FragmentFade); fragmentTransaction.Commit(); }
private static void Print_Discovery_info(DiscoveryInfo I) { String Output = "Discovery Info \n"; Output += "\n distance:" + I.distance.Value; Output += "\n fadeUT:" + I.fadeUT; Output += "\n lastObservedTime:" + I.lastObservedTime; Output += "\n Level:" + I.Level; Output += "\n mass:" + I.mass.Value; Output += "\n name:" + I.name.Value; Output += "\n objectSize:" + I.objectSize; Output += "\n referenceLifetime:" + I.referenceLifetime; Output += "\n signalStrengthLevel:" + I.signalStrengthLevel.Value; Output += "\n signalStrengthPercent:" + I.signalStrengthPercent.Value; Output += "\n situation:" + I.situation.Value; Output += "\n size:" + I.size.Value; Output += "\n speed:" + I.speed.Value; Output += "\n trackingStatus:" + I.trackingStatus.Value; Output += "\n type:" + I.type.Value; Output += "\n unobservedLifetime:" + I.unobservedLifetime; Output += "\n GetHashCode:" + I.GetHashCode(); Output += "\n GetType:" + I.GetType(); //Output += "\n GetSignalLife:" + I.GetSignalLife( ); //Output += "\n GetSignalStrength:" + I.GetSignalStrength(); Debug.Log(Output); }
protected void sendPressRelease(Vessel komet) { try { Log("Generating press release"); StringBuilder resultsMessage = new StringBuilder(); MessageSystem.Message msg; string[] kometNameItems = komet.vesselName.Split(new char[] { '/' }); resultsMessage.AppendLine(kometNameItems[1] + "'s Komet has been discovered! It has been designated " + komet.vesselName + " by astronomers."); resultsMessage.AppendLine(" "); resultsMessage.AppendLine("We currently know very little about the komet, other than the following:"); resultsMessage.AppendLine(" "); resultsMessage.AppendLine("Discovered: " + KSPUtil.dateTimeFormatter.PrintDateCompact(komet.DiscoveryInfo.lastObservedTime, false, false)); resultsMessage.AppendLine("Orbiting: " + komet.orbit.referenceBody.name); resultsMessage.AppendLine("Size Category: " + DiscoveryInfo.GetSizeClassSizes(komet.DiscoveryInfo.objectSize)); resultsMessage.AppendLine("Orbital Period: " + KSPUtil.PrintTimeLong(komet.orbit.period)); resultsMessage.AppendLine(komet.DiscoveryInfo.signalStrengthPercent.OneLiner); msg = new MessageSystem.Message(kometNameItems[1] + "'s Komet Discovered!", resultsMessage.ToString(), MessageSystemButton.MessageButtonColor.GREEN, MessageSystemButton.ButtonIcons.ACHIEVE); MessageSystem.Instance.AddMessage(msg); } catch (Exception ex) { Log("Oops: " + ex); } }
static void Main(string[] args) { ServiceCollection services = new ServiceCollection(); //实例化两个客户端 BaseClient baseClient = new BaseClient(services); BaseClient baseClientz = new BaseClient(services); //使用JObject读取配置文件 Newtonsoft.Json.Linq.JObject cfgobj = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(System.IO.File.ReadAllTextAsync("config.json").Result); //反序列化配置生成客户端配置信息(local DiscoveryInfo cfg = Newtonsoft.Json.JsonConvert.DeserializeObject <DiscoveryInfo>(cfgobj["cfglocal"].ToString()); //生成客户端配置信息2(基于zookeeper的服务发现,thrift服务器) DiscoveryInfo cfgz = Newtonsoft.Json.JsonConvert.DeserializeObject <DiscoveryInfo>(cfgobj["cfgzookeeper"].ToString()); //生成容器 var provider = services.BuildServiceProvider(); baseClient.GetRemoteApps(provider, cfg); baseClientz.GetRemoteApps(provider, cfgz); //通过客户端实例调用方法 var a = baseClient.RunApp(provider, "echo", "{\"name\":\"jone\"}"); var b = baseClientz.RunApp(provider, "echo", "{\"name\":\"simis\"}"); Console.WriteLine($"{a} {b}"); Console.ReadKey(); }
void OnReceivedServerResponse(DiscoveryInfo info) { // check if data is valid if (!IsDataFromServerValid(info)) { return; } // invoke event this.onReceivedServerResponse?.Invoke(info); }
//public async Task Transfer(DiscoveryDto transferDto) //{ // try // { // var uri = "https://localhost:44357/api/Banking"; // var transferContent = new StringContent(JsonConvert.SerializeObject(transferDto), // System.Text.Encoding.UTF8, "application/json"); // var response = await _apiClient.PostAsync(uri, transferContent); // response.EnsureSuccessStatusCode(); // } // catch (Exception ex) // { // throw; // } //} public async Task Discovery(DiscoveryDto transferDto) { try { var uri = "https://localhost:44357/api/Discovery"; for (int i = 0; i < transferDto.noOfAssetScanReq; i++) { var discoveryInfo = new DiscoveryInfo() { Id = Guid.NewGuid().ToString(), ScanType = "Asset" }; var transferContent = new StringContent(JsonConvert.SerializeObject(discoveryInfo), System.Text.Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync(uri, transferContent); response.EnsureSuccessStatusCode(); } for (int i = 0; i < transferDto.noOfAccountScanReq; i++) { var discoveryInfo = new DiscoveryInfo() { Id = Guid.NewGuid().ToString(), ScanType = "Account" }; var transferContent = new StringContent(JsonConvert.SerializeObject(discoveryInfo), System.Text.Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync(uri, transferContent); response.EnsureSuccessStatusCode(); } for (int i = 0; i < transferDto.noOfBothScanReq; i++) { var discoveryInfo = new DiscoveryInfo() { Id = Guid.NewGuid().ToString(), ScanType = "Both" }; var transferContent = new StringContent(JsonConvert.SerializeObject(discoveryInfo), System.Text.Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync(uri, transferContent); response.EnsureSuccessStatusCode(); } } catch (Exception ex) { throw; } }
void OnReceivedBroadcast(DiscoveryInfo info) { if (info.KeyValuePairs.ContainsKey(kSignatureKey) && info.KeyValuePairs[kSignatureKey] == GetCachedSignature()) { // signature matches // send response Profiler.BeginSample("Send response"); byte[] bytes = ConvertDictionaryToByteArray(m_responseData); m_serverUdpCl.Send(bytes, bytes.Length, info.EndPoint); Profiler.EndSample(); } }
/// <summary> /// Counts the untracked asteroids currently in the game. Does not throw exceptions. /// </summary> /// <returns>The number of untracked asteroids.</returns> private static int countUntrackedAsteroids() { int count = 0; foreach (Vessel v in FlightGlobals.Vessels) { DiscoveryInfo trackState = v.DiscoveryInfo; // This test will fail if and only if v is an unvisited, untracked asteroid // It does not matter whether or not it was tracked in the past if (trackState != null && !trackState.HaveKnowledgeAbout(DiscoveryLevels.StateVectors)) { count++; } } return(count); }
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { tmr.Stop(); tmr.Dispose(); DiscoveryInfo info = discover.dicoveryMap.ElementAt(e.Position).Value; ParcelableDiscoverInfo parcel = new ParcelableDiscoverInfo(); parcel.info = info; Bundle bundle = new Bundle(); bundle.PutParcelable("info", parcel); Intent subActivity = new Intent(this, typeof(MonitorActivity)); subActivity.PutExtra("bundle", bundle); StartActivity(subActivity); }
/// <summary> /// Analyzes the type. /// </summary> /// <param name="type">The type.</param> /// <returns>The discovery information.</returns> internal List <DiscoveryInfo> AnalyzeType(Type type) { List <DiscoveryInfo> result = new List <DiscoveryInfo>(); // only analyze public instance methods that aren't inherited MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (MethodInfo methodInfo in methods) { DiscoveryInfo resultItem = this.AnalyzeMethod(type, methodInfo); if (resultItem != null) { result.Add(resultItem); } } return(result); }
public UnitTest1() { ServiceCollection services = new ServiceCollection(); //实例化客户端 baseClient = new BaseClient(services); //服务发现配置 DiscoveryInfo cfg = new DiscoveryInfo() { Connstring = "192.168.100.159:2181", ProtocolType = DiscoveryType.Zookeeper, TimeOut = 5000 }; //生成容器 provider = services.BuildServiceProvider(); //初始化客户端 baseClient.GetRemoteApps(provider, cfg); }
public Task <bool> ProcessDiscoveryRequest(DiscoveryInfo discoveryInfo) { _logger.LogInformation("Discovery processs start for Scan ID {0}", discoveryInfo.Id); //Logic for discovery request process Task.Delay(3000); //delay _logger.LogInformation("Discovery processs complete for Scan ID {0}", discoveryInfo.Id); //Publish event to RabbitMQ if (discoveryInfo.ScanType == "Account") { _bus.Publish(new StartAccountScanEvent(discoveryInfo.Id, discoveryInfo.ScanType, discoveryInfo.Payload)); } else { _bus.Publish(new StartAssetScanEvent(discoveryInfo.Id, discoveryInfo.ScanType, discoveryInfo.Payload)); } return(Task.FromResult <bool>(true)); }
public void Udp_Multi_Discovery() { List <DiscoveryInfo> infos = new List <DiscoveryInfo>(); List <ResonanceUdpDiscoveryService <DiscoveryInfo, JsonEncoder> > services = new List <ResonanceUdpDiscoveryService <DiscoveryInfo, JsonEncoder> >(); int servicesCount = 10; for (int i = 0; i < servicesCount; i++) { DiscoveryInfo info = new DiscoveryInfo(); info.Identity = $"Test Identity {i}"; infos.Add(info); ResonanceUdpDiscoveryService <DiscoveryInfo, JsonEncoder> service = new ResonanceUdpDiscoveryService <DiscoveryInfo, JsonEncoder>(info, 1984); services.Add(service); service.Start(); } ResonanceUdpDiscoveryClient <DiscoveryInfo, JsonDecoder> client = new ResonanceUdpDiscoveryClient <DiscoveryInfo, JsonDecoder>( 1984, (s1, s2) => s1.DiscoveryInfo.Identity == s2.DiscoveryInfo.Identity); var discoveredDervices = client.Discover(TimeSpan.FromSeconds(10)); Assert.IsTrue(discoveredDervices.Count == servicesCount); var discoveredServicesOrdered = discoveredDervices.OrderBy(x => x.DiscoveryInfo.Identity).ToList(); for (int i = 0; i < discoveredServicesOrdered.Count; i++) { Assert.IsTrue(discoveredServicesOrdered[i].DiscoveryInfo.Identity == infos[i].Identity); } services.ForEach(x => x.Dispose()); client.Dispose(); }
/// <summary> /// Extracts the data. /// </summary> /// <param name="type">The type.</param> /// <param name="method">The method.</param> /// <returns>The discovery information.</returns> internal DiscoveryInfo ExtractData(Type type, MethodInfo method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } if (method.DeclaringType == null) { return(null); } DiscoveryInfo info = new DiscoveryInfo { AssemblyQualifiedName = method.DeclaringType.AssemblyQualifiedName, AssemblyPath = this.pathUnderInvestigation, AssemblyName = method.Module.Name, Namespace = method.DeclaringType.Namespace, ClassName = type.Name, MethodName = method.Name }; IEnumerable <TagAttribute> tagAttributesClass = type.GetCustomAttributes <TagAttribute>(false); IEnumerable <TagAttribute> tagAttributesMethod = method.GetCustomAttributes <TagAttribute>(false); AddTags(info, tagAttributesClass as TagAttribute[], tagAttributesMethod as TagAttribute[]); DiaNavigationData data = this.AnalyzeDiaData(string.Concat(info.Namespace, ".", type.Name), method.Name); if (data == null) { return(info); } info.LineOfCode = data.MinLineNumber; info.ClassFilePath = data.FileName; return(info); }
public static bool IsDataFromServerValid(DiscoveryInfo data) { // data must contain signature which matches, and port number return(data.KeyValuePairs.ContainsKey(kSignatureKey) && data.KeyValuePairs[kSignatureKey] == GetCachedSignature() && data.KeyValuePairs.ContainsKey(kPortKey)); }
private static void Print_Discovery_info(DiscoveryInfo I) { String Output = "Discovery Info \n"; Output += "\n distance:" + I.distance.Value; Output += "\n fadeUT:" + I.fadeUT; Output += "\n lastObservedTime:" + I.lastObservedTime; Output += "\n Level:" + I.Level; Output += "\n mass:" + I.mass.Value; Output += "\n name:" + I.name.Value; Output += "\n objectSize:" + I.objectSize; Output += "\n referenceLifetime:" + I.referenceLifetime; Output += "\n signalStrengthLevel:" + I.signalStrengthLevel.Value; Output += "\n signalStrengthPercent:" + I.signalStrengthPercent.Value; Output += "\n situation:" + I.situation.Value; Output += "\n size:" + I.size.Value; Output += "\n speed:" + I.speed.Value; Output += "\n trackingStatus:" + I.trackingStatus.Value; Output += "\n type:" + I.type.Value; Output += "\n unobservedLifetime:" + I.unobservedLifetime; Output += "\n GetHashCode:" + I.GetHashCode(); Output += "\n GetType:" + I.GetType(); //Output += "\n GetSignalLife:" + I.GetSignalLife( ); //Output += "\n GetSignalStrength:" + I.GetSignalStrength(); Debug.Log(Output); }
public void Connect(DiscoveryInfo info) { monitor.info = info; monitor.Connect(); }
public void ShowMonitor(DiscoveryInfo info) { monitorScreen.Connect(info); discoverScreen.gameObject.SetActive(false); monitorScreen.gameObject.SetActive(true); }
public void Connect(DiscoveryInfo info) { this.gameObject.SetActive(false); app.ShowMonitor(info); }