public void TestNonCriticalTCMetrics()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListStatisticsRatio();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "66070" },
                { "CRITICAL", "false" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>
            {
                "CAST Rules", "Total Vulnerabilities", "Added Vulnerabilities", "Removed Vulnerabilities",
                "Avoid Methods with a very low comment/code ratio (7846)", "128", "8", "2",
                "Action Mappings should have few forwards (7132)", "77", "8", "2"
            };

            TestUtility.AssertTableContent(table, expectedData, 4, 3);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public Setting AddConnection(WSConnection connection, bool isActive, out StatesEnum state)
        {
            using (ISettingRepository settingRepository = new SettingsRepository())
            {
                var setting = settingRepository.GetSeting();

                if (!CommonBLL.CheckService(connection))
                {
                    state = StatesEnum.ServiceInvalid;
                    return(setting);
                }

                if (!setting.WSConnections.Any(x => x.Equals(connection)))
                {
                    setting.WSConnections.Add(connection);
                }
                else
                {
                    state = StatesEnum.ConnectionAlreadyExist;
                }


                if (isActive)
                {
                    setting.ChangeActiveConnection(connection.Uri.ToString());
                    state = StatesEnum.ConnectionAddedAndActivated;
                }
                else
                {
                    state = StatesEnum.ConnectionAddedSuccessfully;
                }

                settingRepository.SaveSetting(setting);

                return(setting);
            }
        }
示例#3
0
        public void TestPreviousButNoPreviousSnapshot()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCresults.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);

            var component = new CastReporting.Reporting.Block.Table.QualityRuleViolations();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "ID", "7846" },
                { "SNAPSHOT", "PREVIOUS" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>();

            expectedData.AddRange(new List <string> {
                "Objects in violation for rule Avoid Methods with a very low comment/code ratio", "PRI"
            });
            expectedData.AddRange(new List <string> {
                "-"
            });
            TestUtility.AssertTableContent(table, expectedData, 2, 11);
        }
