Example #1
0
        private int BatchInsert <T>(string tableName, T[] batchData, int count, MySqlConnection cnn, MySqlTransaction trans)
        {
            Type type = typeof(T);
            ComboClass <string, string[], List <TableFieldAttribute> > cache;
            ComboClass <Type, int> key = new ComboClass <Type, int>(typeof(T), count);

            lock (_syncRoot) {
                if (!_bulkCaches.TryGetValue(key, out cache))
                {
                    cache = BuildBulkCache(tableName, type, count);
                    _bulkCaches.Add(key, cache);
                }
            }

            string sql = cache.V1;

            string[] parameters = cache.V2;
            List <TableFieldAttribute> attrs = cache.V3;

            object[] objs = new object[attrs.Count * count];
            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < attrs.Count; j++)
                {
                    objs[i * attrs.Count + j] = attrs[j].Field.GetValue(batchData[i]);
                }
            }

            MySqlCommand cmd = new MySqlCommand(sql, cnn, trans);

            cmd.CommandTimeout = CommandTimeout;
            cmd.CommandType    = CommandType.Text;
            SpFillParameters(cmd, parameters, objs);
            return(cmd.ExecuteNonQuery());
        }
Example #2
0
        private ComboClass <DataTable, List <TableFieldAttribute> > BuildBulkCache(Type t)
        {
            DataTable table = new DataTable();

            FieldInfo[] fields = t.GetFields();

            List <TableFieldAttribute> attrs = new List <TableFieldAttribute>();

            foreach (FieldInfo field in fields)
            {
                TableFieldAttribute fieldAttr = AttributeHelper.TryGetAttribute <TableFieldAttribute>(field);
                if (fieldAttr != null)
                {
                    DataColumn column = new DataColumn();
                    column.ColumnName = fieldAttr.ColumnName;
                    column.DataType   = fieldAttr.FieldType ?? field.FieldType;
                    table.Columns.Add(column);

                    fieldAttr.Field   = field;
                    fieldAttr.Column  = column;
                    fieldAttr.Context = new SqlBulkCopyColumnMapping(column.ColumnName, column.ColumnName);
                    attrs.Add(fieldAttr);
                }
            }

            ComboClass <DataTable, List <TableFieldAttribute> > cache = new ComboClass <DataTable, List <TableFieldAttribute> >();

            cache.V1 = table;
            cache.V2 = attrs;

            return(cache);
        }
Example #3
0
        private ComboClass <string, string[], List <TableFieldAttribute> > BuildBulkCache(string tableName, Type t, int batchCount)
        {
            List <string> param = new List <string>();

            FieldInfo[] fields = t.GetFields();

            List <TableFieldAttribute> attrs = new List <TableFieldAttribute>();

            foreach (FieldInfo field in fields)
            {
                TableFieldAttribute fieldAttr = AttributeHelper.TryGetAttribute <TableFieldAttribute>(field);
                if (fieldAttr != null)
                {
                    attrs.Add(fieldAttr);
                    fieldAttr.Field = field;
                }
            }

            StringBuilder sqlAll = new StringBuilder();

            for (int i = 0; i < batchCount; i++)
            {
                StringBuilder sqlBefore = new StringBuilder();
                StringBuilder sqlAfter  = new StringBuilder();
                StringBuilder sqlUpdate = new StringBuilder();

                sqlBefore.AppendFormat("INSERT INTO {0} (", tableName);
                for (int j = 0; j < attrs.Count; j++)
                {
                    var attr = attrs[j];
                    sqlBefore.AppendFormat("{0}", attr.ColumnName);

                    int paramOrder = i * attrs.Count + j;
                    sqlAfter.AppendFormat("@v_p{0}", paramOrder);
                    sqlUpdate.AppendFormat("{0}=@v_p{1}", attr.ColumnName, paramOrder);
                    param.Add("@p" + paramOrder);

                    if (j != attrs.Count - 1)
                    {
                        sqlBefore.Append(",");
                        sqlAfter.Append(",");
                        sqlUpdate.Append(",");
                    }
                }
                sqlAll.Append(sqlBefore.ToString());
                sqlAll.Append(") VALUES (");
                sqlAll.Append(sqlAfter.ToString());
                sqlAll.Append(") ON DUPLICATE KEY UPDATE ");
                sqlAll.Append(sqlUpdate.ToString());
                sqlAll.Append(";\r\n");
            }

            var cache = new ComboClass <string, string[], List <TableFieldAttribute> >();

            cache.V1 = sqlAll.ToString();
            cache.V2 = param.ToArray();
            cache.V3 = attrs;

            return(cache);
        }
        public static RpcServerObserverItem GetServerItem(string service, string method, string fromService, string fromComputer)
        {
            RpcServerObserverItem ret;
            var key = new ComboClass<string, string, string, string>(service, method, fromService, fromComputer);

            lock (_syncServer) {
                if (!_serverDic.TryGetValue(key, out ret)) {
                    ret = new RpcServerObserverItem(service, method, fromService, fromComputer);
                    _serverDic.Add(key, ret);
                }
            }
            return ret;
        }
        public static RpcClientObserverItem GetClientItem(string serverUri, string service, string method, string serviceRole)
        {
            RpcClientObserverItem ret;
            var key = new ComboClass<string, string, string>(serverUri, service, method);

            lock (_syncClient) {
                if (!_clientDic.TryGetValue(key, out ret)) {
                    ret = new RpcClientObserverItem(serverUri, service, method, serviceRole);
                    _clientDic.Add(key, ret);
                }
            }
            return ret;
        }
