internal static KeyValueListResult DeserializeKeyValueListResult(JsonElement element)
        {
            Optional <IReadOnlyList <KeyValueData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <KeyValueData> array = new List <KeyValueData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(KeyValueData.DeserializeKeyValueData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new KeyValueListResult(Optional.ToList(value), nextLink.Value));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets data for a given key
        /// </summary>
        /// <param name="category">The category</param>
        /// <param name="collection">The collection</param>
        /// <param name="key">The key for which to get the data</param>
        /// <returns>A tuple of <see cref="string"/> with the key data and <see cref="string"/> with the keywords associated with the key</returns>
        public async Task <(string data, string keywords)> Get(string category, string collection, string key)
        {
            var dbKeys = KeyValueData.GetNormalizedDbKeys(category, collection, key);
            var data   = await _context.KeyValues.FindAsync(dbKeys.ToArray <object>());

            return(data?.MetaData, data?.Keywords);
        }
Esempio n. 3
0
 /// <summary>
 /// 根据指定字段列表获取对象
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static T GetBy(bool isOr, bool isLike, params KeyValueData[] kvs)
 {
     try
     {
         StringBuilder where;
         if (isOr)
         {
             where = new StringBuilder("1=0");
         }
         else
         {
             where = new StringBuilder("1=1");
         }
         if (kvs == null)
         {
             kvs = new KeyValueData[] { };
         }
         foreach (KeyValueData kv in kvs)
         {
             if (isOr)
             {
                 where.AppendFormat(" or {0}='{1}'", kv.KeyName, kv.KeyValue);
             }
             else
             {
                 where.AppendFormat(" and {0}='{1}'", kv.KeyName, kv.KeyValue);
             }
         }
         return(db.find <T>(where.ToString()).first());
     }
     catch { return(default(T)); }
 }
Esempio n. 4
0
        public async Task Execute(Block block, BlockContext db = null)
        {
            using (var _db = new BlockContext(_options))
            {
                BlockContext currentdb = null;
                currentdb = _db;
                if (db != null)
                {
                    currentdb = db;
                }

                var list = new List <KeyValueData>();
                foreach (var envelope in block.Data.Envelopes)
                {
                    var txid     = envelope.TxReqeust.Data.TxId;
                    var writeSet = envelope.PayloadReponse.TxReadWriteSet.WriteSet;
                    foreach (var set in writeSet)
                    {
                        var model = new KeyValueData();
                        model.Key       = set.Key;
                        model.Value     = set.Value;
                        model.Version   = block.Header.Number + "_" + envelope.TxReqeust.Data.TxId;
                        model.ChannelId = envelope.TxReqeust.Data.Channel.ChannelId;
                        model.Deleted   = false;
                        list.Add(model);
                    }
                    var del = envelope.PayloadReponse.TxReadWriteSet.DeletedSet;
                    foreach (var set in del)
                    {
                        var model = new KeyValueData();
                        model.Key       = set.Key;
                        model.Version   = block.Header.Number + "_" + envelope.TxReqeust.Data.TxId;
                        model.ChannelId = envelope.TxReqeust.Data.Channel.ChannelId;
                        model.Deleted   = true;
                        list.Add(model);
                    }
                }

                foreach (var item in list)
                {
                    var model = currentdb.KeyValueData.Where(p => p.ChannelId == item.ChannelId && p.Key == item.Key).FirstOrDefault();
                    if (model == null)
                    {
                        currentdb.Add(item);
                    }
                    else
                    {
                        model.Value   = item.Value;
                        model.Version = item.Version;
                        currentdb.Update(model);
                    }
                }

                await currentdb.SaveChangesAsync();
            }
        }
Esempio n. 5
0
        private void FillStats(KeyValueData unit)
        {
            KeyValue kv       = unit.KeyValue;
            bool     isIncome = false;
            int      cost     = unit.TotalGoldCost;

            if (isIncome = cost == -1)
            {
                cost = unit.TangoCost;
            }
            float dmg           = (kv["AttackDamageMin"].GetFloat() + kv["AttackDamageMax"].GetFloat()) / 2;
            float ar            = kv["AttackRate"].GetFloat();
            float dps           = dmg / ar;
            float dps_p_c       = cost != -1 ? dps / cost : 0;
            float health        = kv["StatusHealth"].GetFloat();
            float armor         = kv["ArmorPhysical"].GetFloat();
            float effHealth     = health / (1 - 0.06f * armor / (1 + 0.06f * Math.Abs(armor)));
            float effHealth_p_g = cost != -1 ? effHealth / cost : 0;
            float range         = kv["AttackRange"].GetFloat();
            float val           = 0;

            if (cost != -1)
            {
                float dpsVal, hpVal = 0;
                if (!isIncome)
                {
                    dpsVal = dps / (cost * (range > 150 ? 1f : 0.7f));
                    hpVal  = effHealth / (cost * (range > 150 ? 1.2f : 3));
                }
                else
                {
                    dpsVal = dps / (cost * (range > 150 ? 0.5f : 0.3f));
                    hpVal  = effHealth / (cost * (range > 150 ? 2.0f : 3.5f));
                }
                val = (dpsVal * dpsVal * hpVal * hpVal);
            }
            int    unitCount  = GetUnitCount(unit);
            float  waveDps    = dps * unitCount;
            float  waveHealth = effHealth * unitCount;
            string stats      = $"Cost : {cost} \n" +
                                $"Damage : {dmg} \n" +
                                $"AttackRate : {ar}\n" +
                                $"DPS : {dps}\n" +
                                $"Health : {health}\n" +
                                $"Armor : {armor}\n" +
                                $"EffHealth : {effHealth}\n" +
                                $"Range : {range}\n" +
                                (cost != -1 ? $"DPS/Cost : {dps_p_c}\n" +
                                 $"EffHealth/Cost : {effHealth_p_g}\n" +
                                 $"Value : {val} (This is just a guideline, abilities arent calculated!)" : "") +
                                (unitCount > 0 ? $"UnitCount : {unitCount} \n" +
                                 $"Wave DPS : {waveDps} \n" +
                                 $"Wave Health : {waveHealth}" : "");

            textBox2.Text = stats;
        }
Esempio n. 6
0
    void Awake()
    {
        Inventory = new Inventory();

        KeyValueData = new KeyValueData();

        Camera.main.GetComponent <CameraFollow>().ObjectToFollow = gameObject;

        m_playerRigidbody = GetComponent <Rigidbody>();
    }
    /// <summary>
    /// 数据上报
    /// </summary>
    /// <param 上报事件名 ="eventName"></param>
    /// <param 具体数据 ="datas"></param>
    public static void ReportEvent(string eventName, Dictionary <string, string> datas)
    {
        CitentReport2Server msg = new CitentReport2Server();

        msg.eventName = eventName;

        msg.datas = KeyValueData.Dictionary2KeyValueDataList(datas);

        JsonMessageProcessingController.SendMessage(msg);
    }
    public override void Log(string eventID, Dictionary <string, string> data)
    {
        ClientReport2Server msg = new ClientReport2Server();

        msg.eventName = eventID;

        msg.datas = KeyValueData.Dictionary2KeyValueDataList(data);

        JsonMessageProcessingController.SendMessage(msg);
    }
Esempio n. 9
0
        /// <summary>
        /// Stores key value pair data against a given category, collection and key
        /// </summary>
        /// <param name="category">The category</param>
        /// <param name="collection">The collection</param>
        /// <param name="key">The key value for which to store key data</param>
        /// <param name="data">A <see cref="string"/> representing the key data</param>
        /// <param name="keywords">A <see cref="string"/> representing the Keywords associated with the data, these keywords will be used to search the data</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation</returns>
        /// <exception cref="DuplicateKeyException">if a record already exist against category, collection and key</exception>
        public async Task Add(string category, string collection, string key, string data, string keywords)
        {
            if (!await KeyExistsIncludingWarning(category, collection, key))
            {
                await _context.AddAsync(KeyValueData.Create(category, collection, key, data, keywords));

                await _context.SaveChangesAsync();

                _cacheProvider.ClearAllCachedEntries();
            }
        }
Esempio n. 10
0
        public void KeyValue(Edict pentKeyvalue, KeyValueData pkvd)
        {
            //Log.Message($"Entity {EntityDictionary.EntityIndex(pentKeyvalue)}/{EntityDictionary.Max} KeyValue ClassName=\"{pkvd.ClassName}\" Key=\"{pkvd.KeyName}\" Value=\"{pkvd.Value}\"");

            if (pkvd.KeyName == "classname")
            {
                if (pentKeyvalue.PrivateData == null)
                {
                    Log.Message($"Creating entity \"{pkvd.Value}\"");

                    //Create the entity instance
                    EntityRegistry.CreateInstance <BaseEntity>(pentKeyvalue);

                    Log.Message("Created entity");
                }
                else
                {
                    var ent = (BaseEntity)pentKeyvalue.PrivateData;

                    //This should never happen
                    if (pkvd.Value != ent.ClassName)
                    {
                        throw new InvalidOperationException($"Second occurence of classname keyvalue has different value (Expected: {ent.ClassName}, actual:{pkvd.Value})");
                    }

                    pkvd.Handled = true;
                    return;
                }
            }

            if (pentKeyvalue.PrivateData == null)
            {
                throw new InvalidOperationException($"Cannot set keyvalue \"{pkvd.KeyName}={pkvd.Value}\" on null entity of class {pkvd.ClassName}");
            }

            pkvd.Handled = false;

            var entity = (BaseEntity)pentKeyvalue.PrivateData;

            //TODO: uniformly handle keyvalue initialization

            switch (pkvd.KeyName)
            {
            case "classname":
            {
                entity.ClassName = pkvd.Value;
                pkvd.Handled     = true;
                break;
            }
            }
        }
Esempio n. 11
0
    public static List <KeyValueData> Dictionary2KeyValueDataList(Dictionary <string, string> dic)
    {
        List <KeyValueData> list = new List <KeyValueData>();

        if (dic != null)
        {
            foreach (var item in dic)
            {
                KeyValueData d = new KeyValueData(item.Key, item.Value);
                list.Add(d);
            }
        }
        return(list);
    }
        public Response SaveBuildNote([FromBody] KeyValueData <string> data)
        {
            var response = new Response();

            try
            {
                SetBuildNote(data.Key, data.Value);
                response.AddSuccessNotification("Application note saved succesfully.");
                return(response);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                response.AddErrorNotification(ex.Message, ex.StackTrace);
                return(response);
            }
        }
Esempio n. 13
0
 private int GetUnitCount(KeyValueData unit)
 {
     foreach (var info in waveInfos.Children)
     {
         if (info.HasChildren)
         {
             if (info.HasKey("Unit"))
             {
                 if (info["Unit"]["NPCName"].GetString().Equals(unit.Name))
                 {
                     return(info["Unit"]["UnitCount"].GetInt());
                 }
             }
         }
     }
     return(-1);
 }
Esempio n. 14
0
    public static KeyValueData[] GETSTUDENTDATA()
    {
        List <KeyValueData> olst = new List <KeyValueData>();
        DataSet             ods  = new DataSet();
        Student_BLogic      BAL_Student_BLogic = new Student_BLogic();

        ods = BAL_Student_BLogic.BAL_Student_BySchoolid(AppSessions.SchoolID);

        foreach (DataRow dr in ods.Tables[0].Rows)
        {
            KeyValueData okey = new KeyValueData();
            okey.Key   = Convert.ToString(dr["StudentID"]);
            okey.Value = Convert.ToString(dr["MobileNo"]);
            olst.Add(okey);
        }
        return(olst.ToArray());
    }
Esempio n. 15
0
        public short Update(KeyValueData keyValueData)
        {
            if (keyValueData == null)
            {
                LogManager.Instance.WriteLog("", new string[] { "" }
                                             , new object[] { keyValueData }, "参数不能为空");
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            if (base.MedQCAccess == null)
            {
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            StringBuilder sbField = new StringBuilder();

            sbField.AppendFormat("{0}='{1}',"
                                 , SystemData.KeyValueDataTable.DATA_GROUP, keyValueData.DATA_GROUP);
            sbField.AppendFormat("{0}='{1}',"
                                 , SystemData.KeyValueDataTable.DATA_KEY, keyValueData.DATA_KEY);
            sbField.AppendFormat("{0}='{1}',"
                                 , SystemData.KeyValueDataTable.DATA_VALUE, keyValueData.DATA_VALUE);
            sbField.AppendFormat("{0}='{1}'"
                                 , SystemData.KeyValueDataTable.VALUE1, keyValueData.VALUE1);
            string szCondition = string.Format("{0}='{1}'", SystemData.KeyValueDataTable.ID, keyValueData.ID);
            string szSQL       = string.Format(SystemData.SQL.UPDATE, SystemData.DataTable.KEY_VALUE_DATA, sbField.ToString(), szCondition);
            int    nCount      = 0;

            try
            {
                nCount = base.MedQCAccess.ExecuteNonQuery(szSQL, CommandType.Text);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, ex);
                return(SystemData.ReturnValue.EXCEPTION);
            }
            if (nCount <= 0)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, "SQL语句执行后返回0!");
                return(SystemData.ReturnValue.EXCEPTION);
            }
            return(SystemData.ReturnValue.OK);
        }