示例#4
0
        public void GetConfQualityRuleChinese()
        {
            WSConnection _connection3 = new WSConnection()
            {
                Url      = "http://dash-aed-tomcat:8888/Dashboard-Noc-170/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            TestUtility.SetCulture("zh-CN");
            ICastRepsitory ccontext = new CastRepository(_connection3);

            if (Environment.UserName != "abd")
            {
                if (ccontext == null)
                {
                    return;
                }
                if (!ccontext.IsServiceValid())
                {
                    return;
                }
            }
            const string cdomainHref = "ADG83/quality-indicators/7126/snapshots/1";
            var          result      = ccontext.GetConfBusinessCriteria(cdomainHref);

            Assert.AreEqual("避免工件的已注释掉代码行/代码行的比率过高", result.Name);

            TestUtility.SetCulture("en-US");
            ICastRepsitory ccontext2    = new CastRepository(_connection3);
            const string   cdomainHref2 = "ADG83/quality-indicators/7126/snapshots/1";
            var            result2      = ccontext2.GetConfBusinessCriteria(cdomainHref2);

            Assert.AreEqual("Avoid Artifacts with high Commented-out Code Lines/Code Lines ratio", result2.Name);
        }
        public void TestNoApplicableRules()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListStatisticsRatio();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "12345" },
                { "CRITICAL", "false" },
                { "LBL", "vulnerabilities" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>
            {
                "CAST Rules", "Total Vulnerabilities", "Added Vulnerabilities", "Removed Vulnerabilities",
                "No applicable rules for given application", "", "", ""
            };

            TestUtility.AssertTableContent(table, expectedData, 4, 2);
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        public void InitializeFromWS()
        {
            //GetActive Connection
            ActiveConnection = Setting?.GetActiveConnection();

            //Get list of domains
            if (_ActiveConnection?.Password == null || _ActiveConnection?.Login == null)
            {
                return;
            }
            try
            {
                using (CastDomainBLL castDomainBLL = new CastDomainBLL(ActiveConnection))
                {
                    Applications = castDomainBLL.GetApplications().Select(app => new ApplicationItem(app));
                    List <CastDomain> domains = castDomainBLL.GetDomains().ToList();
                    foreach (CastDomain domain in domains)
                    {
                        if (domain.DBType.Equals("AAD"))
                        {
                            Categories = castDomainBLL.GetCategories();
                        }
                    }
                    if (Categories == null)
                    {
                        Categories = new List <string>();
                    }

                    SelectedTab = 0;
                }
            }
            catch (Exception ex)
            {
                MessageManager.OnErrorOccured(ex);
            }
        }
示例#7
0
        /// <summary>
        /// loads precalculated param evaluations of a dataset from DB
        /// </summary>
        public static void LoadParams()
        {
            string json = WSConnection.GetParamStatistics();

            string [][] ret = Newtonsoft.Json.JsonConvert.DeserializeObject <string[][]>(json);
            if (ret.Length == 0)
            {
                var processids = WSConnection.GetProcessesWhere(new List <Tuple <string, string, string, string> >());
                DataContainers = new PredictiveProcessCollection(processids);
                foreach (ParamEvaluation eva in DataContainers.ParamEvaluations.Values)
                {
                    WSConnection.InsertParamStatistic(eva.ParamName, eva.ParamType.ToString(), eva.ValueCount, eva.DistinctValues.Select(x => x.Item1));
                }
            }
            else
            {
                DataContainers = new PredictiveProcessCollection(new List <PredictiveProcessData>());
                for (int i = 0; i < ret.Length; i++)
                {
                    DataContainers.ParamEvaluations.Add(ret[i][0], new ParamEvaluation(ret[i][0], ret[i][1], ret[i][2].Split(';').ToList(), int.Parse(ret[i][3])));
                }
            }
            loadedAll = true;
        }
示例#8
0
        public static void NewScriptFromSocket(ScriptStructure NewScriptStructure, WSConnection ScriptConnection)
        {
            ScriptBuffer NewBuffer = new ScriptBuffer();

            NewBuffer.Script                    = new ScriptTB();
            NewBuffer.Script.TargetID           = NewScriptStructure.TargetID;
            NewBuffer.Script.BlockID            = NewScriptStructure.BlockID;
            NewBuffer.Script.BlockName          = NewScriptStructure.BlockName;
            NewBuffer.Script.CommandCounter     = NewScriptStructure.CommandCounter;
            NewBuffer.Script.CommandName        = NewScriptStructure.CommandName;
            NewBuffer.Script.DelayTime          = (int)NewScriptStructure.DelayTime;
            NewBuffer.Script.DeviceCategory     = NewScriptStructure.DeviceCategory.ToString();
            NewBuffer.Script.DeviceName         = NewScriptStructure.DeviceName.ToString();
            NewBuffer.Script.ExecutionNumber    = NewScriptStructure.ExecutionNumber.Value;
            NewBuffer.Script.ExecutionTimeEnd   = NewScriptStructure.ExecutionTimeEnd;
            NewBuffer.Script.ExecutionTimeStart = NewScriptStructure.ExecutionTimeStart;
            NewBuffer.Script.Owner              = NewScriptStructure.Owner;
            NewBuffer.Script.Parameter          = String.Join(",", NewScriptStructure.Parameter);
            NewBuffer.Script.ScriptState        = NewScriptStructure.ScriptState.ToString();
            NewBuffer.Script.StationName        = NewScriptStructure.StationName.ToString();
            NewBuffer.WSConnection              = ScriptConnection;

            NewScriptBuffer.Enqueue(NewBuffer);
        }
示例#9
0
        /// <summary>
        /// Implement Add service Command
        /// </summary>
        private void ExecuteAddCommand(object prameter)
        {
            try
            {
                WSConnection conn = new WSConnection(NewConnectionUrl, NewConnectionLogin, NewConnectionPassword, string.Empty);

                StatesEnum state;
                Setting = SettingsBLL.AddConnection(conn, false, out state);

                if (state == StatesEnum.ConnectionAddedAndActivated || state == StatesEnum.ConnectionAddedSuccessfully)
                {
                    WSConnections = new ObservableCollection <WSConnection>(Setting.WSConnections);

                    NewConnectionUrl = NewConnectionLogin = NewConnectionPassword = string.Empty;
                }

                MessageManager.OnServiceAdded(conn.Url, state);
            }
            catch (UriFormatException ex)
            {
                LogHelper.Instance.LogInfo(ex.Message);
                MessageManager.OnServiceAdded(NewConnectionUrl, StatesEnum.ServiceInvalid);
            }
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="help"></param>
        /// <returns></returns>
        private static string GenerateReport(XmlCastReport arguments, out string help)
        {
            if (arguments.ReportType != null)
            {
                string reportPath    = string.Empty;
                string tmpReportFile = string.Empty;

                try
                {
                    help = string.Empty;

                    //Get RG settings
                    var settings = SettingsBLL.GetSetting();
                    LogHelper.Instance.LogInfo("RG settings have been read successfully");

                    //Initialize temporary directory
                    string workDirectory = SettingsBLL.GetApplicationPath();
                    //tmpReportFile = PathUtil.CreateTempCopy(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath, arguments.Template.Name));
                    //tmpReportFile = PathUtil.CreateTempCopy(workDirectory, arguments.Template.Name);

                    //Initialize Web services

                    var connection = new WSConnection(arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name, string.Empty);
                    using (CommonBLL commonBLL = new CommonBLL(connection))
                    {
                        if (!commonBLL.CheckService())
                        {
                            help = string.Format("Webservice can't be access or is bad formatted. Url:{0} Username:{1} Password:{2}", arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name);
                            return(string.Empty);
                        }
                    }
                    LogHelper.Instance.LogInfo("Web services Initialized successfully");

                    List <Application> Apps = new List <Application>();

                    try
                    {
                        using (CastDomainBLL castDomainBLL = new CastDomainBLL(connection))
                        {
                            if (arguments.Tag == null)
                            {
                                Apps = castDomainBLL.GetCommonTaggedApplications(null);
                            }
                            else
                            {
                                Apps = castDomainBLL.GetCommonTaggedApplications(arguments.Tag.Name);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogInfo("Error occured while trying get applications for the portfolio");
                    }

                    Application[] SelectedApps = Apps.ToArray <Application>();
                    LogHelper.Instance.LogInfo("Applications is the portfolio found successfully");
                    string[] AppsToIgnorePortfolioResult = PortfolioBLL.BuildPortfolioResult(connection, SelectedApps);
                    LogHelper.Instance.LogInfo("Build result for the portfolio");
                    string[]           SnapsToIgnore = null;
                    List <Application> N_Apps        = new List <Application>();
                    //Remove from Array the Ignored Apps
                    for (int i = 0; i < SelectedApps.Count(); i++)
                    {
                        int intAppYes = 0;
                        foreach (string s in AppsToIgnorePortfolioResult)
                        {
                            if (s == SelectedApps[i].Name)
                            {
                                intAppYes = 1;
                                break;
                            }
                            else
                            {
                                intAppYes = 0;
                            }
                        }

                        if (intAppYes == 0)
                        {
                            N_Apps.Add(SelectedApps[i]);
                        }
                    }
                    Application[] N_SelectedApps = N_Apps.ToArray();

                    List <Snapshot> Snapshots = new List <Snapshot>();

                    try
                    {
                        using (CastDomainBLL castDomainBLL = new CastDomainBLL(connection))
                        {
                            Snapshots = castDomainBLL.GetAllSnapshots(N_SelectedApps);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogInfo("Error occured while trying get snapshots of applications for the portfolio");
                    }
                    LogHelper.Instance.LogInfo("Snapshots is the portfolio found successfully");
                    List <Snapshot> N_Snaps = new List <Snapshot>();
                    if (Snapshots != null)
                    {
                        Snapshot[] SelectedApps_Snapshots = Snapshots.ToArray <Snapshot>();
                        SnapsToIgnore = PortfolioSnapshotsBLL.BuildSnapshotResult(connection, SelectedApps_Snapshots, true);
                        LogHelper.Instance.LogInfo("Build result for snapshots in portfolio");

                        for (int i = 0; i < SelectedApps_Snapshots.Count(); i++)
                        {
                            int intRemoveYes = 0;
                            foreach (string s in SnapsToIgnore)
                            {
                                if (s == SelectedApps_Snapshots[i].Href)
                                {
                                    intRemoveYes = 1;
                                    break;
                                }
                                else
                                {
                                    intRemoveYes = 0;
                                }
                            }
                            if (intRemoveYes == 0)
                            {
                                N_Snaps.Add(SelectedApps_Snapshots[i]);
                            }
                        }

                        Snapshot[] N_SelectedApps_Snapshots = N_Snaps.ToArray();

                        //GenerateReportPortfolio(N_SelectedApps, N_SelectedApps_Snapshots);
                        //string tmpReportFile = String.Empty;
                        string tmpReportFileFlexi = String.Empty;

                        try
                        {
                            //Create temporary report
                            //string workDirectory = SettingsBLL.GetApplicationPath();
                            //tmpReportFile = PathUtil.CreateTempCopy(workDirectory + "\\Portfolio\\", arguments.Template.Name);
                            tmpReportFile = PathUtil.CreateTempCopy(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath + "\\Portfolio", arguments.Template.Name));
                            if (tmpReportFile.Contains(".xlsx"))
                            {
                                tmpReportFileFlexi = PathUtil.CreateTempCopyFlexi(workDirectory, arguments.Template.Name);
                            }
                            //Build report
                            ReportData reportData = new ReportData();
                            if (arguments.Category != null && arguments.Tag != null)
                            {
                                reportData = new ReportData()
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    Applications     = N_SelectedApps,
                                    Category         = arguments.Category.Name,
                                    Tag                 = arguments.Tag.Name,
                                    snapshots           = N_SelectedApps_Snapshots,
                                    IgnoresApplications = AppsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = SnapsToIgnore
                                };
                            }
                            else if (arguments.Category != null && arguments.Tag == null)
                            {
                                reportData = new ReportData()
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    Applications     = N_SelectedApps,
                                    Category         = arguments.Category.Name,
                                    Tag                 = null,
                                    snapshots           = N_SelectedApps_Snapshots,
                                    IgnoresApplications = AppsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = SnapsToIgnore
                                };
                            }
                            else if (arguments.Category == null && arguments.Tag != null)
                            {
                                reportData = new ReportData()
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    Applications     = N_SelectedApps,
                                    Category         = null,
                                    Tag                 = arguments.Tag.Name,
                                    snapshots           = N_SelectedApps_Snapshots,
                                    IgnoresApplications = AppsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = SnapsToIgnore
                                };
                            }
                            else
                            {
                                reportData = new ReportData()
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    Applications     = N_SelectedApps,
                                    Category         = null,
                                    Tag                 = null,
                                    snapshots           = N_SelectedApps_Snapshots,
                                    IgnoresApplications = AppsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = SnapsToIgnore
                                };
                            }

                            using (IDocumentBuilder docBuilder = BuilderFactory.CreateBuilder(reportData, tmpReportFile))
                            {
                                docBuilder.BuildDocument();
                            }
                            LogHelper.Instance.LogInfo("Report generated successfully");

                            //Set filte report
                            SetFileName(arguments);

                            if (string.IsNullOrEmpty(settings.ReportingParameter.GeneratedFilePath))
                            {
                                reportPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), arguments.File.Name);
                            }
                            else
                            {
                                reportPath = Path.Combine(settings.ReportingParameter.GeneratedFilePath, arguments.File.Name);
                            }


                            if (tmpReportFile.Contains(".xlsx"))
                            {
                                tmpReportFile = tmpReportFileFlexi;
                            }

                            //Copy report file to the selected destination
                            File.Copy(tmpReportFile, reportPath, true);
                        }
                        catch (Exception ex)
                        {
                            reportPath = String.Empty;

                            throw (ex);
                        }
                        finally
                        {
                            if (!String.IsNullOrEmpty(tmpReportFile))
                            {
                                File.Delete(tmpReportFile);
                            }
                        }
                    }


                    return(reportPath);
                }
                catch (Exception ex)
                {
                    help = string.Format("An exception occured : {0}", ex);
                    return(string.Empty);
                }
                finally
                {
                    if (!string.IsNullOrEmpty(tmpReportFile))
                    {
                        File.Delete(tmpReportFile);
                    }
                }
            }
            else
            {
                string tmpReportFile = string.Empty;

                try
                {
                    help = string.Empty;

                    //Get RG settings
                    var settings = SettingsBLL.GetSetting();
                    LogHelper.Instance.LogInfo("RG settings have been read successfully");

                    //Initialize temporary directory
                    string workDirectory = SettingsBLL.GetApplicationPath();
                    tmpReportFile = PathUtil.CreateTempCopy(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath, arguments.Template.Name));

                    //Initialize Web services

                    var connection = new WSConnection(arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name, string.Empty);
                    using (CommonBLL commonBLL = new CommonBLL(connection))
                    {
                        if (!commonBLL.CheckService())
                        {
                            help = string.Format("Webservice can't be access or is bad formatted. Url:{0} Username:{1} Password:{2}", arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name);
                            return(string.Empty);
                        }
                    }
                    LogHelper.Instance.LogInfo("Web services Initialized successfully");


                    //Initialize Application
                    Application application = GetApplication(arguments.Application.Name, connection);
                    if (application == null)
                    {
                        help = string.Format("Application {0} can't be found.", arguments.Application.Name);
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo(string.Format("Application {0} Initialized successfully", arguments.Application.Name));

                    //Initialize snapshots
                    SetSnapshots(connection, application);
                    if (application.Snapshots == null)
                    {
                        help = "There is no snapshots for this application.";
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo(string.Format("List of Snapshots Initialized successfully", arguments.Application.Name));

                    //Build Application results
                    ApplicationBLL.BuildApplicationResult(connection, application);
                    LogHelper.Instance.LogInfo(string.Format("Application results built successfully", arguments.Application.Name));


                    //Set current snapshot
                    Snapshot currentSnapshot = GetSnapshotOrDefault(arguments.Snapshot.Current, application.Snapshots, 0);
                    if (currentSnapshot == null)
                    {
                        help = string.Format("Current snapshot {0} can't be found", arguments.Snapshot.Current.Name);
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo(string.Format("Current snapshot {0} initialized successfully", currentSnapshot.Name));

                    //Build current snapshot results
                    SnapshotBLL.BuildSnapshotResult(connection, currentSnapshot, true);
                    LogHelper.Instance.LogInfo(string.Format("Result of current snapshot {0} built successfully", currentSnapshot.Name));

                    //Set previous snapshot
                    Snapshot prevSnapshot = GetSnapshotOrDefault(arguments.Snapshot.Previous, application.Snapshots, 1);
                    if (arguments.Snapshot.Previous != null && !string.IsNullOrEmpty(arguments.Snapshot.Previous.Name) && prevSnapshot == null)
                    {
                        help = string.Format("Previous snapshot {0} can't be found", arguments.Snapshot.Previous.Name);
                        return(string.Empty);
                    }
                    if (prevSnapshot != null)
                    {
                        LogHelper.Instance.LogInfo(string.Format("Previous snapshot {0} Initialized successfully", prevSnapshot.Name));
                    }

                    //Build previous snapshot results
                    if (prevSnapshot != null)
                    {
                        SnapshotBLL.BuildSnapshotResult(connection, prevSnapshot, false);
                        LogHelper.Instance.LogInfo(string.Format("Result of previous snapshot {0}  built successfully", prevSnapshot.Name));
                    }


                    //Build report
                    ReportData reportData = new ReportData()
                    {
                        FileName         = tmpReportFile,
                        Application      = application,
                        CurrentSnapshot  = currentSnapshot,
                        PreviousSnapshot = prevSnapshot,
                        Parameter        = settings.ReportingParameter,
                        RuleExplorer     = new RuleBLL(connection),
                        SnapshotExplorer = new SnapshotBLL(connection, currentSnapshot),
                        CurrencySymbol   = "$"
                    };

                    using (IDocumentBuilder docBuilder = BuilderFactory.CreateBuilder(reportData, ""))
                    {
                        docBuilder.BuildDocument();
                    }
                    LogHelper.Instance.LogInfo("Report generated successfully");

                    //Set filte report
                    SetFileName(arguments);

                    string reportPath;
                    if (string.IsNullOrEmpty(settings.ReportingParameter.GeneratedFilePath))
                    {
                        reportPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), arguments.File.Name);
                    }
                    else
                    {
                        reportPath = Path.Combine(settings.ReportingParameter.GeneratedFilePath, arguments.File.Name);
                    }


                    File.Copy(tmpReportFile, reportPath, true);
                    LogHelper.Instance.LogInfo("Report moved to generation directory successfully");

                    return(reportPath);
                }
                catch (Exception ex)
                {
                    help = string.Format("An exception occured : {0}", ex);
                    return(string.Empty);
                }
                finally
                {
                    if (!string.IsNullOrEmpty(tmpReportFile))
                    {
                        File.Delete(tmpReportFile);
                    }
                }
            }
        }
