public TData GetJobSpaceData <TData>(string jobSpace, string busiType, TData defaultVal = default(TData))
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            var dataVal = db.HashGet(jobSpace, busiType);

            if (!dataVal.HasValue)
            {
                return(defaultVal);
            }

            try
            {
                if (typeof(TData).IsPrimitive)
                {
                    //todo 基元类型特殊处理
                }
                var data = JsonConvert.DeserializeObject <TData>(dataVal.ToString());

                return(data);
            }
            catch (Exception ex)
            {
                db.HashDelete(jobSpace, busiType);
                _log.Error($"GetJobSpaceData,解析数据出错, jobSpace:{jobSpace},busiType:{busiType} ", ex);
                return(defaultVal);
            }
        }
        /// <summary>
        /// jobSpace下对应busiType的数据删除
        /// </summary>
        /// <param name="jobSpace"></param>
        /// <param name="busiType"></param>
        public void ClearJobSpace(string jobSpace, string busiType)
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            db.HashDelete(jobSpace, jobSpace);
        }
示例#3
0
        /// <summary>
        /// 从客户端空间中取出任务(通常是上次客户端没有完成的)
        /// </summary>
        /// <param name="jobSpaceName"></param>
        /// <returns></returns>
        public void ClearClientJobSpace(string jobSpaceName)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            db.HashDelete(jobSpaceName, this.Setting.JobBusiType);
        }
        public bool QueryPage(Table table, uint fromRow, uint toRow, WithEnums with, Dictionary <string, object> parms, out IDataWrapper reader)
        {
            RedisValue pattern = default;

            if (!string.IsNullOrEmpty(table.WhereSQL))
            {
                string where = table.WhereSQL;

                foreach (string key in parms.Keys)
                {
                    where = where.Replace("@" + key, parms[key].ToString());
                }

                pattern = where;
            }

            try
            {
                RedisKey[] keys = redisServer.Keys(dbIndex, pattern, (int)(toRow - fromRow + 1), 0,
                                                   (int)((fromRow - 1) / (toRow - fromRow + 1))).ToArray();
                RedisValue[] values = redisDB.StringGet(keys);

                reader = new RedisWrapper(keys, values);

                return(true);
            }
            catch (Exception ex)
            {
                reader    = null;
                LastError = ex.Message;
                Logger.WriteLogExcept(LogTitle, ex);

                return(false);
            }
        }
示例#5
0
        /// <summary>
        /// 从任务队列取出任务
        /// </summary>
        /// <param name="job"></param>
        /// <param name="rightFirst"></param>
        /// <returns></returns>
        public bool TryGetJob_FromJobQueue(out TJob job, bool rightFirst = true)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var jobIdVal = rightFirst
                ? db.ListRightPopAsync(this.Setting.JobList_Queue_Name).Result
                : db.ListLeftPopAsync(this.Setting.JobList_Queue_Name).Result;

            if (!jobIdVal.HasValue)
            {
                job = default(TJob);
                return(false);
            }

            var jobIdStr = jobIdVal.ToString();
            var jobVal   = db.HashGet(this.Setting.JobList_Hash_Name, jobIdStr);

            if (!jobVal.HasValue)
            {
                job = default(TJob);
                return(false);
            }
            var jobStr = jobVal.ToString();

            job = JsonConvert.DeserializeObject <TJob>(jobStr);

            if (job == null)
            {
                return(false);
            }

            return(true);
        }
示例#6
0
        public void TestAddItem()
        {
            var persistenceCacheStackEntity = new PersistenceCacheStackEntity("test", new object(), null);
            var addResult = new RedisWrapper().Push(persistenceCacheStackEntity);

            Assert.IsTrue(addResult);
        }
        public void TestSynchFromRedis()
        {
            var testClass = new UnitTestClass()
            {
                TestDescription = "TestSynchFromRedis",
                TestId          = 4
            };

            var persistenceCacheStackEntity = new PersistenceCacheStackEntity("TestSynchFromRedis", testClass, null);

            var redisWrapper = new RedisWrapper();

            // add fake object into Redis
            var addResult = redisWrapper.Push(persistenceCacheStackEntity);

            Assert.IsTrue(addResult);

            var objectCached = redisWrapper.Get(persistenceCacheStackEntity.Key);

            Assert.IsNotNull(objectCached);

            // synch from Redis
            var persistenceCacheStack = new PersistenceCacheStackClient <UnitTestClass>(true);

            var obj = persistenceCacheStack.GetItem("TestSynchFromRedis");

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj.TestId == 4);
        }
