示例#1
0
        static void Main(string[] args)
        {
            point p1 = new point(1, 3, '*');

            p1.Draw();

            point p2 = new point(4, 5, '#');

            p2.Draw();

            List <int> numlist = new list <int>();

            numlist.Add(0);
            numlist.Add(1);
            numlist.Add(2);

            int x = numlist[0];
            int y = numlist[1];
            int z = numlist[2];

            foreach (int i in numlist)
            {
                Console.WriteLine(i);
            }

            numlist.RemoveAt(0);

            List <point> plist = new list <point>();

            plist.Add(p1);
            plist.Add(p2);
            Console.ReadLine();
        }
示例#2
0
文件: Lab8.cs 项目: annie-bunny/lab8
        static void Main(string[] args)
        {
            Trainn t = new Trainn("1A2V", "Start", 6, typeTraine.skTrain);

            WriteLine($"{t.ToString()}");

            SByte     a  = 0;
            Byte      b  = 0;
            Int16     c  = 0;
            Int32     d  = 0;
            Int64     e  = 0;
            String    s  = "";
            Exception ex = new Exception();

            Object[] types = { a, b, c, d, e, s, ex, new Trainn(), new Program(), new int[] { 1, 2, 3 } };

            foreach (var item in types)
            {
                WriteLine($"{item.GetType().Name}-{item.GetType().IsValueType}");
            }

            FirmTrain ft = new FirmTrain("Фирменное название", 1.6, "1A2V", "Start", 6, typeTraine.skTrain);

            WriteLine($"{ft}");

            list <int> l = new list <int>();

            kl.Add(1);
            l.Add(2);
            l.Add(3);

            l.Print();

            ReadKey();
        }
示例#3
0
        public list osMatchString(string src, String pattern, integer start)
        {
            list result = new list();

            if (start < 0)
            {
                start = src.Length + start;
            }

            if (start < 0 || start >= src.Length)
            {
                Verbose("osMatchString(\"{0}\", \"{1}\", {2})={3}", src, pattern, start, result.ToVerboseString());
                return(result);  // empty list
            }

            // Find matches beginning at start position
            Regex matcher = new Regex(pattern);
            Match match   = matcher.Match(src, start);

            while (match.Success)
            {
                foreach (System.Text.RegularExpressions.Group g in match.Groups)
                {
                    if (g.Success)
                    {
                        result.Add(new String(g.Value));
                        result.Add(new integer(g.Index));
                    }
                }

                match = match.NextMatch();
            }
            Verbose("osMatchString(\"{0}\", \"{1}\", {2})={3}", src, pattern, start, result.ToVerboseString());
            return(result);
        }
示例#4
0
        private void send(fastCSharp.net.tcp.commandServer.socket client, string message, string[] users)
        {
            list <userInfo> userInfos = new list <userInfo>(this.users.Count);
            string          user      = (string)client.ClientUserInfo;
            hashString      userHash  = user;

            Monitor.Enter(userLock);
            try
            {
                if (this.users.ContainsKey(userHash))
                {
                    if (users == null)
                    {
                        foreach (userInfo userInfo in this.users.Values)
                        {
                            if (userInfo.User != user && userInfo.OnMessage != null)
                            {
                                userInfos.Add(userInfo);
                            }
                        }
                    }
                    else
                    {
                        userInfo userInfo;
                        foreach (string receiveUser in users)
                        {
                            if (receiveUser != user && this.users.TryGetValue(receiveUser, out userInfo))
                            {
                                if (userInfo.OnMessage != null)
                                {
                                    userInfos.Add(userInfo);
                                }
                            }
                        }
                    }
                }
            }
            finally { Monitor.Exit(userLock); }
            if (OnMessage != null)
            {
                OnMessage(new message {
                    User = user, Time = date.NowSecond, Message = message
                });
            }
            if (userInfos.Count != 0)
            {
                if (newMessageHandle == null)
                {
                    newMessageHandle = newMessage;
                }
                task.Tiny.Add(newMessageHandle, new messageUsers {
                    Users = userInfos, Message = new message {
                        User = user, Time = date.NowSecond, Message = message
                    }
                });
            }
        }
示例#5
0
 /// <summary>
 /// TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">TCP验证实例</param>
 public @ServiceName(fastCSharp.setup.cSharp.tcpServer attribute = null, fastCSharp.setup.cSharp.tcpBase.ITcpVerify verify = null)
     : base(attribute ?? fastCSharp.setup.cSharp.tcpServer.GetConfig("@ServiceName"), verify /*IF:ServiceAttribute.VerifyType*/ ?? new @TcpVerifyType() /*IF:ServiceAttribute.VerifyType*/)
 {
     #region NAME OnCommands
     list <keyValue <hashBytes, keyValue <action <socket, int>, bool> > > .unsafer onCommands = new list <keyValue <hashBytes, keyValue <action <socket, int>, bool> > >(@MethodIndexs.Length + 1).Unsafer;
     onCommands.Add(new keyValue <hashBytes, keyValue <action <socket, int>, bool> >(closeCommandData, new keyValue <action <socket, int>, bool>(new action <socket, int>(close), false)));
     #region LOOP MethodIndexs
     onCommands.Add(new keyValue <hashBytes, keyValue <action <socket, int>, bool> >(formatMethodKeyName("@Method.MethodKeyFullName"), new keyValue <action <socket, int>, bool>(@MethodIndexName, @IsInputParameter)));
     #endregion LOOP MethodIndexs
     this.onCommands = new staticDictionary <hashBytes, keyValue <action <socket, int>, bool> >(onCommands.List);
     #endregion NAME OnCommands
 }
示例#6
0
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns>写入位置,失败返回-1</returns>
        internal long UnsafeWrite(ref memoryPool.pushSubArray data)
        {
            subArray <byte> dataArray = data.Value;

            Monitor.Enter(bufferLock);
            if (isDisposed == 0)
            {
                long fileBufferLength = this.fileBufferLength;
                this.fileBufferLength += dataArray.length;
                if (isWritting == 0)
                {
                    int length = currentIndex + dataArray.length;
                    if (length < bufferLength && flushCount == 0)
                    {
                        Buffer.BlockCopy(dataArray.array, dataArray.startIndex, buffer, currentIndex, dataArray.length);
                        checkFlushTime = date.nowTime.Now.AddTicks(checkFlushTicks);
                        currentIndex   = length;
                        bufferIndex    = this.fileBufferLength;
                        flushWait.Reset();
                        Monitor.Exit(bufferLock);
                        data.Push();
                        setCheckFlush();
                    }
                    else
                    {
                        buffers.array[0] = data;
                        buffers.UnsafeAddLength(1);
                        bufferSize  += dataArray.length;
                        isFlush      = 0;
                        isWritting   = 1;
                        isCopyBuffer = 0;
                        flushWait.Reset();
                        Monitor.Exit(bufferLock);
                        threadPool.TinyPool.FastStart(this, thread.callType.FileStreamWriteFile);
                    }
                }
                else
                {
                    try
                    {
                        buffers.Add(ref data);
                        bufferSize  += dataArray.length;
                        isCopyBuffer = 0;
                        flushWait.Reset();
                    }
                    finally { Monitor.Exit(bufferLock); }
                }
                return(fileBufferLength);
            }
            Monitor.Exit(bufferLock);
            data.Push();
            return(-1);
        }
示例#7
0
        static void Main(string[] args)
        {
            List <string> liststrings = new list <string>();

            liststrings.Add("a new object");
            liststrings.Add("another object");
            liststrings.Add("a third one");
            foreach (var liststring in liststrings)
            {
                Console.WriteLine(liststring);
            }
        }
示例#8
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="cacheValue">缓存数据</param>
        /// <param name="value">更新后的数据</param>
        /// <param name="oldValue">更新前的数据</param>
        private void onUpdated(valueType cacheValue, valueType value, valueType oldValue, fastCSharp.code.memberMap <modelType> memberMap)
        {
            keyType key = getKey(value);

            if (cacheValue == null)
            {
                list <valueType> values;
                if (queueCache.Remove(key, out values))
                {
                    foreach (valueType removeValue in values)
                    {
                        counter.Remove(removeValue);
                    }
                }
            }
            else
            {
                keyType oldKey = getKey(oldValue);
                if (!key.Equals(oldKey))
                {
                    list <valueType> values = queueCache.Get(key, null), oldValues = queueCache.Get(oldKey, null);
                    if (values != null)
                    {
                        if (oldValues != null)
                        {
                            values.Add(cacheValue);
                            if (!oldValues.Remove(cacheValue))
                            {
                                log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                            }
                        }
                        else
                        {
                            values.Add(counter.Add(cacheValue));
                        }
                    }
                    else if (oldValues != null)
                    {
                        if (oldValues.Remove(cacheValue))
                        {
                            counter.Remove(cacheValue);
                        }
                        else
                        {
                            log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true);
                        }
                    }
                }
            }
        }
