public void Cleanup()
 {
     definition = null;
     build1Executed = 0;
     build2Executed = 0;
     build3Executed = 0;
 }
Beispiel #2
0
 private void Create(BaseClass baseClass, Write write)
 {
     BaseClass = baseClass;
     Define = new Define();
     Init = new Init(this);
     Write = write;
 }
Beispiel #3
0
 /// <summary>
 /// 移動処理.
 /// </summary>
 /// <param name='type'>
 /// Type.
 /// </param>
 private void Move( Define.RotateType type )
 {
     int horizontal = type == Define.RotateType.Left ? -1 : type == Define.RotateType.Right ? 1 : 0;
     int vertical = type == Define.RotateType.Forward ? 1 : type == Define.RotateType.Back ? -1 : 0;
     WorldMapData.AddWorldPosition( horizontal, vertical );
     StartMove();
     SetRotate( type );
 }
 public void Three_tasks_where_two_depend_on_one()
 {
     definition = Define.It(d =>
     {
         d.Task("build1", t => build1Executed++, "build2", "build3");
         d.Task("build2", t => build2Executed++, "build3");
         d.Task("build3", t => build3Executed++);
     });
     definition.ExecuteTasksWithName("build1");
 }
Beispiel #5
0
 /// <summary>
 /// 添加“消息”
 /// </summary>
 /// <param name="logType"></param>
 /// <param name="strMsg"></param>
 public static void AppendMessage(Define.enumLogType logType, string strMsg)
 {
     Validate();
     if (logType == Define.enumLogType.Operate)
     {
         m_OperationalLogger.AppendMessage(strMsg);
     }
     else
     {
         m_ExceptionLogger.AppendMessage("[" + logType.ToString() + "]" + strMsg);
     }
 }
Beispiel #6
0
		/// <summary>
		/// 获得消息包的字节流
		/// </summary>
		/// <param name="remoteIp">远程主机地址</param>
		/// <param name="packageNo">包编号</param>
		/// <param name="command">命令</param>
		/// <param name="options">参数</param>
		/// <param name="userName">用户名</param>
		/// <param name="hostName">主机名</param>
		/// <param name="content">正文消息</param>
		/// <param name="extendContents">扩展消息</param>
		/// <returns></returns>
		public static Entity.PackedNetworkMessage BuildNetworkMessage(IPEndPoint remoteIp, ulong packageNo, Define.Consts.Commands command, ulong options, string userName, string hostName, byte[] content, byte[] extendContents)
		{
			using (System.IO.MemoryStream bufferStream = new System.IO.MemoryStream())
			{
				int maxLength = Consts.MAX_UDP_PACKAGE_LENGTH;
				byte[] buffer;
				/*
							 * 注意:
							 * 1.优先保证扩展信息,如果不能保证则返回失败
							 * 2.保证扩展消息的前提下,文本消息可以截取
							 * */
				//写入消息头
				ulong cmdInfo = (ulong)command | options;
				buffer = System.Text.Encoding.Default.GetBytes(string.Format("{0}:{1}:{2}:{3}:{4}:", (char)Consts.VersionNumber, packageNo, userName, hostName, cmdInfo));
				bufferStream.Write(buffer, 0, buffer.Length);
				//计算扩展消息
				int extendMessageLength = extendContents == null ? 0 : extendContents.Length;
				if (extendMessageLength + bufferStream.Length > maxLength)
				{
					extendContents = null;
				}
				extendMessageLength = extendContents == null ? 0 : extendContents.Length + 1;
				//写入文本消息
				if (content != null)
				{
					if (content.Length <= maxLength - extendMessageLength - bufferStream.Length)
						bufferStream.Write(content, 0, content.Length);
					else
						bufferStream.Write(content, 0, maxLength - extendMessageLength - (int)bufferStream.Length);
				}
				//写入扩展消息?
				if (extendMessageLength > 0)
				{
					bufferStream.WriteByte(0);
					bufferStream.Write(extendContents, 0, extendMessageLength - 1);
				}
				bufferStream.Seek(0, System.IO.SeekOrigin.Begin);
				buffer = bufferStream.ToArray();

				return new Entity.PackedNetworkMessage()
				{
					PackageCount = 1,
					PackageIndex = 0,
					Data = buffer,
					SendTimes = 0,
					PackageNo = packageNo,
					RemoteIP = remoteIp,
					//回避BUG:全局参数里面,Absence 选项和 SendCheck 是一样的
					IsReceiveSignalRequired = command != Consts.Commands.Br_Absence && Define.Consts.Check(options, Consts.Cmd_Send_Option.SendCheck) && remoteIp.Address != IPAddress.Broadcast,
					Version = 0
				};
			}
		}
        public void AddsSymbol()
        {
            Func<Context, SimpleExpression> expression = (context) => new SimpleExpression(context.Address + 3);

            var instr = new Define("test", expression);
            Assert.AreEqual("test", instr.DefinedSymbol.Identifier);
            Assert.AreEqual(LabelType.Private, instr.DefinedSymbol.SymbolType);
            Assert.AreEqual(expression, instr.Expression);

            Context.Address = 5;

            Assert.IsEmpty(instr.Construct(Context).ToList());
            Assert.AreEqual((Int128)8, Context.SymbolTable["test"].Value);
        }
        public void Two_tasks_where_one_depend_on_the_other()
        {
            definition = Define.It(d =>
            {
                d.Task("Check", t => checkExecuted=true);

                d.Task("Build", () => {
                    buildExecuted = true;
                    return new FakeMsBuild
                    {
                        Solution = @"C:\project\somesolution.sln",
                        MaxCpuCount = 2,
                        Properties = new { },
                        Targets = new[] { "Clean", "Build" }
                    };
                }, "Check");
            });
        }