示例#8
0
        /// <summary>
        /// redis测试
        /// </summary>
        private static void TestRedis()
        {
            var redisClient = new RedisWrapper();
            var result      = string.Empty;

            //get
            var name = redisClient.Get("name");

            if (name.IsNullOrEmpty())
            {
                redisClient.GetOrAdd("name", () => { return("kobe"); });
            }

            //add
            redisClient.Add("id", "100");
            result = redisClient.Get("id");

            //update
            redisClient.Update("id", "101", 3 * 60);
            result = redisClient.Get("id");

            //remove
            redisClient.Remove("id");
            result = redisClient.Get("id");
        }
示例#9
0
        /// <summary>
        /// 添加任务到任务队列
        /// </summary>
        /// <param name="job"></param>
        /// <param name="addToQueueLeft">true则添加到队列左侧,false则右侧</param>
        /// <param name="forceAdd">忽略jobidlist_hash是否已经存在,强制添加</param>
        public bool AddJobToQueue(TJob job, bool addToQueueLeft = true, bool forceAdd = false)
        {
            var taskIdStr = job.Id.ToString();
            var taskStr   = JsonConvert.SerializeObject(job);
            var client    = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db        = client.GetDatabase(this.Setting.Redis_DBIndex);
            var tran      = db.CreateTransaction();

            //检查任务是否已存在
            var existCondition = Condition.HashNotExists(this.Setting.JobList_Hash_Name, taskIdStr);

            if (!forceAdd)
            {
                //如果不是强制添加,则进行重复判定
                tran.AddCondition(existCondition);
            }
            //强制覆盖hashset
            tran.HashSetAsync(this.Setting.JobList_Hash_Name, taskIdStr, taskStr);
            if (addToQueueLeft)
            {
                //添加到队列左侧
                tran.ListLeftPushAsync(this.Setting.JobList_Queue_Name, taskIdStr);
            }
            else
            {
                //添加到队列右侧
                tran.ListRightPushAsync(this.Setting.JobList_Queue_Name, taskIdStr);
            }

            var result = tran.Execute();

            return(result);
        }
示例#10
0
        /// <summary>
        /// 总任务数(包含各客户端未完成的)
        /// </summary>
        /// <returns></returns>
        public long GetJobCount_Total()
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);
            var length = db.HashLength(this.Setting.JobList_Hash_Name);

            return(length);
        }
示例#11
0
        /// <summary>
        /// 任务是否存在
        /// </summary>
        /// <param name="jobId"></param>
        /// <returns></returns>
        public bool IsJobExists(TId jobId)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);
            var exists = db.HashExists(this.Setting.JobList_Hash_Name, jobId.ToString());

            return(exists);
        }
        public void EndJob(Job job)
        {
            Test_JobManager.GetInstance().EndJob(job);
            var connection = RedisWrapper.GetConnection(Test_Config.Redis_Server);
            var db         = connection.GetDatabase(Test_Config.Redis_DBIndex);

            //处理数量+1
            db.StringIncrement(Test_Config.Job_Customer_Process_Count);
        }
示例#13
0
        public virtual void SaveJobResult <TResult>(TJob job, TResult result)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var resultVal = JsonConvert.SerializeObject(result);

            db.HashSet(Setting.JobResultList_Hash_Name, job.Id.ToString(), resultVal);
        }
        /// <summary>
        /// 客户端 keepalive, todo:看起来放到client中更合适一些
        /// </summary>
        /// <param name="client"></param>
        public void ClientKeepAlive(TClient client)
        {
            var clientIdStr = client.Setting.ClientId;
            var clientStr   = JsonConvert.SerializeObject(client);
            var conn        = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db          = conn.GetDatabase(this.Setting.Redis_DbIndex);

            db.HashSet(this.Setting.ClientList_Hash_Name, clientIdStr, clientStr);
            db.HashSet(this.Setting.ClientList_KeepAlive_Hash_Name, clientIdStr, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        }
示例#15
0
        /// <summary>
        /// 清除所有任务
        /// </summary>
        public virtual void Clear()
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);
            var tran   = db.CreateTransaction();

            tran.KeyDeleteAsync(this.Setting.JobList_Queue_Name);
            tran.KeyDeleteAsync(this.Setting.JobList_Hash_Name);

            tran.Execute();
        }
