Ejemplo n.º 1
0
 internal ProjectHandler(string name, DevSiteLoginInfo info)
 {
     this.Name     = name;
     DevConnection = info.TryConnect();
     DevSite       = info;
     Preference    = GetProjectPreference();
 }
Ejemplo n.º 2
0
 static MainForm()
 {
     Version        = Assembly.GetExecutingAssembly().GetName().Version;
     Storage        = new LocalStorage();
     DefaultDevSite = new DevSiteLoginInfo();
     Projects       = new ProjectCollection();
 }
Ejemplo n.º 3
0
        private void SetDevSite(DevSiteLoginInfo devSite)
        {
            this.DevSite = devSite;
            try
            {
                DevConnection = this.DevSite.TryConnect();
                Status        = ProjectStatus.Succeed;
            }
            catch
            {
                Status = ProjectStatus.LoadFail;
            }

            XmlHelper  h   = new XmlHelper(this.Preference);
            XmlElement de  = h.GetElement("Property/DevSite");
            XmlNode    dep = de.ParentNode;

            dep.RemoveChild(de);
            de = devSite.XmlContent.GetElement(".");
            XmlNode node = dep.OwnerDocument.ImportNode(de, true);

            dep.AppendChild(node);

            if (MainForm.CurrentProject != null)
            {
                MainForm.CurrentProject.UpdateProjectPreference(this.Preference);
            }
        }
 internal ProjectHandler CreateProjectHandler(string projectName, DevSiteLoginInfo siteInfo)
 {
     foreach (string p in _projects)
     {
         if (p == projectName)
         {
             return(new ProjectHandler(projectName, siteInfo));
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        internal void Init(bool warring)
        {
            Status = ProjectStatus.Unload;

            Preference = GetProjectPreference();

            if (Preference == null)
            {
                if (warring)
                {
                    MessageBox.Show("無法取得專案設定檔!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return;
            }

            XmlHelper  pref           = new XmlHelper(Preference);
            XmlElement devSiteElement = pref.GetElement("Property[@Name='DevSite']/DevSite");

            if (devSiteElement == null)
            {
                string msg = "無法取得專案『" + this.Name + "』開發站台連線設定, 是否重新設定開發站台位置?";
                ShowResetMessage(this.Name, msg);
            }
            else
            {
                DevSite = DevSiteLoginInfo.Load(devSiteElement);

                try
                {
                    DevConnection = DevSite.TryConnect();
                    Status        = ProjectStatus.Succeed;
                }
                catch
                {
                    string msg = "專案『" + this.Name + "』開發站台連線失敗, 是否重新設定開發站台位置?";
                    ShowResetMessage(this.Name, msg);
                }
            }
        }
 internal ProjectEventArgs(string projectName, DevSiteLoginInfo devSite)
 {
     ProjectName = projectName;
     DevSite     = devSite;
 }
        internal void LoadProject(string projectName, DevSiteLoginInfo devSite, bool checkDup, XmlElement source)
        {
            if (this._projects.Contains(projectName))
            {
                throw new Exception("專案已經存在");
            }

            XmlHelper sourceHelper = new XmlHelper(source);

            if (checkDup)
            {
                Connection    devConnection = devSite.TryConnect();
                Envelope      evn           = devConnection.SendRequest("UDSManagerService.ListContracts", new Envelope());
                XmlHelper     rsp           = new XmlHelper(evn.Body);
                StringBuilder contracts     = new StringBuilder();
                foreach (XmlElement contractElement in sourceHelper.GetElements("Property/Contract"))
                {
                    string contractName = contractElement.GetAttribute("Name");
                    if (rsp.GetElement("Contract[@Name='" + contractName + "']") != null)
                    {
                        contracts.Append(contractName).Append("\n");
                    }
                }

                evn = devConnection.SendRequest("UDTService.DDL.ListTables", new Envelope());
                rsp = new XmlHelper(evn.Body);
                StringBuilder tables = new StringBuilder();
                foreach (XmlElement contractElement in rsp.GetElements("Property/Table"))
                {
                    string tableName = contractElement.GetAttribute("Name");
                    if (rsp.GetElement("Table[@Name='" + tableName + "']") != null)
                    {
                        tables.Append(tableName).Append("\n");
                    }
                }
                StringBuilder msg = new StringBuilder();
                if (tables.Length > 0)
                {
                    msg.Append("檢查到重覆資料表 : \n").Append(tables);
                }

                if (contracts.Length > 0)
                {
                    msg.Append("檢查到重覆 Contract : \n").Append(contracts);
                }

                if (msg.Length > 0)
                {
                    throw new Exception(msg.ToString());
                }
            }

            string filepath = MainForm.Storage.GetPropertyValue(LOCAL_FILE_PATH, projectName);

            this.InternalAddProject(projectName, devSite, filepath);

            ProjectHandler ph = this.CreateProjectHandler(projectName, devSite);

            UDSHandler uds = ph.GetUDSHandler();
            XmlElement ce  = sourceHelper.GetElement("Property[@Name='UDS']");

            if (ce != null)
            {
                uds.ImportContracts(ce, true);
            }

            UDTHandler udt = ph.GetUDT();
            XmlElement te  = sourceHelper.GetElement("Property[@Name='UDT']");

            if (te != null)
            {
                udt.SetTables(te, true);
            }

            if (ProjectAdded != null)
            {
                ProjectAdded.Invoke(this, new ProjectEventArgs(projectName, devSite));
            }
        }
Ejemplo n.º 8
0
        private void LoadDevProject(string projectName, DevSiteLoginInfo devSite)
        {
            ReloadProjectList();

            foreach (ToolStripMenuItem item in cmOpenProject.DropDownItems)
            {
                item.Checked = item.Text == projectName;
            }

            MainForm.CurrentProject = Projects.LoadProjectHandler(projectName);

            if (CurrentProject == null)
            {
                return;
            }

            if (CurrentProject.Status == ProjectStatus.LoadFail)
            {
                return;
            }

            //ProjectHandler project = null;
            //if (devSite != null)
            //    project = new ProjectHandler(projectName, devSite);
            //else
            //    project = new ProjectHandler(projectName);
            ProjectHandler project = MainForm.CurrentProject;

            tvProjects.Nodes.Clear();

            TreeNode tn = tvProjects.Nodes.Add(projectName);

            tn.SelectedImageKey = "project";
            tn.ImageKey         = "project";
            ProjectNodeHandler projectNodeHandler = new ProjectNodeHandler(tn, project);

            projectNodeHandler.Reloaded += new EventHandler(projectNodeHandler_Reloaded);
            tn.Tag = projectNodeHandler;

            TreeNode udtNode = tn.Nodes.Add("UDT");

            udtNode.ImageKey         = "udts";
            udtNode.SelectedImageKey = "udts";
            udtNode.ToolTipText      = "自訂資料表";
            UDTNodeHandler udtNodeHandler = new UDTNodeHandler(udtNode);

            udtNode.Tag = udtNodeHandler;
            udtNodeHandler.Reload();
            MainForm.CurrentUDT = udtNodeHandler.UDTHandler;

            TreeNode udsNode = tn.Nodes.Add("UDS");

            udsNode.ImageKey         = "udss";
            udsNode.SelectedImageKey = "udss";
            udsNode.ToolTipText      = "自訂服務";
            UDSNodeHandler udsNodeHandler = new UDSNodeHandler(udsNode);

            udsNode.Tag = udsNodeHandler;
            udsNodeHandler.Reload();
            MainForm.CurrentUDS = udsNodeHandler.UDSHandler;

            TreeNode fileNode = tn.Nodes.Add("檔案管理");

            fileNode.SelectedImageKey = "upload";
            fileNode.ImageKey         = "upload";

            MainForm.CurrentFileNodeHandler = null;
            if (MainForm.LoginArgs.SucceedModuleLogin)
            {
                fileNode.ToolTipText = string.Empty;
                FileNodeHandler fileNodeHandler = new FileNodeHandler(fileNode);
                fileNode.Tag = fileNodeHandler;
                MainForm.CurrentFileNodeHandler = fileNodeHandler;
            }
            else
            {
                fileNode.ToolTipText = "檔案管理伺服器登入失敗";
            }
            tvProjects.ExpandAll();
            udtNodeHandler.CollapseOutsideProject();
            udsNodeHandler.CollapseOutsideProject();
        }
Ejemplo n.º 9
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            err.Clear();

            if (string.IsNullOrWhiteSpace(txtProjectName.Text))
            {
                err.SetError(txtProjectName, "專案名稱不可空白");
            }
            else if (!ProjectHandler.ValidName(txtProjectName.Text))
            {
                err.SetError(txtProjectName, "專案名稱必須為英文或數字組成");
            }

            if (MainForm.Projects.Contains(txtProjectName.Text))
            {
                err.SetError(txtProjectName, "專案名稱已被使用");
            }

            if (!chkUseDefault.Checked)
            {
                if (string.IsNullOrWhiteSpace(txtAP.Text))
                {
                    err.SetError(txtAP, "開發站不可空白");
                }

                if (string.IsNullOrWhiteSpace(txtUser.Text) && cboContract.Text != "_dev")
                {
                    err.SetError(txtUser, "帳號不可空白");
                }

                if (string.IsNullOrWhiteSpace(txtPwd.Text) && cboContract.Text != "_dev")
                {
                    err.SetError(txtPwd, "密碼不可空白");
                }
            }

            if (string.IsNullOrWhiteSpace(txtProjectPath.Text))
            {
                err.SetError(txtProjectPath, "專案本機檔案路徑不可空白");
            }
            else if (!Directory.Exists(txtProjectPath.Text))
            {
                err.SetError(txtProjectPath, "指定的本機檔案路徑不存在");
            }

            foreach (Control ctrl in this.Controls)
            {
                if (string.IsNullOrEmpty(err.GetError(ctrl)))
                {
                    continue;
                }
                return;
            }

            try
            {
                if (chkUseDefault.Checked)
                {
                    MainForm.DefaultDevSite.TryConnect();
                }
                else
                {
                    Connection connection = new Connection();
                    connection.Connect(txtAP.Text, cboContract.Text, txtUser.Text, txtPwd.Text);
                }
            }
            catch (Exception ex)
            {
                if (chkUseDefault.Checked)
                {
                    err.SetError(chkUseDefault, "登入失敗 : " + ex.Message);
                }
                else
                {
                    err.SetError(txtAP, "登入失敗 : " + ex.Message);
                }
                return;
            }

            DevSiteLoginInfo info = new DevSiteLoginInfo();

            if (chkUseDefault.Checked)
            {
                info = MainForm.DefaultDevSite;
            }
            else
            {
                info.AccessPoint  = txtAP.Text;
                info.ContractName = cboContract.Text;
                info.User         = txtUser.Text;
                info.Password     = txtPwd.Text;
            }
            MainForm.Projects.AddProject(txtProjectName.Text, info, txtProjectPath.Text);

            this.Close();
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            err.Clear();

            if (string.IsNullOrWhiteSpace(txtProjectName.Text))
            {
                err.SetError(txtProjectName, "專案名稱不可空白");
            }

            if (MainForm.Projects.Contains(txtProjectName.Text))
            {
                err.SetError(txtProjectName, "專案名稱已被使用");
            }

            if (string.IsNullOrEmpty(txtFileName.Text))
            {
                err.SetError(btnBro, "請選擇檔案");
            }

            if (!File.Exists(txtFileName.Text))
            {
                err.SetError(btnBro, "檔案不存在");
            }

            if (!chkUseDefault.Checked)
            {
                if (string.IsNullOrWhiteSpace(txtAP.Text))
                {
                    err.SetError(txtAP, "開發站不可空白");
                }

                if (string.IsNullOrWhiteSpace(txtUser.Text))
                {
                    err.SetError(txtUser, "帳號不可空白");
                }

                if (string.IsNullOrWhiteSpace(txtPwd.Text))
                {
                    err.SetError(txtPwd, "密碼不可空白");
                }
            }

            foreach (Control ctrl in this.Controls)
            {
                if (string.IsNullOrEmpty(err.GetError(ctrl)))
                {
                    continue;
                }
                return;
            }

            try
            {
                if (chkUseDefault.Checked)
                {
                    MainForm.DefaultDevSite.TryConnect();
                }
                else
                {
                    Connection connection = new Connection();
                    connection.Connect(txtAP.Text, "admin", txtUser.Text, txtPwd.Text);
                }
            }
            catch (Exception ex)
            {
                err.SetError(txtAP, "登入失敗 : " + ex.Message);
                return;
            }

            DevSiteLoginInfo info = new DevSiteLoginInfo();

            if (chkUseDefault.Checked)
            {
                info = MainForm.DefaultDevSite;
            }
            else
            {
                info.AccessPoint = txtAP.Text;
                info.User        = txtUser.Text;
                info.Password    = txtPwd.Text;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(txtFileName.Text);

            try
            {
                MainForm.Projects.LoadProject(txtProjectName.Text, info, rbCheck.Checked, doc.DocumentElement);
            }
            catch (Exception ex)
            {
                MessageBox.Show("載入失敗 : \n" + ex.Message, "失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.Close();
        }