private void btnOK_Click(object sender, EventArgs e) { cls_Version_Info tmpVer = new cls_Version_Info(); if (txtVersion.Text.Trim() == "") { MessageBox.Show("Please input the version number!", "Error"); return; } else { //Check if version number is duplicated or not if (!delgCheckVersion(txtVersion.Text.Trim())) { MessageBox.Show("Version number is duplicate!", "Error"); return; } } if (txtPath.Text.Trim() == "") { MessageBox.Show("Please input the application image path!", "Error"); return; } tmpVer.ap_type = this.application_key; tmpVer.ap_version = txtVersion.Text.Trim(); tmpVer.ap_upload_path_name = txtPath.Text.Trim(); tmpVer.ap_description = txtDescription.Text.Trim(); tmpVer.update_time = DateTime.Now; delgSetVersion(tmpVer); this.Close(); }
private string get_destination_dir(cls_Version_Info ver) { string strDest; //strDest = "C:\\VersionControl\\" + ver.ap_type + "\\" + ver.ap_version + "\\"; strDest = "\\" + ver.ap_type + "\\" + ver.ap_version + "\\"; return(strDest); }
private void btnRemove_Click(object sender, EventArgs e) { string strVersion; string strDestinationDir; if (lvVersionList.SelectedItems.Count == 0) { MessageBox.Show("Please select the version number first!", "Error"); return; } if (MessageBox.Show("Are you sure to delete this version?", "Confirm Message", MessageBoxButtons.OKCancel) != DialogResult.OK) { lvVersionList.Focus(); return; } strVersion = lvVersionList.SelectedItems[0].Text; if (this.ver_mgr.version_list.ContainsKey(this.application_key)) { KeyValuePair <string, List <cls_Version_Info> > kv = this.ver_mgr.version_list.Where(p => p.Key == this.application_key).FirstOrDefault(); if (kv.Value != null) { cls_Version_Info ver = kv.Value.Where(o => o.ap_version == strVersion).FirstOrDefault(); if (ver != null) { strDestinationDir = get_destination_dir(ver); if (Directory.Exists(strDestinationDir)) { Directory.Delete(strDestinationDir, true); } kv.Value.Remove(ver); } else { MessageBox.Show("Version number not found", "Error"); return; } } else { MessageBox.Show("Version list not found", "Error"); return; } } else { MessageBox.Show("Application not found", "Error"); return; } SaveVersionConfig(); RefreshVersionList(); }
private void cmbFirmwareVersion_SelectedIndexChanged(object sender, EventArgs e) { string strVersion; strVersion = cmbFirmwareVersion.Text.Trim(); KeyValuePair <string, List <cls_Version_Info> > kv = this.ver_mgr.version_list.Where(p => p.Key == "FIRMWARE").FirstOrDefault(); cls_Version_Info ver = kv.Value.Where(o => o.ap_version == strVersion).FirstOrDefault(); this.ver_info = ver; }
//Delegate function check duplicate version number bool CheckDuplicateVersion(string ver_no) { if (this.ver_mgr.version_list.ContainsKey(this.application_key)) { KeyValuePair <string, List <cls_Version_Info> > kv = this.ver_mgr.version_list.Where(p => p.Key == this.application_key).FirstOrDefault(); cls_Version_Info ver = kv.Value.Where(o => o.ap_version == ver_no).FirstOrDefault(); if (ver != null) { return(false); } else { return(true); } } else { return(true); } }
private void RefreshVersionList() { lvVersionList.BeginUpdate(); lvVersionList.Items.Clear(); if (this.ver_mgr.version_list.Count > 0) { foreach (KeyValuePair <string, List <cls_Version_Info> > kv in this.ver_mgr.version_list) { if (kv.Value.Count > 0) { ListViewItem lvItem = new ListViewItem(kv.Key); //Select the newest update time verson object from list cls_Version_Info ver = kv.Value.OrderByDescending(p => p.update_time).FirstOrDefault(); lvItem.SubItems.Add(ver.ap_version); lvItem.SubItems.Add(ver.update_time.ToString()); lvVersionList.Items.Add(lvItem); } } } lvVersionList.EndUpdate(); }
//Delegate function to setup application version information void SetVersionInfo(cls_Version_Info ver_info) { string strPrefix = "C:\\VersionControl"; string strDestinationDir; string strDestinationName; string strDestinationMD5; string strMD5; strDestinationDir = get_destination_dir(ver_info); strDestinationName = ver_info.ap_version + ".zip"; strDestinationMD5 = ver_info.ap_version + ".md5"; //Compress Image files try { var zip = new ZipFile(); zip.AddDirectory(ver_info.ap_upload_path_name); if (!Directory.Exists(strPrefix + strDestinationDir)) { Directory.CreateDirectory(strPrefix + strDestinationDir); } string tmp = strPrefix + strDestinationDir + strDestinationName; zip.Save(strPrefix + strDestinationDir + strDestinationName); } catch (Exception ex) { MessageBox.Show("Zip file exception -> " + ex.Message, "Error"); return; } //Add MD5 checksum file try { strMD5 = GetMD5HashFromFile(strPrefix + strDestinationDir + strDestinationName); //StreamWriter output = new StreamWriter(strDestinationDir + strDestinationMD5); //output.Write(strMD5); //output.Close(); } catch (Exception ex) { MessageBox.Show("Create MD5 file exception -> " + ex.Message, "Error"); return; } ver_info.ap_store_path_name = strDestinationDir + strDestinationName; //ver_info.md5_store_path_name = strDestinationDir + strDestinationMD5; ver_info.md5_string = strMD5; if (this.ver_mgr.version_list.ContainsKey(this.application_key)) { KeyValuePair <string, List <cls_Version_Info> > kv = this.ver_mgr.version_list.Where(p => p.Key == this.application_key).FirstOrDefault(); kv.Value.Add(ver_info); } else { List <cls_Version_Info> tmpVer = new List <cls_Version_Info>(); tmpVer.Add(ver_info); this.ver_mgr.version_list.TryAdd(this.application_key, tmpVer); } SaveVersionConfig(); }