Esempio n. 16
0
        private void FillTreeView()
        {
            foreach (var builder in builders = LegionFeatures.Builders)
            {
                var node = treeView1.Nodes.Add(builder.Name);
                foreach (var unit in builder.Units)
                {
                    units.Add(unit);
                    var unitNode = node.Nodes.Add(unit.ShortBuilderName);
                }
            }
            var incomeNode = treeView1.Nodes.Add("incomeunit");

            foreach (var unit in LegionFeatures.IncomeUnits)
            {
                units.Add(unit);
                incomeNode.Nodes.Add(unit.ShortIncomeName);
            }
            var waveNode = treeView1.Nodes.Add("unit");

            foreach (var unit in LegionFeatures.WaveUntis)
            {
                units.Add(unit);
                waveNode.Nodes.Add(unit.ShortWaveName);
            }
            treeView1.ExpandAll();

            treeView1.AfterSelect += (s, e) =>
            {
                TreeNode selected = e.Node;
                var      unit     = GetUnit(selected);
                if (unit != null)
                {
                    currentUnit   = unit;
                    textBox1.Text = unit.Text;
                    textBox1.ClearUndo();
                }
            };
        }
Esempio n. 17
0
        private void monthCalendar_DayClick(object sender, Pabo.Calendar.DayClickEventArgs e)
        {
            DateItem dateItem = new DateItem();

            dateItem.Date           = DateTime.Parse(e.Date);
            dateItem.DateColor      = Color.Black;
            dateItem.ImageListIndex = 0;


            short shRet = SystemData.ReturnValue.OK;

            foreach (DateItem item in (sender as Pabo.Calendar.MonthCalendar).Dates)
            {
                if (item.Date == dateItem.Date)
                {
                    KeyValueData keyValueDate = item.Tag as KeyValueData;
                    if (keyValueDate != null)
                    {
                        shRet = KeyValueDataAccess.Instance.Delete(keyValueDate.ID);
                    }
                    (sender as Pabo.Calendar.MonthCalendar).Dates.Remove(item);
                    return;
                }
            }

            KeyValueData key = new KeyValueData();

            key.DATA_GROUP = "holiday";
            key.DATA_KEY   = "日期";
            key.DATA_VALUE = dateItem.Date.ToString("yyyy-MM-dd");
            key.VALUE1     = this.Year.ToString();
            key.ID         = key.MakeID();
            shRet          = KeyValueDataAccess.Instance.Insert(key);
            dateItem.Tag   = key;
            (sender as Pabo.Calendar.MonthCalendar).Dates.Add(dateItem);
        }