示例#16
0
        public TestBase()
        {
            m_database = new Database(kDatabaseName, kDatabaseUser, kDatabasePassword, Thread.CurrentThread.ManagedThreadId);

            RedisWrapper.Initialise("test");

            m_data       = new MySqlData(kDatabaseName, kDatabaseUser, kDatabasePassword);
            m_currencies = m_data.GetAllCurrencies();

            m_defaultSymbolPair = CurrencyHelpers.GetMarketSymbolPair(m_currencies["bitBTC"], m_currencies[kBtc]);
            m_alternateMarket   = CurrencyHelpers.GetMarketSymbolPair(m_currencies["bitGOLD"], m_currencies[kBtc]);

            Thread thread = new Thread(() =>
            {
                string bitsharesUrl      = "http://localhost:65066/rpc";
                string bitsharesUser     = "******";
                string bitsharesPassword = "******";
                string bitsharesAccount  = "gatewaytest";

                string bitcoinUrl      = "http://localhost:18332";
                string bitcoinUser     = "******";
                string bitcoinPassword = "******";
                bool bitcoinUseTestNet = true;

                string database         = kDatabaseName;
                string databaseUser     = kDatabaseUser;
                string databasePassword = kDatabasePassword;

                string apiListen = kApiRoot;

                // create a scheduler so we can be sure of thread affinity
                AsyncPump scheduler = new AsyncPump(Thread.CurrentThread, OnException);

                m_api = new MetaDaemonApi(new RpcConfig {
                    m_url = bitsharesUrl, m_rpcUser = bitsharesUser, m_rpcPassword = bitsharesPassword
                },
                                          new RpcConfig {
                    m_url = bitcoinUrl, m_rpcUser = bitcoinUser, m_rpcPassword = bitcoinPassword, m_useTestnet = bitcoinUseTestNet
                },
                                          bitsharesAccount,
                                          database, databaseUser, databasePassword,
                                          apiListen, null, null, "gatewayclient", "http://192.168.0.2:1235/", "192.168.0.2", scheduler);

                m_api.m_ApiServer.m_HttpServer.m_DdosProtector.m_Enabled = false;

                scheduler.RunWithUpdate(m_api.Start, m_api.Update, 1);

                Console.WriteLine("meta thread exiting...");
            });

            thread.Start();
        }
示例#17
0
        /// <summary>
        /// 从客户端空间中取出任务(通常是上次客户端没有完成的)
        /// </summary>
        /// <param name="jobSpaceName"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        public virtual bool TryGetJob_FromClientJobSpace(string jobSpaceName, out TJob job)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var jobIdVal = db.HashGet(jobSpaceName, this.Setting.JobBusiType);

            if (!jobIdVal.HasValue)
            {
                job = default(TJob);
                return(false);
            }

            try
            {
                var jobIdStr = jobIdVal.ToString();
                var jobVal   = db.HashGet(this.Setting.JobList_Hash_Name, jobIdStr);
                if (!jobVal.HasValue)
                {
                    job = default(TJob);
                    return(false);
                }
                try
                {
                    var jobStr = jobVal.ToString();
                    job = JsonConvert.DeserializeObject <TJob>(jobStr);

                    if (job == null)
                    {
                        return(false);
                    }

                    return(true);
                }
                catch (System.Exception ex)
                {
                    _log.Error($"TryGetJobList_FromClientJobSpace时,解析任务出错, jobSpaceName:{jobSpaceName},jobBusiType:{this.Setting.JobBusiType} jobId:{jobIdStr}, jobVal:{jobVal}", ex);

                    db.HashDelete(this.Setting.JobList_Hash_Name, jobIdStr);
                    throw;
                }
            }
            catch (System.Exception ex)
            {
                _log.Error($"TryGetJobList_FromClientJobSpace时,解析任务出错, jobSpaceName:{jobSpaceName},jobBusiType:{this.Setting.JobBusiType} jobIdVal:{jobIdVal}", ex);

                db.HashDelete(jobSpaceName, this.Setting.JobBusiType);

                job = default(TJob);
                return(false);
            }
        }
        public void SetJobSpaceData <TData>(string jobSpace, string busiType, TData data)
        {
            if (typeof(TData).IsPrimitive)
            {
                //todo 基元类型特殊处理
            }
            var dataStr = JsonConvert.SerializeObject(data);

            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            db.HashSet(jobSpace, busiType, dataStr);
        }
