/// <summary> /// Returns the folder datarow object if folder exists, otherwise returns null /// </summary> /// <param name="Connection"></param> /// <param name="FolderName"></param> /// <returns></returns> private static FoldersRow GetFolderByName(TDSettings.ConnectionRow connectionRow, string folderName) { DataRow[] folders; FoldersRow result; folders = _instance.Folders.Select("Name = '" + folderName + "' AND UserID = " + connectionRow.ConnectionId.ToString()); if (folders == null || folders.GetLength(0) == 0) { result = null; } else { //length should be 1 result = (FoldersRow)folders[0]; } return result; }
/// <summary> /// Checks for the predefined folder structure and build it together with the predefined queries /// </summary> /// <param name="Connection"></param> public static void RefreshTreePerUser(TDSettings.ConnectionRow connectionRow) { int parentID; DataRow[] folders; FoldersRow folder, productFolder; //Check for the default structure of folders and queries //Check for folder "Product Queries" folder = GetFolderByName(connectionRow, "Product Queries"); if (folder == null) { //create product queries folder folder = CreateFolder(connectionRow, "Product Queries", 0, -1); if (folder == null) throw new Exception("Queries folder structure is corrupted!"); } parentID = folder.ID; DataRow[] Queries; string productName = String.Empty; QueriesRow query; #region add each product as a folder in the tree CatalogueManager catalogues = CatalogueManager.Instance(); NameValueCollection products = catalogues.GetCataloguesForConnection (connectionRow.ConnectionId ).catalogueProduct; folders = _instance.Folders.Select("ParentID = " + parentID.ToString() + " AND UserID = " + connectionRow.ConnectionId.ToString()); for (int i = folders.GetLength(0)-1; i >=0; i--) { productFolder = (FoldersRow)folders[i]; //check if product belongs to the current user bool belongsToCurrentUser = false; for (int index = 0; index < products.Count; index++) { if (folder.Name == products.GetKey(index).Split(',')[1]) { belongsToCurrentUser = true; break; } } if (!belongsToCurrentUser) { productFolder.Delete(); //folder.Delete(); } } //generate new product folders for (int i = 0; i < products.Count; i++) { productName = products.GetKey(i).Split(',')[1]; CreateProductFolderDefaultQueries(connectionRow, parentID, productName); } #endregion //Check for the default folder "My Queries" folder = GetFolderByName(connectionRow, "My Queries"); if (folder == null) { //think about throuwing error folder = CreateFolder(connectionRow, "My Queries", 0, -1); if (folder == null) { throw new Exception("Queries folder structure is corrupted!"); } } #region Check if exists predefined query My Opened BUGS Queries = _instance.Queries.Select("Name = 'My opened bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My opened bugs"; query.Description = "All my opened bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForOpenedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion #region Check if exists predefined query My Closed BUGS Queries = _instance.Queries.Select("Name = 'My closed bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My closed bugs"; query.Description = "All my closed bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForClosedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion #region Check if exists predefined query My Fixed BUGS Queries = _instance.Queries.Select("Name = 'My fixed bugs' AND FolderID = " + folder.ID); if (Queries.GetLength(0) == 0) { query = _instance.Queries.NewQueriesRow(); query.Name = "My fixed bugs"; query.Description = "All my fixed bugs for any product"; query.FolderID = folder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForFixedBugsQuery(String.Empty, true, connectionRow.UserName)); } #endregion //Update Tree with the default structure _instance.Folders.AcceptChanges(); _instance.Queries.AcceptChanges(); _instance.ParametersValues.AcceptChanges(); }
private static FoldersRow CreateFolder(TDSettings.ConnectionRow connectionRow, string forlderName, int levelId, int parentId) { FoldersRow newFolder = _instance.Folders.NewFoldersRow(); newFolder.Name = forlderName; newFolder.UserID = connectionRow.ConnectionId; newFolder.LevelID = levelId; newFolder.ParentID = parentId; newFolder.ReadOnly = true; newFolder.Expanded = false; newFolder.Deleted = false; _instance.Folders.AddFoldersRow(newFolder); _instance.AcceptChanges(); return newFolder; }
private static string CreateProductFolderDefaultQueries(TDSettings.ConnectionRow connectionRow, int parentId, string productName) { FoldersRow productFolder = GetFolderByName(connectionRow, productName); QueriesRow query; if (productFolder == null) productFolder = CreateFolder(connectionRow, productName, 1, parentId); if (productFolder != null) { //********************************************************************* query = _instance.Queries.NewQueriesRow(); query.Name = "Opened bugs"; query.Description = "Opened bugs for the product [" + productName + "]"; query.FolderID = productFolder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForOpenedBugsQuery(productName, false, String.Empty)); //********************************************************************* query = _instance.Queries.NewQueriesRow(); query.Name = "Closed bugs"; query.Description = "Closed bugs for the product [" + productName + "]"; query.FolderID = productFolder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForClosedBugsQuery(productName, false, String.Empty)); //********************************************************************* query = _instance.Queries.NewQueriesRow(); query.Name = "Fixed bugs"; query.Description = "Fixed bugs for the product [" + productName + "]"; query.FolderID = productFolder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForFixedBugsQuery(productName, false, String.Empty)); //********************************************************************* query = _instance.Queries.NewQueriesRow(); query.Name = "All bugs"; query.Description = "All bugs for the product [" + productName + "]"; query.FolderID = productFolder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForAllBugsQuery(productName, true, String.Empty)); //********************************************************************* query = _instance.Queries.NewQueriesRow(); query.Name = "My bugs"; query.Description = "All my bugs for the product [" + productName + "]"; query.FolderID = productFolder.ID; query.TypeID = Convert.ToByte(_queryTypes.Predefined); _instance.Queries.AddQueriesRow(query); _instance.AddParameterValuesForQuery(query, GetParamsForAllBugsQuery(productName, true, connectionRow.UserName)); } return productName; }
public void AddUserSubtree(TreeView treeView, TDSettings.ConnectionRow connectionRow) { DataRow[] rows; TreeNode nodeUser; //find the node in the tree corresponding to the user-connection TreeNode[] nodesUser = treeView.Nodes.Find("User " + connectionRow.ConnectionId.ToString(), true); if (nodesUser.GetLength(0) == 1) { nodeUser = nodesUser[0]; //find all folders of the user and sort them on LevelID rows = _instance.Folders.Select("UserID = " + Int16.Parse(nodeUser.Name.Replace("User", String.Empty)).ToString(), "LevelID, Name, ID, ParentID"); TreeNode node = new TreeNode(); if (rows.GetLength(0) == 0) nodeUser.ForeColor = System.Drawing.Color.Gray; //check if product list changed on the server CatalogueManager catalogues = CatalogueManager.Instance(); NameValueCollection products = catalogues.GetCataloguesForConnection(connectionRow.ConnectionId).catalogueProduct; string productName = String.Empty; FoldersRow productsRootFolder = GetFolderByName(connectionRow, "Product Queries"); if (productsRootFolder == null) { productsRootFolder = CreateFolder(connectionRow, "Product Queries", 0, -1); } //check if local user xml still contains deleted products // if contains one, delete it for (int i = rows.GetLength(0) - 1; i >= 0; i--) { FoldersRow folder = (FoldersRow)rows[i]; if ((folder.ParentID == productsRootFolder.ID) && (products[folder.Name + "," + folder.Name] == null)) folder.Delete(); } //check if new product is missing from the local user structure for (int i = 0; i < products.Count; i++) { productName = products.GetKey(i).Split(',')[1]; FoldersRow productFolder = GetFolderByName(connectionRow, productName); if (productFolder == null) { CreateProductFolderDefaultQueries(connectionRow, productsRootFolder.ID, productName); } } rows = _instance.Folders.Select("UserID = " + Int16.Parse(nodeUser.Name.Replace("User", String.Empty)).ToString(), "LevelID, Name, ID, ParentID"); //add each folder(except deleted ones) as a TreeNode in the TreeView foreach (DataRow dr in rows) { FoldersRow folder = (FoldersRow)dr; //protect agains folders that do not have the Deleted tag (protect agains null value) try { folder.Deleted = folder.Deleted; } catch { folder.Deleted = false; } if (!folder.Deleted) { if (folder.ParentID == -1) { node = nodeUser.Nodes.Add("folder " + folder.ID.ToString(), folder.Name, "Folder"); } else { FoldersRow parentFolder = _instance.Folders.FindByID(folder.ParentID); if (parentFolder.Deleted) { folder.Deleted = true; } TreeNode[] nodes = nodeUser.Nodes.Find("folder " + folder.ParentID.ToString(), true); if (nodes.GetLength(0) == 1) { node = nodes[0].Nodes.Add("folder " + folder.ID.ToString(), folder.Name, "Folder"); } } if (!folder.Deleted) { node.SelectedImageKey = "Folder"; node.Tag = new NodeDescription(NodeType.Folder, folder); //add queries associated with the folder as tree nodes DataRow[] queries = _instance.Queries.Select("FolderId = " + folder.ID); foreach (DataRow query in queries) { QueriesRow queryRow = (QueriesRow)query; AddQueryToTreeNode(node, queryRow); } } } } } }
public void LoadDefaultDataForUserId(TreeView treeView, TDSettings.ConnectionRow connectionRow) { string defaultFileName = Application.StartupPath + Path.DirectorySeparatorChar + _defaultFileName; try { if (File.Exists(defaultFileName)) { TDSQueriesTree treeStructure = new TDSQueriesTree(); treeStructure.ReadXml(defaultFileName); //treeStructure.WriteXml("c:\\test.xml"); BuildTreeStructureForUserId(treeStructure, connectionRow ); } } catch (IOException) { throw (new IOException("File " + defaultFileName + " does not exist.")); } }
private static Catalogues LoadMainCatalogues(TDSettings.ConnectionRow connectionRow, BackgroundWorker backgroudWorker) { #if DEBUG string methodName = "LoadMainCatalogues"; #endif #if DEBUG System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); #endif backgroudWorker.ReportProgress(0); backgroudWorker.ReportProgress(10); // when refresh catalogues, it is no need to verify login. IUser user = (IUser)BLControllerFactory.GetRegisteredConcreteFactory(connectionRow.ConnectionId ); string userIsLogged = user.LogOnToBugzilla(connectionRow.UserName, connectionRow.Password); #if DEBUG watch.Stop(); MyLogger.Write(watch.ElapsedMilliseconds.ToString(), methodName, LoggingCategory.Debug); watch.Start(); #endif if (userIsLogged.Length > 0) { // this could happen because a wrong password was saved. backgroudWorker.ReportProgress(100); return null; } IUtilities catalogue = (IUtilities)BLControllerFactory.GetRegisteredConcreteFactory(connectionRow.ConnectionId ); string[] catalogNames = new string[] { "classification", "product", "bug_status", "resolution", "bug_severity", "priority", "rep_platform", "op_sys", "short_desc_type", "field0-0-0", "type0-0-0" }; // get all the main catalogues (catalogues without dependencies) used in the application // request ArrayList collCatalogues = catalogue.GetCatalogues(catalogNames); #if DEBUG watch.Stop(); MyLogger.Write(watch.ElapsedMilliseconds.ToString(), methodName, LoggingCategory.Debug); watch.Start(); #endif // get the connection/user information MyZilla.BusinessEntities.Catalogues cataloguesPerUser = new MyZilla.BusinessEntities.Catalogues(connectionRow.ConnectionId); #region Main Catalogues // get the product catalogue List<string> lstProduct = collCatalogues[1] as List<string>; cataloguesPerUser.catalogueProduct = new NameValueCollection(); foreach (string strProduct in lstProduct) { cataloguesPerUser.catalogueProduct.Add(strProduct, string.Empty); } backgroudWorker.ReportProgress(80); // get the rest of the main catalogues and populate the corresponding controls. // string[] catalogNames = new string[] {"product", // "bug_status", // "resolution", // "bug_severity", // "priority", // "rep_platform", // "op_sys", // "short_desc_type"}; cataloguesPerUser.catalogueStatus = collCatalogues[2] as List<string>; cataloguesPerUser.catalogueResolution = collCatalogues[3] as List<string>; cataloguesPerUser.catalogueSeverity = collCatalogues[4] as List<string>; cataloguesPerUser.cataloguePriority = collCatalogues[5] as List<string>; cataloguesPerUser.catalogueHardware = collCatalogues[6] as List<string>; cataloguesPerUser.catalogueOS = collCatalogues[7] as List<string>; cataloguesPerUser.catalogueStringOperators = collCatalogues[8] as List<string>; cataloguesPerUser.catalogueFields = collCatalogues[9] as List<string>; cataloguesPerUser.catalogueOperators = collCatalogues[10] as List<string>; #endregion backgroudWorker.ReportProgress(100); #if DEBUG watch.Stop(); MyLogger.Write(watch.ElapsedMilliseconds.ToString(), methodName, LoggingCategory.Debug); #endif return cataloguesPerUser; }
private static Catalogues GetCataloguesForUser(TDSettings.ConnectionRow currentConnection, BackgroundWorker bkgWork) { MyZilla.BusinessEntities.Catalogues cataloguesPerUser = null; string connInfo = _appSettings.GetConnectionInfo(currentConnection.ConnectionId); try { #if DEBUG System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); #endif bkgWork.ReportProgress(0, connInfo); bkgWork.ReportProgress(10, connInfo); // when refresh catalogues, it is no need to verify login. IUser user = (IUser)BLControllerFactory.GetRegisteredConcreteFactory(currentConnection.ConnectionId); // TO DO: eliminate the last param. string loggedUser = user.LogOnToBugzilla(currentConnection.UserName, currentConnection.Password); if (loggedUser.Length > 0) { // this could happen if a wrong password was saved. bkgWork.ReportProgress(100, connInfo); throw new Exception(loggedUser); } IUtilities catalogue = (IUtilities)BLControllerFactory.GetRegisteredConcreteFactory(currentConnection.ConnectionId); string[] catalogNames = new string[] { "classification", "product", "bug_status", "resolution", "bug_severity", "priority", "rep_platform", "op_sys", "short_desc_type", "field0-0-0", "type0-0-0" }; // get all the main catalogues (catalogues without dependencies) used in the application // request ArrayList collCatalogues = catalogue.GetCatalogues(catalogNames); // get the connection/user information cataloguesPerUser = new MyZilla.BusinessEntities.Catalogues(currentConnection.ConnectionId); #region Main Catalogues // get the product catalogue List<string> lstProduct = collCatalogues[1] as List<string>; cataloguesPerUser.catalogueProduct = new NameValueCollection(); foreach (string strProduct in lstProduct) { cataloguesPerUser.catalogueProduct.Add(strProduct, string.Empty); } // get the rest of the main catalogues and populate the corresponding controls. // string[] catalogNames = new string[] {"product", // "bug_status", // "resolution", // "bug_severity", // "priority", // "rep_platform", // "op_sys", // "short_desc_type"}; cataloguesPerUser.catalogueStatus = collCatalogues[2] as List<string>; cataloguesPerUser.catalogueResolution = collCatalogues[3] as List<string>; cataloguesPerUser.catalogueSeverity = collCatalogues[4] as List<string>; cataloguesPerUser.cataloguePriority = collCatalogues[5] as List<string>; cataloguesPerUser.catalogueHardware = collCatalogues[6] as List<string>; cataloguesPerUser.catalogueOS = collCatalogues[7] as List<string>; cataloguesPerUser.catalogueStringOperators = collCatalogues[8] as List<string>; cataloguesPerUser.catalogueFields = collCatalogues[9] as List<string>; cataloguesPerUser.catalogueOperators = collCatalogues[10] as List<string>; #endregion bkgWork.ReportProgress(40, connInfo); #region Dependent catalogues // component and version catalogues // request ArrayList al = catalogue.GetValuesForDependentCatalogues(0, cataloguesPerUser.catalogueProduct); cataloguesPerUser.catalogueComponent = al[0] as NameValueCollection; cataloguesPerUser.catalogueVersion = al[1] as NameValueCollection; cataloguesPerUser.catalogueTargetMilestone = al[2] as NameValueCollection; #endregion bkgWork.ReportProgress(80, connInfo); #if DEBUG watch.Stop(); MyLogger.Write(watch.ElapsedMilliseconds.ToString(), "GetCataloguesForUser", LoggingCategory.Debug); #endif } catch (Exception ex) { MyLogger.Write(ex, "GetCataloguesForUser", LoggingCategory.Exception); throw; } finally { bkgWork.ReportProgress(100, connInfo); } return cataloguesPerUser; }
public SavingData( OperationType operation, TDSettings.ConnectionRow connectionRow ) { _operation = operation; _connectionRow = connectionRow; }
public void SaveGlobalSettings(TDSettings.GlobalSettingsRow globalSettingsRow) { if (this.GlobalSettings.Rows.Count == 0 ) { TDSettings.GlobalSettingsRow newGlobalSettingsRow = this.GlobalSettings.NewGlobalSettingsRow(); newGlobalSettingsRow.ShowLoadingForm = globalSettingsRow.ShowLoadingForm; newGlobalSettingsRow.MainFormHeight = globalSettingsRow.MainFormHeight; newGlobalSettingsRow.MainFormWidth = globalSettingsRow.MainFormWidth; newGlobalSettingsRow.TreePanelWidth = globalSettingsRow.TreePanelWidth; newGlobalSettingsRow.ConfirmSuccessfullyEditBug = globalSettingsRow.ConfirmSuccessfullyEditBug; newGlobalSettingsRow.ShowBugsCount = globalSettingsRow.ShowBugsCount; newGlobalSettingsRow.ReportFilesPath = globalSettingsRow.ReportFilesPath; this.GlobalSettings.Rows.Add(newGlobalSettingsRow); } else { (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).ShowLoadingForm = globalSettingsRow.ShowLoadingForm; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).MainFormHeight = globalSettingsRow.MainFormHeight; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).MainFormWidth = globalSettingsRow.MainFormWidth; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).TreePanelWidth = globalSettingsRow.TreePanelWidth; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).ConfirmSuccessfullyEditBug = globalSettingsRow.ConfirmSuccessfullyEditBug ; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).ShowBugsCount = globalSettingsRow.ShowBugsCount ; (this.GlobalSettings.Rows[0] as TDSettings.GlobalSettingsRow).ReportFilesPath = globalSettingsRow.ReportFilesPath ; } this.SaveXML( null ); }
public void EditConnection(TDSettings.ConnectionRow connectionValues) { TDSettings.ConnectionRow[] rowConn = this.Connection.Select("ConnectionId=" + connectionValues.ConnectionId) as TDSettings.ConnectionRow[]; if (rowConn != null && rowConn.Length == 1) { rowConn[0].ConnectionName = connectionValues.ConnectionName; rowConn[0].URL = connectionValues.URL; rowConn[0].Type = connectionValues.Type; rowConn[0].UserName = connectionValues.UserName; rowConn[0].Password = connectionValues.Password; rowConn[0].RememberPassword = connectionValues.RememberPassword; rowConn[0].ActiveUser = connectionValues.ActiveUser; rowConn[0].Charset = connectionValues.Charset; SavingData sp = new SavingData(OperationType.EditConnection, rowConn[0]); this.SaveXML(sp); } }