Esempio n. 18
0
        public short GetHolidays(string year, ref List <KeyValueData> lstKeyValueDatas)
        {
            if (base.MedQCAccess == null)
            {
                return(SystemData.ReturnValue.PARAM_ERROR);
            }
            StringBuilder sbField = new StringBuilder();

            sbField.AppendFormat("{0},", SystemData.KeyValueDataTable.DATA_GROUP);
            sbField.AppendFormat("{0},", SystemData.KeyValueDataTable.DATA_KEY);
            sbField.AppendFormat("{0},", SystemData.KeyValueDataTable.DATA_VALUE);
            sbField.AppendFormat("{0},", SystemData.KeyValueDataTable.VALUE1);
            sbField.AppendFormat("{0}", SystemData.KeyValueDataTable.ID);
            string szCondition = " 1=1";

            szCondition = string.Format("{0} AND {1}='{2}'"
                                        , szCondition
                                        , SystemData.KeyValueDataTable.DATA_GROUP
                                        , SystemData.DataGroup.holiday);
            if (!string.IsNullOrEmpty(year))
            {
                szCondition = string.Format("{0} AND {1}='{2}'"
                                            , szCondition
                                            , SystemData.KeyValueDataTable.VALUE1
                                            , year);
            }
            string szSQL = string.Format(SystemData.SQL.SELECT_WHERE
                                         , sbField.ToString(), SystemData.DataTable.KEY_VALUE_DATA, szCondition);

            IDataReader dataReader = null;

            try
            {
                dataReader = base.MedQCAccess.ExecuteReader(szSQL, CommandType.Text);
                if (dataReader == null || dataReader.IsClosed || !dataReader.Read())
                {
                    return(SystemData.ReturnValue.RES_NO_FOUND);
                }
                if (lstKeyValueDatas == null)
                {
                    lstKeyValueDatas = new List <KeyValueData>();
                }
                do
                {
                    KeyValueData keyValueData = new KeyValueData();
                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        if (dataReader.IsDBNull(i))
                        {
                            continue;
                        }
                        switch (dataReader.GetName(i))
                        {
                        case SystemData.KeyValueDataTable.DATA_GROUP:
                            keyValueData.DATA_GROUP = dataReader.GetValue(i).ToString();
                            break;

                        case SystemData.KeyValueDataTable.DATA_KEY:
                            keyValueData.DATA_KEY = dataReader.GetString(i);
                            break;

                        case SystemData.KeyValueDataTable.DATA_VALUE:
                            keyValueData.DATA_VALUE = dataReader.GetString(i);
                            break;

                        case SystemData.KeyValueDataTable.ID:
                            keyValueData.ID = dataReader.GetString(i);
                            break;

                        case SystemData.KeyValueDataTable.VALUE1:
                            keyValueData.VALUE1 = dataReader.GetString(i);
                            break;

                        default: break;
                        }
                    }
                    lstKeyValueDatas.Add(keyValueData);
                } while (dataReader.Read());
                return(SystemData.ReturnValue.OK);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("", new string[] { "szSQL" }, new object[] { szSQL }, ex);
                return(SystemData.ReturnValue.EXCEPTION);
            }
            finally { base.MedQCAccess.CloseConnnection(false); }
        }
