예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="application"></param>
 /// <returns></returns>
 private static void SetSnapshots(WSConnection connection, Domain.Application application)
 {
     using (ApplicationBLL applicationBLL = new ApplicationBLL(connection, application))
     {
         applicationBLL.SetSnapshots();
     }
 }
        public async Task <ApplicationModel> CreateAsync(ApplicationCreateCommand cmd)
        {
            var result = await ExecuteAsync <ApplicationCreateCommand, ApplicationCreateCommandValidator, ApplicationModel>(cmd, async() =>
            {
                // check to see if the application already exists by name
                var existingApp = Get <Domain.Application>(a => a.Name.ToLower().Equals(cmd.Name.ToLower()));

                // if the application exists just return it
                if (null != existingApp)
                {
                    return(ApplicationFactory.ConvertToModel(existingApp));
                }

                // create the application
                var app = new Domain.Application(name: cmd.Name,
                                                 apiKey: cmd.ApiKey,
                                                 createdByUserId: MessageContext.UserId);

                // save the application
                await Database.SaveAsync(app).ConfigureAwait(false);

                // convert the application to it's model
                var model = ApplicationFactory.ConvertToModel(app);

                // publish the domain event
                Publish(new ApplicationCreatedEvent(model, MessageContext));

                // return the application model
                return(model);
            }).ConfigureAwait(false);

            return(result);
        }
예제 #3
0
        public async Task <Domain.Application> SaveApplication(Domain.Application application)
        {
            var newApplication = _mapper.Map <ApplicationDocument>(application);

            await _context.Application.InsertOneAsync(newApplication);

            return(_mapper.Map <Domain.Application>(newApplication));
        }
예제 #4
0
        public async Task <Domain.Application> UpdateApplication(int applicationId, Domain.Application application)
        {
            var idToBeUpdated = await _context.Application.Find(e => e.Application == applicationId).Project(app => app.Id).SingleOrDefaultAsync();

            var applicationEdited = _mapper.Map <ApplicationDocument>(application);

            applicationEdited.Id = idToBeUpdated;

            var result = await _context.Application.ReplaceOneAsync(app => app.Application == applicationId, applicationEdited);

            return(_mapper.Map <Domain.Application>(applicationEdited));
        }
예제 #5
0
        internal static ApplicationModel ConvertToModel(Domain.Application data)
        {
            if (null == data)
            {
                return(null);
            }

            var model = MapBaseProperties <ApplicationModel>(data);

            model.Name   = data.Name;
            model.ApiKey = data.ApiKey;

            return(model);
        }
예제 #6
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);
                    }
                }
            }
        }