Exemple #1
0
        private void LoadForm()
        {
            tbParentLocation.Text   = _asset.Location;
            tbAssetName.Text        = _asset.Name;
            tbSerialNumber.Text     = _asset.SerialNumber;
            tbAssetTag.Text         = _asset.AssetTag;
            cbOverwriteData.Checked = _asset.OverwriteData;

            _assetTypes.Populate();

            // Recover the category of the current asset so that we can select it correctly in the combo
            AssetType assetType = _assetTypes.FindByName(_asset.TypeAsString);

            if (assetType == null)
            {
                assetType = _assetTypes[0];
            }

            AssetType assetCategory = _assetTypes.GetParent(assetType);

            // We now need to add the Asset Type categories to the combo box
            cbAssetCategories.BeginUpdate();

            cbAssetCategories.Items.Clear();

            AssetTypeList categories = _assetTypes.EnumerateCategories();

            foreach (AssetType category in categories)
            {
                cbAssetCategories.Items.Add(category);
            }

            int index = cbAssetCategories.Items.IndexOf(assetCategory);

            cbAssetCategories.SelectedIndex = (index != -1) ? index : 0;

            cbAssetCategories.EndUpdate();

            FillAssetTypes(assetCategory);
            FillStockStatuses(_asset.StockStatus);

            // ...and select the asset type for the asset
            index = cbAssetTypes.Items.IndexOf(assetType);
            cbAssetTypes.SelectedIndex = (index != -1) ? index : 0;

            FillAssetMakes(assetType.AssetTypeID);
            FillAssetModels(assetType.AssetTypeID);

            InitializeNotesTab();
            PopulateSuppliers();
            InitializeDocumentsTab();

            FillUserDefinedData();
            //Added by Sojan E John KTS Infotech
            ClearControlsSupportContract();
            FillControlsOnLoad();
            FillSupportContractComboBox();
            FillSuppliersComboBox();
            InitialiseSupportContractTab();
        }
        /// <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
            _assetType.Name = tbCategoryName.Text;
            _assetType.Icon = tbIconFile.Text;
            //
            AssetTypeList listAssetTypes = new AssetTypeList();

            listAssetTypes.Populate();

            // Does this name duplicate an existing item?
            AssetType existingAsset = listAssetTypes.FindByName(tbCategoryName.Text);

            if (existingAsset != null)
            {
                if (_assetType.AssetTypeID != existingAsset.AssetTypeID)
                {
                    MessageBox.Show("An Asset Category of this name has already been created, please enter a different name for this category");
                    tbCategoryName.Focus();
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }

            // OK the name is fine so either create a new category or update an existing one
            _assetType.Add();
        }
