コード例 #1
0
        /*
         * Click create new items button
         * */
        private void m_tmsi_new_Click(object sender, EventArgs e)
        {
            AddItem item     = new AddItem();
            String  itemName = "";

            System.Object configObj = null;
            if (item.ShowDialog() == DialogResult.OK)
            {
                if (this.m_tv_Items.SelectedNode == null)
                {
                    return;
                }
                try
                {
                    itemName = this.m_tv_Items.SelectedNode.Text.ToString();
                    //System.Type typeName = System.Type.GetType("PB." + itemName);
                    System.Type typeName = MainPage.GetAssembly().GetType("PB." + itemName);

                    if (typeName != null)
                    {
                        configObj = System.Activator.CreateInstance(typeName);
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    return;
                }

                if (configObj == null)
                {
                    MessageBox.Show("请选择正常的模板类型.", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    return;
                }

                configObj = CreateProtoObject(configObj);

                String path = item.m_tb_Name.Text.ToString() + ".bin";
                this.m_tv_Items.SelectedNode.Nodes.Add(path);

                StringBuilder builderPath = new StringBuilder();
                String        fullName    = builderPath.Append(MainPage.m_TemplatePath).Append("\\").Append(itemName).Append("\\").Append(path).ToString();

                using (var file = System.IO.File.Create(fullName.ToString()))
                {
                    ProtoBuf.Serializer.Serialize(file, configObj);
                }
            }
        }
コード例 #2
0
ファイル: MainPage.cs プロジェクト: LazyPlanet/TemplateEditor
        public static void AddItem()
        {
            AddItem item = new AddItem();

            if (item.ShowDialog() == DialogResult.OK)
            {
                String itemName;
                System.Object configObj = null;
                if (m_ServerConfig.m_tv_Items.SelectedNode == null) return;
                try
                {
                    itemName = m_ServerConfig.m_tv_Items.SelectedNode.Text.ToString();
                    System.Type typeName = MainPage.GetAssembly().GetType("PB." + itemName);
                    if (typeName != null) configObj = System.Activator.CreateInstance(typeName);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    return;
                }

                if (configObj == null)
                {
                    MessageBox.Show("请选择正常的模板类型.", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    return;
                }

                String path = item.m_tb_Name.Text.ToString() + ".bin";
                m_ServerConfig.m_tv_Items.SelectedNode.Nodes.Add(path);

                StringBuilder builderPath = new StringBuilder();
                String fullName = builderPath.Append(MainPage.m_TemplatePath).Append("\\").Append(itemName).Append("\\").Append(path).ToString();

                using (var file = System.IO.File.Create(fullName.ToString()))
                {
                    ProtoBuf.Serializer.Serialize(file, configObj);
                }
            }
        }
コード例 #3
0
        private void m_tmsi_new_Click(object sender, EventArgs e)
        {
            AddItem addItem = new AddItem();
            try
            {
                if (addItem.ShowDialog() == DialogResult.OK)
                {
                    String itemName = addItem.m_tb_Name.Text.ToString();
                    System.Type typeName = MainPage.GetMessage(itemName);
                    if (typeName == null)
                    {
                        MessageBox.Show("请填写正确的配置类型", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return;
                    }

                    if (!CheckMessage(typeName)) return;

                    String path = new StringBuilder(itemName).ToString();
                    this.m_tv_Items.Nodes.Add(path);

                    String binFile = new StringBuilder(MainPage.m_ServerConfigPath).Append(itemName).ToString();
                    System.IO.File.Create(binFile).Close();
                    SVNMgr.Add(binFile);

                    String csvFile = new StringBuilder(MainPage.m_ServerConfigPath).Append(itemName).Append(".csv").ToString();
                    System.IO.File.Create(csvFile).Close();
                    SVNMgr.Add(csvFile);

                    String luaFile = new StringBuilder(MainPage.m_ClientConfigPath).Append(itemName).Append(".lua").ToString();
                    System.IO.File.Create(luaFile).Close();
                    SVNMgr.Add(luaFile);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("创建配置失败 : " + ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }
        }