示例#1
0
 static Coder()
 {
     codes = new StringArray[EnumAttribute <CodeLanguage> .GetMaxValue(-1) + 1];
     for (int index = codes.Length; index != 0; codes[--index] = new StringArray())
     {
         ;
     }
 }
示例#2
0
        static SocketBase()
        {
            BufferPool = SubBuffer.Pool.GetPool((int)Config.BufferSize >= (int)Config.HeadSize ? Config.BufferSize : Config.HeadSize);

            int dateCacheSize = (Date.ToByteLength + 7) & (int.MaxValue - 7), AutoCSerServerSize = (AutoCSerServer.Length + 7) & (int.MaxValue - 7);

            dateCache = new Pointer {
                Data = Unmanaged.GetStatic64(dateCacheSize + AutoCSerServerSize, false)
            };
            responseServer = new Pointer {
                Data = dateCache.Byte + dateCacheSize
            };

            fixed(char *AutoCSerServerFixed = AutoCSerServer) StringExtension.WriteBytesNotNull(AutoCSerServerFixed, AutoCSerServer.Length, responseServer.Byte);

            byte[] responseServerEnd = (AutoCSerServer + @"Content-Length: 0

").getBytes();
            errorResponseDatas = new byte[EnumAttribute <ResponseState> .GetMaxValue(-1) + 1][];
            foreach (ResponseState type in System.Enum.GetValues(typeof(ResponseState)))
            {
                ResponseStateAttribute state = EnumAttribute <ResponseState, ResponseStateAttribute> .Array((int)type);

                if (state != null && state.IsError)
                {
                    string stateData    = state.Text;
                    byte[] responseData = new byte[httpVersionSize + stateData.Length + responseServerEnd.Length];
                    fixed(byte *responseDataFixed = responseData)
                    {
                        writeHttpVersion(responseDataFixed);
                        state.Write(responseDataFixed + httpVersionSize);
                    }

                    int index = httpVersionSize + stateData.Length;
                    System.Buffer.BlockCopy(responseServerEnd, 0, responseData, index, responseServerEnd.Length);
                    errorResponseDatas[(int)type] = responseData;
                    if (type == ResponseState.NotFound404)
                    {
                        byte[] html          = Encoding.UTF8.GetBytes("<html><head>" + AutoCSer.WebView.CharsetTypeAttribute.GetHtml(AutoCSer.WebView.CharsetType.Utf8) + "<title>404 Error, 请将链接中的 #! 或者 # 修改为 ?</title></head><body>404 Error, 请将链接中的 #! 或者 # 修改为 ?</body></html>");
                        byte[] contentLength = EncodingCache.Ascii.GetBytesNotEmpty(AutoCSerServer + "Content-Length: " + html.Length.toString() + @"

");
                        searchEngine404Data = new byte[httpVersionSize + stateData.Length + contentLength.Length + html.Length];
                        fixed(byte *responseDataFixed = searchEngine404Data)
                        {
                            writeHttpVersion(responseDataFixed);
                            state.Write(responseDataFixed + httpVersionSize);
                        }

                        System.Buffer.BlockCopy(contentLength, 0, searchEngine404Data, index = httpVersionSize + stateData.Length, contentLength.Length);
                        System.Buffer.BlockCopy(html, 0, searchEngine404Data, index         += contentLength.Length, html.Length);
                    }
                }
            }
        }
示例#3
0
        static DbType()
        {
            #region SQL数据类型转C#类型集合
            toCSharpTypes = new Type[EnumAttribute <SqlDbType> .GetMaxValue(-1) + 1];
            toCSharpTypes[(int)SqlDbType.BigInt]           = typeof(long);
            toCSharpTypes[(int)SqlDbType.Binary]           = typeof(byte[]);
            toCSharpTypes[(int)SqlDbType.Bit]              = typeof(bool);
            toCSharpTypes[(int)SqlDbType.Char]             = typeof(string);
            toCSharpTypes[(int)SqlDbType.DateTime]         = typeof(DateTime);
            toCSharpTypes[(int)SqlDbType.Decimal]          = typeof(decimal);
            toCSharpTypes[(int)SqlDbType.Float]            = typeof(double);
            toCSharpTypes[(int)SqlDbType.Image]            = typeof(byte[]);
            toCSharpTypes[(int)SqlDbType.Int]              = typeof(int);
            toCSharpTypes[(int)SqlDbType.Money]            = typeof(decimal);
            toCSharpTypes[(int)SqlDbType.NChar]            = typeof(string);
            toCSharpTypes[(int)SqlDbType.NText]            = typeof(string);
            toCSharpTypes[(int)SqlDbType.NVarChar]         = typeof(string);
            toCSharpTypes[(int)SqlDbType.Real]             = typeof(float);
            toCSharpTypes[(int)SqlDbType.UniqueIdentifier] = typeof(Guid);
            toCSharpTypes[(int)SqlDbType.SmallDateTime]    = typeof(DateTime);
            toCSharpTypes[(int)SqlDbType.SmallInt]         = typeof(short);
            toCSharpTypes[(int)SqlDbType.SmallMoney]       = typeof(decimal);
            toCSharpTypes[(int)SqlDbType.Text]             = typeof(string);
            toCSharpTypes[(int)SqlDbType.Timestamp]        = typeof(byte[]);
            toCSharpTypes[(int)SqlDbType.TinyInt]          = typeof(byte);
            toCSharpTypes[(int)SqlDbType.VarBinary]        = typeof(byte[]);
            toCSharpTypes[(int)SqlDbType.VarChar]          = typeof(string);
            toCSharpTypes[(int)SqlDbType.Variant]          = typeof(object);
            //CSharpType[(int)SqlDbType.Xml] = typeof();
            //CSharpType[(int)SqlDbType.Udt] = typeof();
            //CSharpType[(int)SqlDbType.Structured] = typeof();
            //CSharpType[(int)SqlDbType.Date] = typeof();
            //CSharpType[(int)SqlDbType.Time] = typeof();
            //CSharpType[(int)SqlDbType.DateTime2] = typeof();
            //CSharpType[(int)SqlDbType.DateTimeOffset] = typeof();
            #endregion

            #region C#类型转SQL数据类型集合
            formCSharpTypes = DictionaryCreator.CreateOnly <Type, SqlDbType>();
            formCSharpTypes.Add(typeof(bool), SqlDbType.Bit);
            formCSharpTypes.Add(typeof(byte), SqlDbType.TinyInt);
            formCSharpTypes.Add(typeof(sbyte), SqlDbType.TinyInt);
            formCSharpTypes.Add(typeof(short), SqlDbType.SmallInt);
            formCSharpTypes.Add(typeof(ushort), SqlDbType.SmallInt);
            formCSharpTypes.Add(typeof(int), SqlDbType.Int);
            formCSharpTypes.Add(typeof(uint), SqlDbType.Int);
            formCSharpTypes.Add(typeof(long), SqlDbType.BigInt);
            formCSharpTypes.Add(typeof(ulong), SqlDbType.BigInt);
            formCSharpTypes.Add(typeof(decimal), SqlDbType.Decimal);
            formCSharpTypes.Add(typeof(float), SqlDbType.Real);
            formCSharpTypes.Add(typeof(double), SqlDbType.Float);
            formCSharpTypes.Add(typeof(string), SqlDbType.NVarChar);
            formCSharpTypes.Add(typeof(DateTime), SqlDbType.DateTime);
            formCSharpTypes.Add(typeof(Guid), SqlDbType.UniqueIdentifier);
            formCSharpTypes.Add(typeof(byte[]), SqlDbType.VarBinary);
            #endregion

            #region 类型默认长度
            MaxEnumValue = EnumAttribute <SqlDbType> .GetMaxValue(-1) + 1;

            sizes = new Pointer {
                Data = Unmanaged.GetStatic64(((MaxEnumValue + 1) & (int.MaxValue - 1)) * sizeof(int), false)
            };
            int *sizeData = sizes.Int;
            for (int i = 0; i != MaxEnumValue; i++)
            {
                sizeData[i] = UnknownSize;
            }
            sizeData[(int)SqlDbType.BigInt] = sizeof(long);
            sizeData[(int)SqlDbType.Binary] = 8000;
            sizeData[(int)SqlDbType.Bit]    = sizeof(bool);
            sizeData[(int)SqlDbType.Char]   = 8000;
            //TypeSize[(int)SqlDbType.Date] = sizeof(long);
            sizeData[(int)SqlDbType.DateTime] = sizeof(long);
            //TypeSize[(int)SqlDbType.DateTime2] = sizeof(long);
            //TypeSize[(int)SqlDbType.DateTimeOffset] = sizeof(long);
            //sizeData[(int)SqlDbType.Decimal] = sizeof(decimal);
            sizeData[(int)SqlDbType.Float] = sizeof(double);
            sizeData[(int)SqlDbType.Image] = int.MaxValue;
            sizeData[(int)SqlDbType.Int]   = sizeof(int);
            //sizeData[(int)SqlDbType.Money] = sizeof(decimal);
            //TypeSize[(int)SqlDbType.NChar] = MaxStringSize;
            sizeData[(int)SqlDbType.NText] = int.MaxValue;
            //TypeSize[(int)SqlDbType.NVarChar] = MaxStringSize;
            sizeData[(int)SqlDbType.Real]             = sizeof(float);
            sizeData[(int)SqlDbType.UniqueIdentifier] = 8;
            sizeData[(int)SqlDbType.SmallDateTime]    = sizeof(long);
            sizeData[(int)SqlDbType.SmallInt]         = sizeof(short);
            //sizeData[(int)SqlDbType.SmallMoney] = sizeof(decimal);
            sizeData[(int)SqlDbType.Text] = int.MaxValue;
            //TypeSize[(int)SqlDbType.Time] = 8;
            sizeData[(int)SqlDbType.Timestamp] = 8;
            sizeData[(int)SqlDbType.TinyInt]   = sizeof(byte);
            sizeData[(int)SqlDbType.VarBinary] = 8000;
            sizeData[(int)SqlDbType.VarChar]   = 8000;
            //TypeSize[(int)SqlDbType.Xml] = -1;
            #endregion
        }
示例#4
0
        /// <summary>
        /// 创建错误输出数据
        /// </summary>
        protected unsafe virtual void createErrorResponse()
        {
            KeyValue <Http.Response, Http.Response>[] errorResponses = new KeyValue <Http.Response, Http.Response> [EnumAttribute <Http.ResponseState> .GetMaxValue(-1) + 1];
            int isResponse = 0;

            try
            {
                byte[] path = new byte[9];
                fixed(byte *pathFixed = path)
                {
                    *pathFixed = (byte)'/';
                    *(int *)(pathFixed + sizeof(int)) = '.' + ('h' << 8) + ('t' << 16) + ('m' << 24);
                    *(pathFixed + sizeof(int) * 2)    = (byte)'l';
                    foreach (Http.ResponseState type in System.Enum.GetValues(typeof(Http.ResponseState)))
                    {
                        Http.ResponseStateAttribute state = EnumAttribute <Http.ResponseState, Http.ResponseStateAttribute> .Array((int)type);

                        if (state != null && state.IsError)
                        {
                            int stateValue = state.Number, value = stateValue / 100;
                            *(pathFixed + 1) = (byte)(value + '0');
                            stateValue      -= value * 100;
                            *(pathFixed + 2) = (byte)((value = stateValue / 10) + '0');
                            *(pathFixed + 3) = (byte)((stateValue - value * 10) + '0');
                            Http.Response response  = null;
                            FileCache     fileCache = file(path, default(SubArray <byte>), ref response, true);
                            if (fileCache == null)
                            {
                                if (response != null)
                                {
                                    response.CancelPool();
                                    errorResponses[(int)type].Set(response, response);
                                    isResponse = 1;
                                }
                            }
                            else
                            {
                                Http.Response gzipResponse;
                                if ((response = fileCache.Response) == null)
                                {
                                    response     = Http.Response.New();
                                    gzipResponse = Http.Response.New();
                                    SubArray <byte> data = fileCache.Data, gzipData = fileCache.GZipData;
                                    if (FileCacheQueue.IsFileCacheHeader && data.Start == FileCache.HttpHeaderSize)
                                    {
                                        response.SetCanHeaderSize(ref data);
                                        gzipResponse.SetCanHeaderSize(ref gzipData);
                                    }
                                    else
                                    {
                                        response.SetBody(ref data);
                                        gzipResponse.SetBody(ref gzipData);
                                    }
                                    gzipResponse.SetContentEncoding(Http.Response.GZipEncoding);
                                }
                                else
                                {
                                    gzipResponse = fileCache.GZipResponse ?? response;
                                }
                                response.SetState(type);
                                gzipResponse.SetState(type);
                                errorResponses[(int)type].Set(response, gzipResponse);
                                isResponse = 1;
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Error, error);
            }
            if (isResponse != 0)
            {
                this.errorResponses = errorResponses;
            }
        }