Exemple #3
0
        private void UpdateInteractiveComputers()
        {
            AssetTypeList listAssetTypes = new AssetTypeList();

            listAssetTypes.Populate();

            AssetType     assetType     = listAssetTypes.FindByName("Computers");
            AssetTypeList computersList = listAssetTypes.EnumerateChildren(assetType.AssetTypeID);

            auditScannerDefinition.InteractiveCategories = computersList.ToString();
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        public bool CategoryAppliesTo(UserDataCategory category, Asset asset)
        {
            // Is this category specific to an asset type?
            if (category.AppliesTo != 0)
            {
                // OK - does the category apply specifically to this asset type?
                if (category.AppliesTo != asset.AssetTypeID)
                {
                    // No - we need to get the parent category of this asset type and check that also then
                    AssetType parentType = _listAssetTypes.FindByName(asset.TypeAsString);
                    if ((parentType == null) || (category.AppliesTo != parentType.ParentID))
                    {
                        return(false);
                    }
                }
            }

            // User data category applies to this type of asset so return true
            return(true);
        }
Exemple #6
0
        public void InsertComputer(string assetName, string groupName, string ipAddress, string macAddress)
        {
            LocationsDAO lwDataAccess = new LocationsDAO();
            SettingsDAO  lSettingsDao = new SettingsDAO();

            // We need to get the root item as all of the domains need to be parented to this
            System.Data.DataTable table     = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain));
            AssetGroup            rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain);

            // Get the child domains - as domains are single level we do not need to recurse
            rootGroup.Populate(false, false, true);

            // We'll loop through the domains first and add then to the database recovering their ids so that
            // we only have to do this once.
            // Does this domain already exist?

            AssetGroup childGroup;

            lock (this)
            {
                childGroup = rootGroup.IsChildGroup(groupName);

                // No - add it as a new group both to the database and to the parent
                if (childGroup == null)
                {
                    childGroup          = new AssetGroup(AssetGroup.GROUPTYPE.domain);
                    childGroup.Name     = groupName;
                    childGroup.ParentID = rootGroup.GroupID;
                    childGroup.GroupID  = lwDataAccess.GroupAdd(childGroup);
                    rootGroup.Groups.Add(childGroup);
                }
            }
            string vendor = String.Empty;

            try
            {
                if (macAddress != String.Empty)
                {
//
// CMD IMPORTANT UNCOMMENT THESE LINES
//                    using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt")))
//                    {
//                        string line;
//                        while ((line = sr.ReadLine()) != null)
//                        {
//                            if (line.StartsWith(macAddress.Substring(0, 8)))
//                            {
//                                if (line.Substring(18).ToUpper().StartsWith("APPLE"))
//                                {
//                                   vendor = line.Substring(18);
//                                    break;
//                                }
//                           }
//                        }
//                    }
                }
            }
            catch (FormatException)
            {
            }

            // Now that we have the ID of the group (even if we just added the group) we can now
            // add the asset to the database also.
            Asset newAsset = new Asset();

            newAsset.Name       = assetName;
            newAsset.MACAddress = macAddress.Replace('-', ':');
            newAsset.Make       = vendor;

            if (vendor.ToUpper().StartsWith("APPLE"))
            {
                // add as an Apple Device
                assetTypes.Populate();
                AssetType parentAssetType = assetTypes.FindByName("Apple Devices");
                if (parentAssetType == null)
                {
                    // Now create a child of this asset type
                    parentAssetType           = new AssetType();
                    parentAssetType.Name      = "Apple Devices";
                    parentAssetType.Auditable = false;
                    parentAssetType.Icon      = "apple.png";
                    parentAssetType.ParentID  = 0;
                    parentAssetType.Add();

                    // Update the internal list
                    assetTypes.Add(parentAssetType);
                }

                assetTypes.Populate();
                parentAssetType = assetTypes.FindByName("Apple Devices");

                AssetType childAssetType = assetTypes.FindByName("Apple Device");
                if (childAssetType == null)
                {
                    // Now create a child of this asset type
                    childAssetType           = new AssetType();
                    childAssetType.Name      = "Apple Device";
                    childAssetType.Auditable = false;
                    childAssetType.Icon      = parentAssetType.Icon;
                    childAssetType.ParentID  = parentAssetType.AssetTypeID;
                    childAssetType.Add();

                    // Update the internal list
                    assetTypes.Add(childAssetType);
                }

                assetTypes.Populate();
                childAssetType       = assetTypes.FindByName("Apple Device");
                newAsset.AssetTypeID = childAssetType.AssetTypeID;
            }

            AssetList assetList             = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true);
            bool      bUpdateAsset          = true;
            bool      bSNMPAsset            = false;
            bool      bExistingAuditedAsset = false;

            foreach (Asset existingAsset in assetList)
            {
                if ((existingAsset.AgentVersion == "SNMP") && (existingAsset.IPAddress == ipAddress))
                {
                    bSNMPAsset = true;
                    break;
                }

                if ((assetName == existingAsset.Name) && (groupName == existingAsset.Domain))
                {
                    // this asset already exists - only need to check if domain or IP have changed
                    // if they have, send it away to be updated
                    if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID)
                    {
                        newAsset           = existingAsset;
                        newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress;
                        newAsset.DomainID  = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID;
                    }
                    else
                    {
                        // asset exists, nothing has changed so don't process
                        bUpdateAsset = false;
                    }
                    break;
                }
                if (!bSNMPAsset && existingAsset.IPAddress == ipAddress && existingAsset.Domain != newAsset.Domain)
                {
                    bExistingAuditedAsset = true;
                    //check for any asset name change if so update asset with audittrail entry
                    if (existingAsset.Name != assetName)
                    {
                        string strOldValue = existingAsset.Name;
                        newAsset      = existingAsset;
                        newAsset.Name = assetName;
                        newAsset.Update();
                        AuditTrailDAO objAuditTrailDAO = new AuditTrailDAO();
                        // Build a blank AuditTrailEntry
                        AuditTrailEntry ate = CreateAteForAssetNameChange(newAsset);
                        ate.Key      = ate.Key + "|" + "Computer Name";
                        ate.OldValue = strOldValue;
                        ate.NewValue = assetName;
                        objAuditTrailDAO.AuditTrailAdd(ate);
                    }
                }
            }

            if (bUpdateAsset && !bSNMPAsset && !bExistingAuditedAsset)
            {
                newAsset.Domain    = childGroup.Name;
                newAsset.DomainID  = childGroup.GroupID;
                newAsset.IPAddress = ipAddress;

                // Add the asset
                newAsset.Add();

                if (lSettingsDao.GetSettingAsBoolean("AutoScanNetwork", false) && lSettingsDao.GetSettingAsBoolean("AutoScanDeployAgent", false))
                {
                    string scannerPath = System.IO.Path.Combine(Application.StartupPath, "scanners") + "\\auditagent\\default.xml";
                    System.IO.File.Copy(scannerPath, "AuditAgent\\AuditAgent.xml", true);
                    Operation newOperation = new Operation(newAsset.AssetID, Operation.OPERATION.deployagent);
                    newOperation.Add();
                }
            }

            if (!bSNMPAsset)
            {
                Interlocked.Increment(ref _foundCounter);
                FireNetworkDiscoveryUpdate(new DiscoveryUpdateEventArgs(_foundCounter.ToString(), "Computer", _maximumCount, 0));
            }
        }