Beispiel #9
0
        public void AddComponentWithExistingDefine()
        {
            Game game = new Game("Test Game");

            Using use = new Using() { File = Path.GetFileName(typeof(TransformComponent).Assembly.Location) };
            game.AddUsing(use);

            Define define = new Define(TransformComponentShort, TransformComponentType);
            use.AddDefine(define);

            Entity entity = new Entity() { Name = "entity" };

            Component component = new Component(game.GetPlugin(TransformComponentShort));
            entity.AddComponent(component);
            game.AddPrototype(entity);

            Assert.AreEqual(1, game.Usings.Count);
            Assert.AreEqual(1, game.Usings.Single().Defines.Count(x => x.Name == TransformComponentShort && x.Class == TransformComponentType));
            Assert.AreEqual(TransformComponentShort, component.Type);
        }
Beispiel #10
0
 /// <summary>
 /// Gets or set an attribute
 /// </summary>
 /// <param name="_key">Attribute key</param>
 /// <returns></returns>
 public Int32 this[Define _key]
 {
     get
     {
         if (this.AttrbitutesData.ContainsKey((UInt32)_key) == true)
         {
             return this.AttrbitutesData[(UInt32)_key];
         }
         return 0;
     }
     set
     {
         if (this.AttrbitutesData.ContainsKey((UInt32)_key) == false)
         {
             this.AttrbitutesData.Add((UInt32)_key, value);
         }
         else
         {
             this.AttrbitutesData[(UInt32)_key] = value;
         }
     }
 }
Beispiel #11
0
 public DefineAdded(Define define)
     : base(NotificationMode.Children)
 {
     Define = define;
 }
Beispiel #12
0
        public void Defines_Can_Be_Retrieved_When_Present()
        {
            var element = new ImmlElement();
            var define = new Define();
            define.Key = Guid.NewGuid().ToString();
            define.Value = Guid.NewGuid().ToString();

            element.Add(define);

            Assert.Equal(1, element.GetDefines().Count);
            Assert.Equal(define.Key, element.GetDefines().First().Key);
            Assert.Equal(define.Value, element.GetDefines().First().Value);
        }
Beispiel #13
0
 /// <summary>
 /// 向きの設定.
 /// </summary>
 /// <param name='type'>
 /// Type.
 /// </param>
 private void SetRotate( Define.RotateType type )
 {
     float angle = (int)type * 90.0f;
     transform.rotation = Quaternion.AngleAxis( angle, Vector3.up );
 }
Beispiel #14
0
    public Define.EMGameProcess SetProcess( Define.EMGameProcess p_ProcessState )
    {
        m_ProcessState = (int)p_ProcessState;

        return GetProcess();
    }
