コード例 #1
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Add this group to the database (only applicable to user locations)
        /// </summary>
        /// <returns></returns>
        public int Add()
        {
            // If this Location already exists then call the update instead
            if (_groupID != 0)
            {
                return(Update(null));
            }

            // If we have not specified a parent but do have a full name then we have a problem in that we
            // do not necessarily have a parent location in the database and in any case we do not know the ID
            // of our parent so should look for it now...
            if ((ParentID == 0) && (_fullname.Contains(@"\")))
            {
                _groupID = ValidateParentPath(_fullname);
            }
            else
            {
                // Add the location to the database
                LocationsDAO lwDataAccess = new LocationsDAO();
                int          groupID      = lwDataAccess.GroupAdd(this);
                if (groupID != 0)
                {
                    AuditChanges(null);
                    _groupID = groupID;
                }
            }

            return(0);
        }
コード例 #2
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Populate this Asset Group with it's children (both child groups and assets)
        /// Note that this may recurse through its children populating them also
        /// Child assets may be excluded !!!
        /// </summary>
        /// <returns></returns>
        public int Populate(bool recurse, bool ignoreChildAssets, bool applyStates)
        {
            // First get child groups
            LocationsDAO lwDataAccess = new LocationsDAO();

            _groups = new AssetGroupList(lwDataAccess.GetGroups(this), _groupType);

            // ...then get child assets
            if (!ignoreChildAssets)
            {
                _assets = new AssetList(new AssetDAO().GetAssets(GroupID, GroupType, applyStates), ignoreChildAssets);
            }

            // If we have been requested to recurse then go through each group
            if (recurse)
            {
                foreach (AssetGroup childGroup in Groups)
                {
                    childGroup.Populate(recurse, ignoreChildAssets, applyStates);
                }
            }

            // Show that we have populated this group
            Populated = true;

            return(0);
        }
コード例 #3
0
        private void AddLocation(UltraListViewItem lvi)
        {
            LocationsDAO lwDataAccess = new LocationsDAO();

            // Create the AssetGroup for this location noting that we need to add the root item name to all
            // locations created as this will be missing from the import text
            string     oldLocation = lvi.Text;
            AssetGroup newGroup    = new AssetGroup();

            newGroup.GroupType = AssetGroup.GROUPTYPE.userlocation;
            if (oldLocation == "")
            {
                newGroup.FullName = _rootName;
            }
            else
            {
                newGroup.FullName = _rootName + AssetGroup.LOCATIONDELIMITER + lvi.Text;
            }
            newGroup.StartIP = lvi.SubItems[0].Text;
            newGroup.EndIP   = lvi.SubItems[1].Text;

            // Add this group and get its database index
            newGroup.Add();

            // Now we need to add the asset (if there is one defined)
            string assetName = lvi.SubItems[2].Text;

            if (assetName != "")
            {
                Asset newAsset = new Asset();
                newAsset.LocationID = newGroup.GroupID;
                newAsset.Name       = assetName;
                newAsset.Add();
            }
        }
コード例 #4
0
        /// <summary>
        /// This function is called to (re)initialize the network explorer view
        /// this is a tree control defined within NetworkExplorerView
        /// </summary>
        private void InitializeNetworkView()
        {
            // clear the existing view
            explorerView.Clear();

            // Are we displaying the computers grouped into domains or user locations - this is held as a flag
            // in the work item controller
            NetworkWorkItemController wiController = explorerView.WorkItem.Controller as NetworkWorkItemController;
            bool showByDomain = wiController.DomainViewStyle;

            // First of all we need to create the root group (domain or location)
            LocationsDAO lwDataAccess = new LocationsDAO();

            AssetGroup.GROUPTYPE displayType = (showByDomain) ? AssetGroup.GROUPTYPE.domain : AssetGroup.GROUPTYPE.userlocation;
            DataTable            table       = lwDataAccess.GetGroups(new AssetGroup(displayType));

            _rootAssetGroup = new AssetGroup(table.Rows[0], displayType);

            // Add the root node to the tree first
            UltraTreeNode rootNode  = new UltraTreeNode("root|" + _rootAssetGroup.FullName, _rootAssetGroup.Name);
            Bitmap        rootImage = (showByDomain) ? Properties.Resources.domain16 : Properties.Resources.location_16;

            rootNode.Override.NodeAppearance.Image         = rootImage;
            rootNode.Override.ExpandedNodeAppearance.Image = rootImage;
            rootNode.Tag = _rootAssetGroup;

            // Set the root node in the Explorer view - note that this will automatically expand the node which will
            // cause it to be populated
            explorerView.RootNode = rootNode;
        }
コード例 #5
0
    private void Search()
    {
        try
        {
            Location loc = new Location();
            loc.BranchCode = "";
            loc.BranchName = "";
            loc.IsActive   = true;
            DataSet dsBranch = new LocationsDAO().SearchLocation(loc);

            //DataSet dsBranch = new LocationsDAO().GetAllBranches();

            if (dsBranch != null && dsBranch.Tables.Count > 0)
            {
                gvBranches.DataSource = dsBranch;
                gvBranches.DataBind();
                trGrid.Visible      = true;
                trNoRecords.Visible = false;
            }
            else
            {
                trNoRecords.Visible = true;
                trGrid.Visible      = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
コード例 #6
0
        /// <summary>
        /// This function is responsible for the actual generation of the Applications Report
        /// It overrides the abstract definition in the base class and stores it's data in the DataSet
        /// </summary>
        public override void GenerateReport(UltraGrid grid)
        {
            // Delete any cached data as we are re-running the report
            _cachedAssetGroups = null;

            // Begin initialization of the Grid
            grid.BeginUpdate();

            // Save the grid layout to a temporary file
            if (grid.Rows.Count != 0)
            {
                SaveTemporaryLayout(grid);
            }

            // Create a new dataSource
            _reportDataSet  = new DataSet("auditdataDataSet");
            grid.DataSource = _reportDataSet;

            // We will always need the list of assets so we may as well get it now
            LocationsDAO lwDataAccess = new LocationsDAO();

            AssetGroup.GROUPTYPE displayType = AssetGroup.GROUPTYPE.userlocation;
            DataTable            table       = lwDataAccess.GetGroups(new AssetGroup(displayType));

            _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType);
            _cachedAssetGroups.Populate(true, _ignoreChildAssets, true);

            // Now apply the filter to these groups
            _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets);

            // Now that we have a definitive list of the assets (as objects) which we want to include in the
            // report we could really do with expanding this list so that ALL of the assets are in a single list
            // and not distributed among the publishers
            _cachedAssetList = _cachedAssetGroups.GetAllAssets();

            // Create the list of report columns which will maintain the data for this report
            _auditDataReportColumns.Populate(_listSelectedFields
                                             , _dictionaryLabels
                                             , _publisherFilter
                                             , _showIncluded
                                             , _showIgnored);

            // Create the tables, columns and relationships as these may have changed since we loaded the report
            CreateTables();

            // Clear any existing data out of the dataset
            _reportDataSet.Tables["AuditData"].Rows.Clear();

            // Generate the data for the report
            GenerateReportData();

            // reload the temprary layout saved around the report generation
            //LoadTemporaryLayout(grid);

            // ...and perform any required initialization of the grid
            InitializeGrid(grid);

            grid.EndUpdate();
        }
コード例 #7
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// return whether or not the specified named group is already a child of this group
        /// </summary>
        /// <param name="childname"></param>
        /// <returns></returns>
        public AssetGroup IsChildGroup(string childname)
        {
            // First get a list of our current children
            LocationsDAO   lwDataAccess = new LocationsDAO();
            AssetGroupList listChildren = new AssetGroupList(lwDataAccess.GetGroups(this), _groupType);

            return(listChildren.FindGroup(childname));
        }
コード例 #8
0
        public void Populate(bool showByDomain, bool ignoreTopAssets, bool ignoreChildAssets)                                                   // CMD 8.4.2 Include additional parameter
        {
            LocationsDAO lwDataAccess = new LocationsDAO();

            AssetGroup.GROUPTYPE displayType = (_showByDomain) ? AssetGroup.GROUPTYPE.domain : AssetGroup.GROUPTYPE.userlocation;
            DataTable            table       = lwDataAccess.GetGroups(new AssetGroup(displayType));

            _rootAssetGroup = new AssetGroup(table.Rows[0], displayType);

            // +CMD 8.4.1 - Changes required to prevent performance issues with large databases.  We can now elect to not display assets and also
            // the tree is load on demand if we do require assets so that we only load them if required.
            //
            // If we need to show assets at the root then populate this now
            if (!ignoreTopAssets)
            {
                _rootAssetGroup.Populate(false, false, true);
            }

            // Populate all levels for this group beneath this group again optionally including assets
            _rootAssetGroup.Populate(true, true, true);

            // Load on demand is active if we are displaying child assets
            locationsTree.Override.ShowExpansionIndicator = (ignoreChildAssets) ? ShowExpansionIndicator.CheckOnDisplay : ShowExpansionIndicator.CheckOnExpand;

            // -CMD 8.4.1
            // begin updating the tree
            locationsTree.BeginUpdate();

            // Add the root node to the tree first
            try
            {
                UltraTreeNode rootNode  = new UltraTreeNode(null, _rootAssetGroup.Name);
                Bitmap        rootImage = (_showByDomain) ? Properties.Resources.domain16 : Properties.Resources.location_16;
                rootNode.Override.NodeAppearance.Image         = rootImage;
                rootNode.Override.ExpandedNodeAppearance.Image = rootImage;
                rootNode.Tag          = _rootAssetGroup;
                rootNode.CheckedState = CheckState.Unchecked;

                // ...add the children to the tree beneath it now
                AddChildNodes(rootNode, _rootAssetGroup);

                // Set the root node in the Explore view
                locationsTree.Nodes.Add(rootNode);

                // Expand the root node
                rootNode.Expanded = true;
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Exception adding tree nodes in [SelectLocationsControl::AddApplicationNode], the exception text was " + ex.Message);
                logger.Error(ex.Message);
            }

            // Finished updating the tree
            locationsTree.EndUpdate();
        }
コード例 #9
0
        /// <summary>
        /// This function is responsible for generating the actual data which will be displayed by the report
        /// </summary>
        protected void GenerateReportData()
        {
            // Create a string representation of the publisher filter list passed to us
            // We need to get the entire licensing information at this point
            AssetGroup.GROUPTYPE displayType        = AssetGroup.GROUPTYPE.userlocation;
            DataTable            table              = new LocationsDAO().GetGroups(new AssetGroup(displayType));
            AssetGroup           _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType);

            _cachedAssetGroups.Populate(true, _ignoreChildAssets, true);

            // Now apply the filter to these groups
            _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets);

            // Now that we have a definitive list of the assets (as objects) which we want to include in the
            // report we could really do with expanding this list so that ALL of the assets are in a single list
            // and not distributed among the publishers
            AssetList _cachedAssetList = _cachedAssetGroups.GetAllAssets();

            _selectedAssets = String.Empty;

            foreach (Asset asset in _cachedAssetList)
            {
                _selectedAssets += asset.Name + ";";
            }

            char[] charsToTrim = { ';' };
            _selectedAssets.TrimEnd(charsToTrim);

            ResetSelectedAssets();

            // OK different reports require different processing so branch here
            switch (_subtype)
            {
            case eHistoryType.changesbetween:
                GenerateChangesBetweenReportData();
                break;

            case eHistoryType.hasbeenaudited:
                GenerateLastAuditDateReportData(true);
                break;

            case eHistoryType.hasnotbeenaudited:
                GenerateLastAuditDateReportData(false);
                break;

            case eHistoryType.lastaudit:
                GenerateLastAuditDateReportData(true);
                break;

            case eHistoryType.mostrecentchanges:
                GenerateMostRecentReportData();
                break;
            }
        }
コード例 #10
0
        /// <summary>
        /// This function is responsible for generating the actual data which will be displayed by the report
        /// </summary>
        protected void GenerateReportData()
        {
            // Create a string representation of the publisher filter list passed to us
            // We need to get the entire licensing information at this point
            FileSystemDAO lwDataAccess = new FileSystemDAO();
            DataTable     dataTable    = lwDataAccess.EnumerateFileSystemFiles(_filterFile);

            // Create a string representation of the publisher filter list passed to us
            // We need to get the entire licensing information at this point
            AssetGroup.GROUPTYPE displayType        = AssetGroup.GROUPTYPE.userlocation;
            DataTable            table              = new LocationsDAO().GetGroups(new AssetGroup(displayType));
            AssetGroup           _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType);

            _cachedAssetGroups.Populate(true, _ignoreChildAssets, true);

            // Now apply the filter to these groups
            _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets);

            // Now that we have a definitive list of the assets (as objects) which we want to include in the
            // report we could really do with expanding this list so that ALL of the assets are in a single list
            // and not distributed among the publishers
            //AssetList _cachedAssetList = _cachedAssetGroups.GetAllAssets();
            //_selectedAssets = String.Empty;

            //foreach (Asset asset in _cachedAssetList)
            //{
            //    _selectedAssets += asset.Name + ";";
            //}

            //char[] charsToTrim = { ';' };
            //_selectedAssets.TrimEnd(charsToTrim);

            _selectedAssets = new AssetDAO().ConvertIdListToNames(new AssetDAO().GetSelectedAssets(), ',');

            ResetSelectedAssets();

            // ...then create InternetReportEntry objects for each returned and add to the view
            foreach (DataRow row in dataTable.Rows)
            {
                FileSystemFile file = new FileSystemFile(row);

                // Check for this being filtered by location/asset
                if (FilterRecord(file))
                {
                    AddRecord(file);
                }
            }
        }