示例#19
0
        /// <summary>
        /// 结束任务
        /// </summary>
        /// <param name="job"></param>
        public virtual void EndJob(TJob job)
        {
            if (job == null)
            {
                return;
            }
            var jobId = job.Id.ToString();

            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            db.HashDeleteAsync(this.Setting.JobList_Hash_Name, jobId);
        }
        public List <TClient> GetClients()
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            var clients_hash = db.HashGetAll(this.Setting.ClientList_Hash_Name);

            try
            {
                var clients_dic = clients_hash
                                  .Where(t => t.Value.HasValue)
                                  .Select(t => JsonConvert.DeserializeObject <TClient>(t.Value))
                                  .ToDictionary(t => t.Setting.ClientId, t => t);

                var clients_keepAlive_hash = db.HashGetAll(this.Setting.ClientList_KeepAlive_Hash_Name);

                foreach (var kv in clients_keepAlive_hash)
                {
                    if (!kv.Value.HasValue)
                    {
                        continue;
                    }
                    var key   = kv.Name;
                    var value = kv.Value;

                    var clientKey = key;
                    if (clients_dic.ContainsKey(clientKey))
                    {
                        var      client = clients_dic[clientKey];
                        DateTime tmpTime;
                        if (DateTime.TryParse(value, out tmpTime))
                        {
                            client.LastKeepAliveAt = tmpTime;
                        }
                        else
                        {
                            //给一个远古时间吧,毕竟null有特殊含义(客户端从未执行keepalive操作)
                            client.LastKeepAliveAt = new DateTime(2000, 1, 1);
                        }
                    }
                }

                return(clients_dic.Values.ToList());
            }
            catch (Exception ex)
            {
                _log.Error($"GetClients error, ClientList_Hash_Name:{this.Setting.ClientList_KeepAlive_Hash_Name}", ex);
                db.KeyDelete(this.Setting.ClientList_KeepAlive_Hash_Name);
                return(new List <TClient>());
            }
        }
示例#21
0
        public virtual bool TryGetJobList_FromClientJobSpace(string jobSpaceName, out List <TJob> jobList)
        {
            jobList = new List <TJob>();
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var jobIdVal = db.HashGet(jobSpaceName, this.Setting.JobBusiType);

            if (!jobIdVal.HasValue)
            {
                return(false);
            }

            try
            {
                var jobIdList = JsonConvert.DeserializeObject <List <TId> >(jobIdVal.ToString());
                foreach (var jobId in jobIdList)
                {
                    var jobVal = db.HashGet(this.Setting.JobList_Hash_Name, jobId.ToString());
                    if (!jobVal.HasValue)
                    {
                        jobList = new List <TJob>();
                        return(false);
                    }
                    try
                    {
                        var jobStr = jobVal.ToString();
                        var job    = JsonConvert.DeserializeObject <TJob>(jobStr);

                        if (job == null)
                        {
                            continue;
                        }
                        jobList.Add(job);
                    }
                    catch (System.Exception ex)
                    {
                        _log.Error($"TryGetJobList_FromClientJobSpace时,解析任务出错, jobSpaceName:{jobSpaceName}, jobId:{jobId},jobVal:{jobVal} ", ex);
                        continue;
                    }
                }
            }
            catch (System.Exception ex)
            {
                //解析失败,忽略
                db.HashDelete(jobSpaceName, this.Setting.JobBusiType);
                _log.Error($"TryGetJobList_FromClientJobSpace时,解析任务id列表出错, jobSpaceName:{jobSpaceName}, jobIdVal:{jobIdVal}", ex);
            }

            return(jobList.Count > 0);
        }
