/// <summary> /// This method adds a range of callbacks to the list of callbacks. Callbacks /// will be executed in the order they have been added. /// </summary> /// <param name="callbacks">The callbacks to execute when the event is being /// processed.</param> public virtual void AddCallbacks(IEnumerable <Action <Event> > callbacks) { if (IsProcessed) { throw new InvalidOperationException("Event is already processed."); } CallbackList.AddRange(callbacks); }
/// <summary> /// This method removes a callback to the list of callbacks. /// </summary> /// <remarks> /// It is not checked if the callback has actually been added before and /// no exception will be thrown if it had not been present. /// </remarks> /// <param name="callback">The callback to remove.</param> public virtual void RemoveCallback(Action <Event> callback) { if (IsProcessed) { throw new InvalidOperationException("Event is already processed."); } CallbackList.Remove(callback); }
public EmissionModuleLoader() { _value = new ParticleSystem.EmissionModule(); bursts = new CallbackList <BurstLoader>(e => { _value.SetBursts(bursts.Select(b => b.Value).ToArray()); }); }
public Initialize(Environment environment, Process process) : base(environment) { CallbackList.Add(process.Resume); IsOk = true; IsTriggered = true; environment.Schedule(this); }
public Initialize(Simulation environment, Process process, int priority) : base(environment) { CallbackList.Add(process.Resume); IsOk = true; IsTriggered = true; environment.Schedule(this, priority); }
public Request(Environment environment, Action <Event> callback, Action <Event> disposeCallback) : base(environment) { CallbackList.Add(callback); this.disposeCallback = disposeCallback; Time = environment.Now; Process = environment.ActiveProcess; }
public RingLoader(CelestialBody body) { // Is this a spawned body? if (body?.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } Value = new GameObject(body.transform.name + "Ring").AddComponent <Ring>(); Value.transform.parent = body.scaledBody.transform; Value.planetRadius = (Single)body.Radius; // Need to check the parent body's rotation to orient the LAN properly Value.referenceBody = body; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> > (e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); foreach (Type loaderType in Parser.ModTypes) { if (loaderType.BaseType == null) { continue; } if (loaderType.BaseType.Namespace != "Kopernicus.Configuration") { continue; } if (!loaderType.BaseType.Name.StartsWith("ComponentParser")) { continue; } if (loaderType.BaseType.GetGenericArguments()[0] != Value.GetType()) { continue; } if (loaderType.BaseType.GetGenericArguments()[1] != componentType) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } }
public void Adding_an_element_calls_back() { int i = 0; var lst = new CallbackList <int>(); lst.OnAdd = (el) => { i++; return(el); }; lst.Add(5); Assert.Equal(1, i); }
/// <summary> /// 根据流程配置获取其对应的所有补偿事件 /// </summary> /// <param name="process"></param> /// <returns></returns> public ConcurrentStack <ProcessConfigureBase> GetProcessCallbackList(ProcessConfigureBase process) { if (process != null && CallbackList.TryGetValue(process.Key, out ConcurrentStack <ProcessConfigureBase> thisCallbackList)) { return(thisCallbackList); } else { return(new ConcurrentStack <ProcessConfigureBase>()); } }
/// <summary> /// Register a handler for messages from client. /// </summary> /// <param name="message">Message to handle.</param> /// <param name="handler">Handler.</param> public void RegisterMessageHandler(string message, Action <ClientMessage> handler) { lock (messageHandlersLock) { if (!messageHandlers.ContainsKey(message)) { messageHandlers[message] = new CallbackList <ClientMessage>(message); } messageHandlers[message].Register(handler); } }
public StorePut(Simulation environment, Action <Event> callback, object value) : base(environment) { if (value == null) { throw new ArgumentNullException("value", "Value to put in a Store cannot be null."); } CallbackList.Add(callback); Value = value; Time = environment.Now; Owner = environment.ActiveProcess; }
public ContainerGet(Environment environment, Action <Event> callback, double amount) : base(environment) { if (amount <= 0) { throw new ArgumentException("Amount must be > 0.", "amount"); } Amount = amount; CallbackList.Add(callback); Time = environment.Now; Process = environment.ActiveProcess; }
public virtual void OnLoaded(object impl) { this.impl = impl; callbacks = CallbackList <object> .DispatchSuccessClear(callbacks, this); SetVolumeImpl(volume); SetLoopingImpl(looping); if (playing) { PlayImpl(); } }
public RingLoader(Ring value) { Value = value; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> > (e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); foreach (Type loaderType in Parser.ModTypes) { if (loaderType.BaseType == null) { continue; } if (loaderType.BaseType.Namespace != "Kopernicus.Configuration") { continue; } if (!loaderType.BaseType.Name.StartsWith("ComponentParser")) { continue; } if (loaderType.BaseType.GetGenericArguments()[0] != Value.GetType()) { continue; } if (loaderType.BaseType.GetGenericArguments()[1] != componentType) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new Keyframe[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new Keyframe[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
// Creates the a PQSMod of type T with given PQS public override void Create(PQS pqsVersion) { base.Create(pqsVersion); // Create the callback list landClasses = new CallbackList <LandClassLoader> ((e) => { mod.landClasses = landClasses.Where(landClass => !landClass.delete) .Select(landClass => landClass.Value).ToArray(); mod.lcCount = mod.landClasses.Length; }); mod.landClasses = new PQSMod_HeightColorMap2.LandClass[mod.lcCount = 0]; }
// Creates the a PQSMod of type T with given PQS public override void Create(PQS pqsVersion) { base.Create(pqsVersion); // Create the callback list LandClasses = new CallbackList <LandClassLoader>(e => { Mod.landClasses = LandClasses.Where(landClass => !landClass.Delete) .Select(landClass => landClass.Value).ToArray(); Mod.lcCount = Mod.landClasses.Length; }); Mod.landClasses = new PQSMod_HeightBiomeMap.LandClass[Mod.lcCount = 0]; }
public RingLoader(CelestialBody body) { // Is this a spawned body? if (body.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } Value = new GameObject(body.transform.name + "Ring").AddComponent <Ring>(); Value.transform.parent = body.scaledBody.transform; Value.planetRadius = (Single)body.Radius; // Need to check the parent body's rotation to orient the LAN properly Value.referenceBody = body; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> >(e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); Type componentLoaderType = typeof(ComponentLoader <,>).MakeGenericType(typeof(Ring), componentType); foreach (Type loaderType in Parser.ModTypes) { if (!componentLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new [] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new [] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
public EmissionModuleLoader(ParticleSystem.EmissionModule module) { _value = module; bursts = new CallbackList <BurstLoader>(e => { _value.SetBursts(bursts.Select(b => b.Value).ToArray()); }); ParticleSystem.Burst[] burstArray = new ParticleSystem.Burst[module.burstCount]; module.GetBursts(burstArray); for (Int32 i = 0; i < module.burstCount; i++) { bursts.Add(burstArray[i], i + 1 == module.burstCount); } }
public virtual void AddCallback(Callback <object> callback) { if (impl != null) { callback.OnSuccess(this); } else if (error != null) { callback.OnFailure(error); } else { callbacks = CallbackList <object> .CreateAdd(callbacks, callback); } }
// Creates the a PQSMod of type T with given PQS public override void Create(PQS pqsVersion) { base.Create(pqsVersion); // Create the callback list lodRanges = new CallbackList <LODRangeLoader> ((e) => { mod.objects = lodRanges.Where(lodRange => !lodRange.delete) .Select(lodRange => lodRange.Value).ToArray(); foreach (GameObject obj in e.Value.objects) { obj.transform.parent = mod.transform; obj.transform.localPosition = Vector3.zero; obj.SetLayerRecursive(GameLayers.LocalSpace); } }); mod.objects = new PQSCity2.LodObject[0]; }
// Creates the a PQSMod of type T with given PQS public override void Create(PQS pqsVersion) { base.Create(pqsVersion); // Create mod components Continental = new SimplexLoader(); ContinentalRuggedness = new SimplexLoader(); ContinentalSharpness = new NoiseModLoader(); ContinentalSharpnessMap = new SimplexLoader(); TerrainType = new SimplexLoader(); // Create the callback list LandClasses = new CallbackList <LandClassLoader>(e => { Mod.landClasses = LandClasses.Where(landClass => !landClass.Delete) .Select(landClass => landClass.Value).ToArray(); }); Mod.landClasses = new PQSMod_VertexPlanet.LandClass[0]; }
public WebServer() { _numActiveHandlers = 0; numActiveHandlersLock = new object(); _requestHandlers = new List <IRequestHandler>(); frameCallbacks = new CallbackList <FrameCallbackParam>("Frame"); dailyCallbacks = new CallbackList <DailyCallbackParam>("Daily"); unlockAreaCallbacks = new CallbackList <UnlockAreaCallbackParam>("UnlockArea"); terrainCallbacks = new CallbackList <TerrainCallbackParam>("Terrain"); lastTime = new DateTime(); IPAddress address = IPAddress.Parse("127.0.0.1"); int port = 7135; //_endpoint = $"http://{address.ToString()}:{port}/"; _endpoint = "xxx"; _listener = new TcpListener(address, port); Log("Created Server"); }
// Creates the a PQSMod of type T with given PQS public override void Create(PQS pqsVersion) { base.Create(pqsVersion); // Create the callback list LodRanges = new CallbackList <LodRangeLoader>(e => { Mod.objects = LodRanges.Where(lodRange => !lodRange.Delete) .Select(lodRange => lodRange.Value).ToArray(); foreach (GameObject obj in e.Value.objects) { obj.transform.parent = Mod.transform; obj.transform.localPosition = Vector3.zero; obj.SetLayerRecursive(GameLayers.LOCAL_SPACE); obj.gameObject.AddOrGetComponent <KopernicusSurfaceObject>().objectName = Mod.name; } }); Mod.objects = new PQSCity2.LodObject[0]; }
/// <summary> /// Creates a new Properties Loader from a spawned CelestialBody. /// </summary> public PropertiesLoader(CelestialBody body) { // Is this a spawned body? if (body.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } // Store values Value = body; // We require a science values object if (Value.scienceValues == null) { Value.scienceValues = new CelestialBodyScienceParams(); } ScienceValues = new ScienceValuesLoader(Value.scienceValues); // isHomeWorld Check Value.isHomeWorld = Value.transform.name == "Kerbin"; // Biomes Biomes = new CallbackList <BiomeLoader>(e => { // Check biome map if (Value.BiomeMap == null) { throw new InvalidOperationException("The Biome Map cannot be null if you want to add biomes."); } // Replace the old biomes list with the new one Value.BiomeMap.Attributes = Biomes.Select(b => b.Value).ToArray(); }); if (body.BiomeMap == null || body.BiomeMap.Attributes == null) { return; } foreach (CBAttributeMapSO.MapAttribute attribute in body.BiomeMap.Attributes) { Biomes.Add(new BiomeLoader(attribute), false); } }
/// <summary> /// 创建一个流程配置,并注册到管道事件 /// </summary> /// <param name="process"></param> /// <param name="callback"></param> public void SetProcess(ProcessConfigureBase process, ProcessConfigureBase callback = null) { process.Key = Guid.NewGuid().ToString(); Processes.Enqueue(process); var thiscallback = new ConcurrentStack <ProcessConfigureBase>(); if (CallbackList.TryGetValue(lastProcessesKey, out ConcurrentStack <ProcessConfigureBase> lastcallback)) { foreach (var item in lastcallback) { thiscallback.Push(item); } } lastProcessesKey = process.Key; if (callback != null) { thiscallback.Push(callback); } CallbackList.TryAdd(lastProcessesKey, thiscallback); }
// Initialize the RingLoader public RingLoader() { // Is this the parser context? if (!Injector.IsInPrefab) { throw new InvalidOperationException("Must be executed in Injector context."); } Value = new GameObject(generatedBody.name + "Ring").AddComponent <Ring>(); Value.transform.parent = generatedBody.scaledVersion.transform; Value.planetRadius = (Single)generatedBody.celestialBody.Radius; // Need to check the parent body's rotation to orient the LAN properly Value.referenceBody = generatedBody.celestialBody; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> > (e => { Value.Components = Components.Select(c => c.Value).ToList(); }); }
// Initialize the RingLoader public RingLoader(Ring value) { Value = value; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> >(e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); Type componentLoaderType = typeof(ComponentLoader <,>).MakeGenericType(typeof(Ring), componentType); foreach (Type loaderType in Parser.ModTypes) { if (!componentLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
public static void BroadcastRemoteCallback(Action <IServiceRemotingCallback> actionDelegate, bool newThread = false) { if (CallbackList != null && CallbackList.Count > 0) { if (newThread) { Task.Factory.StartNew(() => { BroadcastRemoteCallback(actionDelegate, false); }); } else { Action <IServiceRemotingCallback> invoke = (IServiceRemotingCallback x) => { try { actionDelegate(x); } catch (CommunicationObjectAbortedException) { CallbackList.Remove(x); } }; try { CallbackList.ForEach(invoke); } catch (CommunicationObjectAbortedException ex) { Console.WriteLine(ex.Message); } } } }
public EventProcessManagerPipline(ILogger logger, EventProcessManagerPipline pipline) { this.logger = logger; this.Key = pipline.Key; this.Processes = new ConcurrentQueue <ProcessConfigureBase>(); foreach (var item in pipline.GetProcessee()) { Processes.Enqueue(item); } ; this.CallbackList = new ConcurrentDictionary <string, ConcurrentStack <ProcessConfigureBase> >(); foreach (var item in pipline.GetCallbackList()) { var callbacklist = new List <ProcessConfigureBase>(); var callbackstack = new ConcurrentStack <ProcessConfigureBase>(); foreach (var child in item.Value) { callbacklist.Add(child); } callbacklist.Reverse();//由于是从栈复制到栈,所以这里需要进行一次反转 callbacklist.ForEach(x => callbackstack.Push(x)); CallbackList.TryAdd(item.Key, callbackstack); } }
public async Task<CallbackList.response> CallbackList(CallbackList.request request, CancellationToken? token = null) { return await SendAsync<CallbackList.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None)); }
/// <summary> /// Specifies a callback when properties change. /// </summary> /// <param name="publisher">The publisher.</param> /// <param name="callback">The callback.</param> /// <param name="propertyNames">The property names.</param> public static void WhenChanged(this INotifyPropertyChanged publisher, Action callback, params string[] propertyNames) { var bindPropertyChanged = false; lock (SyncLock) { // Create the subscription set for the publisher if it does not exist. if (Subscriptions.ContainsKey(publisher) == false) { Subscriptions[publisher] = new SubscriptionSet(); // if it did not exist before, we need to bind to the // PropertyChanged event of the publisher. bindPropertyChanged = true; } foreach (var propertyName in propertyNames) { // Create the set of callback references for the publisher's property if it does not exist. if (Subscriptions[publisher].ContainsKey(propertyName) == false) { Subscriptions[publisher][propertyName] = new CallbackList(); } // Add the callback for the publisher's property changed Subscriptions[publisher][propertyName].Add(callback); } } // Make an initial call callback(); // No need to bind to the PropertyChanged event if we are already bound to it. if (bindPropertyChanged == false) { return; } // Finally, bind to property changed publisher.PropertyChanged += (s, e) => { CallbackList propertyCallbacks = null; lock (SyncLock) { // we don't need to perform any action if there are no subscriptions to // this property name. if (Subscriptions[publisher].ContainsKey(e.PropertyName) == false) { return; } // Get the list of alive subscriptions for this property name propertyCallbacks = Subscriptions[publisher][e.PropertyName]; } // Call the subscription's callbacks foreach (var propertyCallback in propertyCallbacks) { // if the subscription is alive, invoke the matching action propertyCallback.Invoke(); } }; }