示例#11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="url"></param>
 /// <param name="currentSnapshot"></param>
 /// <param name="previousSnapshot"></param>
 public BaseBLL(WSConnection connection)
 {
     Connection = connection;
 }
示例#12
0
 protected ICastRepsitory GetRepository(WSConnection Connection)
 {
     return(new CastRepository(Connection));
 }
 public async Task <WSConnection> deleteSubcriber(WSConnection con)
 {
     return(await wsContext.DeleteAsync(con));
 }
示例#14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentSnapshot"></param>
 /// <param name="previousSnapshot"></param>
 public ApplicationBLL(WSConnection connection, Application application)
     : base(connection)
 {
     _Application = application;
 }
        public void TestOneSnapshot()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCresults.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();
            var component = new CastReporting.Reporting.Block.Table.QualityRuleViolationsBookmarks();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "ID", "7424" },
                { "COUNT", "1" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>
            {
                "Objects in violation for rule Avoid using SQL queries inside a loop",
                "",
                "Violation #1    Avoid using SQL queries inside a loop",
                "Object Name: aedtst_exclusions_central.adg_central_grades_std",
                "Object Type: MyObjType",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\SQL\\central.sql",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\Java\\AADAdmin\\AadSite\\sources\\com\\castsoftware\\aad\\site\\AadSite.java",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\Java\\AADAdmin\\AadSite\\sources\\com\\castsoftware\\aad\\site\\AadSite.java",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
            };

            TestUtility.AssertTableContent(table, expectedData, 1, 29);

            var cellsProperties = table.CellsAttributes;

            Assert.AreEqual(27, cellsProperties.Count);
        }