示例#22
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            Logger.WriteInformation("Initializing");

            try
            {
                HttpClient = new HttpClient();
                HttpClient.DefaultRequestHeaders.Add("User-Agent",
                                                     "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
                var pSolution = (IVsSolution)GetService(typeof(SVsSolution));
                var result    = pSolution.AdviseSolutionEvents(new SolutionEventsHandler(), out SolutionEventsHandlerId);
                Settings      = new Settings();
                UserImages    = new UserImageCache();
                Redis         = new RedisWrapper();
                Slack         = new SlackWrapper();
                LocalIdeModel = new LocalIDEModel();
                IDEWrapper    = new IDEWrapper((EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)));


                var versionedAssembly = GetVersionedAssembly();
                SourceControlRepo = new CachedSourceControlRepository(
                    new GitRepository(),
                    GetVersionedType <ISourceControlRepository>(versionedAssembly, "TeamCoding.Documents.SourceControlRepositories.TeamFoundationServiceRepository"),
                    new SolutionNameBasedRepository());
                CaretInfoProvider          = GetVersionedType <ICaretInfoProvider>(versionedAssembly, "TeamCoding.Documents.CaretInfoProvider");
                CaretAdornmentDataProvider = GetVersionedType <ICaretAdornmentDataProvider>(versionedAssembly, "TeamCoding.Documents.CaretAdornmentDataProvider");
                IdentityProvider           = new CachedFailoverIdentityProvider(new VSOptionsIdentityProvider(),
                                                                                new CredentialManagerIdentityProvider(new[] { "git:https://github.com", "https://github.com/" }),
                                                                                new VSIdentityProvider(),
                                                                                new MachineIdentityProvider());
                ConnectionWrapper        = new SqlConnectionWrapper();
                WindowsServiceClient     = new WinServiceClient(Settings.SharedSettings.WinServiceIPAddressProperty);
                RemoteModelChangeManager = new CombinedRemoteModelPersister(new RedisRemoteModelPersister(),
                                                                            new SharedFolderRemoteModelPersister(),
                                                                            new SlackRemoteModelPersister(),
                                                                            new SqlServerRemoteModelPersister(ConnectionWrapper),
                                                                            new WinServiceRemoteModelPersister(WindowsServiceClient));
                LocalModelChangeManager = new CombinedLocalModelPersister(new RedisLocalModelPersister(LocalIdeModel),
                                                                          new SharedFolderLocalModelPersister(LocalIdeModel),
                                                                          new SlackLocalModelPersister(LocalIdeModel),
                                                                          new SqlServerLocalModelPersister(ConnectionWrapper, LocalIdeModel),
                                                                          new WinServiceLocalModelPersister(WindowsServiceClient, LocalIdeModel));
                RemoteModelChangeManager.RemoteModelReceived += RemoteModelChangeManager_RemoteModelReceived;
                TeamCoding.VisualStudio.ToolWindows.OverviewWindow.OverviewCommand.Initialize(this);
            }
            catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached)
            {
                Logger.WriteError(ex);
            }
        }
        /// <summary>
        /// 移除指定客户端
        /// </summary>
        /// <param name="clientKey">客户端key</param>
        public void RemoveClient(string clientKey)
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            var client = GetClient(clientKey);

            if (client != null)
            {
                ClearJobSpace(client.JobSpaceName);
            }
            db.HashDelete(this.Setting.ClientList_Hash_Name, clientKey);
            db.HashDelete(this.Setting.ClientList_KeepAlive_Hash_Name, clientKey);
        }