コード例 #11
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Update this Group defininition in the database
        /// </summary>
        /// <returns></returns>
        public int Update(AssetGroup oldgroup)
        {
            LocationsDAO lwDataAccess = new LocationsDAO();

            if (this._groupID == 0)
            {
                Add();
            }
            else
            {
                lwDataAccess.GroupAdd(this);
                AuditChanges(oldgroup);
            }

            return(0);
        }
コード例 #12
0
        /// <summary>
        /// Load the records from the input file into the list view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormImportLocations_Load(object sender, EventArgs e)
        {
            // recover the root group as we need its name to prefix to all created location names
            LocationsDAO lwDataAccess   = new LocationsDAO();
            DataTable    table          = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.userlocation));
            AssetGroup   rootAssetGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.userlocation);

            _rootName = rootAssetGroup.Name;

            // try and read the CSV file into the list view
            try
            {
                using (CSVReader csv = new CSVReader(_fromFile))
                {
                    // Read each line from the file noting that we MUST have 4 columns and 4 only
                    string[] fields;
                    while ((fields = csv.GetCSVLine()) != null)
                    {
                        if (fields.Length != 4)
                        {
                            continue;
                        }

                        // Add the 4 fields to the ListView
                        UltraListViewSubItem[] subItemArray = new UltraListViewSubItem[3];
                        subItemArray[0]       = new UltraListViewSubItem();
                        subItemArray[0].Value = fields[1];
                        subItemArray[1]       = new UltraListViewSubItem();
                        subItemArray[1].Value = fields[2];
                        subItemArray[2]       = new UltraListViewSubItem();
                        subItemArray[2].Value = fields[3];
                        //
                        UltraListViewItem item = new UltraListViewItem(fields[0], subItemArray);
                        item.CheckState = (lvRecords.Items.Count == 0) ? CheckState.Unchecked : CheckState.Checked;
                        lvRecords.Items.Add(item);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Failed to import the file " + _fromFile + ".  Reason: " + ex.Message, "Import Failed");
            }
        }
コード例 #13
0
        private void UpdateInteractiveLocations()
        {
            auditScannerDefinition.InteractiveLocations.Clear();

            DataTable  table        = new LocationsDAO().GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.userlocation));
            AssetGroup rootLocation = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.userlocation);

            // Populate all levels for this user location
            rootLocation.Populate(true, false, true);

            auditScannerDefinition.RootLocation = rootLocation.Name;

            foreach (AssetGroup childLocation in rootLocation.Groups)
            {
                childLocation.Assets.Clear();
                auditScannerDefinition.InteractiveLocations.Add(childLocation);
                SaveInteractiveLocation(childLocation);
            }
        }