示例#16
0
    // Start is called before the first frame update
    void Start()
    {
        websocket = GetComponent <WSConnection>();

        motionPoints = new List <Point>();
    }
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentSnapshot"></param>
 /// <param name="previousSnapshot"></param>
 public PortfolioSnapshotsBLL(WSConnection connection, Snapshot[] snapshot)
     : base(connection)
 {
     _Snapshot = snapshot;
 }
        /// <summary>
        /// Date Modified:  03/Jan/2018
        /// Modified By:    JMonteza
        /// (description)   Save photo in Directory and call TM-API to save it in Panda
        /// </summary>
        /// <returns></returns>
        private bool SavePhoto(string sEntityType)
        {
            bool bReturn = false;

            try
            {
                string sFileExtension = "";
                string sLocation      = "";
                string sIDName        = "";

                if (sEntityType == "shuttle")
                {
                    sFileExtension = Path.GetExtension(FileUploadImageShuttle.FileName);
                    sLocation      = Server.MapPath("~/FileUploaded/HotelShuttle/");
                    sIDName        = "HotelID";
                }
                else if (sEntityType == "logo")
                {
                    sFileExtension = Path.GetExtension(FileUploadImageLogo.FileName);
                    sLocation      = Server.MapPath("~/FileUploaded/HotelLogo/");
                    sIDName        = "HotelID";
                }
                sFileExtension = sFileExtension.Replace(".", "");

                string[] sImageExtension = ConfigurationManager.AppSettings["ImageExtension"].ToString().Split(",".ToCharArray());
                if (sImageExtension.Contains(sFileExtension.ToLower().Trim()))
                {
                    string sBranchID = uoHiddenFieldBranchID.Value;

                    DirectoryInfo dir   = new DirectoryInfo(sLocation);
                    FileInfo[]    files = dir.GetFiles(sBranchID + ".*");
                    if (files.Length > 0)
                    {
                        //File exists
                        foreach (FileInfo file in files)
                        {
                            file.Delete();
                        }
                    }
                    //else
                    //{
                    //    //File does not exist
                    //}

                    //save photo in directory
                    sLocation += sBranchID + "." + sFileExtension.ToLower();
                    if (sEntityType == "shuttle")
                    {
                        FileUploadImageShuttle.SaveAs(sLocation);
                    }
                    else if (sEntityType == "logo")
                    {
                        FileUploadImageLogo.SaveAs(sLocation);
                        sEntityType = "hotel";
                    }


                    bReturn = WSConnection.SaveToMediaServer(sIDName, sBranchID, sFileExtension.ToLower(), sEntityType);
                    bReturn = true;
                }
                else
                {
                    AlertMessage("Invalid extension file", true);
                }
                return(bReturn);
            }
            catch (Exception ex)
            {
                AlertMessage(ex.Message, true);
                return(bReturn);
            }
        }
示例#19
0
 public static async Task StartConnectionAsync(LoginObject loginInfor)
 {
     _connection = new WSConnection();
     await _connection.StartConnectionAsync(Constants.ServerAddress, loginInfor);
 }
