public Task EnqueueEvent <TEntity>(ResourceEventType type, TEntity resource) where TEntity : class, IKubernetesObject <V1ObjectMeta> { var controller = Services.GetRequiredService <ManagedResourceController <TEntity> >() as MockManagedResourceController <TEntity>; return(controller?.EnqueueEvent(type, resource) ?? Task.CompletedTask); }
public void Can_Deserialize_ResourceEventV1(Type resourceType, ResourceEventType expectedEventType) { JsonSerializerSettings serializerSettings = KubeResourceClient.SerializerSettings; serializerSettings.Formatting = Formatting.Indented; JsonSerializer serializer = JsonSerializer.Create(serializerSettings); ResourceEventV1 <KubeResourceV1> expectedResourceEvent = new ResourceEventV1 <KubeResourceV1> { EventType = expectedEventType, Resource = resourceType != null ? (KubeResourceV1)Activator.CreateInstance(resourceType) : null }; StringBuilder buffer = new StringBuilder(); using (StringWriter bufferWriter = new StringWriter(buffer)) using (JsonWriter jsonWriter = new JsonTextWriter(bufferWriter)) { serializer.Serialize(jsonWriter, expectedResourceEvent); jsonWriter.Flush(); } Log.LogInformation("Serialised event JSON:\n{EventJson:l}", buffer.ToString()); serializerSettings.Converters.Add( new ResourceEventV1Converter(typeof(KubeResourceV1).Assembly) ); serializer = JsonSerializer.Create(serializerSettings); ResourceEventV1 <KubeResourceV1> actualResourceEvent; using (StringReader bufferReader = new StringReader(buffer.ToString())) using (JsonReader jsonReader = new JsonTextReader(bufferReader)) { actualResourceEvent = serializer.Deserialize <ResourceEventV1 <KubeResourceV1> >(jsonReader); } Assert.NotNull(actualResourceEvent); Assert.Equal(expectedResourceEvent.EventType, actualResourceEvent.EventType); if (expectedResourceEvent.Resource != null) { Assert.NotNull(actualResourceEvent.Resource); Assert.IsType(expectedResourceEvent.Resource.GetType(), actualResourceEvent.Resource); } else { Assert.Null(actualResourceEvent.Resource); } }
private void OnEventHandler(ResourceEventType eventType, string addData) { switch (eventType) { case ResourceEventType.load_complete: switch (addData) { case ResourceStatic.COMMON: togglePart.gameObject.SetActive(true); editPart.gameObject.SetActive(true); break; } break; } }
public override void Publish <T>(ResourceEventType type, T payload) { byte[] messageBodyBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)); IBasicProperties props = channel.CreateBasicProperties(); props.ContentType = "application/json"; props.DeliveryMode = 2; props.Headers = new Dictionary <string, object> { { nameof(ResourceEventType), type.ToString() }, { nameof(Type), typeof(T).AssemblyQualifiedName } }; channel.BasicPublish(BlockInfo.Name, BlockInfo.Name, props, messageBodyBytes); }
public Task EnqueueEvent(ResourceEventType type, TEntity resource) => HandleResourceEvent(new QueuedEvent(type, resource));
private bool ResourceHasEvent(ResourceEventType et) => typeof(T).GetAttributeValue((EmitEventsAttribute a) => a.EventTypes)?.Contains(et) == true;
public ResourceEventArgs(ResourceEventType type, dynamic resource) { Resource = resource; EventType = type; }
public abstract void Publish <T>(ResourceEventType type, T payload);
private void OnEventHandler(ResourceEventType eventType, string addData) { switch (eventType) { case ResourceEventType.load_complete: switch (addData) { case "LoadingModule": GameObject loadingObjPrefab = GameMgr.resourceMgr.GetGameObject("prefab/loadingmodule.ab", "LoadingModule"); loadingObj = Instantiate(loadingObjPrefab) as GameObject; loadingObj.name = "LoadingModule"; loadingObj.transform.SetParent(canvasTrans, false); StartCoroutine(GameMgr.resourceMgr.LoadCommonRes()); break; case ResourceStatic.COMMON: InitUILayers(); Application.targetFrameRate = 60; GameMgr.audioMgr.InitAudio(); #if UNITY_ANDROID gameObject.AddComponent <AndroidBackButton>(); #endif config_module_item guild = (config_module_item)GameMgr.resourceMgr.config_module.GetItem((int)ModuleEnum.GUILD); StartCoroutine(GameMgr.resourceMgr.LoadModule(guild.ab_name, guild.prefab_name)); break; case "GuildModule": config_module_item guild_item = GameMgr.resourceMgr.config_module.GetItemByPrefabName(addData); OnAddUIModule(guild_item); config_module_item prompt = (config_module_item)GameMgr.resourceMgr.config_module.GetItem((int)ModuleEnum.PROMPT); StartCoroutine(GameMgr.resourceMgr.LoadModule(prompt.ab_name, prompt.prefab_name)); break; default: if (addData == "PromptModule") { config_module_item login = (config_module_item)GameMgr.resourceMgr.config_module.GetItem((int)ModuleEnum.LOGIN); StartCoroutine(GameMgr.resourceMgr.LoadModule(login.ab_name, login.prefab_name)); } if (addData == "LoginModule") { DestroyImmediate(loadingObj); } config_module_item module_item = GameMgr.resourceMgr.config_module.GetItemByPrefabName(addData); if (module_item != null) { OnAddUIModule(module_item); } break; } break; } }