Exemple #1
0
 public static async Task <int> GetCountAsync(DBKey id)
 {
     return(await CountByDBKeyAsync(new COMMON_IN_DATA_DBKeyOnly()
     {
         DBKey = id
     }));
 }
Exemple #2
0
 Group(TypeSize.DBKey _parentKey, string _name, Color _color, bool _IsOn)
 {
     ownKey     = new DBKey(_parentKey, _name);
     saved_name = Name;
     RColor     = _color;
     IsOn       = _IsOn;
 }
Exemple #3
0
        /// <summary>
        /// check if key is renamed
        /// </summary>
        /// <param name="oldDefinitionKeys"></param>
        /// <param name="newDefinitionKeys"></param>
        /// <returns>true if renamed</returns>
        private bool IsKeyRenamed(List <DBKey> oldDefinitionKeys, List <DBKey> newDefinitionKeys)
        {
            // Compare dbname of real keys
            for (int idx = 0; idx < oldDefinitionKeys.Count; idx++)
            {
                DBKey oldKey = oldDefinitionKeys[idx];
                DBKey newKey = null;

                for (int i = 0; i < newDefinitionKeys.Count; i++)
                {
                    if (newDefinitionKeys[i].Isn == oldKey.Isn)
                    {
                        newKey = newDefinitionKeys[i];
                        break;
                    }
                }

                if (oldKey.CheckMask(KeyMasks.KeyTypeReal) && newKey != null)
                {
                    if (!oldKey.KeyDBName.Equals(newKey.KeyDBName))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #4
0
        /// <summary>
        /// build sort key
        /// </summary>
        /// <returns>DbKey</returns>
        internal DBKey Build()
        {
            DBKey sortKey = new DBKey();

            sortKey.SetMask(KeyMasks.KeySortMask);
            sortKey.SetMask(KeyMasks.KeyTypeVirtual);
            if (mainView.LocalDataviewManager.Task.UniqueSort == UniqueTskSort.Unique)
            {
                sortKey.SetMask(KeyMasks.UniqueKeyModeMask);
            }
            else
            {
                sortKey.SetMask(KeyMasks.DuplicateKeyModeMask);
            }
            for (int i = 0; i < RuntimeSorts.getSize(); i++)
            {
                int indexInView = RuntimeSorts.getSort(i).fldIdx;


                if (IsFieldSortable(indexInView))
                {
                    Sort      sort = RuntimeSorts.getSort(i);
                    DBSegment seg  = BuildSegment(sort.dir, sort.fldIdx);
                    sortKey.Segments.Add(seg);
                }
            }

            if (sortKey.Segments.Count == 0)
            {
                return(null);
            }

            return(sortKey);
        }
Exemple #5
0
        public async Task <bool> StartMining(DBKey userId)
        {
            if (userId == GlobalDefine.INVALID_DBKEY)
            {
                return(false);
            }

            UserBasicData userBasicData = new UserBasicData();

            if (await userBasicData.FromDBAsync(userId) == false)
            {
                return(false);
            }

            lock (Items)
            {
                if (Items.ContainsKey(userId))
                {
                    return(false);
                }

                var miningData = new MiningData()
                {
                    UserId         = userId,
                    NextMiningTime = DateTime.UtcNow.AddSeconds(RandomEx.Range(MiningTimeRange.min.TotalSeconds, MiningTimeRange.max.TotalSeconds)),
                    LastMiningTime = DateTime.UtcNow,
                };
                miningData.RefreshSessionExpireTime();

                Items.Add(userId, miningData);
            }
            return(true);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="valueStr"></param>
        /// <returns></returns>
        protected virtual bool setDBKeyAttribute(DBKey dbKey, string attribute, string valueStr)
        {
            int tmp;

            switch (attribute)
            {
            case ConstInterface.MG_ATTR_KEY_DB_NAME:
                dbKey.KeyDBName = XmlParser.unescape(valueStr);
                break;

            case ConstInterface.MG_ATTR_ISN:
                IntUtil.TryParse(valueStr, out tmp);
                dbKey.Isn = tmp;
                break;

            case ConstInterface.MG_ATTR_FLAGS:
                IntUtil.TryParse(valueStr, out tmp);
                dbKey.Flags = tmp;
                break;

            default:
                return(false);
            }
            return(true);
        }
Exemple #7
0
 public AccountBasicData FindByAccountDBKey(DBKey accountDBKey)
 {
     lock (Items)
     {
         return(Items.Find(item => item.AccountDBKey == accountDBKey));
     }
 }
Exemple #8
0
 public static void LogHistory(DBKey accountDBKey, string userAgent, string comment, string ipAddress, DateTime historyTime)
 {
     Task.Run(async() =>
     {
         await LogHistoryAsync(accountDBKey, userAgent, comment, ipAddress, historyTime);
     });
 }
Exemple #9
0
        /// <summary>
        /// apply runtime sort on Main View.
        /// </summary>
        /// <param name="sortCollection"></param>
        /// <returns>bool</returns>
        public bool ApplySort(SortCollection sortCollection)
        {
            bool sortKeySet = false;

            if (sortCollection != null && sortCollection.getSize() > 0)
            {
                // Build SortKey
                SortKeyBuilder sortKeyBuilder = new SortKeyBuilder(this, sortCollection);
                DBKey          sortKey        = sortKeyBuilder.Build();

                //Set it on LocalDataviewHeader of main source
                if (sortKey != null)
                {
                    //Get the dataviewHeader of Main Source.
                    ((LocalDataviewHeader)this.DataSourceViewDefinition).SortKey = sortKey;
                    sortKeySet = true;
                }
            }
            else
            {
                ((LocalDataviewHeader)this.DataSourceViewDefinition).SortKey = null;
            }

            return(sortKeySet);
        }
Exemple #10
0
        /// <summary>
        /// Convert DataSource from old DataSourceDefinition to new DataSourceDefinition. It create temporaryDataSource definition and perform all operations
        /// on temporary DataSourcedefinition and return it.
        /// </summary>
        /// <param name="fromDataSourceDefinition"></param>
        /// <param name="toDataSourceDefinition"></param>
        /// <returns>Temporary DataSourceDefinition</returns>
        private DataSourceDefinition ConvertDataSource(DataSourceDefinition fromDataSourceDefinition, DataSourceDefinition toDataSourceDefinition)
        {
            Logger.Instance.WriteSupportToLog("convertDataSource():>>>> ", true);
            Logger.Instance.WriteSupportToLog(String.Format("convertDataSource(): converting table {0}", fromDataSourceDefinition.Name), true);

            GatewayResult result = null;

            string temporaryTableName = GetTemporaryTableName(fromDataSourceDefinition.Id);

            DataSourceDefinition temporaryDataSourceDefinition = (DataSourceDefinition)toDataSourceDefinition.Clone();

            temporaryDataSourceDefinition.Name = temporaryTableName;

            // In order to genearte temporary key name for the temporary dbh set magic key mask on the keys.
            for (int keyIndex = 0; keyIndex < temporaryDataSourceDefinition.Keys.Count; keyIndex++)
            {
                DBKey key = temporaryDataSourceDefinition.Keys[keyIndex];
                key.SetMask(KeyMasks.MagicKeyMask);
            }

            // Delete temporary table, if exists
            result = GatewayCommandsFactory.CreateFileDeleteCommand(temporaryTableName, temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            if (!result.Success && result.ErrorCode != GatewayErrorCode.FileNotExist)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

            // Open source and temporary table
            temporaryDataSourceDefinition.SetMask(DbhMask.CheckExistMask);
            result = GatewayCommandsFactory.CreateFileOpenCommand(temporaryTableName, temporaryDataSourceDefinition, Access.Write, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                result = GatewayCommandsFactory.CreateFileOpenCommand(fromDataSourceDefinition.Name, fromDataSourceDefinition, Access.Read, ClientManager.Instance.LocalManager).Execute();
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

            //Convert values of source table and insert it into temporary table
            ConvertAndInsertValues(fromDataSourceDefinition, temporaryDataSourceDefinition);

            //Close source and temporary table
            result = GatewayCommandsFactory.CreateFileCloseCommand(temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                GatewayCommandsFactory.CreateFileCloseCommand(fromDataSourceDefinition, ClientManager.Instance.LocalManager).Execute();
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
            }

            Logger.Instance.WriteSupportToLog("convertDataSource():<<<< ", true);

            return(temporaryDataSourceDefinition);
        }
Exemple #11
0
 Etalon(Group.DBKey _parentKey, int _Id, DateTime _Dt, string _SOP, bool _IsOn)
     : base(_parentKey.TSName)
 {
     ownKey = new DBKey(_parentKey, _Id);
     Dt     = _Dt;
     SOP    = _SOP;
     IsOn   = _IsOn;
 }
Exemple #12
0
 public bool FromJSON(JToken token)
 {
     AccountDBKey   = JSONUtility.GetValue(token, "AccountDBKey", Default.AccountDBKey);
     PermissionType = JSONUtility.GetValueEnum(token, "PermissionType", Default.PermissionType);
     Level          = JSONUtility.GetValue(token, "Level", Default.Level);
     RegisterTime   = JSONUtility.GetValue(token, "RegisterTime", Default.RegisterTime);
     return(true);
 }
Exemple #13
0
        public async Task <IActionResult> Modify([FromBody] AdDesignModels.Modify.Request request)
        {
            // Check session validation
            if (await CheckSessionValidationAndSignOutAsync() == false)
            {
                return(APIResponse(ErrorCode.InvalidSession));
            }

            // Check valid parameters
            if (request == null || request.IsValidParameters() == false)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            DBKey        adDesignId   = request.AdDesignId;
            AdDesignData adDesignData = new AdDesignData();

            // Check validation
            if (await adDesignData.FromDBAsync(adDesignId) == false)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            if (UserId != adDesignData.UserId)
            {
                return(APIResponse(ErrorCode.BadRequest));
            }

            AdResourceData adResourceData = new AdResourceData();

            if (await adResourceData.FromDBAsync(request.AdResourceId) == false)
            {
                return(APIResponse(ErrorCode.InvalidParameters));
            }

            // Update to db
            var updateQuery = new DBQuery_AdDesign_Update();
            var item        = updateQuery.IN.Item;

            request.Copy(item);
            item.UserId       = UserId;
            item.AdDesignType = adResourceData.AdDesignType;
            if (await DBThread.Instance.ReqQueryAsync(updateQuery) == false)
            {
                return(APIResponse(ErrorCode.DatabaseError));
            }

            // Response
            var response = new AdDesignModels.Modify.Response();

            if (await response.FromDBAsync(item.AdDesignId) == false)
            {
                return(APIResponse(ErrorCode.DatabaseError));
            }

            return(Success(response));
        }
Exemple #14
0
 Tube(TypeSize.DBKey _parentKey, Int64 _Id, DateTime _Dt, string _Name, string _SG, double _Metric, string _SOP)
     : base(_parentKey.TSName)
 {
     ownKey = new DBKey(_parentKey, _Id);
     Dt     = _Dt;
     Name   = _Name;
     SG     = _SG;
     Metric = _Metric;
     SOP    = _SOP;
 }
Exemple #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributes"></param>
        internal void SetDBKeyAttributes(DBKey dbKey, NameValueCollection attributes)
        {
            IEnumerator enumerator = attributes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                String attr = (String)enumerator.Current;
                setDBKeyAttribute(dbKey, attr, attributes[attr]);
            }
        }
Exemple #16
0
        public static async Task LogHistoryAsync(DBKey accountDBKey, string userAgent, string comment, string ipAddress, DateTime historyTime)
        {
            DBQuery_Account_History_Insert query = new DBQuery_Account_History_Insert();

            query.IN.AccountDBKey = accountDBKey;
            query.IN.UserAgent    = userAgent;
            query.IN.Comment      = comment;
            query.IN.IPAddress    = ipAddress;
            query.IN.HistoryTime  = historyTime;
            await DBThread.Instance.ReqQueryAsync(query);
        }
Exemple #17
0
        public bool UpdateSession(DBKey userId)
        {
            MiningData miningData;

            if (Items.TryGetValueEx_LockThis(userId, out miningData))
            {
                miningData.RefreshSessionExpireTime();
                return(true);
            }
            return(false);
        }
Exemple #18
0
        public static DbContext GetContext(DBKey index)
        {
            string key = GetKey(index);
            DbContext dc = (ProductContext)HttpContext.Current.Items[key];

            if(dc==null){
                dc = new ProductContext();
                HttpContext.Current.Items.Add(key,dc);
            }

            return dc;
        }
Exemple #19
0
        // 비용 차감
        private async Task PaymentCostToDBAsync(DBKey userId, decimal cost)
        {
            if (userId > 0 && cost > 0)
            {
                var addBalanceQuery = new DBQuery_Balance_Add();
                addBalanceQuery.IN.UserId       = userId;
                addBalanceQuery.IN.CurrencyType = CurrencyTypes.HENA;
                addBalanceQuery.IN.Amount       = -cost;

                await DBThread.Instance.ReqQueryAsync(addBalanceQuery);
            }
        }
Exemple #20
0
                public virtual bool IsValidParameters()
                {
                    if (DBKey.CheckValidations(AdDesignId, AdResourceId) == false)
                    {
                        return(false);
                    }

                    if (string.IsNullOrEmpty(Name) || Name.Length < 2)
                    {
                        return(false);
                    }

                    return(true);
                }
Exemple #21
0
 public bool FromJSON(JToken token)
 {
     AccountDBKey        = JSONUtility.GetValue(token, "AccountDBKey", Default.AccountDBKey);
     CreateTime          = JSONUtility.GetValue(token, "CreateTime", Default.CreateTime);
     GivenName           = JSONUtility.GetValue(token, "GivenName", Default.GivenName);
     SurName             = JSONUtility.GetValue(token, "SurName", Default.SurName);
     Username            = JSONUtility.GetValue(token, "Username", Default.Username);
     EMail               = JSONUtility.GetValue(token, "EMail", Default.EMail);
     Password            = JSONUtility.GetValue(token, "Password", Default.Password);
     RegionCodeForNumber = JSONUtility.GetValue(token, "RegionCodeForNumber", Default.RegionCodeForNumber);
     CountryCode         = JSONUtility.GetValue(token, "CountryCode", Default.CountryCode);
     NationalNumber      = JSONUtility.GetValue(token, "NationalNumber", Default.NationalNumber);
     return(true);
 }
Exemple #22
0
        public static async Task <bool> FromDBByUserIdAsync(this UserData item, DBKey userId, bool takeBasicData)
        {
            List <Task> tasks = new List <Task>();

            if (takeBasicData)
            {
                tasks.Add(item.BasicData.FromDBByEmailAsync(userId));
            }
            tasks.Add(item.Permissions.FromDBByUserIdAsync(userId));

            await Task.WhenAll(tasks.ToArray());

            return(Array.TrueForAll(tasks.ToArray(), (Task t) => { return t is Task <bool>?((Task <bool>)t).Result: true; }));
        }
Exemple #23
0
        private List <DBField> BuildFields(DBKey key)
        {
            List <DBField> fields = new List <DBField>(DataSourceViewDefinition.DbFields);

            //check that all the fields of the key are in the field's list

            //if (key != null)
            //   foreach (var item in key.Segments)
            //   {
            //      if (!fields.Contains(item.Field))
            //         fields.Add(item.Field);
            //   }
            return(fields);
        }
Exemple #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="elementName"></param>
        /// <param name="elementValue"></param>
        /// <param name="attributes"></param>
        public void endElement(string elementName, string elementValue, NameValueCollection attributes)
        {
            switch (elementName)
            {
            case ConstInterface.MG_TAG_KEYS:
            case ConstInterface.MG_TAG_SEGS:
            case ConstInterface.MG_TAG_FLDS:
                // closing collection - do nothing
                return;

            case ConstInterface.MG_TAG_DBH:
            case ConstInterface.MG_TAG_DBH_DATA_ID:
                // set the attributes
                dataSourceBuilder.SetAttributes(dataSourceDefinition, attributes);
                break;

            case ConstInterface.MG_TAG_FLD:
                // create the field and add it to the DataSourceDefinition
                DBField field = new DBField();
                dataSourceBuilder.SetDBFieldAttributes(field, attributes);
                dataSourceBuilder.AddField(dataSourceDefinition, field);
                break;

            case ConstInterface.MG_TAG_KEY:
                // create the key and add it to the DataSourceDefinition
                DBKey key = new DBKey();
                dataSourceBuilder.SetDBKeyAttributes(key, attributes);
                // Add the segments collection and reset the local one
                key.Segments = segments;
                segments     = new List <DBSegment>();
                dataSourceBuilder.AddKey(dataSourceDefinition, key);
                break;

            case ConstInterface.MG_TAG_SEG:
                // create the segment and add it to the DataSourceDefinition
                DBSegment segment = new DBSegment();
                dataSourceBuilder.SetDBSegmentAttributes(segment, attributes, dataSourceDefinition.Fields);
                dataSourceBuilder.AddSegment(dataSourceDefinition, segment);
                break;

            case ConstInterface.MG_TAG_SEGMENT:
                // Get the segment's isn and add the segment to the local segment collection. This way it will be added
                // later to the right key
                int isn;
                IntUtil.TryParse((string)attributes.GetValues(0)[0], out isn);
                segments.Add(dataSourceDefinition.Segments.Find(x => x.Isn == isn));
                break;
            }
        }
Exemple #25
0
        public static async Task <bool> FromDBAsync(this AdDesignData item, DBKey adDesignId)
        {
            var query = new DBQuery_AdDesign_Select();

            query.IN.DBKey = adDesignId;

            await DBThread.Instance.ReqQueryAsync(query);

            if (query.OUT.FirstItem == null)
            {
                return(false);
            }

            query.OUT.FirstItem.Copy(item);
            return(true);
        }
Exemple #26
0
        public MiningReportData FindOrAdd(DBKey userId, DateTime reportDate)
        {
            var MiningReport = Find(userId, reportDate);

            if (MiningReport == null)
            {
                MiningReport = new MiningReportData()
                {
                    UserId       = userId,
                    ReportDate   = reportDate,
                    MiningAmount = 0m,
                };
                Add(MiningReport);
            }
            return(MiningReport);
        }
Exemple #27
0
        public static async Task <bool> FromDBAsync(this BalanceData item, DBKey userId, CurrencyTypes currencyType)
        {
            var query = new DBQuery_Balance_Select();

            query.IN.UserId       = userId;
            query.IN.CurrencyType = currencyType;

            await DBThread.Instance.ReqQueryAsync(query);

            if (query.OUT.FirstItem == null)
            {
                return(false);
            }

            query.OUT.FirstItem.Copy(item);
            return(true);
        }
Exemple #28
0
        public static string GetKey(DBKey index)
        {
            switch (index)
            {

                case DBKey.SALES:
                    return "__SALES_" + HttpContext.Current.GetHashCode().ToString("x");
                //case MEL:
                //    return "__MELDC_" + HttpContext.Current.GetHashCode().ToString("x") + Thread.CurrentContext.ContextID.ToString();
                //case SAM:
                //    return "__SAMDC_" + HttpContext.Current.GetHashCode().ToString("x") + Thread.CurrentContext.ContextID.ToString();
                //case DCNPINR:
                //    return "__DCNPINR_" + HttpContext.Current.GetHashCode().ToString("x") + Thread.CurrentContext.ContextID.ToString();
                default:
                    return string.Empty;

            }
        }
Exemple #29
0
        public BalanceData FindOrAdd(DBKey userId, CurrencyTypes currencyType)
        {
            var balance = Find(userId, currencyType);

            if (balance == null)
            {
                balance = new BalanceData()
                {
                    UserId       = userId,
                    CurrencyType = currencyType,
                    Amount       = 0m,
                    CreateTime   = DateTime.UtcNow,
                    LastUpdate   = DateTime.UtcNow,
                };
                Add(balance);
            }
            return(balance);
        }
Exemple #30
0
        public static async Task <bool> FromDBAsync(this UserPermissionData item
                                                    , DBKey userId, UserPermissionTypes permissionType)
        {
            var query = new DBQuery_User_Permission_Select();

            query.IN.UserId         = userId;
            query.IN.PermissionType = permissionType;
            var result = await DBThread.Instance.ReqQueryAsync(query);

            var permissionData = query.OUT.Items.Find(permissionType);

            if (permissionData != null)
            {
                permissionData.Copy(item);
                return(true);
            }
            return(false);
        }
Exemple #31
0
        public RevenueReportData FindOrAdd(DBKey userId, DateTime reportDate)
        {
            var RevenueReport = Find(userId, reportDate);

            if (RevenueReport == null)
            {
                RevenueReport = new RevenueReportData()
                {
                    UserId       = userId,
                    ReportDate   = reportDate,
                    Revenue      = 0m,
                    DisplayCount = 0,
                    ClickCount   = 0,
                };
                Add(RevenueReport);
            }
            return(RevenueReport);
        }
Exemple #32
0
        public static async Task <bool> FromDBAsync(this AccountPermissionData item
                                                    , DBKey accountDBKey, AccountPermissionType permissionType)
        {
            var query = new DBQuery_Account_Permission_Select();

            query.IN.AccountDBKey   = accountDBKey;
            query.IN.PermissionType = permissionType;
            var result = await DBThread.Instance.ReqQueryAsync(query);

            var permissionData = query.OUT.Items.Find(permissionType);

            if (permissionData != null)
            {
                permissionData.CopyTo(ref item);
                return(true);
            }
            return(false);
        }