示例#20
0
        public void TestUnchanged3BC()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCresults.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);

            var component = new CastReporting.Reporting.Block.Table.ViolationsListByBC();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "COUNT", "ALL" },
                { "BCID", "60014|60016|60013" },
                { "FILTER", "UNCHANGED" },
                { "NAME", "FULL" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>();

            expectedData.AddRange(new List <string> {
                "Violation Status", "PRI", "Exclusion Status", "Action Status", "Rule Name", "Business criterion name", "Object Name", "Object Status"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "320", "n/a", "pending", "Avoid instantiations inside loops", "Efficiency", "CastReporting.Reporting.Block.Table.TechnicalCriteriaRules.Content", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "320", "n/a", "pending", "Avoid instantiations inside loops", "Efficiency", "CastReporting.Reporting.Block.Table.TechnoLoC.Content", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "1,288", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Security", "CastReporting.Reporting.Helper", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "168", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Security", "CastReporting.Mediation.Interfaces", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "168", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Security", "CastReporting.Reporting.Builder", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "112", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Security", "CastReporting.Reporting", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "4,452", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Robustness", "CastReporting.Reporting.Builder.BlockProcessing", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "126", "n/a", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Robustness", "CastReporting.Mediation.Interfaces", "unchanged"
            });
            expectedData.AddRange(new List <string> {
                "unchanged", "84", "added", "n/a", "Avoid cyclical calls and inheritances between namespaces content", "Robustness", "CastReporting.UI.WPF", "unchanged"
            });
            TestUtility.AssertTableContent(table, expectedData, 8, 10);
        }
示例#21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="snapshots"></param>
 public PortfolioSnapshotsBLL(WSConnection connection, Snapshot[] snapshots)
     : base(connection)
 {
     Snapshots = snapshots;
 }
        public void TestNocountMetric()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListViolationsBookmarks();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "7846" }
            };
            var table = component.Content(reportData, config);

            Assert.AreEqual(1, table.NbColumns);
            Assert.AreEqual(69, table.NbRows);
            Assert.AreEqual("Violations", table.Data.ElementAt(0));
            Assert.AreEqual("Objects in violation for rule Avoid Methods with a very low comment/code ratio", table.Data.ElementAt(2));
            Assert.AreEqual("# Violations: 128", table.Data.ElementAt(3));
            Assert.AreEqual("Violation #5    Avoid Methods with a very low comment/code ratio", table.Data.ElementAt(55));
            Assert.AreEqual("Object Name: com.castsoftware.aed.common.AedCommandLine.getFormattedMsg", table.Data.ElementAt(56));
            Assert.AreEqual("Object Type: MyObjType", table.Data.ElementAt(57));
            Assert.AreEqual("File path: C:\\jenkins6_slave\\workspace\\CAIP_8.3.3_TestE2E_CSS_ADG\\Work\\CAST\\Deploy\\Dream Team\\DssAdmin\\DssAdmin\\MetricTree.cpp", table.Data.ElementAt(58));

            var cellsProperties = table.CellsAttributes;

            Assert.AreEqual(58, cellsProperties.Count);
            Assert.AreEqual(Color.Gray, cellsProperties[0].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[1].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[2].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[3].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[4].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[5].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[6].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[7].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[8].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[9].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[10].BackgroundColor);
            Assert.AreEqual(Color.Lavender, cellsProperties[11].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[12].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[13].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[14].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[15].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[16].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[17].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[18].BackgroundColor);

            Assert.AreEqual(Color.White, cellsProperties[57].BackgroundColor);
        }
示例#23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentSnapshot"></param>
 /// <param name="previousSnapshot"></param>
 public SnapshotBLL(WSConnection connection, Snapshot snapshot)
     : base(connection)
 {
     _Snapshot = snapshot;
 }
        public void TestMetricsStdTag()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListViolationsBookmarks();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "CWE" },
                { "COUNT", "-1" }
            };
            var table = component.Content(reportData, config);

            Assert.AreEqual(1, table.NbColumns);
            Assert.AreEqual(210, table.NbRows);
            Assert.AreEqual("Violations", table.Data.ElementAt(0));
            Assert.AreEqual("Objects in violation for rule Avoid using SQL queries inside a loop", table.Data.ElementAt(2));
            Assert.AreEqual("# Violations: 86", table.Data.ElementAt(3));
            Assert.AreEqual("Violation #7    Avoid using SQL queries inside a loop", table.Data.ElementAt(179));
            Assert.AreEqual("Object Name: aedtst_exclusions_central.adgc_delta_debt_removed", table.Data.ElementAt(180));
            Assert.AreEqual("Object Type: MyObjType", table.Data.ElementAt(181));
            Assert.AreEqual("File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\SQL\\central.sql", table.Data.ElementAt(182));
            Assert.AreEqual("File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\Java\\AADAdmin\\AadSite\\sources\\com\\castsoftware\\aad\\site\\AadSite.java", table.Data.ElementAt(198));
            Assert.AreEqual("1203 :         }", table.Data.ElementAt(205));

            var cellsProperties = table.CellsAttributes;

            Assert.AreEqual(197, cellsProperties.Count);
            Assert.AreEqual(Color.Gray, cellsProperties[0].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[1].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[2].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[3].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[4].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[5].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[6].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[7].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[8].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[9].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[10].BackgroundColor);
            Assert.AreEqual(Color.Lavender, cellsProperties[11].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[12].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[13].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[14].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[15].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[16].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[17].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[18].BackgroundColor);

            Assert.AreEqual(Color.Gainsboro, cellsProperties[35].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[170].BackgroundColor);
        }