コード例 #14
0
        /// <summary>
        /// generate the most recent history records for each asset
        /// </summary>
        protected void GenerateMostRecentReportData()
        {
            // Get a complete list of groups and assets and then apply our filters to this list
            LocationsDAO lwDataAccess = new LocationsDAO();

            AssetGroup.GROUPTYPE displayType = AssetGroup.GROUPTYPE.userlocation;
            DataTable            table       = lwDataAccess.GetGroups(new AssetGroup(displayType));
            AssetGroup           assetGroups = new AssetGroup(table.Rows[0], displayType);

            assetGroups.Populate(true, false, true);

            // Now apply the filter to these groups
            assetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets);

            // Now that we have a definitive list of the assets (as objects) which we want to include in the
            // report we could really do with expanding this list so that ALL of the assets are in a single list
            // and not distributed among the publishers
            AssetList listAssets = assetGroups.GetAllAssets();

            // OK - get the last audit trail records for these assets - the last audit date is stored in the
            // Asset object so we don't need to get that again
            foreach (Asset asset in listAssets)
            {
                // Skip any assets not audited yet
                if (asset.LastAudit.Ticks == 0)
                {
                    continue;
                }

                // Get the audit trail records for this asset
                DataTable historyTable = new AuditTrailDAO().GetAssetAuditHistory(asset, asset.LastAudit, DateTime.Now);

                // Add the entries in the data table as ATE records to our DataSet
                foreach (DataRow row in historyTable.Rows)
                {
                    AuditTrailEntry ate = new AuditTrailEntry(row);
                    AddChangesRecord(ate);
                }
            }
        }
