Пример #1
0
        public static bool RefreshSessionIdentity(string sessionid)
        {
            SessionIdentity si = new SessionIdentity();

            if (_SessionPools.TryGetValue(sessionid, out si))
            {
                si.CreatedTime = DateTime.Now;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private ISession GetNodeSession(string nodeid)
        {
            ISession result = null;

            mRemoteNodeSessions.TryGetValue(nodeid, out result);
            return(result);
        }
Пример #3
0
        public void Progress(string studyInstUID, int completed)
        {
            try
            {
                mr.WaitOne();
                mr.Reset();

                DownloadItem oldItem = null;

                if (downloadItems.TryGetValue(studyInstUID, out oldItem))
                {
                    DownloadItem newItem = new DownloadItem()
                    {
                        Completed = oldItem.Completed + 1,
                    };
                }
                else
                {
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                mr.Set();
            }
        }
Пример #4
0
        internal void Aggregate <TType>(IDomainEvent <TType> domainEvent)
            where TType : IDomainEvent <TType>
        {
            List <object> handlers;

            if (eventHandlerLists.TryGetValue(typeof(TType), out handlers))
            {
                foreach (var handler in handlers.Cast <IHandleDomainEvent <TType> >())
                {
                    dynamic dynHandler = handler;
                    dynHandler.Handle((TType)domainEvent);
                }

                genericEventHandlersLock.EnterReadLock();
                try
                {
                    foreach (var handler in genericEventHandlers)
                    {
                        dynamic dynHandler = handler;
                        dynHandler.Handle((TType)domainEvent);
                    }
                }
                finally
                {
                    genericEventHandlersLock.ExitReadLock();
                }
            }
        }
Пример #5
0
        public static TypeDescriptor GetDescriptor(Type PropertyType)
        {
            TypeDescriptor instance;

            if (!InstanceCache.TryGetValue(PropertyType, out instance))
            {
                throw new Exception("没有缓存PropertyType,错误.");
            }
            return(instance);
        }
Пример #6
0
        internal ClientActionHanler GetHandler(MethodInfo method)
        {
            ClientActionHanler result;

            if (!mHandlers.TryGetValue(method, out result))
            {
                result            = new ClientActionHanler(method);
                mHandlers[method] = result;
            }
            return(result);
        }
Пример #7
0
 public T Create<T>()
 {
     Type type = typeof(T);
     object result;
     if (!mAPI.TryGetValue(type, out result))
     {
         result = DispatchProxy.Create<T, HttpClusterApiProxy>();
         mAPI[type] = result;
         ((HttpClusterApiProxy)result).Cluster = this;
     }
     return (T)result;
 }
Пример #8
0
 public object this[string name]
 {
     get
     {
         mProperties.TryGetValue(name, out object data);
         return(data);
     }
     set
     {
         mProperties[name] = value;
     }
 }
Пример #9
0
        /// <summary>
        /// Retrieve a KineticaType object by the type label.
        /// </summary>
        /// <param name="typeName">The label/name of the type.</param>
        /// <returns></returns>
        private KineticaType GetType(string typeName)
        {
            KineticaType type = null;
            string       typeId;

            if (typeNameLookup.TryGetValue(typeName, out typeId))
            {
                knownTypes.TryGetValue(typeId, out type);
            }

            return(type);
        }
Пример #10
0
        public bool TryLock(string key, RegisterServiceInfo locker, bool checkReady = true)
        {
            if (checkReady && IsReady == false)
            {
                throw new Exception("lock key is not ready");
            }

            KeyObject keyObj = null;

            while (true)
            {
                if (_cache.TryGetValue(key, out keyObj) == false)
                {
                    if (_cache.TryAdd(key, new KeyObject()
                    {
                        Key = key,
                        Locker = locker.ServiceId
                    }))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (keyObj.Locker == locker.ServiceId)
                    {
                        keyObj.RemoveTime = null;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Пример #11
0
        public static bool TryGetDeviceInfo(string key, out DeviceInfo device)
        {
            _deviceInfos = _impl.GetData("DeviceInfo") as ConcurrentDictionary <string, DeviceInfo>;
            if (_deviceInfos == null)
            {
                lock (_sync)
                {
                    if (_deviceInfos == null)
                    {
                        _deviceInfos = LoadDeviceInfo();
                    }
                }
            }

            return(_deviceInfos.TryGetValue(key, out device));
        }
Пример #12
0
        public static I CreateProxy <I, T, K>()
            where T : I, new()
            where K : IInterceptor
        {
            Type   classType = typeof(T);
            string keyName   = classType.FullName;

            Type aopType = null;

            if (!typeDic.TryGetValue(keyName, out aopType))
            {
                ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(keyName, keyName + Guid.NewGuid().ToString());
                aopType = BulidType(classType, moduleBuilder, typeof(K));
                typeDic.TryAdd(keyName, aopType);
            }

            return((I)Activator.CreateInstance(aopType));
        }
Пример #13
0
        public void ClockBatchGo111111111111()
        {
            DateTime                 _now    = DateTime.Now;
            ClockInEntity            Db      = new ClockInEntity();
            IEnumerable <ClockBatch> allData = (from r in Db.ClockBatch
                                                where r.flag == true
                                                select r).ToList();
            //.Where(r => _now.Subtract(Convert.ToDateTime(r.LastClockTime)).TotalHours > 1);
            //.Where(r => _now.TimeOfDay.TotalHours-  Convert.ToDateTime(Convert.ToDateTime(r.LastClockTime).ToShortTimeString()).TimeOfDay.TotalHours > 1);
            var     ClassName    = "";
            JObject studentsJson = null;
            string  strResult    = "";
            IEnumerable <JToken> studentsList;
            //获取所有班级
            var           temp     = allData.GroupBy(x => x.ClassName).Select(g => new { g.Key }).ToList();
            List <string> allClass = new List <string>();

            temp.ForEach(x => _dicSucClass.TryAdd(x.Key, true));
            try
            {
                foreach (var model in allData.OrderBy(P => Guid.NewGuid()))
                {
                    _dicSucClass.TryGetValue(model.ClassName, out bool b);
                    if (!b)
                    {
                        continue;
                    }
                    if (model.StartClockTime == null || _now.Subtract(Convert.ToDateTime(model.LastClockTime)).TotalHours < 1)
                    {
                        continue;
                    }
                    if (DateTime.Parse(Convert.ToDateTime(model.StartClockTime.ToString()).ToShortTimeString()).TimeOfDay > _now.TimeOfDay)
                    {
                        continue;
                    }

                    ClassName = System.Text.RegularExpressions.Regex.Replace(model.ClassName, @"[^0-9]+", "");
                    var response1 = HttpPost(posturl1, "idcard=" + model.CardId);
                    strResult = Unicode2String(response1);//正常字符串结果
                    if (strResult.Contains("第一步成功"))
                    {
                        try
                        {
                            studentsJson = JObject.Parse(response1);
                        }
                        catch (Exception)
                        {
                            model.ClockState   = false;
                            model.FailedReason = strResult;
                            Db.ClockBatch.Attach(model);
                            Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                            Db.SaveChanges();
                            continue;
                        }
                        studentsList = studentsJson["data"]["classes"].AsEnumerable();
                        foreach (var item in studentsList)
                        {
                            //找到班级名称对应的班级ID 放入班级ID字典  从右边取10个字符,然后正则取纯数字。OS:我是被逼的
                            if (ClassName.Equals(System.Text.RegularExpressions.Regex.Replace(item["tname"].ToString().Remove(0, item["tname"].ToString().Length - 10), @"[^0-9]+", "")))
                            {
                                if (!_dicClassID.ContainsKey(model.ClassName))
                                {
                                    _dicClassID.TryAdd(ClassName, item["id"].ToString());
                                    break;
                                }
                            }
                            ;
                        }
                        if (!_dicClassID.ContainsKey(ClassName))
                        {
                            //logger.Warn($"打卡失败,请该工号{model.CardId}是否在该班级");
                            continue;
                        }

                        var response2 = HttpPost(posturl2, "class_id=" + _dicClassID[ClassName]
                                                 , new Dictionary <string, string>()
                        {
                            { "cookie", _dicCookie[string.Format("idcard={0}", model.CardId)] }
                        });
                        if (JObject.Parse(response2).ToString().Contains("成功"))
                        {
                            model.LastClockTime = DateTime.Now;
                            model.ClockState    = true;
                            model.FailedReason  = "";
                            model.Times++;
                            Db.ClockBatch.Attach(model);
                            Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                            Db.SaveChanges();
                            allClass.Remove(model.ClassName);
                            Thread.Sleep(new Random().Next(3000, 6000));
                        }
                        else if ((JObject.Parse(response2).ToString().Contains("已签到")))
                        {
                            model.ClockState   = false;
                            model.FailedReason = JObject.Parse(response2)["msg"].ToString() + DateTime.Now.ToString();
                            Db.ClockBatch.Attach(model);
                            Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                            Db.SaveChanges();
                        }
                        else
                        {
                            model.ClockState   = false;
                            model.FailedReason = JObject.Parse(response2)["msg"].ToString() + DateTime.Now.ToString();
                            Db.ClockBatch.Attach(model);
                            Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                            Db.SaveChanges();
                            _dicSucClass.TryRemove(model.ClassName, out bool aa);
                        }
                    }
                    else
                    {
                        model.ClockState   = false;
                        model.FailedReason = strResult;
                        Db.ClockBatch.Attach(model);
                        Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                        Db.SaveChanges();
                        _dicSucClass.TryRemove(model.ClassName, out bool bb);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #14
0
        public void ClockBatchGo()
        {
            _dicCookie.Clear();
            _dicClassID.Clear();
            _dicSucClass.Clear();
            ClockInEntity            Db      = new ClockInEntity();
            IEnumerable <ClockBatch> allData = (from r in Db.ClockBatch
                                                where r.flag == true
                                                select r).ToList();
            //.Where(r => _now.Subtract(Convert.ToDateTime(r.LastClockTime)).TotalHours > 1);
            //.Where(r => _now.TimeOfDay.TotalHours-  Convert.ToDateTime(Convert.ToDateTime(r.LastClockTime).ToShortTimeString()).TimeOfDay.TotalHours > 1);
            var     ClassName    = "";
            JObject studentsJson = null;
            string  strResult1   = "";
            string  strResult2   = "";
            IEnumerable <JToken> studentsList;
            //获取所有班级
            var           temp     = allData.GroupBy(x => x.ClassName).Select(g => new { g.Key }).ToList();
            List <string> allClass = new List <string>();

            temp.ForEach(x => _dicSucClass.TryAdd(x.Key, 2));
            try
            {
                foreach (var model in allData.OrderBy(P => Guid.NewGuid()))
                {
                    try
                    {
                        //该班失败的次数大于成功的次数 会停止该班的打卡
                        _dicSucClass.TryGetValue(model.ClassName, out int b);
                        if (b <= 0)
                        {
                            continue;
                        }
                        if (model.StartClockTime == null || DateTime.Now.Subtract(Convert.ToDateTime(model.LastClockTime)).TotalHours < 0.5)
                        {
                            continue;
                        }
                        if (DateTime.Parse(Convert.ToDateTime(model.StartClockTime.ToString()).ToShortTimeString()).TimeOfDay > DateTime.Now.TimeOfDay)
                        {
                            continue;
                        }

                        ClassName = System.Text.RegularExpressions.Regex.Replace(model.ClassName, @"[^0-9]+", "");
                        var response1 = HttpPost(posturl1, "idcard=" + model.CardId);
                        strResult1 = Unicode2String(response1);//正常字符串结果
                        if (strResult1.Contains("第一步成功"))
                        {
                            try
                            {
                                studentsJson = JObject.Parse(response1);
                            }
                            catch (Exception ex)
                            {
                                logger.Warn($"第一步网站JSON返回解析错误{strResult1}");
                                model.ClockState    = false;
                                model.FailedReason += strResult1 + DateTime.Now;
                                Db.ClockBatch.Attach(model);
                                Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                                Db.SaveChanges();
                                _dicSucClass[model.ClassName]--;
                                continue;
                            }
                            studentsList = studentsJson["data"]["classes"].AsEnumerable();
                            if (!_dicClassID.ContainsKey(model.ClassName))
                            {
                                foreach (var item in studentsList)
                                {
                                    //找到班级名称对应的班级ID 放入班级ID字典  删除“2019”再做数字匹配
                                    if (ClassName.Equals(Regex.Replace(item["tname"].ToString().Replace("2019", ""), @"[^0-9]+", "")))
                                    {
                                        _dicClassID.TryAdd(model.ClassName, item["id"].ToString());//key用model.ClassName是因为有:不同老师的班,但是数字相同的情况
                                        break;
                                    }
                                    ;
                                }
                            }
                            if (!_dicClassID.ContainsKey(model.ClassName))
                            {
                                model.FailedReason += $"打卡失败,请该工号{model.CardId}是否在该班级";
                                Db.ClockBatch.Attach(model);
                                Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                                Db.SaveChanges();
                                _dicSucClass[model.ClassName]--;
                                continue;
                            }

                            var response2 = HttpPost(posturl2, "class_id=" + _dicClassID[model.ClassName]
                                                     , new Dictionary <string, string>()
                            {
                                { "cookie", _dicCookie[string.Format("idcard={0}", model.CardId)] }
                            });
                            try
                            {
                                strResult2 = JObject.Parse(response2).ToString();
                            }
                            catch (Exception)
                            {
                                logger.Warn($"第二步网站JSON返回解析错误{Unicode2String(response2)}");
                                _dicSucClass[model.ClassName]--;
                                continue;
                            }
                            if (strResult2.Contains("成功"))
                            {
                                model.LastClockTime = DateTime.Now;
                                model.ClockState    = true;
                                model.FailedReason  = "";
                                model.Times++;
                                Db.ClockBatch.Attach(model);
                                Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                                Db.SaveChanges();
                                _dicSucClass[model.ClassName]++; //此次操作成功次数
                                Thread.Sleep(new Random().Next(500, 1001));
                            }
                            else if ((strResult2.Contains("已签")))
                            {
                                if (DateTime.Now.Subtract(Convert.ToDateTime(model.LastClockTime)).TotalHours > 0.5)
                                {
                                    model.Times++;
                                }
                                model.LastClockTime = DateTime.Now;
                                model.ClockState    = true;
                                model.FailedReason += JObject.Parse(response2)["msg"].ToString() + DateTime.Now.ToString();
                                Db.ClockBatch.Attach(model);
                                Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                                Db.SaveChanges();
                                _dicSucClass[model.ClassName]++; //此次操作成功次数
                            }
                            else
                            {
                                model.ClockState    = false;
                                model.FailedReason += JObject.Parse(response2)["msg"].ToString() + DateTime.Now.ToString();
                                Db.ClockBatch.Attach(model);
                                Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                                Db.SaveChanges();
                                //_dicSucClass.TryRemove(model.ClassName, out int aa);
                                _dicSucClass[model.ClassName]--;
                            }
                        }
                        else
                        {
                            model.ClockState    = false;
                            model.FailedReason += strResult1 + DateTime.Now;
                            Db.ClockBatch.Attach(model);
                            Db.Entry <ClockBatch>(model).State = EntityState.Modified;
                            Db.SaveChanges();
                            //_dicSucClass.TryRemove(model.ClassName, out bool bb);
                            _dicSucClass[model.ClassName]--;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Fatal($"遍历内部错误,错误工号{model.CardId}错误信息{ex},已continue,继续下一个打卡用户!!!!预期外的错误!!!!{DateTime.Now.ToString()}");
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
        }