Beispiel #15
0
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="host">远程主机</param>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <returns>返回发出的消息包编号</returns>
		public ulong SendWithNoCheck(Host host, Define.Consts.Commands cmd, ulong options, string normalMsg, string extendMessage)
		{
			return Send(host, host == null ? broadcastEndPoint : host.HostSub.Ipv4Address, cmd, options, normalMsg, extendMessage, false);
		}
 public void Cleanup()
 {
     definition = null;
     checkExecuted = false;
     buildExecuted = false;
 }
Beispiel #17
0
		/// <summary>
		/// 获得消息包的字节流
		/// </summary>
		/// <param name="remoteIp">远程主机地址</param>
		/// <param name="packageNo">包编号</param>
		/// <param name="command">命令</param>
		/// <param name="options">参数</param>
		/// <param name="userName">用户名</param>
		/// <param name="hostName">主机名</param>
		/// <param name="content">正文消息</param>
		/// <param name="extendContents">扩展消息</param>
		/// <returns></returns>
		public static Entity.PackedNetworkMessage[] BuildNetworkMessage(IPEndPoint remoteIp, ulong packageNo, Define.Consts.Commands command, ulong options, string userName, string hostName, byte[] content, byte[] extendContents)
		{
			options |= (ulong)Define.Consts.Cmd_Send_Option.Content_Unicode;

			//每次发送所能容下的数据量
			var maxBytesPerPackage = Define.Consts.MAX_UDP_PACKAGE_LENGTH - PackageHeaderLength;
			//压缩数据流
			var ms = new System.IO.MemoryStream();
			var zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress);
			var bw = new System.IO.BinaryWriter(zip, System.Text.Encoding.Unicode);
			//写入头部数据
			bw.Write(packageNo);						//包编号
			bw.Write(((ulong)command) | options);		//命令|选项

			bw.Write(userName);				//用户名
			bw.Write(hostName);				//主机名

			bw.Write(content == null ? 0 : content.Length);					//数据长度

			//写入消息数据
			if (content != null) bw.Write(content);
			bw.Write(extendContents == null ? 0 : extendContents.Length);	//补充数据长度
			if (extendContents != null) bw.Write(extendContents);
			bw.Close();
			zip.Close();
			ms.Flush();
			ms.Seek(0, System.IO.SeekOrigin.Begin);

			//打包数据总量
			var dataLength = (int)ms.Length;

			var packageCount = (int)Math.Ceiling(dataLength * 1.0 / maxBytesPerPackage);
			var pnma = new PackedNetworkMessage[packageCount];
			for (var i = 0; i < packageCount; i++)
			{
				var count = i == packageCount - 1 ? dataLength - maxBytesPerPackage * (packageCount - 1) : maxBytesPerPackage;

				var buf = new byte[count + PackageHeaderLength];
				buf[0] = VersionHeader;
				BitConverter.GetBytes(packageNo).CopyTo(buf, 1);
				BitConverter.GetBytes(dataLength).CopyTo(buf, 9);
				BitConverter.GetBytes(packageCount).CopyTo(buf, 13);
				BitConverter.GetBytes(i).CopyTo(buf, 17);
				buf[21] = Define.Consts.Check(options, Define.Consts.Cmd_All_Option.RequireReceiveCheck) ? (byte)1 : (byte)0;	//包确认标志?

				ms.Read(buf, 32, buf.Length - 32);

				pnma[i] = new Entity.PackedNetworkMessage()
				{
					Data = buf,
					PackageCount = packageCount,
					PackageIndex = i,
					PackageNo = packageNo,
					RemoteIP = remoteIp,
					SendTimes = 0,
					Version = 2,
					IsReceiveSignalRequired = buf[21] == 1
				};
			}
			ms.Close();

			return pnma;
		}
Beispiel #18
0
		/// <summary>
		/// 直接向目标IP发送信息
		/// </summary>
		/// <param name="host">远程主机</param>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <returns>返回发出的消息包编号</returns>
		public ulong SendByIp(IPEndPoint remoteEndPoint, Define.Consts.Commands cmd, ulong options, string normalMsg, string extendMessage)
		{
			return Send(null, remoteEndPoint ?? broadcastEndPoint, cmd, options, normalMsg, extendMessage, false);
		}