コード例 #15
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Delete the current location from the database
        /// </summary>
        public bool Delete()
        {
            LocationsDAO lwDataAccess = new LocationsDAO();

            // As locations are hierarchical we cannot just delete a location without first deleting ALL
            // children and we cannot do that if any of our descendants are still being referenced
            // Get a list of all of our children
            AssetGroupList children = new AssetGroupList(lwDataAccess.GetGroups(this), GroupType);

            // Loop through each child and try and delete them first before we delete ourselves - this actually
            // causes recursion through this deletion function as children may have children and so on...
            foreach (AssetGroup childGroup in children)
            {
                if (!childGroup.Delete())
                {
                    return(false);
                }
            }

            // Only now can we delete ourselves as all of our children have been handled.
            if (lwDataAccess.GroupDelete(this) != 0)
            {
                return(false);
            }

            // ...and audit the deletion
            AuditTrailEntry ate = new AuditTrailEntry();

            ate.Date      = DateTime.Now;
            ate.Class     = AuditTrailEntry.CLASS.location;
            ate.Type      = AuditTrailEntry.TYPE.deleted;
            ate.Key       = _name;
            ate.AssetID   = 0;
            ate.AssetName = "";
            ate.Username  = System.Environment.UserName;
            new AuditTrailDAO().AuditTrailAdd(ate);
            return(true);
        }
