Example #1
0
        public List <CardSubItem> GetCardSubItemList(long cardid)
        {
            List <CardSubItem> list = null;

            if (string.IsNullOrEmpty(_ConnectionString))
            {
                LogHelper.Log("CardData-GetCardSubItemList:" + "File ERROR");
                return(list);
            }
            try
            {
                LockUtils.LockEnter(_ConnectionString);
                DapperHelper db  = new DapperHelper(this._ConnectionString);
                string       sql = $"select * from cardsubitem where cardid=@cardid";
                list = db.QueryList <CardSubItem>(sql, new { cardid });
            }
            catch (Exception ex)
            {
                LogHelper.Log("CardData-GetCardSubItemList:" + ex.ToString());
            }
            finally
            {
                LockUtils.LockExit(_ConnectionString);
            }
            return(list);
        }
Example #2
0
        /// <summary>
        /// 获取卡片主表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CardItem GetCardItem(long id)
        {
            CardItem item = null;

            if (string.IsNullOrEmpty(_ConnectionString))
            {
                LogHelper.Log("CardData-GetCardItem:" + "File ERROR");
                return(item);
            }
            try
            {
                LockUtils.LockEnter(_ConnectionString);
                DapperHelper db  = new DapperHelper(this._ConnectionString);
                string       sql = $"select * from carditem where id=@id";
                item = db.QueryFirst <CardItem>(sql, new { id });
            }
            catch (Exception ex)
            {
                LogHelper.Log("CardData-GetCardItem:" + ex.ToString());
            }
            finally
            {
                LockUtils.LockExit(_ConnectionString);
            }
            return(item);
        }
