Example #1
0
        public void GetEvents()
        {
            UpdateInfo updateInfo = null;

            try
            {
                GuildWarsController guildWarsController = new GuildWarsController();
                updateInfo = guildWarsController.Update();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                CouchbaseManager.SetServiceState(false);
            }
            finally
            {
                if (updateInfo != null)
                {
                    if (!updateInfo.IsActive)
                    {
                        Console.WriteLine("[{0}] Number of active worlds: {1}.", DateTime.Now,
                                          updateInfo.ActiveWorldsCount);
                    }
                    Console.WriteLine(updateInfo.Message);
                }
            }
        }
        public static void Test()
        {
            var clientConfiguration = new ClientConfiguration()
            {
                Servers = new List <Uri>(), BucketConfigs = new Dictionary <string, BucketConfiguration>()
            };


            clientConfiguration.Servers.Add(new Uri("http://10.0.2.190:8091/pools"));
            //var authenticator = new PasswordAuthenticator("username", "password");
            var clusterCredentials = new ClusterCredentials {
                BucketCredentials = new Dictionary <string, string>()
            };

            clusterCredentials.BucketCredentials.Add("MOTK-UserSession", "ruanyun2014");
            var manager = new CouchbaseManager(clientConfiguration, clusterCredentials);
            var bucket  = manager.GetBucket("MOTK-UserSession");

            // var query = bucket.CreateQuery("test", "tv").Limit(5000);
            //var result1 = bucket.Query<dynamic>(query);

            bucket.Upsert(CacheObject.Key, new CacheObject()
            {
                ObjId = 33, ObjName = "ss", Remark = ".Net Core Write"
            });
            var result = bucket.Get <CacheObject>(CacheObject.Key);

            Console.WriteLine(JsonConvert.SerializeObject(result));
        }
Example #3
0
        // GET api/worlds
        public object GetLocalizedWorlds(string lang)
        {
            string key;

            switch (lang.ToLower())
            {
            case "de":
            {
                key = CouchbaseKeys.WorldNamesDe;
                break;
            }

            case "es":
            {
                key = CouchbaseKeys.WorldNamesEs;
                break;
            }

            case "fr":
            {
                key = CouchbaseKeys.WorldNamesFr;
                break;
            }

            default:
            {
                key = CouchbaseKeys.WorldNamesEn;
                break;
            }
            }
            return(CouchbaseManager.GetWorlds(key));
        }
Example #4
0
        public UpdateInfo Update()
        {
            UpdateInfo updateInfo = new UpdateInfo()
            {
                ActiveWorldsCount     = 0
                , ActiveWorldsUpdates = 0
                , Message             = string.Format("[{0}] The previous update process is still active. Will try again later.", DateTime.Now)
            };
            ServiceState serviceState = CouchbaseManager.GetServiceState();

            if (serviceState.IsActive)
            {
                updateInfo.IsActive = serviceState.IsActive;
                return(updateInfo);
            }
            CouchbaseManager.SetServiceState(true);
            if (_activeWorlds != null)
            {
                foreach (World world in _activeWorlds)
                {
                    //TODO need to make this Asynchronous
                    if (DateTime.Now - world.LastActive < new TimeSpan(0, 0, _minutesBeforeAWorldBecomesInactive, 0))
                    {
                        string key      = CouchbaseKeys.GenerateKeyForWorld(world);
                        bool   isStored = CouchbaseManager.Instance.Store(
                            StoreMode.Set
                            , key
                            , _guildWars2ApiHandler.GetEvent(world)
                            );
                        if (isStored)
                        {
                            updateInfo.ActiveWorldsUpdates++;
                            Console.WriteLine(
                                "[{0}] {1} Updated."
                                , DateTime.Now
                                , key);
                        }
                        updateInfo.ActiveWorldsCount++;
                    }
                }
            }
            updateInfo.Message = string.Format(updateInfo.ActiveWorldsUpdates == 0 ? "[{0}] No updates." : "[{0}] Done with all updates.", DateTime.Now);
            CouchbaseManager.SetServiceState(false);
            return(updateInfo);
        }
Example #5
0
        /// <summary>
        /// Create CouchbaseManager object by CouchbaseConfig
        /// </summary>
        /// <param name="config">Config json</param>
        /// <returns></returns>
        public CouchbaseManager CreateManager(CouchbaseConfig config)
        {
            var r      = LoadConfig(config);
            var bucket = new Type.OneToManyList <string, string>();

            foreach (var item in config.Buckets)
            {
                bucket.Add(item.ServerName, item.BucketName);
            }

            CouchbaseManager couchbaseManager = new CouchbaseManager()
            {
                Cluster    = r,
                ConfigData = JsonConvert.SerializeObject(config),
                Buckets    = bucket,
            };

            return(couchbaseManager);
        }
Example #6
0
        /// <summary>
        /// Create CouchbaseManager object by config string
        /// </summary>
        /// <param name="config">Config json</param>
        /// <returns></returns>
        public CouchbaseManager CreateManager(string config)
        {
            var r      = LoadCouchbaseConfig(config);
            var bucket = new Type.OneToManyList <string, string>();

            foreach (var item in r.couchbaseConfig.Buckets)
            {
                bucket.Add(item.ServerName, item.BucketName);
            }

            CouchbaseManager couchbaseManager = new CouchbaseManager()
            {
                Cluster    = r.cluster,
                ConfigData = config,
                Buckets    = bucket,
            };

            return(couchbaseManager);
        }
Example #7
0
        public void TestCouchbase()
        {
            var testClass = new TestClass()
            {
                PropA = "1", PropB = 1, PropC = 1.2
            };
            var testClass1 = new TestClass()
            {
                PropA = "2", PropB = 2, PropC = 2.2
            };
            var obj = new List <TestClass>();

            obj.Add(testClass);
            obj.Add(testClass1);

            CouchbaseManager.ResetCouchClientBySectionName("couchbase");
            CouchbaseManager.Add <List <TestClass> >("key11", obj);

            var dd = CouchbaseManager.Get <List <TestClass> >("key11");

            //CouchbaseManager.SectionName = "bucketV2";
            CouchbaseManager.ResetCouchClientBySectionName("bucketV2");
            CouchbaseManager.Add <List <TestClass> >("key12", obj);
        }
Example #8
0
 public void Stop()
 {
     CouchbaseManager.SetServiceState(false);
     _timer.Stop();
 }
Example #9
0
 // GET api/worlds
 public object Get()
 {
     return(CouchbaseManager.GetWorlds(CouchbaseKeys.WorldNamesEn));
 }
Example #10
0
 public DummyCouchbaseStorage(CouchbaseManager manager, string storageName) : base(manager, storageName)
 {
 }
Example #11
0
 public CouchbaseStorageLongoMatch(CouchbaseManager manager, string storageName) : base(manager, storageName)
 {
 }
 public CouchbaseStorageLongoMatch(CouchbaseManager manager, string storageName)
     : base(manager, storageName)
 {
 }