コード例 #16
0
ファイル: AssetGroup.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// This function is typically called prior to adding a new location where we have not set the
        /// parentID as we do not know it yet - in this case we need to ensure that the path to the new location
        /// has been created as we cannot create an isolated child
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        protected int ValidateParentPath(string path)
        {
            LocationsDAO lwDataAccess = new LocationsDAO();

            // We are passed the path of the item in question for whom we are checking for the existance of their
            // parent.  To do this we must build the name of that parent
            int index = path.LastIndexOf(LOCATIONDELIMITER);

            if (index == 0)
            {
                return(0);
            }

            // ...and make the name of our parent
            string ourParentPath = path.Substring(0, index);

            // Check the database for this location
            int parentID = lwDataAccess.LocationFind(ourParentPath);

            // Does our parent exist?  If so then we can create ourselves and pass this back
            if (parentID != 0)
            {
                AssetGroup ourGroup = new AssetGroup();
                ourGroup.FullName  = path;
                ourGroup.GroupType = GROUPTYPE.userlocation;
                ourGroup.ParentID  = parentID;
                ourGroup.Add();

                // ... and return the ID of the newly added group as the parent
                return(ourGroup.GroupID);
            }

            else
            {
                // Our parent did not exist - iterate back up the tree
                return(ValidateParentPath(ourParentPath));
            }
        }
コード例 #17
0
ファイル: LocationsTabView.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Populates the child folder of a tree node
        /// </summary>
        private void PopulateChildLocations(UltraTreeNode node)
        {
            //	If we have already populated this node's Nodes collection, return
            if (node.HasNodes == true)
            {
                return;
            }

            // Get the locations beneath that specified
            AssetGroup parentGroup = node.Tag as AssetGroup;

            // So request the database for a list of locations beneath that specified
            LocationsDAO lwDataAccess = new LocationsDAO();
            DataTable    table        = lwDataAccess.GetGroups(parentGroup);

            // ...and add these locations to the tree as children of the selected node
            foreach (DataRow row in table.Rows)
            {
                AssetGroup    newLocation = new AssetGroup(row, AssetGroup.GROUPTYPE.userlocation);
                UltraTreeNode childNode   = node.Nodes.Add(newLocation.FullName, newLocation.Name);
                childNode.Tag = newLocation;
            }
        }
コード例 #18
0
ファイル: LocationsTabView.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Add the root item(s) to the locations tree
        /// </summary>
        private void PopulateRoot()
        {
            // Get the root node (they should only be one and one only)
            LocationsDAO lwDataAccess = new LocationsDAO();
            DataTable    table        = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.userlocation));

            if (table.Rows.Count == 0)
            {
                return;
            }
            AssetGroup    rootLocation = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.userlocation);
            UltraTreeNode rootNode     = this.locationsTree.Nodes.Add("home", rootLocation.Name);

            rootNode.Override.NodeAppearance.Image         = Properties.Resources.location_16;
            rootNode.Override.ExpandedNodeAppearance.Image = Properties.Resources.location_16;
            rootNode.Tag = rootLocation;

            // ...and force an automatic expansion of the root node as we want to display the top level nodes
            // on entry to this pane
            rootNode.Expanded = true;

            // Ensure that the root node is selected
            rootNode.Selected = true;
        }