Esempio n. 19
0
 protected override void Awake()
 {
     base.Awake();
     KeyValueData = new KeyValueData();
 }
        private void DisplayTreeView(ImageTreeViewItem root, String name, List<String> items)
        {
            List<KeyValueData> kvList = new List<KeyValueData>();

            foreach (String key in items)
            {
                int value = BindingT.GetValue(name, key);
                if (BindingT.IsTable(value))
                {
                    ImageTreeViewItem node = new ImageTreeViewItem();
                    node.SelectedImage = new BitmapImage(new Uri("Resource/Image/file1.png", UriKind.Relative));
                    node.UnselectedImage = new BitmapImage(new Uri("Resource/Image/file.png", UriKind.Relative));
                    node.Text = key;
                    node.TableName = key;
                    node.Selected += TreeViewItem_Selected;
                    root.Items.Add(node);

                    TreeViewItemContextMenu cm = new TreeViewItemContextMenu();
                    cm.Name = key;
                    cm.OwnerName = name;
                    cm.BindingItem = node;
                    cm.RootItem = root;
                    node.ContextMenu = cm;
                    cm.AddItem.Click += new RoutedEventHandler(AddItem_Click);
                    cm.DeleteItem.Click += new RoutedEventHandler(DeleteItem_Click);

                    List<String> subItems = BindingT.GetTableKeys(key);
                    DisplayTreeView(node, key, subItems);
                    continue;
                }

                KeyValueData kvData = new KeyValueData();
                if (BindingT.IsBool(value))
                {
                    bool bv = BindingT.ToBool(value);
                    kvData.AttachToTfsValue(key, ValueType.Bool, bv.ToString());
                }
                else if (BindingT.IsByte(value))
                {
                    byte bv = BindingT.ToByte(value);
                    kvData.AttachToTfsValue(key, ValueType.Byte, bv.ToString());
                }
                else if (BindingT.IsDouble(value))
                {
                    double dv = BindingT.ToDouble(value);
                    kvData.AttachToTfsValue(key, ValueType.Double, dv.ToString());
                }
                else if (BindingT.IsFloat(value))
                {
                    float fv = BindingT.ToFloat(value);
                    kvData.AttachToTfsValue(key, ValueType.Float, fv.ToString());
                }
                else if (BindingT.IsInt32(value))
                {
                    int i32v = BindingT.ToInt32(value);
                    kvData.AttachToTfsValue(key, ValueType.Int32, i32v.ToString());
                }
                else if (BindingT.IsInt64(value))
                {
                    Int64 i64v = BindingT.ToInt64(value);
                    kvData.AttachToTfsValue(key, ValueType.Int64, i64v.ToString());
                }
                else if (BindingT.IsString(value))
                {
                    string sv = BindingT.ToString(value);
                    kvData.AttachToTfsValue(key, ValueType.String, sv);
                }

                kvList.Add(kvData);
            }

            DataTable dt = new DataTable(name);
            dt.Columns.Add("Key", typeof(string));
            dt.Columns.Add("Type", typeof(string));
            dt.Columns.Add("Data", typeof(string));
            foreach (KeyValueData kvd in kvList)
            {
                dt.Rows.Add(kvd.Key, kvd.Type, kvd.Data);
            }

            TableData tab = new TableData();
            tab.Name = name;
            tab.DataSource = dt;
            tab.Item = kvList;
            root.Tag = tab;
        }