/// <summary>
        /// Called to show the list of applications for a specific publisher
        /// </summary>
        /// <param name="forPublisher"></param>
        public void ShowPublisher(string forPublisher)
        {
            // JML_LINDE
            if (forPublisher == null)
            {
                return;
            }

            try
            {
                _tabView.SuspendLayout();

                DataRow[] dataRows;
                // Get the work item controller
                ApplicationsWorkItemController wiController = _tabView.WorkItem.Controller as ApplicationsWorkItemController;

                // ...and from there settings which alter what we display in this view
                bool   showIncluded    = wiController.ShowIncludedApplications;
                bool   showIgnored     = wiController.ShowIgnoredApplications;
                string publisherFilter = wiController.PublisherFilter;

                // If we have not been supplied a publisher to display then flag that we are not displaying
                // a publisher at this time, regardless save the supplied publisher
                if (forPublisher == null)
                {
                    _isPublisherDisplayed = false;

                    // OK there is no explicit publisher but is there a general publisher filter that we
                    // will need to supply to reduce the number of Publishers reported?
                    if (wiController.PublisherFilter != "")
                    {
                        publisherFilter = wiController.PublisherFilter;
                    }
                }

                else
                {
                    _isPublisherDisplayed = true;
                    _currentPublisher     = forPublisher;
                    publisherFilter       = forPublisher;
                }

                // Initialize the tab view now that we know what we are displaying
                InitializeTabView();

                // Call database function to return list of applications (for the specified publisher)
                ApplicationsDAO lwDataAccess      = new ApplicationsDAO();
                DataTable       applicationsTable = lwDataAccess.GetApplications(forPublisher, showIncluded, showIgnored);

                // Set the header text and image for the tab view based on whether we are displaying
                // all (possibly filtered) publishers or a sepcific publisher
                _tabView.HeaderText  = (forPublisher == null) ? MiscStrings.AllPublishers : forPublisher;
                _tabView.HeaderImage = Properties.Resources.application_publisher_72;

                DataTable applicationInstancesTable = new ApplicationInstanceDAO().GetApplicationInstances(forPublisher);
                DataTable applicationLicensesTable  = new LicensesDAO().GetApplicationLicenses();

                // get a list of aliased applications - will save processing time later
                List <int> aliasedToApplicationsList = new List <int>();

                foreach (DataRow dataRow in lwDataAccess.GetAliasedToApplications().Rows)
                {
                    aliasedToApplicationsList.Add(Convert.ToInt32(dataRow[0]));
                }

                // ...the create InstalledApplication objects for each returned and add to the view
                foreach (DataRow row in applicationsTable.Rows)
                {
                    InstalledApplication thisApplication = new InstalledApplication(row);

                    // Read instances/licenses of this application

                    dataRows = applicationInstancesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadInstances1(dataRows);

                    dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadLicenses1(dataRows);

                    // find any applications which are aliased to this application as we also need their licenses
                    if (aliasedToApplicationsList.Contains(thisApplication.ApplicationID))
                    {
                        foreach (DataRow dataRow in lwDataAccess.GetAliasedApplicationsByApplicationId(thisApplication.ApplicationID).Rows)
                        {
                            dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + dataRow[0]);
                            thisApplication.LoadLicenses1(dataRows);
                        }
                    }

                    // ...and add to the tab view
                    _tabView.AddApplication(thisApplication);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in ShowPublisher()", ex);
            }
            finally
            {
                _tabView.ResumeLayout();
            }
        }