Example #3
0
        /// <summary>
        /// 创建或者更新客户资料
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long CreateOrUpdate(CardSubItem model)
        {
            if (string.IsNullOrEmpty(_ConnectionString))
            {
                LogHelper.Log("CardData-CreateOrUpdate:" + "File ERROR");
                return(0);
            }
            try
            {
                bool isExist = model.id > 0;
                LockUtils.LockEnter(_ConnectionString);
                DapperHelper db = new DapperHelper(this._ConnectionString);
                if (isExist)
                {
                    //仅仅更新
                    try
                    {
                        var param = ConvertHelper <CardSubItem> .ModelToDic(model);

                        db.Update <CardSubItem>(param, "id", model.id);
                        return(model.id);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log("CardData-CreateOrUpdate:" + ex.ToString());
                    }
                    finally
                    {
                        db.Close();
                    }
                }
                else
                {
                    //新增
                    try
                    {
                        return(CheckData.Check_Long(db.ExecuteScalar(DapperHelper.CompileInsert <CardSubItem>(model, "id", "sl"), model)));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log("CardData-CreateOrUpdate:" + ex.ToString());
                    }
                    finally
                    {
                        db.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log("CardData-CreateOrUpdate:" + ex.ToString());
            }
            finally
            {
                LockUtils.LockExit(_ConnectionString);
            }
            return(0);
        }
Example #4
0
        public static void ReleaseCompany()
        {
            var ctx = ScenarioContext.Current.Get <CsaContext>(ContextKeys.POM_CONTEXT);

            if (ctx.OriginalAccount != null)
            {
                LockUtils.ReleaseAccount("coid", ctx.OriginalAccount["CM"].First().ID);
            }
        }
Example #5
0
 /// <summary>
 /// Tells the <c>ConnectionManager</c> that it can go ahead and connect if appropriate.
 /// </summary>
 /// <returns>a task which will yield true if this method results in a successful connection, or
 /// if we are in offline mode and don't need to make a connection</returns>
 public Task <bool> Start()
 {
     return(LockUtils.WithWriteLock(_lock, () =>
     {
         if (_started)
         {
             return Task.FromResult(_initialized);
         }
         _started = true;
         return OpenOrCloseConnectionIfNecessary(false); // not awaiting
     }));
 }
Example #6
0
        /// <inheritdoc/>
        public async Task <bool> IdentifyAsync(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            User newUser = _userDecorator.DecorateUser(user);
            User oldUser = newUser; // this initialization is overwritten below, it's only here to satisfy the compiler

            LockUtils.WithWriteLock(_stateLock, () =>
            {
                oldUser = _user;
                _user   = newUser;
            });

            // If we had cached data for the new user, set the current in-memory flag data state to use
            // that data, so that any Variation calls made before Identify has completed will use the
            // last known values. If we did not have cached data, then we update the current in-memory
            // state to reflect that there is no flag data, so that Variation calls done before completion
            // will receive default values rather than the previous user's values. This does not modify
            // any flags in persistent storage, and (currently) it does *not* trigger any FlagValueChanged
            // events from FlagTracker.
            var cachedData = _dataStore.GetCachedData(newUser);

            if (cachedData != null)
            {
                _log.Debug("Identify found cached flag data for the new user");
            }
            _dataStore.Init(
                newUser,
                cachedData ?? new DataStoreTypes.FullDataSet(null),
                false // false means "don't rewrite the flags to persistent storage"
                );

            EventProcessorIfEnabled().RecordIdentifyEvent(new EventProcessorTypes.IdentifyEvent
            {
                Timestamp = UnixMillisecondTime.Now,
                User      = user
            });
            if (oldUser.Anonymous && !newUser.Anonymous && !_config.AutoAliasingOptOut)
            {
                EventProcessorIfEnabled().RecordAliasEvent(new EventProcessorTypes.AliasEvent
                {
                    Timestamp    = UnixMillisecondTime.Now,
                    User         = user,
                    PreviousUser = oldUser
                });
            }

            return(await _connectionManager.SetUser(newUser));
        }
Example #7
0
 /// <summary>
 /// Updates the current user.
 /// </summary>
 /// <param name="user">the new user</param>
 /// <returns>a task that is completed when we have received data for the new user, if the
 /// data source is online, or completed immediately otherwise</returns>
 public Task <bool> SetUser(User user)
 {
     return(LockUtils.WithWriteLock(_lock, () =>
     {
         if (_disposed)
         {
             return Task.FromResult(false);
         }
         _user = user;
         _initialized = false;
         return OpenOrCloseConnectionIfNecessary(true);
     }));
 }
Example #8
0
 /// <summary>
 /// Sets whether the application is currently in the background.
 /// </summary>
 /// <remarks>
 /// When in the background, we use a different data source (polling, at a longer interval)
 /// and we do not send diagnostic events.
 /// </remarks>
 /// <param name="inBackground">true if the application is now in the background</param>
 public void SetInBackground(bool inBackground)
 {
     LockUtils.WithWriteLock(_lock, () =>
     {
         if (_disposed || _inBackground == inBackground)
         {
             return;
         }
         _inBackground = inBackground;
         _log.Debug("Background mode is changing to {0}", inBackground);
         _ = OpenOrCloseConnectionIfNecessary(true); // not awaiting
     });
 }
Example #9
0
 /// <summary>
 /// Sets whether we should be able to make network connections, and attempts to connect if appropriate.
 /// </summary>
 /// <remarks>
 /// Besides updating the value of the <see cref="NetworkEnabled"/> property, we do the
 /// following:
 ///
 /// If <c>networkEnabled</c> is false, we drop our current connection (if any), and we will not
 /// make any connections no matter what other properties are changed as long as this property is
 /// still true.
 ///
 /// If <c>networkEnabled</c> is true and we already have a connection, nothing happens.
 ///
 /// If <c>networkEnabled</c> is true and we have no connection, but other conditions disallow
 /// making a connection (or we do not have an update processor factory), nothing happens.
 ///
 /// If <c>networkEnabled</c> is true, and we do not yet have a connection, and no other
 /// conditions disallow making a connection, and we have an update processor factory,
 /// we create an update processor and tell it to start.
 ///
 /// The returned task is immediately completed unless we are making a new connection, in which
 /// case it is completed when the update processor signals success or failure. The task yields
 /// a true result if we successfully made a connection <i>or</i> if we decided not to connect
 /// because we are in offline mode. In other words, the result is true if
 /// <see cref="Initialized"/> is true.
 /// </remarks>
 /// <param name="networkEnabled">true if we think we can make network connections</param>
 /// <returns>a task as described above</returns>
 public Task <bool> SetNetworkEnabled(bool networkEnabled)
 {
     return(LockUtils.WithWriteLock(_lock, () =>
     {
         if (_disposed || _networkEnabled == networkEnabled)
         {
             return Task.FromResult(false);
         }
         _networkEnabled = networkEnabled;
         _log.Info("Network availability is now {0}", networkEnabled);
         return OpenOrCloseConnectionIfNecessary(false); // not awaiting
     }));
 }
Example #10
0
 /// <summary>
 /// Sets whether the client should always be offline, and attempts to connect if appropriate.
 /// </summary>
 /// <remarks>
 /// Besides updating the value of the <see cref="ForceOffline"/> property, we do the
 /// following:
 ///
 /// If <c>forceOffline</c> is true, we drop our current connection (if any), and we will not
 /// make any connections no matter what other properties are changed as long as this property is
 /// still true.
 ///
 /// If <c>forceOffline</c> is false and we already have a connection, nothing happens.
 ///
 /// If <c>forceOffline</c> is false and we have no connection, but other conditions disallow
 /// making a connection (or we do not have an update processor factory), nothing happens.
 ///
 /// If <c>forceOffline</c> is false, and we do not yet have a connection, and no other
 /// conditions disallow making a connection, and we have an update processor factory,
 /// we create an update processor and tell it to start.
 ///
 /// The returned task is immediately completed unless we are making a new connection, in which
 /// case it is completed when the update processor signals success or failure. The task yields
 /// a true result if we successfully made a connection <i>or</i> if we decided not to connect
 /// because we are in offline mode. In other words, the result is true if
 /// <see cref="Initialized"/> is true.
 /// </remarks>
 /// <param name="forceOffline">true if the client should always be offline</param>
 /// <returns>a task as described above</returns>
 public Task <bool> SetForceOffline(bool forceOffline)
 {
     return(LockUtils.WithWriteLock(_lock, () =>
     {
         if (_disposed || _forceOffline == forceOffline)
         {
             return Task.FromResult(false);
         }
         _forceOffline = forceOffline;
         _log.Info("Offline mode is now {0}", forceOffline);
         return OpenOrCloseConnectionIfNecessary(false); // not awaiting
     }));
 }
Example #11
0
        public void Dispose()
        {
            IDataSource dataSource = null;

            LockUtils.WithWriteLock(_lock, () =>
            {
                if (_disposed)
                {
                    return;
                }
                dataSource  = _dataSource;
                _dataSource = null;
                _disposed   = true;
            });
            dataSource?.Dispose();
        }
Example #12
0
        // When this method is called, we are no longer holding the lock.

        private bool SetInitializedIfUpdateProcessorStartedSuccessfully(Task <bool> task)
        {
            if (task.IsCompleted)
            {
                if (task.IsFaulted)
                {
                    // Don't let exceptions from the update processor propagate up into the SDK. Just say we didn't initialize.
                    LogHelpers.LogException(_log, "Failed to initialize LaunchDarkly connection", task.Exception);
                    return(false);
                }
                var success = task.Result;
                if (success)
                {
                    LockUtils.WithWriteLock(_lock, () =>
                    {
                        _initialized = true;
                    });
                    return(true);
                }
            }
            return(false);
        }
        public void WhenISelectAnAccountWithProration(string proration)
        {
            var imis = Context <IMIS>(IMIS);

            Name cm    = null;
            int  count = 0;

            while (count < 10)
            {
                IEnumerable <Name> names;
                if (proration == "with")
                {
                    names = imis.FindAccountWithProration(15);
                }
                else
                {
                    names = imis.FindAccountWithoutProration(15);
                }
                var coId = LockUtils.PickUnusedAccount("coid", names.Select(o => o.ID));
                if (coId != null)
                {
                    cm = names.Where(o => o.ID == coId).First();
                    break;
                }
                count += 1;
                Task.Delay(RandUtils.RandInt(1000, 2000)).Wait();
            }

            cm.ShouldNotBeNull();
            cm.ID.ShouldNotBeEmpty();

            Console.WriteLine($"CO_ID={cm.ID}");

            var account = new Account(imis, cm.ID);

            Ctx.OriginalAccount = account;
        }