示例#9
0
文件: log.cs 项目: khaliyo/fastCSharp
            /// <summary>
            /// 字符串
            /// </summary>
            /// <returns>字符串</returns>
            public override string ToString()
            {
                if (toString == null)
                {
                    list<string>.unsafer errorString = new list<string>(2).Unsafer;
                    if (Message != null) errorString.Add("附加信息 : " + Message);
                    if (StackFrame != null) errorString.Add("堆栈帧信息 : " + StackFrame.toString());
                    if (StackTrace != null) errorString.Add("堆栈信息 : " + StackTrace.ToString());
                    if (Exception != null) errorString.Add("异常信息 : " + Exception.ToString());
                    if (Type != exceptionType.None) errorString.Add("异常类型 : " + Type.ToString());
                    toString = errorString[0] + @"
" + errorString[1];
                }
                return toString;
            }
示例#10
0
        static void TestaaOpiskelija()
        {
            opiskelija mina = new opiskelija();

            mina.Nimi = "petri";
            Color väri = mina.väri;

            opiskelija        sina        = new opiskelija("kata");
            List <opiskelija> Opiskelijat = new list <opiskelija>();

            Opiskelijat.Add(mina);
            Opiskelijat.Add(sina);

            Console.WriteLine("{0} ja {1} ollaan opiskelijoita", mina.Nimi, sina.Nimi);
        }
        /// <summary>
        /// TCP调用客户端调用结束
        /// </summary>
        /// <param name="client">TCP调用服务器信息</param>
        /// <param name="returnType">是否回调成功</param>
        protected void _end_(ref clientIdentity client, fastCSharp.net.returnValue.type returnType)
        {
            if (isDisposed == 0)
            {
                if (returnType == fastCSharp.net.returnValue.type.Success)
                {
                    Monitor.Enter(clientLock);
                    callCount -= clients[client.Index].End(client.Identity);
                    Monitor.Exit(clientLock);
                }
                else
                {
                    Monitor.Enter(clientLock);
                    keyValue <clientType, keyValue <host, int> > errorClient = clients[client.Index].Error(client.Identity);
                    if (errorClient.Key == null)
                    {
                        Monitor.Exit(clientLock);
                    }
                    else
                    {
                        callCount -= errorClient.Value.Value;
                        try
                        {
                            freeIndexs.Add(client.Index);
                        }
                        finally
                        {
                            Monitor.Exit(clientLock);
                            pub.Dispose(ref errorClient.Key);

                            host host     = errorClient.Value.Key;
                            bool isCreate = newServer(ref host);
                            if (isCreate)
                            {
                                tryCheck();
                                log.Default.Add("恢复TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false);
                            }
                            else
                            {
                                log.Default.Add("移除TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false);
                            }
                        }
                    }
                }
            }
            client.Identity = int.MinValue;
            client.Client   = null;
        }
示例#12
0
        /// <summary>
        /// 获取匹配分页集合
        /// </summary>
        /// <param name="pageSize">分页长度</param>
        /// <param name="currentPage">当前页号</param>
        /// <param name="isValue">数据匹配器</param>
        /// <param name="count">匹配数据总数</param>
        /// <returns>匹配分页集合</returns>
        internal list <valueType> GetArrayPage(int pageSize, int currentPage, func <valueType, bool> isValue, out int count)
        {
            int valueCount = 0;

            array.page page            = new array.page(Array.Length, pageSize, currentPage);
            int        currentPageSize = page.CurrentPageSize;

            list <valueType> .unsafer values = new list <valueType>(page.CurrentPageSize).Unsafer;
            int skipCount = page.SkipCount;

            currentPageSize += skipCount;
            foreach (valueType value in Array)
            {
                if (isValue(value))
                {
                    if (valueCount >= skipCount && valueCount < currentPageSize)
                    {
                        values.Add(value);
                    }
                    ++valueCount;
                }
            }
            count = valueCount;
            return(values.List);
        }
示例#13
0
            ///// <summary>
            ///// Session类型
            ///// </summary>
            //public memberType SessionType;
            ///// <summary>
            ///// 安装入口
            ///// </summary>
            ///// <param name="parameter">安装参数</param>
            ///// <returns>是否安装成功</returns>
            //public override bool Run(auto.parameter parameter)
            //{
            //    webConfig webConfig = parameter.WebConfig;
            //    if (webConfig == null) return true;
            //    SessionType = webConfig.SessionType;
            //    return base.Run(parameter);
            //}
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void nextCreate()
            {
                string typeCallName = type.FullName;

                if (typeCallName.StartsWith(AutoParameter.DefaultNamespace, StringComparison.Ordinal) && typeCallName[AutoParameter.DefaultNamespace.Length] == '.')
                {
                    typeCallName = typeCallName.Substring(AutoParameter.DefaultNamespace.Length + 1);
                }

                bool isAjaxLoadType = false;
                Type baseType       = type.Type.BaseType;

                if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(fastCSharp.code.cSharp.ajax.loader <>))
                {
                    isAjaxLoadType = true;
                }

                int methodIndex = methods.Count;

                methods.Add(code.methodInfo.GetMethods <fastCSharp.code.cSharp.webCall>(type, code.memberFilters.PublicInstance, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute)
                            .getArray(value => new methodIndex
                {
                    Method            = value,
                    MethodIndex       = methodIndex++,
                    WebCallMethodType = type,
                    TypeAttribute     = Attribute,
                    TypeCallName      = typeCallName,
                    IsAjaxLoad        = isAjaxLoadType && value.MemberName == "Load" && value.ReturnType.Type == typeof(void) && value.Parameters.Length == 0,
                    IgnoreCase        = AutoParameter.WebConfig.IgnoreCase
                }));
            }
示例#14
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void nextCreate()
            {
                string typeCallName = type.FullName;

                if (typeCallName.StartsWith(AutoParameter.DefaultNamespace, StringComparison.Ordinal) && typeCallName[AutoParameter.DefaultNamespace.Length] == '.')
                {
                    typeCallName = typeCallName.Substring(AutoParameter.DefaultNamespace.Length + 1);
                }
                if (typeCallName.StartsWith("ajax.", StringComparison.Ordinal))
                {
                    typeCallName = typeCallName.Substring("ajax.".Length);
                }

                int methodIndex = methods.Count;

                methodIndex[] methodIndexs = code.methodInfo.GetMethods <fastCSharp.code.cSharp.ajax>(type, code.memberFilters.PublicInstance, false, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute, Attribute.IsInheritAttribute)
                                             .getArray(value => new methodIndex
                {
                    Method            = value,
                    MethodIndex       = methodIndex++,
                    WebViewMethodType = type,
                    TypeAttribute     = Attribute,
                    TypeCallName      = typeCallName,
                    IgnoreCase        = AutoParameter.WebConfig.IgnoreCase
                });
                if (methodIndexs.Length != 0)
                {
                    methods.Add(methodIndexs);
                    if (Attribute.IsExportTypeScript)
                    {
                        ts.Create(AutoParameter, type, methodIndexs);
                    }
                }
            }
示例#15
0
            /// <summary>
            /// 嵌套类型处理
            /// </summary>
            /// <param name="type">类型</param>
            /// <param name="reflectedType">上层类型</param>
            private void reflectedType(Type type, Type reflectedType)
            {
                list <Type> reflectedTypeList = new list <Type>();

                do
                {
                    reflectedTypeList.Add(reflectedType);
                    reflectedType = reflectedType.ReflectedType;
                }while (reflectedType != null);
                Type[] reflectedTypeArray = reflectedTypeList.Unsafer.Array;
                int    reflectedTypeIndex = reflectedTypeList.Count - 1;

                reflectedType = reflectedTypeArray[reflectedTypeIndex];
                nameStream.Write(reflectedType.Namespace);
                do
                {
                    nameStream.Write('.');
                    nameStream.Write(reflectedType.Name);
                    if (reflectedTypeIndex == 0)
                    {
                        reflectedType = type;
                        type          = null;
                    }
                    else
                    {
                        reflectedType = reflectedTypeArray[--reflectedTypeIndex];
                    }
                }while (reflectedType != null);
            }
示例#16
0
        public void AddToRentalCart(Book book, DateTime dateDue)
        {
            Rental obj = new Rental(book, dateDue);

            rentalCart.Add(obj);

            Console.WriteLine("Added to the rental cart " + book.BookName + " Book " + book.BookId + " for the Patron " + base.FirstName + " " + base.LastName);
        }
示例#17
0
        //查看老师课表
        public List <TeacherCourse> SelectTeacherCourse(TeacherCourse tchCourse)
        {
            TeacherCourse tchCourse    = tchCourseDal.SelectById();
            list <Course> searchedCour = new list <Course>();

            searchedCour.Add(tchCourse);
            return(searchedCour);
        }
示例#18
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="task">任务信息</param>
        /// <returns>任务添加是否成功</returns>
        internal bool add(taskInfo task)
        {
            bool isTask = false;

            Monitor.Enter(taskLock);
            try
            {
                if (!isStop)
                {
                    if (threadCount != maxThreadCount && freeThreadCount == 0)
                    {
                        ++threadCount;
                        try
                        {
                            if (maxThreadCount == 1)
                            {
                                threadPool.Start(runTask, Dispose);
                            }
                            else if (threadCount != 1)
                            {
                                threadPool.Start(runManyTask);
                            }
                            else
                            {
                                threadPool.Start(runManyTask, Dispose);
                            }
                        }
                        catch (Exception error)
                        {
                            log.Default.Add(error, null, true);
                            Monitor.Enter(waitFreeLock);
                            try
                            {
                                Monitor.Enter(waitLock);
                                try
                                {
                                    if (--threadCount == finallyThreadCount)
                                    {
                                        Monitor.PulseAll(waitLock);
                                    }
                                }
                                finally { Monitor.Exit(waitLock); }
                                if (threadCount == freeThreadCount)
                                {
                                    Monitor.PulseAll(waitFreeLock);
                                }
                            }
                            finally { Monitor.Exit(waitFreeLock); }
                        }
                    }
                    tasks.Add(task);
                    Monitor.Pulse(taskLock);
                    isTask = true;
                }
            }
            finally { Monitor.Exit(taskLock); }
            return(isTask);
        }
示例#19
0
 internal void AddClient(commandClient client)
 {
     if (Clients == null)
     {
         Clients = new list <commandClient>(sizeof(int));
     }
     Clients.Add(client);
     client.ChangeTcpRegisterServicesVersion();
 }
示例#20
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="value">新增的数据</param>
        private void onInserted(valueType value)
        {
            keyType          key    = getKey(value);
            list <valueType> values = queueCache.Get(key, null);

            if (values != null)
            {
                values.Add(counter.Add(value));
            }
        }
示例#21
0
 /// <summary>
 /// 创建TCP调用客户端
 /// </summary>
 private void createClient()
 {
     fastCSharp.net.tcpClient value = newClient();
     if (value.IsStart)
     {
         Monitor.Enter(clientLock);
         try
         {
             clients.Add(value);
             --createCount;
         }
         finally { Monitor.Exit(clientLock); }
         pulseWait();
     }
     else
     {
         onClientError(null);
     }
 }
示例#22
0
            public static list operator +(list a, object b)
            {
                list l = new list();

                if ((object)a != null)
                {
                    l.AddRange(a);
                }
                l.Add(b);
                return(l);
            }
示例#23
0
 /// <summary>
 /// 添加回调用户
 /// </summary>
 /// <param name="userInfo">用户信息</param>
 public void Add(userInfo userInfo)
 {
     if (userInfo.OnPoll == null)
     {
         userInfo.Messages.Add(Message);
     }
     else
     {
         OnPolls.Add(userInfo.OnPoll);
         userInfo.OnPoll = null;
     }
 }
示例#24
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="value">新增的数据</param>
        private void onInserted(valueType value)
        {
            keyType          key    = getKey(value);
            list <valueType> values = queueCache.Get(key, null);

            if (values != null)
            {
                valueType newValue = fastCSharp.setup.constructor <valueType> .New;
                copyFrom(newValue, value, memberMap);
                values.Add(newValue);
            }
        }
示例#25
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void nextCreate()
            {
                keyValue <methodInfo, fastCSharp.code.cSharp.webSocket> loadMethod = fastCSharp.code.cSharp.webSocket.GetLoadMethod(type.Type);

                LoadMethod    = loadMethod.Key;
                LoadAttribute = loadMethod.Value;
                sockets.Add(new socketType {
                    type = type, Attribute = Attribute, DefaultNamespace = AutoParameter.DefaultNamespace + ".", Index = sockets.Count, IgnoreCase = AutoParameter.WebConfig.IgnoreCase
                });
                IsServer = false;
                create(true);
            }
示例#26
0
        /// <summary>
        /// 添加历史对象
        /// </summary>
        /// <param name="value">历史对象</param>
        public void Push(object value)
        {
            if (value != null)
            {
                if (parents.IndexOf(value) != -1)
                {
                    log.Default.Throw(@"循环引用 : " + value.GetType().fullName() + @"
" + parents.joinString(" => ", loopValue => loopValue.GetType().fullName()), true, true);
                }
                parents.Add(this);
            }
        }
示例#27
0
        /// <summary>
        /// 用户列表更新
        /// </summary>
        /// <param name="user">新增用户名</param>
        private void userChange(string user)
        {
            string[] users;
            int      userVersion = int.MinValue;

            while (userVersion != this.userVersion && Interlocked.CompareExchange(ref onUserChangedLock, 1, 0) == 0)
            {
                try
                {
                    Monitor.Enter(userLock);
                    try
                    {
                        users       = this.users.Keys.getArray(value => value.ToString());
                        userVersion = this.userVersion;
                        foreach (userInfo userInfo in this.users.Values)
                        {
                            if ((userInfo.User != user || userVersion != int.MinValue) && userInfo.OnUserChanged != null)
                            {
                                onUserChangeds.Add(userInfo);
                            }
                        }
                    }
                    finally { Monitor.Exit(userLock); }
                    while (userVersion == this.userVersion && onUserChangeds.Count != 0)
                    {
                        try
                        {
                            userInfo userInfo = onUserChangeds.Pop();
                            if (!userInfo.OnUserChanged(users))
                            {
                                removeUsers.Add(userInfo.User);
                            }
                        }
                        catch { }
                    }
                    onUserChangeds.Empty();
                }
                finally { onUserChangedLock = 0; }
                if (removeUsers.Count != 0)
                {
                    foreach (string removeUser in removeUsers)
                    {
                        logout(user);
                    }
                    removeUsers.Empty();
                }
            }
            if (user != null && OnLogin != null)
            {
                OnLogin(user);
            }
        }
示例#28
0
        static void Main(string[] args)
        {
            List <double> AllNumbers = new list <double>();

            Console.WriteLine("Please enter a number");
            string usersAnswerAsString  = Console.ReadLine();
            double usersAnswersAsdouble = Convert.ToDouble(usersAnswerAsString);

            AllNumbers.Add(usersAnswersAsdouble);

            Console.WriteLine("Do you want to enter another number?");
            string enterAnotherNumber = Console.ReadLine();

            while (enterAnotherNumber == "yes")
            {
                Console.WriteLine("Please enter a number");
                string usersAnswerAsString  = Console.ReadLine();
                double usersAnswersAsdouble = Convert.ToDouble(usersAnswerAsString);
                AllNumbers.Add(usersAnswersAsdouble);

                Console.WriteLine("Do you want to enter another number?");
                string enterAnotherNumber = Console.ReadLine();
            }
        }
示例#29
0
        public void VectorFind()
        {
            List <string> findme = new list <string>();

            findme.Add("A7b3625 see4 Ñ");
            findme.Find("Ñ");
            findme.Find("");
            findme.Find("7");
            findme.Find("35");
            findme.Find("A7b3625 see4 Ñ");
            findme.Find("0");
            findme.Find("a4");
            findme.Find("85");
            findme.Find("8 cross");
            findme.Find("cross");
        }
示例#30
0
 /// <summary>
 /// 根据成员属性获取自定义属性集合
 /// </summary>
 /// <typeparam name="attributeType">自定义属性类型</typeparam>
 /// <param name="member">成员属性</param>
 /// <param name="isInherit">是否包含继承属性</param>
 /// <returns>自定义属性集合</returns>
 public static list <attributeType> customAttributes <attributeType>
     (this MemberInfo member, bool isInherit) where attributeType : Attribute
 {
     if (member != null)
     {
         attributeType        value;
         list <attributeType> values = new list <attributeType>();
         foreach (object attribute in member.GetCustomAttributes(typeof(attributeType), isInherit))
         {
             value = attribute as attributeType;
             if (value != null)
             {
                 values.Add(value);
             }
         }
         return(values);
     }
     return(null);
 }
示例#31
0
 /// <summary>
 /// 线程入池
 /// </summary>
 /// <param name="thread">线程池线程</param>
 internal void Push(thread thread)
 {
     while (Interlocked.CompareExchange(ref threadLock, 1, 0) != 0)
     {
         Thread.Sleep(1);
     }
     try
     {
         if (isDisposed)
         {
             thread.Stop();
         }
         else
         {
             threads.Add(thread);
         }
     }
     finally { threadLock = 0; }
 }
示例#32
0
 /// <summary>
 /// 替换子节点
 /// </summary>
 /// <param name="oldNode">待替换的子节点</param>
 /// <param name="newNode">新的子节点</param>
 /// <returns>是否存在待替换的子节点</returns>
 public bool ReplaceChild(htmlNode oldNode, htmlNode newNode)
 {
     bool isReplace = false;
     if (oldNode != null && newNode != null)
     {
         int oldIndex = this[oldNode];
         if (oldIndex != -1)
         {
             if (newNode.TagName == string.Empty)
             {
                 oldNode.Parent = null;
                 if (newNode.children == null) children.RemoveAt(oldIndex);
                 else
                 {
                     foreach (htmlNode value in newNode.children) value.Parent = this;
                     if (newNode.children.Count == 1) children[oldIndex] = newNode.children[0];
                     else if (oldIndex == children.Count - 1)
                     {
                         children.RemoveAt(oldIndex);
                         children.Add(newNode.children);
                     }
                     else
                     {
                         list<htmlNode>.unsafer values = new list<htmlNode>(children.Count + newNode.children.Count).Unsafer;
                         int newIndex = 0;
                         while (newIndex != oldIndex) values.Add(children[newIndex++]);
                         values.List.Add(newNode.children);
                         for (oldIndex = children.Count; ++newIndex != oldIndex; values.Add(children[newIndex])) ;
                         children = values.List;
                     }
                 }
                 newNode.children = null;
                 isReplace = true;
             }
             else if (!newNode.IsNode(this))
             {
                 int newIndex = this[newNode];
                 if (newIndex == -1)
                 {
                     if (newNode.Parent != null) newNode.Parent.RemoveChild(newNode);
                     newNode.Parent = this;
                     children[oldIndex] = newNode;
                     oldNode.Parent = null;
                 }
                 else
                 {
                     children[oldIndex] = newNode;
                     oldNode.Parent = null;
                     children.RemoveAt(newIndex);
                 }
                 isReplace = true;
             }
         }
     }
     return isReplace;
 }
示例#33
0
        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="fileName">模板文件名</param>
        /// <returns>代码</returns>
        private static list<string> code(string fileName)
        {
            string code = File.ReadAllText(fileName);
            int index = code.IndexOf(@"*/

", StringComparison.Ordinal);
            if (index != -1)
            {
                int startIndex = index += 4;
                Dictionary<string, replace> keys = new Dictionary<string, replace>();
                replace replace;
                foreach (string keyValue in code.Substring(0, index).Split(new string[] { "/*" }, StringSplitOptions.None).sub(1))
                {
                    if ((index = keyValue.IndexOf(':')) != -1 && keyValue.EndsWith(@"*/
", StringComparison.Ordinal))
                    {
                        keys[keyValue.Substring(0, index)] = replace = new replace
                        {
                            values = new subString(keyValue, ++index, keyValue.Length - index - 4).Split(';').getArray(value => value.Split(','))
                        };
                        replace.indexs = new list<int>[replace.values[0].Count];
                        for (index = 0; index != replace.indexs.Length; replace.indexs[index++] = new list<int>()) ;
                    }
                    else error.Add("自定义数据错误 : " + keyValue);
                }
                list<string> codeList = new list<string>();
                for (code = code.Substring(startIndex), startIndex = 0, index = code.IndexOf("/*", StringComparison.Ordinal); index != -1; index = code.IndexOf("/*", startIndex))
                {
                    codeList.Add(code.Substring(startIndex, index - startIndex));
                    if ((startIndex = code.IndexOf("*/", index, StringComparison.Ordinal) + 2) != 1 && startIndex != index + 4)
                    {
                        string name = code.Substring(index, startIndex - index);
                        if ((index = code.IndexOf(name, startIndex, StringComparison.Ordinal)) != -1)
                        {
                            startIndex = index + name.Length;
                            name = name.Substring(2, name.Length - 4);
                            if (name[name.Length - 1] == ']')
                            {
                                int arrayIndex = name.LastIndexOf('[') + 1;
                                if (arrayIndex == 0 || !int.TryParse(name.Substring(arrayIndex, name.Length - arrayIndex - 1), out index))
                                {
                                    error.Add("自定义名称索引错误 : " + name);
                                    index = 0;
                                }
                                else name = name.Substring(0, arrayIndex - 1);
                            }
                            else index = 0;
                            if (keys.TryGetValue(name, out replace))
                            {
                                replace.indexs[index].Add(codeList.Count);
                                codeList.Add(string.Empty);
                            }
                            else error.Add("自定义名称不匹配 : " + name);
                        }
                        else error.Add("自定义名称不匹配 : " + name);
                    }
                    else
                    {
                        error.Add("自定义名称错误 : " + code.Substring(index));
                        startIndex = code.Length;
                    }
                }
                codeList.Add(code.Substring(startIndex));
                string[] codes = codeList.ToArray();
                list<string> values = new list<string>();
                replace[] replaces = keys.Values.getArray();
                do
                {
                    index = replaces.Length;
                    while (--index >= 0 && ++replaces[index].index == replaces[index].values.Length) ;
                    if (index == -1) break;
                    while (++index != replaces.Length) replaces[index].index = 0;
                    for (index = replaces.Length; --index >= 0; )
                    {
                        replace = replaces[index];
                        list<subString> replaceCode = replace.values[replace.index];
                        for (startIndex = replace.indexs.Length; --startIndex >= 0; )
                        {
                            foreach (int codeIndex in replace.indexs[startIndex]) codes[codeIndex] = replaceCode[startIndex];
                        }
                    }
                    values.Add(string.Concat(codes));
                }
                while (true);
                return values;
            }
            else error.Add("自定义文件错误 : " + fileName);
            return null;
        }
示例#34
0
 /// <summary>
 /// class样式筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterClass(filter path, keyValue<list<htmlNode>, bool> value)
 {
     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
     if (path.values == null)
     {
         string name = path.value;
         foreach (htmlNode node in value.Key)
         {
             string className = node["class"];
             if (className != null && className.Split(' ').indexOf(name) != -1) newValues.Add(node);
         }
     }
     else
     {
         staticHashSet<string> names = path.values;
         foreach (htmlNode node in value.Key)
         {
             string className = node["class"];
             if (className != null)
             {
                 foreach(string name in className.Split(' '))
                 {
                     if (names.Contains(name))
                     {
                         newValues.Add(node);
                         break;
                     }
                 }
             }
         }
     }
     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
 }
示例#35
0
 /// <summary>
 /// 合并同域cookie(用于处理跨域BUG)
 /// </summary>
 /// <param name="address">URI地址</param>
 /// <param name="responseHeaderCookie">HTTP头cookie信息</param>
 /// <param name="replaceCookie">需要替换的cookie</param>
 public void MergeDomainCookie(Uri address, string responseHeaderCookie, string replaceCookie)
 {
     if (address != null)
     {
         int index;
         string name;
         Cookie newCookie;
         CookieCollection cookies = new CookieCollection();
         Dictionary<string, Cookie> replaceCookies = null;
         if (responseHeaderCookie != null && responseHeaderCookie.Length != 0)
         {
             replaceCookies = new Dictionary<string, Cookie>();
             DateTime expires;
             string value, domain, path, expiresString;
             string lastCookie = null;
             list<string> newCookies = new list<string>();
             foreach (string cookie in responseHeaderCookie.Split(','))
             {
                 if (lastCookie == null)
                 {
                     string lowerCookie = cookie.ToLower();
                     index = lowerCookie.IndexOf("; expires=", StringComparison.Ordinal);
                     if (index == -1) index = lowerCookie.IndexOf(";expires=", StringComparison.Ordinal);
                     if (index == -1 || cookie.IndexOf(';', index + 10) != -1) newCookies.Add(cookie);
                     else lastCookie = cookie;
                 }
                 else
                 {
                     newCookies.Add(lastCookie + "," + cookie);
                     lastCookie = null;
                 }
             }
             Dictionary<string, string> cookieInfo = new Dictionary<string, string>();
             foreach (string cookie in newCookies)
             {
                 newCookie = null;
                 foreach (subString values in cookie.Split(';'))
                 {
                     if ((index = values.IndexOf('=')) != 0)
                     {
                         if ((index = values.IndexOf('=')) == -1)
                         {
                             name = values.Trim();
                             value = string.Empty;
                         }
                         else
                         {
                             name = values.Substring(0, index).Trim();
                             value = values.Substring(index + 1);
                         }
                         if (newCookie == null) newCookie = new Cookie(web.cookie.FormatCookieName(name), web.cookie.FormatCookieValue(value));
                         else cookieInfo[name.toLower()] = value;
                     }
                 }
                 if (cookieInfo.TryGetValue("expires", out expiresString)
                     && DateTime.TryParse(expiresString, out expires))
                 {
                     newCookie.Expires = expires;
                 }
                 if (cookieInfo.TryGetValue("path", out path)) newCookie.Path = path;
                 replaceCookies[newCookie.Name] = newCookie;
                 newCookie = new Cookie(newCookie.Name, newCookie.Value, newCookie.Path);
                 if (cookieInfo.TryGetValue("domain", out domain)) newCookie.Domain = domain;
                 Cookies.Add(address, newCookie);
                 cookieInfo.Clear();
             }
         }
         if (replaceCookie != null && replaceCookie.Length != 0)
         {
             if (replaceCookies == null) replaceCookies = new Dictionary<string, Cookie>();
             foreach (subString cookie in replaceCookie.Split(';'))
             {
                 if ((index = cookie.IndexOf('=')) != 0)
                 {
                     if (index == -1)
                     {
                         name = web.cookie.FormatCookieName(cookie.Trim());
                         newCookie = new Cookie(name, string.Empty);
                     }
                     else
                     {
                         name = web.cookie.FormatCookieName(cookie.Substring(0, index).Trim());
                         newCookie = new Cookie(name, web.cookie.FormatCookieValue(cookie.Substring(index + 1)));
                     }
                     if (replaceCookies.ContainsKey(name)) replaceCookies[name].Value = newCookie.Value;
                     else replaceCookies.Add(name, newCookie);
                 }
             }
         }
         bool isCookie;
         foreach (Cookie cookie in Cookies.GetCookies(address))
         {
             if (isCookie = replaceCookies != null && replaceCookies.ContainsKey(cookie.Name))
             {
                 newCookie = replaceCookies[cookie.Name];
             }
             else newCookie = new Cookie(cookie.Name, cookie.Value, HttpUtility.UrlDecode((cookie.Path)));
             cookies.Add(newCookie);
             if (isCookie) replaceCookies.Remove(cookie.Name);
             newCookie.Expires = cookie.Expires;
             cookie.Expired = true;
         }
         if (replaceCookies != null)
         {
             foreach (Cookie cookie in replaceCookies.Values) cookies.Add(cookie);
         }
         if (cookies.Count != 0)
         {
             try { Cookies.Add(address, cookies); }
             catch (Exception error)
             {
                 log.Default.Add(error, "合并同域cookie失败", true);
             }
         }
     }
 }
示例#36
0
 /// <summary>
 /// 合并同域cookie(用于处理跨域BUG)
 /// </summary>
 /// <param name="address">URI地址</param>
 /// <param name="cookies">默认cookie集合信息</param>
 /// <param name="documentCookie">登录后的cookie信息</param>
 /// <param name="httpOnlyCookie">登录后的httpOnly相关cookie信息</param>
 public void MergeDomainCookie(Uri address, list<Cookie> cookies, string documentCookie, string httpOnlyCookie)
 {
     if (cookies != null)
     {
         foreach (Cookie cookie in cookies) Cookies.Add(address, cookie);
     }
     if (address != null)
     {
         list<Cookie> newCookies = new list<Cookie>();
         Dictionary<string, int> nameCounts = null;
         list<string> documentCookies = new list<string>(2);
         if (documentCookie.length() != 0) documentCookies.Unsafer.Add(documentCookie);
         if (httpOnlyCookie.length() != 0) documentCookies.Unsafer.Add(httpOnlyCookie);
         if (documentCookies.Count != 0)
         {
             int index, nextCount, count;
             string name;
             Cookie newCookie;
             Dictionary<string, int> nextNameCounts = new Dictionary<string, int>();
             nameCounts = new Dictionary<string, int>();
             foreach (string nextCookie in documentCookies)
             {
                 nextNameCounts.Clear();
                 foreach (subString cookie in nextCookie.Split(';'))
                 {
                     if (cookie.Length != 0 && (index = cookie.IndexOf('=')) != 0)
                     {
                         if (index == -1)
                         {
                             name = web.cookie.FormatCookieName(cookie.Trim());
                         }
                         else name = web.cookie.FormatCookieName(cookie.Substring(0, index).Trim());
                         if (nextNameCounts.TryGetValue(name, out nextCount)) nextNameCounts[name] = ++nextCount;
                         else nextNameCounts.Add(name, nextCount = 1);
                         if (!nameCounts.TryGetValue(name, out count)) count = 0;
                         if (nextCount > count)
                         {
                             if (index == -1) newCookie = new Cookie(name, string.Empty);
                             else newCookie = new Cookie(name, web.cookie.FormatCookieValue(cookie.Substring(index + 1)));
                             newCookies.Add(newCookie);
                             if (count != 0) newCookie.HttpOnly = true;
                             if (count == 0) nameCounts.Add(name, nextCount);
                             else nameCounts[name] = nextCount;
                         }
                     }
                 }
             }
         }
         foreach (Cookie cookie in Cookies.GetCookies(address))
         {
             if (nameCounts != null && nameCounts.ContainsKey(cookie.Name)) cookie.Expired = true;
         }
         if (newCookies.Count != 0)
         {
             try
             {
                 foreach (Cookie cookie in newCookies) Cookies.Add(address, cookie);
             }
             catch (Exception error)
             {
                 log.Default.Add(error, "合并同域cookie失败", true);
             }
         }
     }
 }
示例#37
0
 /// <summary>
 /// 常量转换
 /// </summary>
 protected constantConverter()
 {
     list<keyValue<hashCode<Type>, func<object, string>>> values = new list<keyValue<hashCode<Type>, func<object, string>>>();
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(bool), convertConstantBoolTo01));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(bool?), convertConstantBoolNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(byte), convertConstantByte));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(byte?), convertConstantByteNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(sbyte), convertConstantSByte));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(sbyte?), convertConstantSByteNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(short), convertConstantShort));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(short?), convertConstantShortNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ushort), convertConstantUShort));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ushort?), convertConstantUShortNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(int), convertConstantInt));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(int?), convertConstantIntNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(uint), convertConstantUInt));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(uint?), convertConstantUIntNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(long), convertConstantLong));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(long?), convertConstantLongNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ulong), convertConstantULong));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ulong?), convertConstantULongNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(float), convertConstantFloat));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(float?), convertConstantFloatNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(double), convertConstantDouble));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(double?), convertConstantDoubleNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(decimal), convertConstantDecimal));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(decimal?), convertConstantDecimalNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(DateTime), convertConstantDateTimeMillisecond));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(DateTime?), convertConstantDateTimeMillisecondNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(string), null));
     converters = new staticDictionary<hashCode<Type>, func<object, string>>(values);
 }