コード例 #19
0
ファイル: ComplianceReport.cs プロジェクト: windygu/AW-master
        private string HandleAssetDetailsData(string assetFilter)
        {
            string        assetValue;
            string        assetCriteria;
            DataTable     resultsDataTable   = new DataTable();
            AssetDAO      lAssetDAO          = new AssetDAO();
            AssetTypesDAO lAssetTypesDAO     = new AssetTypesDAO();
            LocationsDAO  lLocationsDAO      = new LocationsDAO();
            string        newIds             = String.Empty;
            string        complianceCriteria = String.Empty;

            //foreach (string assetFilter in applicationFilters)
            //{
            assetCriteria = assetFilter.Substring(41, assetFilter.IndexOf("and _value") - 43);

            switch (assetCriteria)
            {
            case "Asset Name":
                complianceCriteria = "_name";
                break;

            case "Location":
                complianceCriteria = "_locationid";
                break;

            case "Date of last Audit":
                complianceCriteria = "_lastaudit";
                break;

            case "IP Address":
                complianceCriteria = "_ipaddress";
                break;

            case "MAC Address":
                complianceCriteria = "_macaddress";
                break;

            case "Make":
                complianceCriteria = "_make";
                break;

            case "Model":
                complianceCriteria = "_model";
                break;

            case "Serial Number":
                complianceCriteria = "_serial_number";
                break;

            case "Category":
                complianceCriteria = "_category";
                break;

            case "Type":
                complianceCriteria = "_type";
                break;

            case "Asset Tag":
                complianceCriteria = "_assettag";
                break;
            }

            if (complianceCriteria == "_category")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lAssetTypesDAO.GetCompliantAssetCategoriesValue(assetValue);
            }
            else if (complianceCriteria == "_type")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lAssetTypesDAO.GetCompliantAssetTypesValue(assetValue);
            }
            else if (complianceCriteria == "_locationid")
            {
                assetValue       = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                resultsDataTable = lLocationsDAO.GetCompliantLocationValues(assetValue);
            }
            else if (complianceCriteria == "_lastaudit")
            {
                if (assetFilter.IndexOf("and _value") != -1)
                {
                    resultsDataTable =
                        lAssetDAO.GetCompliantAssetValueForLastAudit(assetFilter.Substring(assetFilter.IndexOf("and _value") + 11));
                }
            }
            else
            {
                assetValue = assetFilter.Substring(assetFilter.LastIndexOf("=") + 2);
                //resultsDataTable = lAssetDAO.GetCompliantAssetValue(complianceCriteria, assetValue, compliantIds);
                resultsDataTable = lAssetDAO.GetCompliantAssetValue(complianceCriteria, assetValue);
            }

            foreach (DataRow compliantRow in resultsDataTable.Rows)
            {
                if (!newIds.Contains(compliantRow.ItemArray[0].ToString()))
                {
                    newIds += compliantRow.ItemArray[0].ToString() + ",";
                }
            }

            newIds = newIds.TrimEnd(',');
            return(newIds);
        }
コード例 #20
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));
            }
        }
コード例 #21
0
        private void PopulatePickerList(List <string> itemParts)
        {
            string category;
            string name;
            string value;

            if (itemParts.Count == 3)
            {
                category = itemParts[0] + "|" + itemParts[1];
                name     = itemParts[2];
            }
            else if (itemParts.Count == 4)
            {
                category = itemParts[0] + "|" + itemParts[1] + "|" + itemParts[2];
                name     = itemParts[3];
            }
            else if (itemParts.Count == 5)
            {
                category = itemParts[0] + "|" + itemParts[1] + "|" + itemParts[2] + "|" + itemParts[3];
                name     = itemParts[4];
            }
            else
            {
                category = itemParts[0];
                name     = itemParts[1];
            }

            cbValuePicker.Items.Clear();
            cbValuePicker.Text = String.Empty;
            cbValuePicker.Refresh();

            DataTable pickerValuesDataTable = new DataTable();

            if (category.StartsWith("UserData|"))
            {
                pickerValuesDataTable = new UserDataDefinitionsDAO().GetUserDataPickerValues(name, category.Split('|')[1]);
            }
            else if (category.StartsWith("Asset Details"))
            {
                string columnName = String.Empty;

                switch (name)
                {
                case "Asset Name":
                    columnName = "_name";
                    break;

                case "Location":
                    columnName = "_locationid";
                    break;

                case "Date of last Audit":
                    columnName = "_lastaudit";
                    break;

                case "IP Address":
                    columnName = "_ipaddress";
                    break;

                case "MAC Address":
                    columnName = "_macaddress";
                    break;

                case "Make":
                    columnName = "_make";
                    break;

                case "Model":
                    columnName = "_model";
                    break;

                case "Serial Number":
                    columnName = "_serial_number";
                    break;

                case "Category":
                    columnName = "_category";
                    break;

                case "Type":
                    columnName = "_type";
                    break;

                case "Asset Tag":
                    columnName = "_assettag";
                    break;
                }

                if (columnName == "_category")
                {
                    pickerValuesDataTable = new AssetTypesDAO().GetAssetCategoriesPickerValues();
                }
                else if (columnName == "_lastaudit")
                {
                    pickerValuesDataTable = new AssetDAO().GetAssetPickerValuesForLastAudit();
                }
                else if (columnName == "_locationid")
                {
                    pickerValuesDataTable = new LocationsDAO().GetLocationPickerValues();
                }
                else if (columnName == "_type")
                {
                    pickerValuesDataTable = new AssetTypesDAO().GetAssetTypesPickerValues();
                }
                else
                {
                    pickerValuesDataTable = new AssetDAO().GetAssetPickerValues(columnName);
                }
            }
            else if (category.StartsWith("Operating Systems"))
            {
                switch (name)
                {
                case "Family":
                    pickerValuesDataTable = new ApplicationsDAO().GetOSPickerValues("_name");
                    break;

                case "Version":
                    pickerValuesDataTable = new ApplicationsDAO().GetOSPickerValues("_version");
                    break;

                case "CD Key":
                    pickerValuesDataTable = new ApplicationInstanceDAO().GetOSPickerValues("_cdkey");
                    break;

                case "Serial Number":
                    pickerValuesDataTable = new ApplicationInstanceDAO().GetOSPickerValues("_productid");
                    break;
                }
            }
            else
            {
                pickerValuesDataTable = lAuditedItemsDAO.GetPickerValue(category, name);
                lblUnits.Text         = lAuditedItemsDAO.GetDisplayUnitValue(category, name);
            }

            foreach (DataRow pickerValueRow in pickerValuesDataTable.Rows)
            {
                value = pickerValueRow.ItemArray[0].ToString();

                if (value != String.Empty)
                {
                    cbValuePicker.Items.Add(value);
                }
            }

            if (cbValuePicker.Items.Count > 0)
            {
                cbValuePicker.SelectedIndex = 0;
            }
        }
