public ActorContextTest() { _ActorContext = new ActorContext(); var factory = new ActorFactory(); _Proxified = new DummyClass(); _Interface = factory.Build<IDummyInterface2>(_Proxified); }
protected override void Receive(ActorContext context) { if (!(context.Message is DbTable dt)) { return; } // 匹配要写入的列 if (_Columns == null) { _Columns = Table.GetColumns(dt.Columns); WriteLog("数据表:{0}/{1}", Table.Name, Table); WriteLog("匹配列:{0}", _Columns.Join(",", e => e.ColumnName)); } // 批量插入 Dal.Session.Insert(Table, _Columns, dt.Cast <IIndexAccessor>()); }
public Contexts() { actor = new ActorContext(); config = new ConfigContext(); debug = new DebugContext(); game = new GameContext(); gameState = new GameStateContext(); input = new InputContext(); snapshot = new SnapshotContext(); var postConstructors = System.Linq.Enumerable.Where( GetType().GetMethods(), method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute)) ); foreach (var postConstructor in postConstructors) { postConstructor.Invoke(this, null); } }
public byte[] SendMessage(ActorContext context, NameValueCollection header, byte[] body) { if (ProfilerLog.ProfilerLogger.IsInfoEnabled) { if (!context.Profile.ContainsKey("_itout_")) { context.Profile.Add("_itout_", $"{DateTime.UtcNow.Ticks}"); } } return(new Out() { Version = 1, Action = PirateXAction.Req, LastNo = context.Request.O, HeaderBytes = GetHeaderBytes(header), BodyBytes = body, Id = context.Token.Rid, Profile = context.Profile }.ToProtobuf()); }
public void Given_Context_ctor_should_set_some_fields() { var parent = new PID("test", "test"); var props = new Props() .WithProducer(() => null) .WithChildSupervisorStrategy(new DoNothingSupervisorStrategy()) .WithReceiveMiddleware(next => (ctx, env) => Actor.Done); var context = new ActorContext(props, parent); Assert.Equal(parent, context.Parent); Assert.Null(context.Message); Assert.Null(context.Sender); Assert.Null(context.Self); Assert.Null(context.Actor); Assert.NotNull(context.Children); Assert.NotNull(context.Children); Assert.Equal(TimeSpan.Zero, context.ReceiveTimeout); }
internal override void Initialize(ActorContext context, ActorDesc actorDesc) { base.Initialize(context, actorDesc); var desc = (PhysicsSceneDesc)actorDesc; // TODO: Enable custom initialization of physics world collisionConf = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConf); broadphase = new DbvtBroadphase(); world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConf); world.Gravity = desc.Gravity; if (desc.Colliders != null) { foreach (var collider in desc.Colliders) { AddCollider(collider); } } }
protected override Task ReceiveAsync(ActorContext context) { if (context.Message is not DbTable dt) { return(null); } // 匹配要写入的列 if (_Columns == null) { _Columns = Table.GetColumns(dt.Columns); WriteLog("数据表:{0}/{1}", Table.Name, Table); WriteLog("匹配列:{0}", _Columns.Join(",", e => e.ColumnName)); } // 批量插入 Dal.Session.Insert(Table, _Columns, dt.Cast <IExtend>()); return(null); }
internal override void Initialize(ActorContext context, ActorDesc actorDesc) { base.Initialize(context, actorDesc); var desc = (RigidBodyDesc)actorDesc; var snapshot = (RigidBodySnapshot)Snapshot; var localInertia = Vector3.Zero; if (!desc.IsKinematic) { desc.Shape.CalculateLocalInertia(desc.Mass, out localInertia); } var motionState = new DefaultMotionState(desc.StartTransform, desc.CenterOfMassOffset); using (var rbInfo = new RigidBodyConstructionInfo(desc.Mass, motionState, desc.Shape, localInertia)) { rbInfo.Friction = desc.Friction; rbInfo.RollingFriction = desc.RollingFriction; rbInfo.Restitution = desc.Restitution; rbInfo.LinearDamping = desc.LinearDamping; rbInfo.AngularDamping = desc.AngularDamping; rigidBody = new RigidBody(rbInfo); rigidBody.UserObject = this; if (desc.IsKinematic) { rigidBody.CollisionFlags |= CollisionFlags.KinematicObject; } Scene.World.AddRigidBody(rigidBody); logger.Debug("Create RigidBody for {0}: Mass: {1}, Shape: {2}, Friction: {3}, RollingFriction: {4}, Restitution: {5}, LinearDamping: {6}, AngularDamping: {7}" , this, 1 / rigidBody.InvMass, rigidBody.CollisionShape, rigidBody.Friction, rigidBody.RollingFriction, rigidBody.Restitution, rigidBody.LinearDamping, rigidBody.AngularDamping); } }
protected override void Receive(ActorContext context) { if (!(context.Message is DbTable dt)) { return; } // 匹配要写入的列 if (_TableName == null) { _TableName = Dal.Db.FormatTableName(Table.TableName); _Columns = Table.GetColumns(dt.Columns); } // 批量插入 var ds = new List <IIndexAccessor>(); foreach (var item in dt) { ds.Add(item); } Dal.Session.Insert(_TableName, _Columns, ds); }
/// <summary> /// 接收消息,批量插入 /// </summary> /// <param name="context"></param> /// <returns></returns> protected override Task ReceiveAsync(ActorContext context) { if (context.Message is not DbTable dt) { return(Task.CompletedTask); } // 匹配要写入的列 if (_Columns == null) { _Columns = Table.GetColumns(dt.Columns); Log?.Info("数据表:{0}/{1}", Table.Name, Table); Log?.Info("匹配列:{0}", _Columns.Join(",", e => e.ColumnName)); } // 批量插入 using var span = Tracer?.NewSpan($"db:WriteDb", Table.TableName); if (IgnorePageError) { try { Dal.Session.Insert(Table, _Columns, dt.Cast <IExtend>()); } catch (Exception ex) { span?.SetError(ex, dt.Rows?.Count); } } else { Dal.Session.Insert(Table, _Columns, dt.Cast <IExtend>()); } return(Task.CompletedTask); }
/// <summary> /// 接收消息,写入文件 /// </summary> /// <param name="context"></param> /// <returns></returns> protected override async Task ReceiveAsync(ActorContext context) { var dt = context.Message as DbTable; var bn = _Binary; using var span = Tracer?.NewSpan($"db:WriteStream", (Stream as FileStream)?.Name); // 写头部结构。没有数据时可以备份结构 if (!_writeHeader) { dt.Total = Total; dt.WriteHeader(bn); // 输出日志 var cs = dt.Columns; var ts = dt.Types; Log?.Info("字段[{0}]:{1}", cs.Length, cs.Join()); Log?.Info("类型[{0}]:{1}", ts.Length, ts.Join(",", e => e.Name)); _writeHeader = true; } var rs = dt.Rows; if (rs == null || rs.Count == 0) { return; } // 写入文件 dt.WriteData(bn); //Stream.Flush(); await Stream.FlushAsync(); //return null; }
protected override void Receive(ActorContext context) { var dt = context.Message as DbTable; var bn = _Binary; // 写头部结构。没有数据时可以备份结构 if (!_writeHeader) { dt.Total = Total; dt.WriteHeader(bn); _writeHeader = true; } var rs = dt.Rows; if (rs == null || rs.Count == 0) { return; } // 写入文件 dt.WriteData(bn); }
public byte[] Seed(ActorContext context, NameValueCollection header, byte cryptobyte, byte[] clientkeys, byte[] serverkeys, byte[] body) { if (ProfilerLog.ProfilerLogger.IsInfoEnabled) { context.Profile.Add("_itout_", $"{DateTime.UtcNow.Ticks}"); } return(new Out() { Version = 1, Action = PirateXAction.Seed, SessionId = context.SessionId, LastNo = context.Request.O, HeaderBytes = GetHeaderBytes(header), BodyBytes = body, Id = context.Token.Rid, ClientKeys = clientkeys, ServerKeys = serverkeys, Crypto = cryptobyte, Profile = context.Profile }.ToProtobuf()); }
protected override async Task ReceiveAsync(ActorContext context) { XTrace.WriteLine("生成Excel数据:{0}", context.Message); await Task.Delay(500); }
/// <summary> /// Register as a named process /// </summary> public static ProcessId Register <T>(this ProcessId self, ProcessName name, ProcessFlags flags = ProcessFlags.Default) => ActorContext.Register <T>(name, self, flags);
/// <summary> /// Register a named process (a kind of DNS for Processes). /// /// If the Process is visible to the cluster (PersistInbox) then the /// registration becomes a permanent named look-up until Process.deregister /// is called. /// /// See remarks. /// </summary> /// <remarks> /// Multiple Processes can register under the same name. You may use /// a dispatcher to work on them collectively (wherever they are in the /// cluster). i.e. /// /// var regd = pid.Register(name); /// Dispatch.Broadcast[regd].Tell("Hello"); /// Dispatch.First[regd].Tell("Hello"); /// Dispatch.LeastBusy[regd].Tell("Hello"); /// Dispatch.Random[regd].Tell("Hello"); /// Dispatch.RoundRobin[regd].Tell("Hello"); /// </remarks> /// <param name="name">Name to register under</param> /// <returns>A ProcessId that allows dispatching to the process via the name. The result /// would look like /disp/reg/name</returns> public static ProcessId Register(this ProcessId self, ProcessName name) => ActorContext.System(self).Register(name, self);
public override void DoAwake(IServiceContainer services){ var contexts = services.GetService<IConstStateService>().Contexts as Contexts; _actorContext = contexts.actor; _gameContext = contexts.game; }
//Constructor public ActorRepository(ActorContext actorcontext) { _ActorContext = actorcontext; }
public WaitForStarts(CountdownEvent countdown) { _countdown = countdown; context = new ActorContext(); }
public ActorsController(ActorContext context) { db = context; }
byte[] IActorNetService.Seed(ActorContext context, NameValueCollection header, byte cryptobyte, byte[] clientkeys, byte[] serverkeys, byte[] body) { throw new NotImplementedException(); }
byte[] IActorNetService.SendMessage(ActorContext context, NameValueCollection headers, byte[] body) { throw new NotImplementedException(); }
/// <summary> /// Register a named process (a kind of DNS for Processes). /// /// If the Process is visible to the cluster (PersistInbox) then the /// registration becomes a permanent named look-up until Process.deregister /// is called. /// /// See remarks. /// </summary> /// <remarks> /// Multiple Processes can register under the same name. You may use /// a dispatcher to work on them collectively (wherever they are in the /// cluster). i.e. /// /// var regd = pid.Register(name); /// Dispatch.Broadcast[regd].Tell("Hello"); /// Dispatch.First[regd].Tell("Hello"); /// Dispatch.LeastBusy[regd].Tell("Hello"); /// Dispatch.Random[regd].Tell("Hello"); /// Dispatch.RoundRobin[regd].Tell("Hello"); /// /// This should be used from within a process' message loop only /// </remarks> /// <param name="name">Name to register under</param> /// <returns>A ProcessId that allows dispatching to the process via the name. The result /// would look like /disp/reg/name</returns> public static ProcessId Register(this ProcessId self) => ActorContext.Register(self.GetName(), self);
public static ActorEntity GetEntityWithId(this ActorContext context, byte value) { return(((Entitas.PrimaryEntityIndex <ActorEntity, byte>)context.GetEntityIndex(Contexts.Id)).GetEntity(value)); }
public ActorController(ActorContext context) { _context = context; }
public Inventory(Actor owner, ActorContext context) { this.owner = owner; this.Money = context.BasicStatus.Money; }
public InitializeEntityCount(Contexts contexts) { _actorContext = contexts.actor; }
public DvdRentalHandler(ActorContext actorContext) { _actorContext = actorContext; }
private void ThreadProcessRequest(NetMQSocket socket) { byte[] response = null; try { var msg = socket.ReceiveFrameBytes(); var sw = new Stopwatch(); sw.Start(); if (Logger.IsTraceEnabled) { Logger.Trace($"ProcessRequest, Thread[{Thread.CurrentThread.ManagedThreadId}] IsThreadPoolThread = {Thread.CurrentThread.IsThreadPoolThread}"); } var din = msg.FromProtobuf <In>(); if (ProfilerLog.ProfilerLogger.IsInfoEnabled) { din.Profile.Add("_itin_", $"{DateTime.UtcNow.Ticks}"); } var context = new ActorContext() { Version = din.Version, //版本号 Action = (byte)din.Action, Request = new PirateXRequestInfo( din.HeaderBytes, //信息头 din.QueryBytes) //信息体 , RemoteIp = din.Ip, LastNo = din.LastNo, SessionId = din.SessionId, Profile = din.Profile, ServerName = din.ServerName, FrontendID = din.FrontendID, ServerItmes = din.Items }; response = _actorService.OnReceive(context); Logger.Warn($"============={sw.ElapsedMilliseconds}============="); } catch (Exception exception) { //TODO 处理,,, Logger.Error(exception); } finally { //socket.SendMoreFrame(address); //socket.SendMoreFrame(""); if (response != null) { socket.SendFrame(response); } else { socket.SendFrame(""); } } //TODO 需要处理 finnaly的异常,感知socket 然后重启 }
public override object callMethod(Scope scope, string name, object[] args) { // Make sure there's a matching verb to be found. Unlike the input // parser, this pays no attention to verb signatures. SourcedItem<Verb> v = _mob.findVerb(name); if (v == null) throw new NotImplementedException("No verb named '" + name + "'."); // Look for the previous verb parameters. Verb.VerbParameters param = (Verb.VerbParameters)scope.baggageGet(Verb.VerbParamsKey); // Make a new one based on it. Most of this will stay the same. var newparam = param.clone(); newparam.self = _mob; newparam.caller = param.self; newparam.args = args; if( Perm.IsVerbAntistick( _mob, name ) ) return v.item.invoke(newparam); else { using( var ac = new ActorContext( _player, v.source.id ) ) return v.item.invoke(newparam); } }