Beispiel #2
0
        private string HandleApplications(string applicationFilter, string compliantIds)
        {
            DataTable applicationInstancesDataTable = new ApplicationInstanceDAO().GetAllInstances(_showIncludedApplications, _showIgnoredApplications);
            string    publisher   = String.Empty;
            string    application = String.Empty;
            string    version     = String.Empty;
            bool      installed   = true;

            DataRow[]     rows;
            List <string> compliantIdList    = Utility.ListFromString(compliantIds, ',', true);
            List <string> newCompliantIdList = new List <string>();
            string        newIds             = String.Empty;

            publisher   = applicationFilter.Substring(26, applicationFilter.IndexOf("' and _name") - 26);
            application = applicationFilter.Substring(applicationFilter.IndexOf("_name = ") + 9, applicationFilter.IndexOf("and _value") - applicationFilter.IndexOf("_name = ") - 11);
            installed   = applicationFilter.Contains("==");

            // check if there is a specific version number to check for this application
            if (applicationFilter.Contains("(v"))
            {
                version     = applicationFilter.Substring(applicationFilter.LastIndexOf("(v") + 2, applicationFilter.LastIndexOf(")") - applicationFilter.LastIndexOf("(v") - 2);
                application = application.Replace(" (v" + version + ")", String.Empty);
            }

            string id;

            for (int i = 0; i < compliantIdList.Count; i++)
            {
                id   = compliantIdList[i];
                rows = applicationInstancesDataTable.Select(
                    String.Format("_ASSETID = {0} AND _PUBLISHER = '{1}' AND _NAME = '{2}' AND _VERSION = '{3}'",
                                  id, publisher.Replace("'", "''"), application.Replace("'", "''"), version.Replace("'", "''")));

                if (installed)
                {
                    if (rows.Length > 0)
                    {
                        newCompliantIdList.Add(id);
                    }
                }
                else
                {
                    if (rows.Length == 0)
                    {
                        newCompliantIdList.Add(id);
                    }
                }
            }

            compliantIdList.Clear();
            compliantIdList.InsertRange(0, newCompliantIdList);
            newCompliantIdList.Clear();

            foreach (string compliantId in compliantIdList)
            {
                if (!newIds.Contains(compliantId))
                {
                    newIds += compliantId + ",";
                }
            }

            return(newIds.TrimEnd(','));
        }
        public void ShowPublisher(int aCompliantType)
        {
            try
            {
                // Get the work item controller
                ApplicationsWorkItemController wiController = _tabView.WorkItem.Controller as ApplicationsWorkItemController;

                // ...and from there settings which alter what we display in this view
                bool   showIncluded    = wiController.ShowIncludedApplications;
                bool   showIgnored     = wiController.ShowIgnoredApplications;
                string publisherFilter = wiController.PublisherFilter;

                _isPublisherDisplayed = false;
                _currentPublisher     = null;

                // Initialize the tab view now that we know what we are displaying
                InitializeTabView();

                // Call database function to return list of applications (for the specified publisher)
                ApplicationsDAO lwDataAccess      = new ApplicationsDAO();
                DataTable       applicationsTable = lwDataAccess.GetApplications(publisherFilter, showIncluded, showIgnored);

                // Set the header text and image for the tab view based on whether we are displaying
                // all (possibly filtered) publishers or a sepcific publisher
                _tabView.HeaderText  = "Generating report data, please wait...";
                _tabView.HeaderImage = Properties.Resources.application_publisher_72;

                _tabView.Refresh();

                DataTable applicationInstancesTable = new ApplicationInstanceDAO().GetApplicationInstances();
                DataTable applicationLicensesTable  = new LicensesDAO().GetApplicationLicenses();

                // get a list of aliased applications - will save processing time later
                List <int> aliasedToApplicationsList = new List <int>();

                foreach (DataRow dataRow in lwDataAccess.GetAliasedToApplications().Rows)
                {
                    aliasedToApplicationsList.Add(Convert.ToInt32(dataRow[0]));
                }

                // ...the create InstalledApplication objects for each returned and add to the view
                foreach (DataRow row in applicationsTable.Rows)
                {
                    InstalledApplication thisApplication = new InstalledApplication(row);

                    // Read instances/licenses of this application
                    DataRow[] dataRows = applicationInstancesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadInstances1(dataRows);

                    dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadLicenses1(dataRows);

                    // find any applications which are aliased to this application as we also need their licenses
                    if (aliasedToApplicationsList.Contains(thisApplication.ApplicationID))
                    {
                        foreach (DataRow dataRow in lwDataAccess.GetAliasedApplicationsByApplicationId(thisApplication.ApplicationID).Rows)
                        {
                            dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + dataRow[0]);
                            thisApplication.LoadLicenses1(dataRows);
                        }
                    }

                    //thisApplication.LoadData();

                    if (CheckApplicationState(aCompliantType, thisApplication))
                    {
                        // ...and add to the tab view
                        _tabView.AddApplication(thisApplication);
                    }
                }

                switch (aCompliantType)
                {
                case 1:
                    _tabView.HeaderText = "Compliant Applications";
                    break;

                case 2:
                    _tabView.HeaderText = "Non-compliant Applications";
                    break;

                default:
                    _tabView.HeaderText = "All Applications";
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in ShowPublisher()", ex);
            }
        }