示例#25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentSnapshot"></param>
 /// <param name="previousSnapshot"></param>
 public PortfolioBLL(WSConnection connection, Application[] application)
     : base(connection)
 {
     _Application = application;
 }
        public void TestTCmetrics()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListViolationsBookmarks();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "61028" },
                { "COUNT", "1" }
            };
            var table = component.Content(reportData, config);

            var expectedData = new List <string>
            {
                "Violations",
                "",
                "Objects in violation for rule Avoid using SQL queries inside a loop",
                "# Violations: 86",
                "Rationale: ",
                "Having an SQL query inside a loop is usually the source of performance and scalability problems especially if the number of iterations become very high (for example if it is dependent on the data returned from the database).\nThis iterative pattern has proved to be very dangerous for application performance and scalability. Database servers perform much better in set-oriented patterns rather than pure iterative ones.",
                "Description: ",
                "This metric retrieves all artifacts using at least one SQL query inside a loop statement.",
                "Remediation: ",
                "The remediation is often to replace the iterative approach based on a loop with a set-oriented one and thus modify the query.",
                "",
                "Violation #1    Avoid using SQL queries inside a loop",
                "Object Name: aedtst_exclusions_central.adg_central_grades_std",
                "Object Type: MyObjType",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\SQL\\central.sql",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\Java\\AADAdmin\\AadSite\\sources\\com\\castsoftware\\aad\\site\\AadSite.java",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
                "File path: D:\\CASTMS\\TST834\\Deploy\\Team\\AADAED\\Java\\AADAdmin\\AadSite\\sources\\com\\castsoftware\\aad\\site\\AadSite.java",
                "1197 : PreparedStatement statement = null;",
                "1198 :         try",
                "1199 :         {",
                "1200 :             statement = consolidatedConn.prepareStatement(insertMessage); ",
                "1201 :             statement.setString(1, message); ",
                "1202 :             statement.executeUpdate(); ",
                "1203 :         }",
                "",
                "",
                "",
                "",
                "",
                "Objects in violation for rule Avoid Methods with a very low comment/code ratio",
                "# Violations: 128",
                "Rationale: ",
                "Maintainability of the code is facilitated if there is documentation in the code. This rule will ensure there are comments within the Artifact",
                "Description: ",
                "Methods should have at least a ratio comment/code > X %\nThe threshold is a parameter and can be changed at will.",
                "Remediation: ",
                "Enrich Artifact code with comments",
                "",
                "Violation #1    Avoid Methods with a very low comment/code ratio",
                "Object Name: com.castsoftware.aad.common.AadCommandLine.dumpStack",
                "Object Type: MyObjType",
                "File path: C:\\jenkins6_slave\\workspace\\CAIP_8.3.3_TestE2E_CSS_ADG\\Work\\CAST\\Deploy\\Dream Team\\DssAdmin\\DssAdmin\\MetricTree.cpp",
                "4904 :      m_bGridModified = FALSE;",
                "4905 :  }",
                "4906 : ",
                "4907 :  void CMetricTreePageDet::Validate()",
                "4908 :  {",
                "4909 :      int i, index, nAggregate, nAggregateCentral, nType, nLastLine;",
                "",
                "",
                "",
                ""
            };

            TestUtility.AssertTableContent(table, expectedData, 1, 66);

            var cellsProperties = table.CellsAttributes;

            Assert.AreEqual(53, cellsProperties.Count);
            Assert.AreEqual(Color.Gray, cellsProperties[0].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[1].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[2].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[3].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[4].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[5].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[6].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[7].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[8].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[9].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[10].BackgroundColor);
            Assert.AreEqual(Color.Lavender, cellsProperties[11].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[12].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[13].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[14].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[15].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[16].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[17].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[18].BackgroundColor);

            Assert.AreEqual(Color.White, cellsProperties[52].BackgroundColor);
        }
示例#27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 protected BaseBLL(WSConnection connection)
 {
     Connection = connection;
 }
        public void TestBCmetrics()
        {
            CastDate currentDate = new CastDate {
                Time = 1484953200000
            };
            ReportData reportData = TestUtility.PrepareApplicationReportData("ReportGenerator",
                                                                             null, @".\Data\CurrentBCTC.json", "AED/applications/3/snapshots/6", "PreVersion 1.5.0 sprint 2 shot 2", "V-1.5.0_Sprint 2_2", currentDate,
                                                                             null, null, null, null, null, null);
            WSConnection connection = new WSConnection()
            {
                Url      = "http://tests/CAST-RESTAPI/rest/",
                Login    = "******",
                Password = "******",
                IsActive = true,
                Name     = "Default"
            };

            reportData.SnapshotExplorer = new SnapshotBLLStub(connection, reportData.CurrentSnapshot);
            reportData.RuleExplorer     = new RuleBLLStub();

            var component = new CastReporting.Reporting.Block.Table.RulesListViolationsBookmarks();
            Dictionary <string, string> config = new Dictionary <string, string>
            {
                { "METRICS", "60011" },
                { "COUNT", "2" }
            };
            var table = component.Content(reportData, config);

            Assert.AreEqual(1, table.NbColumns);
            Assert.AreEqual(206, table.NbRows);
            Assert.AreEqual("Violations", table.Data.ElementAt(0));
            Assert.AreEqual("Objects in violation for rule Action Mappings should have few forwards", table.Data.ElementAt(2));
            Assert.AreEqual("# Violations: 77", table.Data.ElementAt(3));
            Assert.AreEqual("Violation #1    Action Mappings should have few forwards", table.Data.ElementAt(9));
            Assert.AreEqual("Violation #2    Action Mappings should have few forwards", table.Data.ElementAt(37));
            Assert.AreEqual("Objects in violation for rule Avoid accessing data by using the position and length", table.Data.ElementAt(69));
            Assert.AreEqual("# Violations: 6", table.Data.ElementAt(70));
            Assert.AreEqual("Objects in violation for rule Avoid artifacts having recursive calls", table.Data.ElementAt(138));
            Assert.AreEqual("# Violations: 12", table.Data.ElementAt(139));
            Assert.AreEqual("1203 :         }", table.Data.ElementAt(201));


            var cellsProperties = table.CellsAttributes;

            Assert.AreEqual(184, cellsProperties.Count);
            Assert.AreEqual(Color.Gray, cellsProperties[0].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[1].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[2].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[3].BackgroundColor);
            Assert.AreEqual(Color.LightGray, cellsProperties[4].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[5].BackgroundColor);
            Assert.AreEqual(Color.Gainsboro, cellsProperties[6].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[7].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[8].BackgroundColor);
            Assert.AreEqual(Color.Lavender, cellsProperties[9].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[10].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[11].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[12].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[13].BackgroundColor);
            Assert.AreEqual(Color.LightYellow, cellsProperties[14].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[15].BackgroundColor);
            Assert.AreEqual(Color.White, cellsProperties[16].BackgroundColor);

            Assert.AreEqual(Color.Gray, cellsProperties[60].BackgroundColor);
            Assert.AreEqual(Color.Gray, cellsProperties[122].BackgroundColor);
        }