コード例 #22
0
        public void NetworkDiscoveryCompleteHandler(object sender, DataEventArgs <List <string[]> > e)
        {
            try
            {
                LocationsDAO lwDataAccess = new LocationsDAO();
                string       macAddress   = String.Empty;
                string       vendor       = String.Empty;
                string       ipAddress    = String.Empty;

                // We need to get the root item as all of the domains need to be parented to this
                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.
                for (int i = 0; i < e.Data.Count; i++)
                {
                    string assetName = e.Data[i][0];
                    string groupName = e.Data[i][1];

                    // Does this domain already exist?
                    AssetGroup 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);
                    }

                    try
                    {
                        // Recover the IP address for the asset
                        ipAddress = Utility.GetIpAddress(assetName);

                        // try to get the MAC address and vendor from IP
                        IPAddress hostIPAddress = IPAddress.Parse(ipAddress);
                        byte[]    ab            = new byte[6];
                        int       len           = ab.Length;

                        int r = SendARP((int)hostIPAddress.Address, 0, ab, ref len);

                        macAddress = BitConverter.ToString(ab, 0, 6);
                    }
                    catch (Exception ex)
                    {
                        // if we hit an invalid IP error here we can just log and carry on
                        log.Error(String.Format("Error {0} with IP address [{1}]", ex.Message, ipAddress));
                    }

                    if (macAddress != String.Empty)
                    {
                        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;
                                }
                            }
                        }
                    }

                    // 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;

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

                    foreach (Asset existingAsset in assetList)
                    {
                        if (assetName == existingAsset.Name)
                        {
                            // 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 (bUpdateAsset)
                    {
                        newAsset.DomainID  = childGroup.GroupID;
                        newAsset.IPAddress = ipAddress;

                        // Add the asset
                        newAsset.Add();
                    }

                    // Does this asset already exist?
                    //if (rootGroup.FindAsset(assetName) == null)
                    //{
                    //    newAsset.DomainID = childGroup.GroupID;
                    //    newAsset.IPAddress = ipAddress;

                    //    // Add the asset
                    //    newAsset.Add();
                    //}
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            //WorkItem.ExplorerView.RefreshView();
            //WorkItem.TabView.RefreshView();
        }
コード例 #23
0
        /// <summary>
        /// Called as want to exit from this form potentially saving the definition or updating
        /// an existing entry
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnOK_Click(object sender, EventArgs e)
        {
            if (tbChild.Text == "")
            {
                MessageBox.Show("You must enter a name for this new Location");
                DialogResult = DialogResult.None;
                return;
            }

            // If we are creating a new Location then we must ensure that we have specified a
            // name which does not already exist for the parent
            if (_parentLocation != null)
            {
                AssetGroup existingLocation = _parentLocation.IsChildGroup(tbChild.Text);
                if (existingLocation != null)
                {
                    // OK this named location exists - is it the same location though
                    if (existingLocation.GroupID != _location.GroupID)
                    {
                        MessageBox.Show("The Location " + tbChild.Text + " already exists at this level.  Please enter a different name for this new Location", "Duplicate Name");
                        DialogResult = DialogResult.None;
                        return;
                    }
                }
            }

            // OK all valid so add this new entry (or update it if already exists)
            LocationsDAO lwDataAccess = new LocationsDAO();

            _location.Name = tbChild.Text;

            // Set the parent name noting that this is the same as our name if we are at the top of the
            // tree and have no parent
            if (_parentLocation == null)
            {
                _location.FullName = _location.Name;
            }
            else
            {
                _location.FullName = _parentLocation.FullName + @"\" + _location.Name;
            }

            // Create '|' delimited strings for the starting and ending IP addresses
            string startIP = "";
            string endIP   = "";

            foreach (UltraListViewItem item in ulvTcpRanges.Items)
            {
                if (startIP != "")
                {
                    startIP += "|";
                }
                if (endIP != "")
                {
                    endIP += "|";
                }
                startIP += item.Text;
                endIP   += item.SubItems[0].Text;
            }
            _location.StartIP = startIP;
            _location.EndIP   = endIP;


            // Add or replace the location
            _location.GroupID = lwDataAccess.GroupAdd(_location);
        }
コード例 #24
0
 public LocationService()
 {
     lObjLocationsDAO = new LocationsDAO();
 }
コード例 #25
0
ファイル: LocationsTabView.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Populates the UltraListView control with the child locations of the Location
        /// represented by the specified UltraTreeNode.
        /// </summary>
        private void PopulateListView(UltraTreeNode node)
        {
            AssetGroup parentGroup;

            if (node != null && node.Tag != null)
            {
                parentGroup = node.Tag as AssetGroup;
            }
            else
            {
                parentGroup = new AssetGroup(AssetGroup.GROUPTYPE.userlocation);
            }

            //	Call BeginUpdate to prevent drawing while we are populating the control
            this.locationsList.BeginUpdate();

            //	Show a wait cursor since this could take a while
            this.Cursor = Cursors.WaitCursor;

            //	Clear the Items collection to removes the directories and files
            //	of the last folder we displayed
            this.locationsList.Items.Clear();

            // So request the database for a list of locations beneath that specified
            LocationsDAO lwDataAccess = new LocationsDAO();
            DataTable    table        = lwDataAccess.GetGroups(parentGroup);

            //	Create an array of UltraListViewItems, with a size equal to the number of directories
            UltraListViewItem[] itemArrayLocations = new UltraListViewItem[table.Rows.Count];

            // ...and add these locations to the tree as children of the selected node
            int index = 0;

            foreach (DataRow row in table.Rows)
            {
                AssetGroup newLocation = new AssetGroup(row, AssetGroup.GROUPTYPE.userlocation);

                //	Create an array of UltraListViewSubItems
                UltraListViewSubItem[] subItemArray = new UltraListViewSubItem[2];

                //	Create new UltraListViewSubItem instances for this item
                subItemArray[0] = new UltraListViewSubItem();
                subItemArray[1] = new UltraListViewSubItem();

                //	Assign the values to the UltraListViewSubItem instances
                subItemArray[0].Value = newLocation.StartIP;
                subItemArray[1].Value = newLocation.EndIP;

                //	Create an UltraListViewItem instance
                UltraListViewItem item = new UltraListViewItem(newLocation.Name, subItemArray);

                //	Store a reference to the associated Location in the item's Tag property
                item.Tag = newLocation;

                //	Add the UltraListViewItem to the array
                itemArrayLocations[index++] = item;
            }

            // Add the items to the Items collection using the AddRange method, so that we only trigger two property
            // change notifications, as opposed to one for each item added to the collection.
            this.locationsList.Items.AddRange(itemArrayLocations);

            //	Assign the items to their respective groups
            //this.AssignItemsToGroups();

            // Auto-size the width of the 'Name' column; if the size of the Items collection is not too large,
            // size all items, but to avoid impacting performance, only size the ones that are currently on-screen
            // if there are a relatively large number of items.
            Infragistics.Win.UltraWinListView.ColumnAutoSizeMode autoSizeMode = Infragistics.Win.UltraWinListView.ColumnAutoSizeMode.Header;

            if (this.locationsList.Items.Count <= 100)
            {
                autoSizeMode |= Infragistics.Win.UltraWinListView.ColumnAutoSizeMode.AllItems;
            }
            else
            {
                autoSizeMode |= Infragistics.Win.UltraWinListView.ColumnAutoSizeMode.VisibleItems;
            }

            this.locationsList.MainColumn.PerformAutoResize(autoSizeMode);

            //	Activate the first item
            if (this.locationsList.ActiveItem == null && this.locationsList.Items.Count > 0)
            {
                this.locationsList.ActiveItem = this.locationsList.Items[0];
            }

            //	Restore the cursor
            this.Cursor = Cursors.Default;

            //	Call EndUpdate to resume drawing operations
            this.locationsList.EndUpdate(true);
        }