Beispiel #1
0
        public static void Perform()
        {
            if (
                File.Exists("IP.httdat") == false ||
                File.Exists("Recv.httdat") == false ||
                File.Exists("Send.httdat") == false
                )
            {
                throw new Exception("このプログラムは Get.exe から呼び出されます。");
            }

            string targetPath = File.ReadAllLines(TARGET_FILE)[0];

            if (StringTools.EndsWithIgnoreCase(targetPath, ".alt.txt") == false)
            {
                return;
            }

            string intervateClassName = File.ReadAllLines(targetPath, Encoding.ASCII)[0];
            Type   intervateClass     = Type.GetType(intervateClassName);

            ReflectTools.MethodUnit intervateCtor = ReflectTools.GetConstructor(intervateClass);
            IIntervent intervate = (IIntervent)intervateCtor.Construct(new object[0]);

            intervate.BeforeDL();
        }
Beispiel #2
0
    /// <summary>
    /// 通过反射从bytes中读取到类中
    /// </summary>
    /// <typeparam name="T">目标类</typeparam>
    /// <param name="t">目标类实例</param>
    /// <param name="buffer">bytes</param>
    /// <param name="nameList">字段名字列表</param>
    /// <param name="typeList">字段类型列表</param>
    /// <param name="fieldDict">反射缓存容器</param>
    public void ReadReflect <T>(T t, ByteBuffer buffer, List <string> nameList, List <EDataType> typeList, Dictionary <string, FieldInfo> fieldDict)
    {
        for (int c = 0; c < nameList.Count; c++)
        {
            EDataType type  = typeList[c];
            string    name  = nameList[c];
            object    value = null;
            switch (type)
            {
            case EDataType.Int:
                value = buffer.ReadInt();
                break;

            case EDataType.Long:
                value = buffer.ReadLong();
                break;

            case EDataType.String:
                value = buffer.ReadString();
                break;

            case EDataType.Float:
                value = buffer.ReadFloat();
                break;
            }
            if (fieldDict.ContainsKey(name))
            {
                fieldDict[name].SetValue(t, value);
            }
            else
            {
                fieldDict.Add(name, ReflectTools.SetValue(t, nameList[c], value));
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// 初始化UI
    /// 如果没有设置语言,默认显示与系统一致的语言
    /// </summary>
    private void InitUI()
    {
        TextsOfUI uiText = new TextsOfUI();

        for (int i = 0; i < uiNames.Count; i++)
        {
            object myClass = ReflectTools.CreateInstacne(uiNames[i]);
            //把Json转换的类,转到myClass中
            ReflectTools.SetFieldFromOtherClass(myClass, texts.WeaponPanel);
            //Debug.Log((string)ReflectTools.GetFieldFromClass(myClass, "WeaponDiscrible_Property_Discrible"));
            string className = Type.GetType(uiNames[i]).Name;
            for (int j = 0; j < ReflectTools.GetFieldsFromClass(myClass).Length; j++)
            {
                string transName = className + "/" + ReflectTools.GetFieldsFromClass(myClass)[j].Name;
                transform.Find(transName.Replace("_", "/")).GetComponent <Text>().text = (string)ReflectTools.GetFieldFromClass(myClass, ReflectTools.GetFieldsFromClass(myClass)[j].Name);
            }
        }
    }
Beispiel #4
0
        private string Builder()
        {
            var table = new DataTableFactory().CreateDataTable(_tableClass).AddDataTableRow(t => t.IsThead = false);

            //创建头部行
            table.AddDataTableRow(t => {
                t.IsThead = true;
            });

            //前置功能列
            foreach (var column in _inputColumns.Where(t => t.IsPrepose))
            {
                table.AddDataTableColumn(t => {
                    t.Value     = column.Title;
                    t.ClassName = column.ClassName;
                });
            }
            //文本列
            foreach (var column in _textColumns)
            {
                table.AddDataTableColumn(t => {
                    t.Value     = column.Title;
                    t.ClassName = column.ClassName;
                });
            }
            //后置功能列
            foreach (var column in _inputColumns.Where(t => !t.IsPrepose))
            {
                table.AddDataTableColumn(t => {
                    t.Value     = column.Title;
                    t.ClassName = column.ClassName;
                });
            }
            //设置标识数据
            table.AddDataTableColumn(t => {
                t.Value     = "";
                t.ClassName = "display_none";
            });

            //创建body
            var list = _dataSorce.ToList();

            foreach (var data in list)
            {
                table.AddDataTableRow();//创建行

                //前置功能列
                foreach (var column in _inputColumns.Where(t => t.IsPrepose))
                {
                    table.AddDataTableColumn(t => {
                        t.Value     = column.InputString;
                        t.ClassName = column.ClassName;
                    });
                }
                //文本列
                foreach (var column in _textColumns)
                {
                    table.AddDataTableColumn(t => {
                        t.Value     = ReflectTools.GetValue(data, column.PropertyName, "");
                        t.ClassName = column.ClassName;
                    });
                }
                //后置功能列
                foreach (var column in _inputColumns.Where(t => !t.IsPrepose))
                {
                    table.AddDataTableColumn(t => {
                        t.Value     = column.InputString;
                        t.ClassName = column.ClassName;
                    });
                }
                //设置标识数据
                table.AddDataTableColumn(t => {
                    t.Value     = string.Format("<input class=\"{0}\" type=\"hidden\" value=\"{1}\" />", _dataKeyClassName, ReflectTools.GetValue(data, _dataKeyPropertyName, ""));
                    t.ClassName = "display_none datamember";
                });
            }
            //table标签
            var tableStr = table.Render();

            //外层DIV
            var divBuilder = new TagBuilder("div");

            divBuilder.AddCssClass(_divClass);
            divBuilder.InnerHtml = tableStr;
            return(divBuilder.ToString());
        }
Beispiel #5
0
		public void Main(ArgsReader ar)
		{
			int portNo = 80;
			DocRoot docRoot = new DocRoot();
			MIMEType mimeType = new MIMEType();

			if (ar.HasArgs())
				portNo = int.Parse(ar.NextArg());

			portNo = IntTools.ToRange(portNo, 1, 65535);

			while (ar.HasArgs())
				docRoot.AddRootDir(ar.NextArg());

			HTTPServerChannel.RequestTimeoutMillis = 30000; // 30 sec
			HTTPServerChannel.ResponseTimeoutMillis = 2 * 86400000; // 2 day
			//HTTPServerChannel.FirstLineTimeoutMillis = 2000; // 2 sec == def
			HTTPServerChannel.IdleTimeoutMillis = 10000; // 10 sec
			HTTPServerChannel.BodySizeMax = 2000000; // 2 MB
			HTTPServerChannel.BuffSize = 500000; // 500 KB

			JsonTools.DecodeStringFilter = v => JString.ToJString(v, true, true, true, true);
			JsonTools.DecodeNestingLevelMax = 30;
			JsonTools.DecodeObjectCountMax = 1000;

			HTTPServer hs = new HTTPServer()
			{
				PortNo = portNo,
				//Backlog = 100, // == def
				//ConnectMax = 30, // == def

				Interlude = () =>
				{
					return Console.KeyAvailable == false;
				},

				HTTPConnected = channel =>
				{
					string method = channel.Method;
					string path = channel.Path;

					HTTPRequest hr = new HTTPRequest();

					hr.IP = channel.Channel.Handler.RemoteEndPoint.ToString(); // TODO
					hr.Method = JString.ToJString(channel.Method, false, false, false, false); // 正規化
					hr.URLPath = JString.ToJString(channel.Path, true, false, false, true); // 正規化

					// HACK ??? ParsePathQuery より前に DecodeURL しているのでクエリに '?', '&', '=' を使えない???

					ParsePathQuery(hr);

					// 特別な処理:アスタリスクの直前までをパスと見なす。
					{
						int i = hr.Path.IndexOf('*');

						if (i != -1)
							hr.Path = hr.Path.Substring(0, i);
					}

					if (hr.Path[hr.Path.Length - 1] == '/')
						hr.Path += "index.html";

					hr.Path = CommonUtils.GetFairRelPath(hr.Path);
					hr.HTTP_Version = JString.ToJString(channel.HTTPVersion, false, false, false, false); // 正規化

					foreach (string[] headerPair in channel.HeaderPairs)
					{
						hr.HeaderPairs.Add(
							JString.ToJString(headerPair[0], true, false, false, true), // 正規化
							JString.ToJString(headerPair[1], true, false, false, true)  // 正規化
							);
					}

					if (hr.Method == "GET")
					{
						hr.Json = null;
					}
					else if (method == "POST")
					{
						hr.Json = JsonTools.Decode(channel.Body); // 正規化
					}
					else
					{
						throw new Exception("不明なメソッド");
					}

					// HACK ??? フォルダの場合の 301 対応

					string targetFile = docRoot.GetRootDirs().Select(v => Path.Combine(v, hr.Path)).FirstOrDefault(v => File.Exists(v));

					if (targetFile == null)
					{
						channel.ResStatus = 404;
					}
					else
					{
						if (StringTools.EndsWithIgnoreCase(targetFile, ".alt.txt"))
						{
							string intervateClassName = File.ReadAllLines(targetFile, Encoding.ASCII)[0];
							Type intervateClass = Type.GetType(intervateClassName + "," + Assembly.GetEntryAssembly().GetName().Name);
							ReflectTools.MethodUnit intervateCtor = ReflectTools.GetConstructor(intervateClass);
							IService service = (IService)intervateCtor.Construct(new object[0]);

							object ret = service.Perform(hr, ref targetFile);

							if (ret != null)
							{
								string sRet = JsonTools.Encode(ObjectTree.Conv(ret));
								byte[] resBody = Encoding.UTF8.GetBytes(sRet);

								channel.ResStatus = 200;
								channel.ResBody_B = resBody;
								channel.ResContentType = "application/json";

								goto endSetResponse;
							}
						}
						channel.ResStatus = 200;

						if (new FileInfo(targetFile).Length <= 2000000)
							channel.ResBody_B = File.ReadAllBytes(targetFile);
						else
							channel.ResBody = ResponseFileReader(targetFile);

						channel.ResContentType = mimeType.FileToContentType(targetFile);

					endSetResponse:
						;
					}
				},
			};

			ProcMain.WriteLog("Server Started");

			hs.Perform();

			ProcMain.WriteLog("Server Ended");
		}