示例#24
0
        public void TestGetItem()
        {
            var persistenceCacheStackEntity = new PersistenceCacheStackEntity("test", new object(), null);

            var redisWrapper = new RedisWrapper();

            var addResult = redisWrapper.Push(persistenceCacheStackEntity);

            Assert.IsTrue(addResult);

            var objectCached = redisWrapper.Get(persistenceCacheStackEntity.Key);

            Assert.IsNotNull(objectCached);
        }
        public async Task Save_and_get_Test()
        {
            var redisSettingsMock = new Mock <IRedisSettings>();

            redisSettingsMock.Setup(settings => settings.RedisAddress).Returns("localhost");
            RedisWrapper redisWrapper = new RedisWrapper(redisSettingsMock.Object);
            var          key          = Guid.NewGuid().ToString();
            var          body         = "Super cool text";
            await redisWrapper.SaveAsync(key, body).ConfigureAwait(false);

            var getResult = await redisWrapper.GetAsync(key).ConfigureAwait(false);

            Assert.That(getResult, Is.EqualTo(body));
        }
示例#26
0
        public virtual TResult GetJobResult <TResult>(TId jobId)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var resultVal = db.HashGet(Setting.JobResultList_Hash_Name, jobId.ToString());

            if (!resultVal.HasValue)
            {
                return(default(TResult));
            }

            return(JsonConvert.DeserializeObject <TResult>(resultVal.ToString()));
        }
        public void Clear()
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            var clients = GetClients();

            foreach (var client in clients)
            {
                ClearJobSpace(client.JobSpaceName);
            }

            db.KeyDelete(this.Setting.ClientList_Hash_Name);
            db.KeyDelete(this.Setting.ClientList_KeepAlive_Hash_Name);
        }
示例#28
0
        public TJob GetJob(TId jobId)
        {
            var client = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db     = client.GetDatabase(this.Setting.Redis_DBIndex);

            var jobVal = db.HashGet(this.Setting.JobList_Hash_Name, jobId.ToString());

            if (!jobVal.HasValue)
            {
                return(null);
            }
            var jobStr = jobVal.ToString();
            var job    = JsonConvert.DeserializeObject <TJob>(jobStr);

            return(job);
        }
示例#29
0
        public async Task <List <MAS_AddressTypeDto> > GetMASAddressType(CancellationToken ct = default(CancellationToken))
        {
            try
            {
                var fieldListTemp = new List <MAS_AddressTypeDto>();
                if (!RedisWrapper.Get(sessionAddressType, Zero, Zero, Zero, out fieldListTemp))
                {
                    fieldListTemp = await DotnetCoreSvr.GetMASAddressType(ct);

                    RedisWrapper.Add(fieldListTemp, sessionAddressType, Zero, Zero, Zero);
                }
                return(fieldListTemp);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public TClient GetClient(string clientId)
        {
            var conn = RedisWrapper.GetConnection(this.Setting.Redis_Server);
            var db   = conn.GetDatabase(this.Setting.Redis_DbIndex);

            var clientVal = db.HashGet(this.Setting.ClientList_Hash_Name, clientId);

            try
            {
                if (!clientVal.HasValue)
                {
                    return(null);
                }
                var client = JsonConvert.DeserializeObject <TClient>(clientVal.ToString());
                if (client == null)
                {
                    return(null);
                }

                var client_keepAliveVal = db.HashGet(this.Setting.ClientList_KeepAlive_Hash_Name, clientId);
                if (client_keepAliveVal.HasValue)
                {
                    DateTime tmpTime;
                    if (DateTime.TryParse(client_keepAliveVal.ToString(), out tmpTime))
                    {
                        client.LastKeepAliveAt = tmpTime;
                    }
                    else
                    {
                        //给一个远古时间吧,毕竟null有特殊含义(客户端从未执行keepalive操作)
                        client.LastKeepAliveAt = new DateTime(2000, 1, 1);
                    }
                }

                return(client);
            }
            catch (Exception ex)
            {
                _log.Error($"GetClient error, ClientList_Hash_Name:{this.Setting.ClientList_KeepAlive_Hash_Name},clientId:{clientId}", ex);
                db.HashDelete(this.Setting.ClientList_KeepAlive_Hash_Name, clientId);
                return(null);
            }
        }