示例#29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="help"></param>
        /// <returns></returns>
        private static string GenerateReport(XmlCastReport arguments, out string help)
        {
            if (arguments.ReportType != null)
            {
                string reportPath    = string.Empty;
                string tmpReportFile = string.Empty;

                try
                {
                    help = string.Empty;

                    //Get RG settings
                    var settings = SettingsBLL.GetSetting();
                    LogHelper.Instance.LogInfo("RG settings have been read successfully");

                    //Initialize temporary directory
                    string workDirectory = SettingsBLL.GetApplicationPath();

                    //Initialize Web services

                    var connection = new WSConnection(arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name, string.Empty)
                    {
                        ApiKey = arguments.ApiKey?.Name.Equals("true") ?? false
                    };
                    using (CommonBLL commonBLL = new CommonBLL(connection))
                    {
                        if (!commonBLL.CheckService())
                        {
                            help = $"Webservice can't be access or is bad formatted. Url:{arguments.Webservice.Name}";
                            return(string.Empty);
                        }
                    }
                    LogHelper.Instance.LogInfo("Web services Initialized successfully");

                    List <Domain.Application> _apps = new List <Domain.Application>();

                    try
                    {
                        using (CastDomainBLL castDomainBLL = new CastDomainBLL(connection))
                        {
                            _apps = castDomainBLL.GetCommonTaggedApplications(arguments.Tag?.Name);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogInfo("Error occured while trying get applications for the portfolio : " + ex.Message);
                    }

                    Domain.Application[] _selectedApps = _apps.ToArray <Domain.Application>();
                    LogHelper.Instance.LogInfo("Applications in the portfolio found successfully");
                    string[] _appsToIgnorePortfolioResult = PortfolioBLL.BuildPortfolioResult(connection, _selectedApps);
                    LogHelper.Instance.LogInfo("Build result for the portfolio");
                    List <Domain.Application> _n_apps = new List <Domain.Application>();
                    //Remove from Array the Ignored Apps
                    foreach (Domain.Application app in _selectedApps)
                    {
                        int intAppYes = 0;
                        foreach (string s in _appsToIgnorePortfolioResult)
                        {
                            if (s == app.Name)
                            {
                                intAppYes = 1;
                                break;
                            }
                            else
                            {
                                intAppYes = 0;
                            }
                        }

                        if (intAppYes == 0)
                        {
                            _n_apps.Add(app);
                        }
                    }
                    Domain.Application[] _n_selectedApps = _n_apps.ToArray();

                    List <Snapshot> _snapshots = new List <Snapshot>();

                    try
                    {
                        using (CastDomainBLL castDomainBLL = new CastDomainBLL(connection))
                        {
                            _snapshots = castDomainBLL.GetAllSnapshots(_n_selectedApps);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Instance.LogInfo("Error occured while trying get snapshots of applications for the portfolio : " + ex.Message);
                    }
                    LogHelper.Instance.LogInfo("Snapshots in the portfolio found successfully");
                    List <Snapshot> _n_snaps = new List <Snapshot>();
                    if (_snapshots != null)
                    {
                        Snapshot[] _selectedApps_snapshots = _snapshots.ToArray <Snapshot>();
                        var        _snapsToIgnore          = PortfolioSnapshotsBLL.BuildSnapshotResult(connection, _selectedApps_snapshots, true);
                        LogHelper.Instance.LogInfo("Build result for snapshots in portfolio");

                        foreach (Snapshot snap in _selectedApps_snapshots)
                        {
                            int intRemoveYes = 0;
                            foreach (string s in _snapsToIgnore)
                            {
                                if (s == snap.Href)
                                {
                                    intRemoveYes = 1;
                                    break;
                                }
                                else
                                {
                                    intRemoveYes = 0;
                                }
                            }
                            if (intRemoveYes == 0)
                            {
                                _n_snaps.Add(snap);
                            }
                        }

                        Snapshot[] _n_selectedApps_snapshots = _n_snaps.ToArray();

                        string tmpReportFileFlexi = string.Empty;

                        try
                        {
                            //Create temporary report
                            tmpReportFile = PathUtil.CreateTempCopy(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath, "Portfolio", arguments.Template.Name));
                            if (tmpReportFile.Contains(".xlsx"))
                            {
                                tmpReportFileFlexi = PathUtil.CreateTempCopyFlexi(workDirectory, arguments.Template.Name);
                            }
                            //Build report
                            ReportData reportData;
                            if (arguments.Category != null && arguments.Tag != null)
                            {
                                reportData = new ReportData
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    ServerVersion    = CommonBLL.GetServiceVersion(connection),
                                    Applications     = _n_selectedApps,
                                    Category         = arguments.Category.Name,
                                    Tag                 = arguments.Tag.Name,
                                    Snapshots           = _n_selectedApps_snapshots,
                                    IgnoresApplications = _appsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = _snapsToIgnore,
                                    Parameter           = settings.ReportingParameter
                                };
                            }
                            else if (arguments.Category != null && arguments.Tag == null)
                            {
                                reportData = new ReportData
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    ServerVersion    = CommonBLL.GetServiceVersion(connection),
                                    Applications     = _n_selectedApps,
                                    Category         = arguments.Category.Name,
                                    Tag                 = null,
                                    Snapshots           = _n_selectedApps_snapshots,
                                    IgnoresApplications = _appsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = _snapsToIgnore,
                                    Parameter           = settings.ReportingParameter
                                };
                            }
                            else if (arguments.Category == null && arguments.Tag != null)
                            {
                                reportData = new ReportData
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    ServerVersion    = CommonBLL.GetServiceVersion(connection),
                                    Applications     = _n_selectedApps,
                                    Category         = null,
                                    Tag                 = arguments.Tag.Name,
                                    Snapshots           = _n_selectedApps_snapshots,
                                    IgnoresApplications = _appsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = _snapsToIgnore,
                                    Parameter           = settings.ReportingParameter
                                };
                            }
                            else
                            {
                                reportData = new ReportData
                                {
                                    FileName         = tmpReportFile,
                                    Application      = null,
                                    CurrentSnapshot  = null,
                                    PreviousSnapshot = null,
                                    RuleExplorer     = new RuleBLL(connection),
                                    CurrencySymbol   = "$",
                                    ServerVersion    = CommonBLL.GetServiceVersion(connection),
                                    Applications     = _n_selectedApps,
                                    Category         = null,
                                    Tag                 = null,
                                    Snapshots           = _n_selectedApps_snapshots,
                                    IgnoresApplications = _appsToIgnorePortfolioResult,
                                    IgnoresSnapshots    = _snapsToIgnore,
                                    Parameter           = settings.ReportingParameter
                                };
                            }

                            using (IDocumentBuilder docBuilder = BuilderFactory.CreateBuilder(reportData, tmpReportFile))
                            {
                                docBuilder.BuildDocument();
                            }
                            LogHelper.Instance.LogInfo("Report generated successfully");

                            //Set filte report
                            SetFileName(arguments);

                            reportPath = Path.Combine(string.IsNullOrEmpty(settings.ReportingParameter.GeneratedFilePath)
                                ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                                : settings.ReportingParameter.GeneratedFilePath, arguments.File.Name);

                            if (tmpReportFile.Contains(".xlsx"))
                            {
                                tmpReportFile = tmpReportFileFlexi;
                            }

                            ConvertToPdfIfNeeded(arguments, ref reportPath, tmpReportFile);
                        }
                        finally
                        {
                            if (!string.IsNullOrEmpty(tmpReportFile))
                            {
                                File.Delete(tmpReportFile);
                            }
                        }
                    }


                    return(reportPath);
                }
                catch (Exception ex)
                {
                    help = $"An exception occured : {ex}";
                    return(string.Empty);
                }
                finally
                {
                    if (!string.IsNullOrEmpty(tmpReportFile))
                    {
                        File.Delete(tmpReportFile);
                    }
                }
            }
            else
            {
                string tmpReportFile      = string.Empty;
                string tmpReportFileFlexi = string.Empty;

                try
                {
                    help = string.Empty;

                    //Get RG settings
                    var settings = SettingsBLL.GetSetting();
                    LogHelper.Instance.LogInfo("RG settings have been read successfully");

                    //Initialize temporary directory
                    string workDirectory = SettingsBLL.GetApplicationPath();
                    tmpReportFile = PathUtil.CreateTempCopy(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath, arguments.Template.Name));
                    if (tmpReportFile.Contains(".xlsx"))
                    {
                        tmpReportFileFlexi = PathUtil.CreateTempCopyFlexi(workDirectory, Path.Combine(settings.ReportingParameter.TemplatePath, arguments.Template.Name));
                    }
                    //Initialize Web services

                    var connection = new WSConnection(arguments.Webservice.Name, arguments.Username.Name, arguments.Password.Name, string.Empty)
                    {
                        ApiKey = arguments.ApiKey?.Name.Equals("true") ?? false
                    };
                    using (CommonBLL commonBLL = new CommonBLL(connection))
                    {
                        if (!commonBLL.CheckService())
                        {
                            help = $"Webservice can't be access or is bad formatted. Url:{arguments.Webservice.Name}";
                            return(string.Empty);
                        }
                    }
                    LogHelper.Instance.LogInfo("Web services Initialized successfully");


                    //Initialize Application
                    Domain.Application application = GetApplication(arguments, connection);
                    if (application == null)
                    {
                        help = arguments.Application != null ? $"Application {arguments.Application.Name} can't be found." : "Application not set in arguments.";
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo($"Application {arguments.Application.Name} Initialized successfully");

                    //Initialize snapshots
                    SetSnapshots(connection, application);
                    if (application.Snapshots == null)
                    {
                        help = "There is no snapshots for this application.";
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo($"List of Snapshots from {arguments.Application.Name} Initialized successfully");

                    //Build Application results
                    ApplicationBLL.BuildApplicationResult(connection, application);
                    LogHelper.Instance.LogInfo($"Application {arguments.Application.Name} results built successfully");


                    //Set current snapshot
                    Snapshot currentSnapshot = GetSnapshotOrDefault(arguments.Snapshot.Current, arguments.Snapshot.CurrentId, application.Snapshots, 0);
                    if (currentSnapshot == null)
                    {
                        help = $"Current snapshot {arguments.Snapshot.Current.Name} can't be found";
                        return(string.Empty);
                    }
                    LogHelper.Instance.LogInfo($"Current snapshot {currentSnapshot.Name} initialized successfully");

                    //Build current snapshot results
                    SnapshotBLL.BuildSnapshotResult(connection, currentSnapshot, true);
                    LogHelper.Instance.LogInfo($"Result of current snapshot {currentSnapshot.Name} built successfully");

                    //Set previous snapshot

                    Snapshot prevSnapshot = GetSnapshotOrDefault(arguments.Snapshot.Previous, arguments.Snapshot.PreviousId, application.Snapshots, -1);
                    if (prevSnapshot != null)
                    {
                        LogHelper.Instance.LogInfo($"Previous snapshot {prevSnapshot.Name} Initialized successfully");

                        //Build previous snapshot results
                        SnapshotBLL.BuildSnapshotResult(connection, prevSnapshot, false);
                        LogHelper.Instance.LogInfo($"Result of previous snapshot {prevSnapshot.Name}  built successfully");
                    }
                    else
                    {
                        if (arguments.Snapshot.Previous == null && arguments.Snapshot.PreviousId == null)
                        {
                            prevSnapshot = application.Snapshots.OrderByDescending(_ => _.Annotation.Date).Where(_ => _.Annotation.Date.DateSnapShot < currentSnapshot.Annotation.Date.DateSnapShot).ElementAtOrDefault(0);
                            if (prevSnapshot == null)
                            {
                                LogHelper.Instance.LogInfo("No Previous snapshot.");
                            }
                            else
                            {
                                SnapshotBLL.BuildSnapshotResult(connection, prevSnapshot, false);
                                LogHelper.Instance.LogInfo($"Result of previous snapshot {prevSnapshot.Name}  built successfully");
                            }
                        }
                        else
                        {
                            help = "Previous snapshot can't be found";
                            return(string.Empty);
                        }
                    }

                    //Build report
                    ReportData reportData = new ReportData
                    {
                        FileName         = tmpReportFile,
                        Application      = application,
                        CurrentSnapshot  = currentSnapshot,
                        PreviousSnapshot = prevSnapshot,
                        Parameter        = settings.ReportingParameter,
                        RuleExplorer     = new RuleBLL(connection),
                        SnapshotExplorer = new SnapshotBLL(connection, currentSnapshot),
                        CurrencySymbol   = "$",
                        ServerVersion    = CommonBLL.GetServiceVersion(connection)
                    };

                    using (IDocumentBuilder docBuilder = BuilderFactory.CreateBuilder(reportData, tmpReportFileFlexi))
                    {
                        docBuilder.BuildDocument();
                    }
                    LogHelper.Instance.LogInfo("Report generated successfully");

                    //Set filte report
                    SetFileName(arguments);

                    var reportPath = Path.Combine(string.IsNullOrEmpty(settings.ReportingParameter.GeneratedFilePath)
                        ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                        : settings.ReportingParameter.GeneratedFilePath, arguments.File.Name);

                    if (tmpReportFile.Contains(".xlsx"))
                    {
                        tmpReportFile = tmpReportFileFlexi;
                    }

                    ConvertToPdfIfNeeded(arguments, ref reportPath, tmpReportFile);

                    LogHelper.Instance.LogInfo("Report moved to generation directory successfully");

                    return(reportPath);
                }
                catch (Exception ex)
                {
                    help = $"An exception occured : {ex}";
                    return(string.Empty);
                }
                finally
                {
                    if (!string.IsNullOrEmpty(tmpReportFile))
                    {
                        File.Delete(tmpReportFile);
                    }
                }
            }
        }
示例#30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 public CastDomainBLL(WSConnection connection)
     : base(connection)
 {
 }