protected void PopulateUserDataDetails(UltraTreeNode rootNode) { if (rootNode.Text != AWMiscStrings.UserDataNode) { return; } UserDataCategoryList userDataCategories = new UserDataCategoryList(UserDataCategory.SCOPE.Asset); userDataCategories.Populate(); foreach (UserDataCategory category in userDataCategories) { if (category.Scope == UserDataCategory.SCOPE.Asset) { UltraTreeNode categoryNode = new UltraTreeNode(AWMiscStrings.UserDataNode + @"|" + category.Name, category.Name); categoryNode.LeftImages.Add(IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Small)); //categoryNode.Tag = eRootTypes.userdata + category.CategoryID; rootNode.Nodes.Add(categoryNode); categoryNode.Tag = eRootTypes.userdata; // Add fields within this category foreach (UserDataField field in category) { UltraTreeNode fieldNode = new UltraTreeNode(categoryNode.Key + @"|" + field.Name, field.Name); fieldNode.LeftImages.Add(IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Small)); fieldNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.Never; //fieldNode.Tag = eRootTypes.userdata; categoryNode.Nodes.Add(fieldNode); fieldNode.Tag = eRootTypes.userdata; } } } }
/// <summary> /// Called as we try an exit from this form - we need to ensure that the category name is unique /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bnOK_Click(object sender, EventArgs e) { // Update the asset type definition with any changes _category.Name = tbCategoryName.Text; _category.Icon = tbIconFile.Text; // Ensure that this Category does not duplicate an existing one UserDataCategoryList listCategories = new UserDataCategoryList(_category.Scope); listCategories.Populate(); UserDataCategory existingCategory = listCategories.FindCategory(_category.Name); if ((existingCategory != null) && (existingCategory.CategoryID != _category.CategoryID)) { MessageBox.Show("A User Defined Data Category with this name already exists, please enter a unique name for this category", "Category Exists"); DialogResult = DialogResult.None; return; } if (!_editing) { _category.TabOrder = new UserDataDefinitionsDAO().GetCountUserDataCategories(UserDataCategory.SCOPE.Asset); } // ...Update or add the category _category.Add(); }
/// <summary> /// Expansion of a field which is based on User Defined Data Fields /// </summary> /// <param name="field"></param> /// <param name="returnDictionary"></param> protected void ExpandUserDataChildren(string field) { // If we have not already done so create the cache for User Defined Data if (_cachedUserDataList == null) { _cachedUserDataList = new UserDataCategoryList(UserDataCategory.SCOPE.Asset); _cachedUserDataList.Populate(); } // The User data Field is formatted as User Data | Category | Field // Split the field into its parts again List <string> listParts = Utility.ListFromString(field, '|', true); // If we have 3 parts then this is easiest as this is an explic field which we just add it if (listParts.Count == 3) { this.Add(new AuditDataReportColumn(AuditDataReportColumn.eFieldType.userdata, field, GetLabelForField(field))); return; } // Ok we are either adding ALL User Data Field for ALL categories or all for a single category string requiredCategory = ""; if (listParts.Count == 2) { requiredCategory = listParts[1]; } // foreach (UserDataCategory category in _cachedUserDataList) { if ((requiredCategory == "" || requiredCategory == category.Name) && (category.Scope == UserDataCategory.SCOPE.Asset)) { foreach (UserDataField dataField in category) { bool alreadyExists = false; field = AWMiscStrings.UserDataNode + "|" + category.Name + "|" + dataField.Name; foreach (AuditDataReportColumn reportColumn in this) { if (reportColumn.FieldName == field) { alreadyExists = true; break; } } if (!alreadyExists) { this.Add(new AuditDataReportColumn(AuditDataReportColumn.eFieldType.userdata, field, GetLabelForField(field))); } } } } }
/// <summary> /// Called as we try to save the picklist - ensure that the name specified does not duplicate an /// existing item and if OK save back to the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bnOK_Click(object sender, EventArgs e) { // If the name is blank then it will be invalid if (this.tbPickListName.Text == "") { MessageBox.Show("Please specify a unique name for this picklist", "Enter Name", MessageBoxButtons.OK, MessageBoxIcon.Information); tbPickListName.Focus(); this.DialogResult = DialogResult.None; return; } // Does the specified value dupliacte an existing picklist? PickListList listPickLists = new PickListList(); listPickLists.Populate(); // foreach (PickList list in listPickLists) { if (list.Name == this.tbPickListName.Text) { // OK the names duplicate but is this in fact the same entry? if (list.PicklistID == _pickList.PicklistID) { continue; } // Nope the name duplicates an existing entry so we can't save it MessageBox.Show("The specified name matches that of an existing picklist, please specify a unique name for this picklist", "Invalid PickList Name"); tbPickListName.Focus(); this.DialogResult = DialogResult.None; return; } } // All OK - update the picklist here and in the database and also any related user-defined data fields UserDataCategoryList listCategories = new UserDataCategoryList(UserDataCategory.SCOPE.Any); listCategories.Populate(); foreach (UserDataCategory category in listCategories) { foreach (UserDataField field in category) { if ((field.Type == UserDataField.FieldType.Picklist) && (field.Value1 == _pickList.Name)) { field.Value1 = tbPickListName.Text; field.Update(); } } } _pickList.Name = tbPickListName.Text; _pickList.Update(); }
private void UpdateInteractiveUserDataCategories() { auditAgentScannerDefinition.InteractiveUserDataCategories.Clear(); AssetTypeList listAssetTypes = new AssetTypeList(); listAssetTypes.Populate(); AssetTypeList computersList = listAssetTypes.EnumerateChildren(listAssetTypes.FindByName("Computers").AssetTypeID); UserDataCategoryList listCategories = new UserDataCategoryList(UserDataCategory.SCOPE.Asset); listCategories.Populate(); // Sort the list to put the categories in Tab Order listCategories.Sort(); // Iterate through the categories foreach (UserDataCategory category in listCategories) { if ((category.AppliesToName != "Computers") && (category.AppliesToName != String.Empty)) { // No - OK is it a type of computer? bool exclude = true; foreach (AssetType assetType in computersList) { if (assetType.Name == category.AppliesToName) { exclude = false; break; } } // If excluded, skip this category if (exclude) { continue; } } UserDataCategories lUserDataCategory = new UserDataCategories(); lUserDataCategory.Name = category.Name; lUserDataCategory.UserFields = category; auditAgentScannerDefinition.InteractiveUserDataCategories.Add(lUserDataCategory); } }
/// <summary> /// Initialize the tab view display /// </summary> /// <param name="theAsset"></param> public void Display(Asset theAsset) { // Save the asset being displayed _displayedAsset = theAsset; // Clear the current list of groups assetListView.Groups.Clear(); assetListView.Items.Clear(); // Add the new group to the list view string groupName = "Audited Data for " + theAsset.Name; UltraListViewGroup group = assetListView.Groups.Add("auditeddata", groupName); // Set the group's properties group.Visible = true; group.Text = groupName; // Now add the items into the group which will act as the placeholders to allow the user // to drill down on the audited data UltraListViewItem item; try { item = assetListView.Items.Add(AWMiscStrings.SummaryNode, "Summary"); item.Group = group; item.Appearance.Image = Properties.Resources.computer96; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; if ((theAsset.LastAudit != DateTime.MinValue) && theAsset.Auditable) { // item = assetListView.Items.Add(AWMiscStrings.ApplicationsNode, "Applications"); item.Group = group; item.Appearance.Image = Properties.Resources.application_72; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // item = assetListView.Items.Add(AWMiscStrings.HardwareNode, "Hardware"); item.Group = group; item.Appearance.Image = Properties.Resources.hardware; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // item = assetListView.Items.Add(AWMiscStrings.InternetNode, "Internet"); item.Group = group; item.Appearance.Image = Properties.Resources.internet_explorer_32; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // item = assetListView.Items.Add(AWMiscStrings.FileSystem, "File System"); item.Group = group; item.Appearance.Image = Properties.Resources.filesystem_32; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // item = assetListView.Items.Add(AWMiscStrings.HistoryNode, "History"); item.Group = group; item.Appearance.Image = Properties.Resources.history; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // item = assetListView.Items.Add(AWMiscStrings.SystemNode, "System"); item.Group = group; item.Appearance.Image = Properties.Resources.system_72; item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; // Add on the User Defined Data Categories (if any) NetworkWorkItemController wiController = WorkItem.Controller as NetworkWorkItemController; UserDataCategoryList listCategories = new UserDataCategoryList(UserDataCategory.SCOPE.Asset); listCategories.Populate(); foreach (UserDataCategory category in listCategories) { // Is this category restricted to a specific asset category or type? if (wiController.CategoryAppliesTo(category, theAsset)) { item = assetListView.Items.Add(AWMiscStrings.UserDataNode + "|" + category.Name, category.Name); item.Group = group; item.Appearance.Image = IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Large); item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True; } } } } catch (Exception ex) { MessageBox.Show("Failed to add list view item, reason: " + ex.Message); } // Set the resize for the columns //this.assetListView.MainColumn.PerformAutoResize(ColumnAutoSizeMode.Header | ColumnAutoSizeMode.AllItems); }
/// <summary> /// Populate our cached lists /// </summary> public void ResetCache() { _cachedApplicationsList = null; _cachedUserDataList = null; _cacheOperatingSystemList = null; }
private void InitializeForm() { // Create the list of user data categories given the appropriate type from that supplied _listCategories = new UserDataCategoryList(_category.Scope); // Populate the 'Categories' combo with possible values _listCategories.Populate(); foreach (UserDataCategory availableCategory in _listCategories) { ValueListItem item = cbCategories.Items.Add(availableCategory, availableCategory.Name); if (availableCategory.CategoryID == _category.CategoryID) { cbCategories.SelectedItem = item; } } // Set the form title Text = (_field.FieldID == 0) ? "New User Data Field" : "User Data Field Properties"; Text += " [" + _category.ScopeAsString + "]"; // Populate the 'Type' combo with possible types Dictionary <UserDataField.FieldType, string> fieldTypes = _field.FieldTypes; foreach (KeyValuePair <UserDataField.FieldType, string> kvp in fieldTypes) { cbFieldType.Items.Add(kvp.Key, kvp.Value); } // Populate the Case Combo with possible input cases Dictionary <UserDataField.FieldCase, string> fieldCases = _field.FieldInputCases; foreach (KeyValuePair <UserDataField.FieldCase, string> kvp in fieldCases) { InputCase.Items.Add(kvp.Key, kvp.Value); } InputCase.SelectedIndex = 0; // Populate the Picklists combo with the names of any picklists that have been defined PickListList picklists = new PickListList(); picklists.Populate(); foreach (PickList picklist in picklists) { Picklist.Items.Add(picklist, picklist.Name); } if (Picklist.Items.Count != 0) { Picklist.SelectedIndex = 0; } // Set the initial data tbFieldName.Text = _field.Name; //TabOrder.Value = field.TabOrder; cbMandatory.Checked = _field.IsMandatory; cbInteractiveInclude.Checked = (_field.ParentScope == UserDataCategory.SCOPE.Asset); // Set the field type in the combo box int selectedIndex = cbFieldType.FindStringExact(fieldTypes[_field.Type]); cbFieldType.SelectedIndex = selectedIndex == -1 ? 0 : selectedIndex; // The remainder of the fields depend on the field type switch ((int)_field.Type) { // For text fields the input length is stored in 'Value1' and Input Case encoded into Value2 case (int)UserDataField.FieldType.Text: selectedIndex = InputCase.FindStringExact(_field.InputCase == "title" ? "TitleCase" : _field.InputCase); InputCase.SelectedIndex = (selectedIndex == -1) ? 0 : selectedIndex; break; // Numeric fields - Minimum is 'Value1' Maximum is 'Value2' case (int)UserDataField.FieldType.Number: break; // For a picklist, the name of the picklist (if any) is stored in 'Value1' case (int)UserDataField.FieldType.Picklist: selectedIndex = (Picklist.FindStringExact(_field.Picklist)); Picklist.SelectedIndex = (selectedIndex == -1) ? 0 : selectedIndex; break; // Environment Variable - the permitted length is stored as 'Value1' with the name of the variable // in question stored as 'Value2' case (int)UserDataField.FieldType.Environment: tbEnvironmentVariableName.Text = _field.EnvironmentVariable; break; // Registry Keys : The Key name is stored as value1 with the value name as Value2 case (int)UserDataField.FieldType.Registry: tbRegistryKey.Text = _field.RegistryKey; tbRegistryValue.Text = _field.RegistryValue; break; //// Boolean Fields - no additional fields required //case (int)UserDataField.FieldType.boolean: // break; // Date Fields - no additional fields required case (int)UserDataField.FieldType.Date: break; // Currency Fields - no additional fields required case (int)UserDataField.FieldType.Currency: break; default: MessageBox.Show("An invalid type has been identified in the User Data Field Definition"); break; } }