GetUniqueId() public method

public GetUniqueId ( ) : long
return long
Ejemplo n.º 1
0
        public void TestSave()
        {
            var cedarContext = Cedar.CedarAppStore.Instance.GetContextOf("IGD");
            long uid = 0;

            if (cedarContext.IsSetupSchemaRequired)
            {
                cedarContext.SetupSchema(new ShardStartegyData() { StrategyType = Strategy.Sequential });

            }
            uid = cedarContext.CurrentShard;

            long? uId = 0;

            var worker = new Cedar.IdWorker(uid);
            uId = worker.GetUniqueId();

            using (ICedarSession cedarSession = new Cedar.AppContext("IGD").GetSession(uId.Value))
            {
                var parameters = new DynamicParameters();
                parameters.Add("firstName", "TArun");
                parameters.Add("lastName", "Kumar");
                cedarSession.Insert("usp_addemployee", parameters, commandType: Cedar.CommandType.StoredProcedure);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// this method will set up schema for new user, will return unique id to application
        /// </summary>
        /// <returns></returns>
        public long SetupSchema(ShardStartegyData dto)
        {
            // call ShardStrategy with app name
            // Strategy will return me shardid.
            // call cedar data method which would execute schema def statements in above shard id

            var dataReader = new DataFactory().GetdataReader(FetchMode.Sql);
            dto.App = _app;
            var shardId = ShardStrategy.ShardSelectionStrategy.SelectShardIdForExistingObject(dto);

            var worker = new IdWorker(shardId);
            var uniqueId = worker.GetUniqueId();
            //_currentShard = uniqueId;
            var appSchema = dataReader.GetAppSchema(shardId);

            var cedarSession = new CedarSession(uniqueId) { EnableTrasaction = true };
            cedarSession.SetupSchema(appSchema);
            cedarSession.Close();
            new DataFactory().GetdataReader(FetchMode.Sql).UpdateShard(shardId);
            _app.Shards = new DataFactory().GetdataReader(FetchMode.Sql).GetAllShardByAppname(_app.ApplicationName);
            return uniqueId;
        }