示例#38
0
 /// <summary>
 /// 子孙节点筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterNode(filter path, keyValue<list<htmlNode>, bool> value)
 {
     list<nodeIndex> values = new list<nodeIndex>();
     nodeIndex index = new nodeIndex { Values = value.Key.getList() };
     if (index.Values.Count != 0)
     {
         if (value.Value)
         {
             HashSet<htmlNode> newValues = new HashSet<htmlNode>(), historyNodes = new HashSet<htmlNode>();
             if (path.values == null)
             {
                 if (path.value != null)
                 {
                     string tagName = path.value;
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             else index = values.Pop();
                         }
                         htmlNode node = index.Values[index.Index];
                         if (node.TagName == tagName) newValues.Add(node);
                         if (node.children.count() == 0 || historyNodes.Contains(node))
                         {
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             if (++index.Index != index.Values.Count) values.Add(index);
                             historyNodes.Add(node);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
                 else
                 {
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             else index = values.Pop();
                         }
                         htmlNode node = index.Values[index.Index];
                         newValues.Add(node);
                         if (node.children.count() == 0 || historyNodes.Contains(node))
                         {
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             if (++index.Index != index.Values.Count) values.Add(index);
                             historyNodes.Add(node);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
             }
             else
             {
                 staticHashSet<string> tagNames = path.values;
                 while (true)
                 {
                     if (index.Values == null)
                     {
                         if (values.Count == 0) break;
                         else index = values.Pop();
                     }
                     htmlNode node = index.Values[index.Index];
                     if (tagNames.Contains(node.TagName)) newValues.Add(node);
                     if (node.children.count() == 0 || historyNodes.Contains(node))
                     {
                         if (++index.Index == index.Values.Count) index.Values = null;
                     }
                     else
                     {
                         if (++index.Index != index.Values.Count) values.Add(index);
                         historyNodes.Add(node);
                         index.Values = node.children;
                         index.Index = 0;
                     }
                 }
             }
             if (newValues.Count != 0)
             {
                 return new keyValue<list<htmlNode>, bool>(new list<htmlNode>(newValues), newValues.Count > 1);
             }
         }
         else
         {
             list<htmlNode> newValues = new list<htmlNode>();
             if (path.values == null)
             {
                 if (path.value != null)
                 {
                     string tagName = path.value;
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             else index = values.Pop();
                         }
                         htmlNode node = index.Values[index.Index];
                         if (node.TagName == tagName) newValues.Add(node);
                         if (node.children.count() == 0)
                         {
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             if (++index.Index != index.Values.Count) values.Add(index);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
                 else
                 {
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             else index = values.Pop();
                         }
                         htmlNode node = index.Values[index.Index];
                         newValues.Add(node);
                         if (node.children.count() == 0)
                         {
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             if (++index.Index != index.Values.Count) values.Add(index);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
             }
             else
             {
                 staticHashSet<string> tagNames = path.values;
                 while (true)
                 {
                     if (index.Values == null)
                     {
                         if (values.Count == 0) break;
                         else index = values.Pop();
                     }
                     htmlNode node = index.Values[index.Index];
                     if (tagNames.Contains(node.TagName)) newValues.Add(node);
                     if (node.children.count() == 0)
                     {
                         if (++index.Index == index.Values.Count) index.Values = null;
                     }
                     else
                     {
                         if (++index.Index != index.Values.Count) values.Add(index);
                         index.Values = node.children;
                         index.Index = 0;
                     }
                 }
             }
             if (newValues.Count != 0)
             {
                 return new keyValue<list<htmlNode>, bool>(newValues, newValues.Count > 1);
             }
         }
     }
     return new keyValue<list<htmlNode>, bool>(null, false);
 }
示例#39
0
 /// <summary>
 /// 根据节点名称删除子节点
 /// </summary>
 /// <param name="tagName">节点名称</param>
 public void removeChildsByTagName(string tagName)
 {
     if (children != null)
     {
         int count = children.Count;
         while (--count >= 0 && children[count].TagName != tagName) ;
         if (count >= 0)
         {
             list<htmlNode>.unsafer values = new list<htmlNode>(children.Count).Unsafer;
             int index = 0;
             for (; index != count; ++index)
             {
                 if (children[index].TagName != tagName) values.Add(children[index]);
             }
             for (count = children.Count; ++index != count; values.Add(children[index])) ;
             children = values.List;
         }
     }
 }
示例#40
0
 /// <summary>
 /// 删除匹配的子节点
 /// </summary>
 /// <param name="isRemove">删除子节点匹配器</param>
 private void removeChilds(func<htmlNode, bool> isRemove)
 {
     if (children != null)
     {
         int count = children.Count;
         while (--count >= 0 && !isRemove(children[count])) ;
         if (count >= 0)
         {
             list<htmlNode>.unsafer values = new list<htmlNode>(children.Count).Unsafer;
             int index = 0;
             for (; index != count; ++index)
             {
                 if (!isRemove(children[index])) values.Add(children[index]);
             }
             for (count = children.Count; ++index != count; values.Add(children[index])) ;
             children = values.List;
         }
     }
 }
示例#41
0
 /// <summary>
 /// 根据节点名称获取子孙节点集合
 /// </summary>
 /// <param name="tagName">节点名称</param>
 /// <returns>匹配的子孙节点集合</returns>
 public list<htmlNode> getNodesByTagName(string tagName)
 {
     list<htmlNode> values = new list<htmlNode>();
     foreach (htmlNode value in Nodes)
     {
         if (value.TagName == tagName) values.Add(value);
     }
     return values;
 }
示例#42
0
 /// <summary>
 /// 分割字符串并返回数值集合(不检查数字合法性)
 /// </summary>
 /// <param name="ints">原字符串</param>
 /// <param name="split">分割符</param>
 /// <returns>数值集合</returns>
 public unsafe static list<int> splitIntNoCheck(this string ints, char split)
 {
     list<int> values = new list<int>();
     if (ints != null && ints.Length != 0)
     {
         fixed (char* intPoint = ints)
         {
             int intValue = 0;
             for (char* next = intPoint, end = intPoint + ints.Length; next != end; ++next)
             {
                 if (*next == split)
                 {
                     values.Add(intValue);
                     intValue = 0;
                 }
                 else
                 {
                     intValue *= 10;
                     intValue += *next;
                     intValue -= '0';
                 }
             }
             values.Add(intValue);
         }
     }
     return values;
 }
示例#43
0
 /// <summary>
 /// 生成HTML
 /// </summary>
 /// <param name="isTag">是否包含当前标签</param>
 /// <returns>HTML</returns>
 public string Html(bool isTag)
 {
     if (TagName != null)
     {
         if (web.html.NonanalyticTagNames.Contains(TagName))
         {
             if (isTag && TagName.Length != 1)
             {
                 using (charStream strings = new charStream())
                 {
                     tagHtml(strings);
                     strings.Write(nodeText.Html);
                     tagRound(strings);
                     return strings.ToString();
                 }
             }
         }
         else
         {
             using (charStream strings = new charStream())
             {
                 if (isTag) tagHtml(strings);
                 if (children.count() != 0)
                 {
                     htmlNode node;
                     list<nodeIndex> values = new list<nodeIndex>();
                     nodeIndex index = new nodeIndex { Values = children };
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             {
                                 index = values.Pop();
                                 index.Values[index.Index].tagRound(strings);
                                 if (++index.Index == index.Values.Count)
                                 {
                                     index.Values = null;
                                     continue;
                                 }
                             }
                         }
                         node = index.Values[index.Index];
                         string nodeTagName = node.TagName;
                         bool isNonanalyticTagNames = nodeTagName != null && web.html.NonanalyticTagNames.Contains(nodeTagName);
                         if (node.children.count() == 0 || nodeTagName == null || isNonanalyticTagNames)
                         {
                             if (nodeTagName != null && nodeTagName.Length != 1) node.tagHtml(strings);
                             strings.Write(node.nodeText.Html);
                             if (nodeTagName != null && nodeTagName.Length != 1) node.tagRound(strings);
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             node.tagHtml(strings);
                             values.Add(index);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
                 if (isTag) tagRound(strings);
                 return strings.ToString();
             }
         }
     }
     return nodeText.Html;
 }
示例#44
0
 /// <summary>
 /// 分割字符串
 /// </summary>
 /// <param name="value">原字符串</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="length">分割字符串长度</param>
 /// <param name="split">分割符</param>
 /// <returns>字符子串集合</returns>
 public unsafe static list<subString> split(this string value, int startIndex, int length, char split)
 {
     array.range range = new array.range(value.length(), startIndex, length);
     if (range.GetCount != length) fastCSharp.log.Default.Throw(log.exceptionType.IndexOutOfRange);
     list<subString> values = new list<subString>();
     if (value != null)
     {
         fixed (char* valueFixed = value)
         {
             char* last = valueFixed + range.SkipCount, end = last + range.GetCount;
             for (char* start = last; start != end; )
             {
                 if (*start == split)
                 {
                     values.Add(new subString(value, (int)(last - valueFixed), (int)(start - last)));
                     last = ++start;
                 }
                 else ++start;
             }
             values.Add(new subString(value, (int)(last - valueFixed), (int)(end - last)));
         }
     }
     return values;
 }
示例#45
0
        /// <summary>
        /// 解析HTML节点
        /// </summary>
        /// <param name="html"></param>
        private void create(string html)
        {
            int length = html.Length;
            children = new list<htmlNode>();
            if (length < 2)
            {
                children.Add(new htmlNode { nodeText = new htmlText { FormatHtml = html }, Parent = this });
            }
            else
            {
                int nextIndex, nodeCount;
                htmlNode nextNode;
                fixed (char* htmlFixed = html + "<")
                {
                    fixedMap spaceFixedMap = new fixedMap(spaceMap.Map);
                    fixedMap spaceSplitFixedMap = new fixedMap(spaceSplitMap);
                    fixedMap tagNameFixedMap = new fixedMap(tagNameMap);
                    fixedMap tagNameSplitFixedMap = new fixedMap(tagNameSplitMap);
                    fixedMap attributeSplitFixedMap = new fixedMap(attributeSplitMap);
                    fixedMap attributeNameSplitFixedMap = new fixedMap(attributeNameSplitMap);
                    int startIndex, tagNameLength;
                    string name, htmlValue;
                    char* startChar = htmlFixed, currentChar = htmlFixed, endChar = htmlFixed + length, scriptChar;
                    char splitChar;
                    while (currentChar != endChar)
                    {
                        for (*endChar = '<'; *currentChar != '<'; ++currentChar) ;
                        if (currentChar != endChar)
                        {
                            if ((*++currentChar & 0xff80) == 0)
                            {
                                if (tagNameFixedMap.Get(*currentChar))
                                {
                                    while ((*startChar & 0xffc0) == 0 && spaceFixedMap.Get(*startChar)) ++startChar;
                                    if (startChar != currentChar - 1)
                                    {
                                        for (scriptChar = currentChar - 2; (*scriptChar & 0xffc0) == 0 && spaceFixedMap.Get(*scriptChar); --scriptChar) ;
                                        children.Add(new htmlNode { nodeText = new htmlText { FormatHtml = html.Substring((int)(startChar - htmlFixed), (int)(scriptChar - startChar) + 1) } });
                                    }
                                    if (*currentChar == '/')
                                    {
                                        #region 标签回合
                                        startChar = currentChar - 1;
                                        if (++currentChar != endChar)
                                        {
                                            while ((*currentChar & 0xffc0) == 0 && spaceFixedMap.Get(*currentChar)) ++currentChar;
                                            if (currentChar != endChar)
                                            {
                                                if ((uint)((*currentChar | 0x20) - 'a') <= 26)
                                                {
                                                    for (*endChar = '>'; (*currentChar & 0xffc0) != 0 || !tagNameSplitFixedMap.Get(*currentChar); ++currentChar) ;
                                                    TagName = html.Substring((int)((startChar += 2) - htmlFixed), (int)(currentChar - startChar)).toLower();
                                                    for (startIndex = children.Count - 1; startIndex >= 0 && (children[startIndex].nodeText.FormatHtml != null || children[startIndex].TagName != TagName); --startIndex) ;
                                                    if (startIndex != -1)
                                                    {
                                                        for (nextIndex = children.Count - 1; nextIndex != startIndex; --nextIndex)
                                                        {
                                                            nextNode = children[nextIndex];
                                                            if (nextNode.nodeText.FormatHtml == null)
                                                            {
                                                                if (web.html.MustRoundTagNames.Contains(nextNode.TagName) && (nodeCount = (children.Count - nextIndex - 1)) != 0)
                                                                {
                                                                    nextNode.children = new list<htmlNode>(children.GetSub(nextIndex + 1, nodeCount), true);
                                                                    children.RemoveRange(nextIndex + 1, nodeCount);
                                                                    foreach (htmlNode value in nextNode.children) value.Parent = nextNode;
                                                                }
                                                            }
                                                            else if (nextNode.nodeText.FormatHtml.Length == 0) nextNode.nodeText.FormatHtml = null;
                                                        }
                                                        nextNode = children[startIndex];
                                                        if ((nodeCount = children.Count - ++startIndex) != 0)
                                                        {
                                                            nextNode.children = new list<htmlNode>(children.GetSub(startIndex, nodeCount), true);
                                                            children.RemoveRange(startIndex, nodeCount);
                                                            foreach (htmlNode value in nextNode.children) value.Parent = nextNode;
                                                        }
                                                        nextNode.nodeText.FormatHtml = string.Empty;//已回合标识
                                                    }
                                                    while (*currentChar != '>') ++currentChar;
                                                    if (currentChar != endChar) ++currentChar;
                                                }
                                                else
                                                {
                                                    for (*endChar = '>'; *currentChar != '>'; ++currentChar) ;
                                                    if (currentChar != endChar) ++currentChar;
                                                    htmlValue = html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar));
                                                    children.Add(new htmlNode { TagName = "/", nodeText = new htmlText { FormatHtml = htmlValue, FormatText = htmlValue } });
                                                }
                                                startChar = currentChar;
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (*currentChar != '!')
                                    {
                                        #region 标签开始
                                        startChar = currentChar;
                                        children.Add(nextNode = new htmlNode());
                                        for (*endChar = '>'; (*currentChar & 0xffc0) != 0 || !tagNameSplitFixedMap.Get(*currentChar); ++currentChar) ;
                                        nextNode.TagName = html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar)).toLower();
                                        if (currentChar == endChar) startChar = endChar;
                                        else
                                        {
                                            #region 属性解析
                                            if (*currentChar != '>')
                                            {
                                                startChar = ++currentChar;
                                                while (currentChar != endChar)
                                                {
                                                    while ((*currentChar & 0xffc0) == 0 && attributeSplitFixedMap.Get(*currentChar)) ++currentChar;
                                                    if (*currentChar == '>')
                                                    {
                                                        if (currentChar != endChar)
                                                        {
                                                            if (*(currentChar - 1) == '/') nextNode.nodeText.FormatHtml = string.Empty;
                                                            startChar = ++currentChar;
                                                        }
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        for (startChar = currentChar++; (*currentChar & 0xffc0) != 0 || !tagNameSplitFixedMap.Get(*currentChar); ++currentChar) ;
                                                        htmlValue = name = checkName(html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar)).toLower());
                                                        if (currentChar != endChar && ((*currentChar & 0xffc0) != 0 || !attributeNameSplitFixedMap.Get(*currentChar)))
                                                        {
                                                            if (*currentChar != '=')
                                                            {
                                                                while ((*currentChar & 0xffc0) == 0 && spaceFixedMap.Get(*currentChar)) ++currentChar;
                                                            }
                                                            if (*currentChar == '=')
                                                            {
                                                                while ((*++currentChar & 0xffc0) == 0 && spaceFixedMap.Get(*currentChar)) ;
                                                                if ((splitChar = *currentChar) != '>')
                                                                {
                                                                    if (splitChar == '"' || splitChar == '\'')
                                                                    {
                                                                        for (startChar = ++currentChar, *endChar = splitChar; *currentChar != splitChar; ++currentChar) ;
                                                                        *endChar = '>';
                                                                    }
                                                                    else
                                                                    {
                                                                        for (startChar = currentChar++; (*currentChar & 0xffc0) != 0 || !spaceSplitFixedMap.Get(*currentChar); ++currentChar) ;
                                                                    }
                                                                    htmlValue = html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar));
                                                                }
                                                            }
                                                        }
                                                        if (nextNode.attributes == null) nextNode.attributes = new Dictionary<string, htmlText>();
                                                        nextNode.attributes[name] = new htmlText { FormatHtml = htmlValue };
                                                        if (currentChar != endChar)
                                                        {
                                                            if (*currentChar == '>')
                                                            {
                                                                if (*(currentChar - 1) == '/') nextNode.nodeText.FormatHtml = string.Empty;
                                                                startChar = ++currentChar;
                                                                break;
                                                            }
                                                            startChar = ++currentChar;
                                                        }
                                                    }
                                                }
                                            }
                                            else startChar = ++currentChar;
                                            #endregion

                                            #region 非解析标签
                                            if (currentChar == endChar) startChar = endChar;
                                            else if (web.html.NonanalyticTagNames.Contains(TagName = nextNode.TagName))
                                            {
                                                scriptChar = endChar;
                                                tagNameLength = TagName.Length + 2;
                                                fixed (char* tagNameFixed = TagName)
                                                {
                                                    while ((int)(endChar - currentChar) > tagNameLength)
                                                    {
                                                        for (currentChar += tagNameLength; *currentChar != '>'; ++currentChar) ;
                                                        if (currentChar != endChar && *(int*)(currentChar - tagNameLength) == (('/' << 16) + '<'))
                                                        {
                                                            if (unsafer.String.EqualCase(currentChar - TagName.Length, tagNameFixed, TagName.Length))
                                                            {
                                                                scriptChar = currentChar - tagNameLength;
                                                                if (currentChar != endChar) ++currentChar;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                if (startChar != scriptChar)
                                                {
                                                    nextNode.nodeText.FormatHtml = nextNode.nodeText.FormatText = html.Substring((int)(startChar - htmlFixed), (int)(scriptChar - startChar));
                                                }
                                                if (scriptChar == endChar) currentChar = endChar;
                                                startChar = currentChar;
                                            }
                                            #endregion
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        #region 注释
                                        startChar = currentChar - 1;
                                        if (++currentChar != endChar)
                                        {
                                            *endChar = '>';
                                            if ((length = (int)(endChar - currentChar)) > 2 && *(int*)currentChar == (('-' << 16) + '-'))
                                            {
                                                for (currentChar += 2; *currentChar != '>'; ++currentChar) ;
                                                while (currentChar != endChar && *(int*)(currentChar - 2) != (('-' << 16) + '-'))
                                                {
                                                    if ((currentChar += 3) < endChar)
                                                    {
                                                        while (*currentChar != '>') ++currentChar;
                                                    }
                                                    else currentChar = endChar;
                                                }
                                            }
                                            else if (length > 9
                                                && (*(int*)currentChar & 0x200000) == ('[' + ('c' << 16))
                                                && (*(int*)(currentChar + 2) & 0x200020) == ('d' + ('a' << 16))
                                                && (*(int*)(currentChar + 4) & 0x200020) == ('t' + ('a' << 16))
                                                && *(currentChar + 6) == '[')
                                            {
                                                for (currentChar += 9; *currentChar != '>'; ++currentChar) ;
                                                while (currentChar != endChar && *(int*)(currentChar - 2) != ((']' << 16) + ']'))
                                                {
                                                    if ((currentChar += 3) < endChar)
                                                    {
                                                        while (*currentChar != '>') ++currentChar;
                                                    }
                                                    else currentChar = endChar;
                                                }
                                            }
                                            else
                                            {
                                                while (*currentChar != '>') ++currentChar;
                                            }
                                            if (currentChar != endChar) ++currentChar;
                                        }
                                        htmlValue = html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar) + (*(currentChar - 1) == '>' ? 0 : 1));
                                        children.Add(new htmlNode { TagName = "!", nodeText = new htmlText { FormatHtml = htmlValue, FormatText = htmlValue } });
                                        startChar = currentChar;
                                        #endregion
                                    }
                                }
                            }
                            else ++currentChar;
                        }
                    }
                    if (startChar != endChar)
                    {
                        *endChar = '>';
                        while ((*startChar & 0xffc0) == 0 && spaceFixedMap.Get(*startChar)) ++startChar;
                        if (startChar != endChar)
                        {
                            for (scriptChar = endChar - 1; (*scriptChar & 0xffc0) == 0 && spaceFixedMap.Get(*scriptChar); --scriptChar) ;
                            children.Add(new htmlNode { nodeText = new htmlText { FormatHtml = html.Substring((int)(startChar - htmlFixed), (int)(scriptChar - startChar) + 1) } });
                        }
                    }
                }
                for (nextIndex = children.Count - 1; nextIndex != -1; nextIndex--)
                {
                    nextNode = children[nextIndex];
                    if (nextNode.nodeText.FormatHtml == null)
                    {
                        if (web.html.MustRoundTagNames.Contains(nextNode.TagName)
                            && (nodeCount = (children.Count - nextIndex - 1)) != 0)
                        {
                            nextNode.children = new list<htmlNode>(children.GetSub(nextIndex + 1, nodeCount), true);
                            children.RemoveRange(nextIndex + 1, nodeCount);
                            foreach (htmlNode value in children) value.Parent = nextNode;
                        }
                    }
                    else if (nextNode.nodeText.FormatHtml.Length == 0) nextNode.nodeText.FormatHtml = null;
                }
                foreach (htmlNode value in children) value.Parent = this;
            }
        }
示例#46
0
 /// <summary>
 /// 子节点筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterChild(filter path, keyValue<list<htmlNode>, bool> value)
 {
     if (path.index < 0)
     {
         if (path.indexs == null)
         {
             if (path.values == null)
             {
                 if (path.value != null)
                 {
                     string tagName = path.value;
                     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
                     foreach (htmlNode nodes in value.Key)
                     {
                         if (nodes.children.count() > 0)
                         {
                             foreach (htmlNode node in nodes.children)
                             {
                                 if (node.TagName == tagName) newValues.Add(node);
                             }
                         }
                     }
                     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
                 }
                 else
                 {
                     int index = 0;
                     foreach (htmlNode nodes in value.Key) if (nodes.children != null) index += nodes.children.Count;
                     if (index != 0)
                     {
                         htmlNode[] newValues = new htmlNode[index];
                         index = 0;
                         foreach (htmlNode nodes in value.Key)
                         {
                             if (nodes.children != null)
                             {
                                 nodes.children.CopyTo(newValues, index);
                                 index += nodes.children.Count;
                             }
                         }
                         return new keyValue<list<htmlNode>, bool>(new list<htmlNode>(newValues, true), value.Value && newValues.Length != 1);
                     }
                     return new keyValue<list<htmlNode>, bool>(null, false);
                 }
             }
             else
             {
                 staticHashSet<string> tagNames = path.values;
                 list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
                 foreach (htmlNode nodes in value.Key)
                 {
                     if (nodes.children.count() != 0)
                     {
                         foreach (htmlNode node in nodes.children)
                         {
                             if (tagNames.Contains(node.TagName)) newValues.Add(node);
                         }
                     }
                 }
                 return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
             }
         }
         else
         {
             list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
             if (path.value != null)
             {
                 string tagName = path.value;
                 staticHashSet<int> indexs = path.indexs;
                 foreach (htmlNode nodes in value.Key)
                 {
                     if (nodes.children.count() != 0)
                     {
                         int index = 0;
                         foreach (htmlNode node in nodes.children)
                         {
                             if (node.TagName == tagName)
                             {
                                 if (indexs.Contains(index)) newValues.Add(node);
                                 ++index;
                             }
                         }
                     }
                 }
             }
             else
             {
                 int[] indexs = path.indexs.GetList().ToArray();
                 foreach (htmlNode nodes in value.Key)
                 {
                     int count = nodes.children.count();
                     if (count > 0)
                     {
                         list<htmlNode> children = nodes.children;
                         for (int index = indexs.Length; --index >= 0; )
                         {
                             if (index < count) newValues.Add(children[index]);
                         }
                     }
                 }
             }
             return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
         }
     }
     else
     {
         list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
         if (path.value != null)
         {
             string tagName = path.value;
             int index = path.index;
             foreach (htmlNode nodes in value.Key)
             {
                 if (nodes.children.count() != 0)
                 {
                     int count = 0;
                     foreach (htmlNode node in nodes.children)
                     {
                         if (node.TagName == tagName)
                         {
                             if (count == index)
                             {
                                 newValues.Add(node);
                                 break;
                             }
                             ++count;
                         }
                     }
                 }
             }
         }
         else
         {
             int index = path.index;
             foreach (htmlNode nodes in value.Key)
             {
                 if (index < nodes.children.count()) newValues.List.Add(nodes.children[index]);
             }
         }
         return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
     }
 }
示例#47
0
 /// <summary>
 /// 根据筛选路径值匹配HTML节点集合
 /// </summary>
 /// <param name="path">筛选路径</param>
 /// <param name="node">筛选节点</param>
 /// <returns>匹配的HTML节点集合</returns>
 public static list<htmlNode> Get(string path, htmlNode node)
 {
     if (path != null && path.Length != 0)
     {
         list<htmlNode> nodes = new list<htmlNode>();
         nodes.Add(node);
         return get(path).get(new keyValue<list<htmlNode>, bool>(nodes, false));
     }
     return null;
 }
示例#48
0
 /// <summary>
 /// 属性值筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterValue(filter path, keyValue<list<htmlNode>, bool> value)
 {
     string name = path.name;
     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
     if (path.values == null && path.value == null)
     {
         foreach (htmlNode node in value.Key)
         {
             if (node.attributes != null && node.attributes.ContainsKey(name)) newValues.Add(node);
         }
     }
     else
     {
         if (path.values == null)
         {
             string nameValue = path.value;
             foreach (htmlNode node in value.Key)
             {
                 if (node[name] == nameValue) newValues.Add(node);
             }
         }
         else
         {
             staticHashSet<string> values = path.values;
             foreach (htmlNode node in value.Key)
             {
                 if (values.Contains(node[name])) newValues.Add(node);
             }
         }
     }
     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
 }
示例#49
0
 /// <summary>
 /// 删除匹配的子孙节点
 /// </summary>
 /// <param name="isRemove">删除节点匹配器</param>
 public void Remove(func<htmlNode, bool> isRemove)
 {
     if (isRemove != null)
     {
         removeChilds(isRemove);
         if (children.count() != 0)
         {
             htmlNode node;
             list<nodeIndex> values = new list<nodeIndex>();
             nodeIndex index = new nodeIndex { Values = children };
             while (true)
             {
                 if (index.Values == null)
                 {
                     if (values.Count == 0) break;
                     else index = values.Pop();
                 }
                 node = index.Values[index.Index];
                 if (node.children != null) node.removeChilds(isRemove);
                 if (node.children.count() == 0)
                 {
                     if (++index.Index == index.Values.Count) index.Values = null;
                 }
                 else
                 {
                     if (++index.Index != index.Values.Count) values.Add(index);
                     index.Values = node.children;
                     index.Index = 0;
                 }
             }
         }
     }
 }
示例#50
0
 public static list ToDoubleList(list src)
 {
     list ret = new list();
     double entry;
     for (int i = 0; i < src.Data.Length - 1; i++)
     {
         if (double.TryParse(src.Data[i].ToString(), out entry))
         {
             ret.Add(entry);
         }
     }
     return ret;
 }
示例#51
0
 /// <summary>
 /// 根据节点名称获取子节点集合
 /// </summary>
 /// <param name="tagName">节点名称</param>
 /// <returns>子节点集合</returns>
 public list<htmlNode> getChildsByTagName(string tagName)
 {
     list<htmlNode>.unsafer values = new list<htmlNode>(children.count()).Unsafer;
     if (children != null)
     {
         foreach (htmlNode value in children)
         {
             if (value.TagName == tagName) values.Add(value);
         }
     }
     return values.List;
 }
示例#52
0
 public static list ToDoubleList(list src)
 {
     list ret = new list();
     double entry;
     for (int i = 0; i < src.Data.Length - 1; i++)
     {
         if (double.TryParse(src.Data[i].ToString(), NumberStyles.Float, Culture.NumberFormatInfo, out entry))
         {
             ret.Add(entry);
         }
     }
     return ret;
 }
示例#53
0
        unsafe static sqlDbType()
        {
            #region C#类型转SQL数据类型集合
            list<keyValue<hashCode<Type>, SqlDbType>> formCSharpType = new list<keyValue<hashCode<Type>, SqlDbType>>();
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(bool), SqlDbType.Bit));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(byte), SqlDbType.TinyInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(sbyte), SqlDbType.TinyInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(short), SqlDbType.SmallInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(ushort), SqlDbType.SmallInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(int), SqlDbType.Int));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(uint), SqlDbType.Int));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(long), SqlDbType.BigInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(ulong), SqlDbType.BigInt));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(decimal), SqlDbType.Decimal));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(float), SqlDbType.Real));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(double), SqlDbType.Float));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(string), SqlDbType.NVarChar));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(DateTime), SqlDbType.DateTime));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(Guid), SqlDbType.UniqueIdentifier));
            formCSharpType.Add(new keyValue<hashCode<Type>, SqlDbType>(typeof(byte[]), SqlDbType.VarBinary));
            formCSharpTypes = new staticDictionary<hashCode<Type>, SqlDbType>(formCSharpType);
            #endregion

            MaxEnumValue = fastCSharp.Enum.GetMaxValue<SqlDbType>(-1) + 1;
            int dataIndex = 0, mapSize = ((MaxEnumValue + 31) >> 5) << 2;
            pointer[] datas = unmanaged.Get(true, mapSize, mapSize, MaxEnumValue * sizeof(int));
            stringTypeMap = new fixedMap(datas[dataIndex++]).Unsafer;
            textImageTypeMap = new fixedMap(datas[dataIndex++]).Unsafer;
            sizes = datas[dataIndex++];

            #region 字符串类型占位集合
            stringTypeMap.Set((int)SqlDbType.Char);
            stringTypeMap.Set((int)SqlDbType.NChar);
            stringTypeMap.Set((int)SqlDbType.VarChar);
            stringTypeMap.Set((int)SqlDbType.NVarChar);
            stringTypeMap.Set((int)SqlDbType.Text);
            stringTypeMap.Set((int)SqlDbType.NText);
            #endregion

            #region 文本类型占位集合
            textImageTypeMap.Set((int)SqlDbType.Text);
            textImageTypeMap.Set((int)SqlDbType.NText);
            textImageTypeMap.Set((int)SqlDbType.Image);
            #endregion

            #region 类型默认长度
            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
        }