Beispiel #19
0
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="remoteEndPoint">远程主机地址</param>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <returns>返回发出的消息包编号</returns>
		public ulong Send(Host host, IPEndPoint remoteEndPoint, Define.Consts.Commands cmd, ulong options, string normalMsg, string extendMessage, bool sendCheck)
		{
			Message cm = Message.Create(host, remoteEndPoint, Config.GetRandomTick(), Config.HostName, Config.HostUserName,
				 cmd, options, normalMsg, extendMessage);
			if (sendCheck) cm.IsRequireReceiveCheck = sendCheck;

			return Send(cm);
		}
Beispiel #20
0
 public CmPlus(Define define)
 {
     _cm = define;
 }
Beispiel #21
0
		/// <summary>
		/// 通过广播发送消息
		/// </summary>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <returns>返回发出的消息包编号</returns>
		public void Send(Define.Consts.Commands cmd, ulong options, string normalMsg, string extendMessage)
		{
			if (!Client.IsInitialized) return;

			SendWithNoCheck(null, cmd, options, normalMsg, extendMessage);
		}
Beispiel #22
0
		/// <summary>
		/// 发送消息并且要求对方返回已接收消息
		/// </summary>
		/// <param name="host">远程主机.如果为null则会抛出异常</param>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <returns>返回发出的消息包编号</returns>
		public ulong SendWithCheck(Host host, Define.Consts.Commands cmd, ulong options, byte[] normalMsg, byte[] extendMessage)
		{
			if (host == null) throw new ArgumentNullException("host");

			return Send(host, host.HostSub.Ipv4Address, cmd, options, normalMsg, extendMessage, true);
		}
Beispiel #23
0
		/// <summary>
		/// 以二进制模式发送消息
		/// </summary>
		/// <param name="host">关联的远程主机,不可以为null</param>
		/// <param name="remoteEndPoint">远程主机地址</param>
		/// <param name="cmd">命令</param>
		/// <param name="options">参数</param>
		/// <param name="normalMsg">常规信息</param>
		/// <param name="extendMessage">扩展消息</param>
		/// <param name="sendCheck">是否检查发送到</param>
		/// <exception cref="InvalidOperationException">如果对方主机不在列表中,或未知是否支持增强协议,则会抛出此异常</exception>
		/// <returns>返回发出的消息包编号</returns>
		public ulong Send(Host host, IPEndPoint remoteEndPoint, Define.Consts.Commands cmd, ulong options, byte[] normalMsg, byte[] extendMessage, bool sendCheck)
		{
			if (!Client.IsInitialized) return 0ul;

			//判断远程主机是否支持这个模式
			if (host == null || !host.IsEnhancedContractEnabled) throw new InvalidOperationException("尚不知道主机是否支持增强协议模式,无法以二进制模式发送消息!");

			Message cm = Message.Create(host, remoteEndPoint, Config.GetRandomTick(), Config.HostName, Config.NickName,
				 cmd, options, "", "");
			cm.ExtendMessageBytes = extendMessage;
			cm.NormalMsgBytes = normalMsg;
			cm.IsRequireReceiveCheck = sendCheck;

			//设置选项
			if (sendCheck)
			{
				cm.Options |= (ulong)Define.Consts.Cmd_All_Option.RequireReceiveCheck;
			}
			cm.Options |= (ulong)Define.Consts.Cmd_All_Option.EnableNewDataContract | (ulong)Define.Consts.Cmd_All_Option.BinaryMessage;

			MessageEventArgs mea = new MessageEventArgs(cm) { Message = cm, IsHandled = false, Host = host };
			OnMessageSending(mea);
			if (mea.IsHandled) return mea.Message.PackageNo;

			Entity.PackedNetworkMessage[] pnm = MessagePackerV2.BuildNetworkMessage(cm);
			PackageEventArgs pea = new PackageEventArgs(pnm.Length > 1, pnm[0], pnm);
			OnPckageSending(pea);
			if (!pea.IsHandled)
			{
				Array.ForEach(pnm, s => { Client.Send(s); });
				OnPackageSended(pea);
			}
			OnMessageSended(mea);

			return cm.PackageNo;
		}