Example #6
0
        public static RpcServerObserverItem GetServerItem(string service, string method, string fromService, string fromComputer)
        {
            RpcServerObserverItem ret;
            var key = new ComboClass <string, string, string, string>(service, method, fromService, fromComputer);

            lock (_syncServer) {
                if (!_serverDic.TryGetValue(key, out ret))
                {
                    ret = new RpcServerObserverItem(service, method, fromService, fromComputer);
                    _serverDic.Add(key, ret);
                }
            }
            return(ret);
        }
Example #7
0
        public static RpcClientObserverItem GetClientItem(string serverUri, string service, string method, string serviceRole)
        {
            RpcClientObserverItem ret;
            var key = new ComboClass <string, string, string>(serverUri, service, method);

            lock (_syncClient) {
                if (!_clientDic.TryGetValue(key, out ret))
                {
                    ret = new RpcClientObserverItem(serverUri, service, method, serviceRole);
                    _clientDic.Add(key, ret);
                }
            }
            return(ret);
        }
        public RpcTcpSimplexConnection(RpcTcpClientChannel channel, TcpUri serverUri, int concurrentConnection)
            : base(RpcConnectionMode.Simplex, RpcConnectionDirection.Client)
        {
            _channel         = channel;
            _serverUri       = serverUri;
            _connections     = new RpcTcpSimplexConnectionWrapper[concurrentConnection];
            _lc              = new LoopCounter(concurrentConnection);
            _connectionCount = new ComboClass <int>(0);

            for (int i = 0; i < concurrentConnection; i++)
            {
                var wrapper = new RpcTcpSimplexConnectionWrapper(this);
                RpcTcpSimplexConnectionManager.AddConnection(wrapper);
                _connections[i] = wrapper;
            }
        }
        /// <summary>
        /// Saving Product
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (TxtProductNumber.Text == "")
                {
                    MessageBox.Show("Enter Product Number");
                    TxtProductNumber.Focus();
                }
                else if (TxtProductName.Text == "")
                {
                    MessageBox.Show("Enter Product Name");
                    TxtProductName.Focus();
                }
                else if (TxtPrice.Text == "")
                {
                    MessageBox.Show("Enter Price");
                    TxtPrice.Focus();
                }
                else if (ComboColor.SelectedIndex == -1)
                {
                    MessageBox.Show("Select Color");
                    ComboColor.Focus();
                }
                else if (ComboClass.SelectedIndex == -1)
                {
                    MessageBox.Show("Select Class");
                    ComboClass.Focus();
                }
                else
                {
                    string message = "Are you sure you want save this record";
                    if (MessageBox.Show(message, "confirmation", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                    {
                        string selectedComboColor = ComboColor.Items[ComboColor.SelectedIndex].ToString();
                        string selectedComboClass = ComboClass.Items[ComboClass.SelectedIndex].ToString();

                        Product objproduct = new Product();
                        objproduct.Color         = selectedComboColor;
                        objproduct.Description   = TxtDescription.Text;
                        objproduct.Name          = TxtProductName.Text;
                        objproduct.Price         = Convert.ToDecimal(TxtPrice.Text);
                        objproduct.ProductNumber = TxtProductNumber.Text;
                        objproduct.ProductClass  = selectedComboClass;
                        objproduct.CreatedDate   = DateTime.Now;
                        objproduct.CLientIDToken = ShareObject.CLientIDToken;
                        // Calling Business Layer
                        ProductBL.AddProduct(objproduct);
                        // Binding data to DataGridView
                        DGData.DataSource = ProductBL.GetData(ShareObject.CLientIDToken);
                        DGData.ReadOnly   = true;
                        Clear();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    public void OnGUI()
    {
        if (!initialized)
        {
            OnEnable();
        }


        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Combo Maker");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Character");
        selectedPopupIndex_character = EditorGUILayout.Popup(selectedPopupIndex_character, characters.ToArray());
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Ability");
        selectedPopupIndex_ability = EditorGUILayout.Popup(selectedPopupIndex_ability, abilitylist.ToArray());
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        #region DMG Control Panel
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("DMG Control Panel");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical();
        selectedPopupIndex_damage = EditorGUILayout.Popup(selectedPopupIndex_damage, damagetypes.ToArray());

        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical();
        damagevalues[selectedPopupIndex_damagevalues] = EditorGUILayout.Slider(damagevalues[selectedPopupIndex_damagevalues], 0, 1);
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
        #endregion
        IsFoldoutUnfolded = EditorGUILayout.Foldout(IsFoldoutUnfolded, "ok", true);
        if (IsFoldoutUnfolded)
        {
            EditorGUI.indentLevel++;
            foreach (ComboClass cc in combolist[0])
            {
#pragma warning disable CS0618 // Type or member is obsolete
                EditorGUILayout.ObjectField(cc.animation, typeof(Animation));
#pragma warning restore CS0618 // Type or member is obsolete
            }

            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel = 0;
        EditorGUILayout.Separator();

        #region record/play btn
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical();
        if (!IsComboPlaying)
        {
            if (GUILayout.Button(((Texture)(Texture)Resources.Load("Textures/stop.png"))))
            {
                Debug.Log("IsComboPlaying: " + IsComboPlaying);
                IsComboPlaying = true;
            }
        }
        else
        {
            if (GUILayout.Button((Texture)Resources.Load("Textures/play.png")))
            {
                Debug.Log("IsComboPlaying: " + IsComboPlaying);
                IsComboPlaying = false;
            }
            //if (GUILayout.Button((Texture)Resources.Load("Textures/record.png"))) {
            //    IsComboRecording ;
            //}
        }
        //GUILayout.Button("");
        EditorGUILayout.EndVertical();
        #endregion

        #region Timeline
        EditorGUILayout.BeginHorizontal();
        float xOffset = 4, yOffset = 140;

        for (int i = 0; i < combolist[selectedPopupIndex_ability].Count; i++)
        {
            //if (combolist[selectedPopupIndex_ability][selectedPopupIndex_combo] == null)
            ComboClass cc = combolist[selectedPopupIndex_ability][i];//new ComboClass(accuracy: Common.Accuracy.GOOD, timewindow: 30f, keycode: KeyCode.A, damage: 2, ability: new Ability());

            //use GUI.Box because editorgui unusable in editorwindow
            //EditorGUI.DrawRect(new Rect(100, 100, combolist[selectedPopupIndex_ability][selectedPopupIndex_combo].timewindow, 100), c);
            var centeredStyle = GUI.skin.GetStyle("Button");
            centeredStyle.alignment = TextAnchor.MiddleCenter;

            //GUI.Box(new Rect(windowPos.x + xOffset,
            //    windowPos.y + yOffset,
            //    cc.timewindow * 100,
            //    100),
            //    cc.keycode.ToString() + "\n " + (float)cc.timewindow + "s",
            //    centeredStyle);

            GUILayout.Box(new GUIContent(cc.keycode.ToString() + "\n " + (float)cc.timewindow + "s"), GUILayout.Width(cc.timewindow * 100), GUILayout.MaxHeight(50));


            xOffset = cc.timewindow;
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndHorizontal();

        #endregion

        EditorGUILayout.BeginHorizontal();



        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        GUILayout.Button("SAVE");
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.EndHorizontal();
    }