private void UploadPublications() { FileType publicationsFileType = FileTypeBLL.GetByName(STR_Publication); Application application = selectedApplication; File file = FileBLL.SavePDF(fileUpload, publicationsFileType); using (var ts = new TransactionScope()) { if (file != null) { application.Files.Add(file); ApplicationBLL.EnsurePersistent(application); lblStatus.Text = "File Uploaded Successfully"; } else { lblStatus.Text = "File Upload Did Not Succeed: Ensure That File Is A PDF File"; } ts.CommitTransaction(); } rptPublications.DataSource = GetFilesOfType(STR_Publication); rptPublications.DataBind(); }
public IApplication Create(string appId, string customerId, string customerName, string customerSex, string customerPhone, string customerAddress, string region, DateTime?dateApplied, DateTime?dateTraved, string offNoteNo, DateTime?offNoteDate, string remark) { ICustomer customer; if (CustomerBLL.IsExisting(customerId)) { customer = CustomerBLL.Get(customerId); customer = CustomerBLL.Update(customer, customerId, customerName, customerSex, customerPhone, customerAddress); } else { customer = CustomerBLL.Create(customerId, customerName, customerSex, customerPhone, customerAddress); } IApplication app = ApplicationBLL.Create(appId, customer.ID, region, dateApplied, dateTraved, offNoteNo, offNoteDate, remark); IStatus status = StatusBLL.Create(appId, JobStatus.None.ToLabel()); return(app); }
protected void ibtnPublicationsRemoveFile_Click(object sender, EventArgs e) { int FileID = 0; bool success = false; success = int.TryParse(((ImageButton)sender).CommandArgument, out FileID); if (success) { File fileToDelete = FileBLL.GetByID(FileID); using (var ts = new TransactionScope()) { FileBLL.DeletePDF(fileToDelete); //Update the current application Application application = selectedApplication; application.Files.Remove(fileToDelete); ApplicationBLL.EnsurePersistent(application); ts.CommitTransaction(); } } rptPublications.DataSource = GetFilesOfType(STR_Publication); rptPublications.DataBind(); }
public override void LoadData() { base.LoadData(); //Add some applications Profile profile = ProfileBLL.GetByID(StaticProperties.ExistingProfileID); Application application = new Application(); application.AppliedPosition = PositionBLL.GetByID(StaticProperties.ExistingPositionID); application.AssociatedProfile = profile; application.Email = StaticProperties.ExistingApplicantEmail; application.LastUpdated = DateTime.Now; profile.Applications = new List <Application> { application }; using (var ts = new TransactionScope()) { ApplicationBLL.EnsurePersistent(application); ProfileBLL.EnsurePersistent(profile); ts.CommitTransaction(); } }
private void createProfileForUser(string email) { Applicant newUser = ApplicationBLL.GetByEmail(email); if (newUser == null) { Response.Redirect(RecruitmentConfiguration.ErrorPage(RecruitmentConfiguration.ErrorType.AUTH)); return; } //Create a blank profile for the logged in user Profile blankProfile = new Profile(); blankProfile.AssociatedApplicant = newUser; blankProfile.FirstName = string.Empty; blankProfile.LastName = string.Empty; blankProfile.Address1 = string.Empty; blankProfile.City = string.Empty; blankProfile.State = string.Empty; blankProfile.LastUpdated = null; using (var ts = new TransactionScope()) { ProfileBLL.EnsurePersistent(blankProfile); ts.CommitTransaction(); } }
private void UploadFiles() { FileType selectedFileType = FileTypeBLL.GetByID(int.Parse(dlistFileTypes.SelectedValue)); //For all fileTypes except for Publications we should remove existing files if (selectedFileType.FileTypeName != STR_Publication && selectedFileType.FileTypeName != STR_LetterOfRec) { RemoveAllFilesOfType(selectedFileType.FileTypeName); } File file = FileBLL.SavePDF(fileUpload, selectedFileType); using (var ts = new TransactionScope()) { if (file != null) { Application application = selectedApplication; application.Files.Add(file); ApplicationBLL.EnsurePersistent(application); lblStatus.Text = "File Uploaded Successfully"; } else { lblStatus.Text = "File Upload Did Not Succeed: Ensure That File Is A PDF File"; } ts.CommitTransaction(); } }
/// <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 ApplicationManager() { ApplicationBLL = new ApplicationBLL(); CustomerBLL = new CustomerBLL(); CaseBLL = new CaseBLL(); CollectionBLL = new CollectionBLL(); StatusBLL = new StatusBLL(); }
public IApplication Update(IApplication item, string appId, ICustomer customer, string customerId, string customerName, string customerSex, string customerPhone, string customerAddress, string region, DateTime?dateApplied, DateTime?dateTraved, string offNoteNo, DateTime?offNoteDate, string remark) { if (!CustomerBLL.IsExisting(customerId)) { customer = CustomerBLL.Create(customerId, customerName, customerSex, customerPhone, customerAddress); } customer = CustomerBLL.Update(customer, customerId, customerName, customerSex, customerPhone, customerAddress); return(ApplicationBLL.Update(item, appId, customer.ID, region, dateApplied, dateTraved, offNoteNo, offNoteDate, remark)); }
/* * /// <summary> * /// Implement Command that Load the templates list of Portfolio * /// </summary> * private void ExecuteLoadTemplatesPortfolioCommand(object parameter) * { * TemplateFiles = SettingsBLL.GetTemplateFileListPortfolio(); * } */ /// <summary> /// Implement Command that Load the current snapshots list /// </summary> private void ExecuteLoadSnapshotsCommand(object parameter) { if (SelectedApplication != null) { using (ApplicationBLL applicationBLL = new ApplicationBLL(ActiveConnection, SelectedApplication.Application)) { applicationBLL.SetSnapshots(); Snaphosts = SelectedApplication.Application.Snapshots.OrderByDescending(_ => _.Annotation.Date.DateSnapShot).ToList(); } } else { Snaphosts = null; } }
public DataTable GetSource(IDictionary <IAttributeDefinition, object> criterias, PagingSetting pagingSetting) { int pageNum = pagingSetting.PageNum; int pageCount = pagingSetting.PageCount; int itemCount = pagingSetting.ItemCount; IList <IApplication> items = ApplicationBLL.GetAllPaged(criterias, ref pageNum, ref pageCount, pagingSetting.PageSize, ref itemCount); pagingSetting.PageNum = pageNum; pagingSetting.PageCount = pageCount; pagingSetting.ItemCount = itemCount; var od = AppCore.AppSingleton.FindObjDef <ApplicationObjDef>(); DataTable source = new DataTable("ApplicaitonList"); source.Columns.AddRange(new DataColumn[] { new DataColumn(od.ID.Name, typeof(System.String)), new DataColumn(od.Type.Name, typeof(System.String)), new DataColumn(od.SubType.Name, typeof(System.String)), new DataColumn(od.CustomerID.Name, typeof(System.String)), new DataColumn(od.CustomerName.Name, typeof(System.String)), new DataColumn(od.CustomerSex.Name, typeof(System.String)), new DataColumn(od.Region.Name, typeof(System.String)), new DataColumn(od.DateApplied.Name, typeof(System.String)), new DataColumn(AppCore.AppSingleton.FindObjDef <StatusObjDef>().Value.Name, typeof(System.String)), }); foreach (IApplication item in items) { source.Rows.Add(new object[] { item.ID, item.Type, item.SubType, item.CustomerID, item.CustomerName, item.CustomerSex, item.Region, item.DateApplied, item.Status == null?JobStatus.None.ToLabel():item.Status.Value }); } return(source); }
/// <summary> /// Send an email to the checked applicants based on whatever template is currently selected (in txtEmailTemplate) /// </summary> protected void btnSendTemplate_Click(object sender, EventArgs e) { StringBuilder errorEmails = new StringBuilder(); var bccAddress = txtBccAddress.Text; //Go through each of the applications foreach (var row in lviewApplications.Items) { CheckBox cEmail = (CheckBox)row.FindControl("chkEmailApplicant"); if (cEmail.Checked) //Should we send to this applicant? { //Get the user and email them int userID = (int)lviewApplications.DataKeys[row.DataItemIndex]["id"]; Application selectedApplication = ApplicationBLL.GetByID(userID); var bodyFromTemplate = new TemplateProcessing().ProcessTemplate(null, selectedApplication, txtEmailTemplate.Text, false); bool success = MessageBLL.SendMessage(WebConfigurationManager.AppSettings["emailFromEmail"], selectedApplication.Email, bccAddress, "UC Davis Recruitment Message", bodyFromTemplate); if (success == false) { errorEmails.AppendFormat("{0}, ", selectedApplication.Email); } } } //Notify the user of the message results if (errorEmails.Length != 0) { errorEmails.Remove(errorEmails.Length - 2, 2); lblSentEmail.Text = string.Format("Could not send email to the following address(es): {0}", errorEmails.ToString()); } else { lblSentEmail.Text = "Email(s) sent successfully"; } }
/// <summary> /// Creates an application on behalf of the currently logged in user, then /// redirects to that application /// </summary> /// <remarks>Checks to make sure the logged in user has an applicant account</remarks> protected void btnPositionApply_Click(object sender, EventArgs e) { Applicant loggedInUser = ApplicantBLL.GetCurrent(); //Make sure the loggedInUser has an Applicant account if (loggedInUser == null) { Trace.Warn("Not Logged Is As Member"); FormsAuthentication.SignOut(); //Causes the user to sign out and redirect FormsAuthentication.RedirectToLoginPage(Request.Url.AbsolutePath); //Make the user log in return; } //If the applicant already has an application for this position, redirect to the app page foreach (Application app in loggedInUser.MainProfile.Applications) { if (app.AppliedPosition == currentPosition) { Response.Redirect(string.Format("{0}?ApplicationID={1}", "Applicant/App.aspx", app.ID)); } } //Now we have a valid applicant, so create the application Application newApplication = new Application(); newApplication.AppliedPosition = currentPosition; newApplication.AssociatedProfile = loggedInUser.MainProfile; newApplication.Email = loggedInUser.Email; newApplication.LastUpdated = DateTime.Now; using (var ts = new TransactionScope()) { //Now save the new application get get back the ID ApplicationBLL.EnsurePersistent(newApplication); ts.CommitTransaction(); } //Redirect to the newly created application Response.Redirect(string.Format("{0}?ApplicationID={1}", "Applicant/App.aspx", newApplication.ID.ToString())); }
protected void dlistApplications_SelectedIndexChanged(object sender, EventArgs e) { int applicationID = 0; if (!int.TryParse(dlistApplications.SelectedValue, out applicationID)) { gViewReferences.Visible = false; btnUpdateList.Visible = false; reqValApplications.Validate(); return; //Return if the selected value is not a valid applicationID } Application currentApplication = ApplicationBLL.GetByID(applicationID); gViewReferences.DataSource = currentApplication.References; gViewReferences.DataBind(); gViewReferences.Visible = true; //Show the references grid btnUpdateList.Visible = gViewReferences.Rows.Count > 0; }
protected void btnUpdateList_Click(object sender, EventArgs e) { using (var ts = new TransactionScope()) { foreach (var row in lviewApplications.Items) { int applicationID = (int)lviewApplications.DataKeys[row.DataItemIndex]["id"]; Application app = ApplicationBLL.GetByID(applicationID); app.InterviewList = ((CheckBox)row.FindControl("chkShortList")).Checked; app.GetReferences = ((CheckBox)row.FindControl("chkReferences")).Checked; app.NoConsideration = ((CheckBox)row.FindControl("chkNoConsideration")).Checked; ApplicationBLL.EnsurePersistent(app); } ts.CommitTransaction(); } lblResult.Text = "Application List Updated"; lviewReferencesToBeNotified.DataBind(); }
/// <summary> /// Removes all files of the given type from the current applicaiton. This removes the files themselves, /// the file info entry and the application files link /// </summary> private void RemoveAllFilesOfType(string fileTypeName) { List <File> existingFiles = GetFilesOfType(fileTypeName); Application application = selectedApplication; if (existingFiles.Count != 0) { using (var ts = new TransactionScope()) { foreach (File existingFile in existingFiles) { application.Files.Remove(existingFile); FileBLL.DeletePDF(existingFile); } ApplicationBLL.EnsurePersistent(application); ts.CommitTransaction(); } } }
public IApplication Delete(string id) { IApplication app = ApplicationBLL.Get(id); if (app != null) { app = ApplicationBLL.Delete(app); } ICase c = CaseBLL.Get(id); if (c != null) { c = CaseBLL.Delete(c); } ICollection col = CollectionBLL.Get(id); if (col != null) { col = CollectionBLL.Delete(col); } return(app); }
public void Dispose() { _caseBLL = null; _applicationBLL = null; StatusBLL = null; }
public CaseManager() { _caseBLL = new CaseBLL(); _applicationBLL = new ApplicationBLL(); StatusBLL = new StatusBLL(); }
public IApplication GetById(string id) { return(ApplicationBLL.Get(id)); }
public override void LoadData() { base.LoadData(); var application = ApplicationBLL.GetByID(StaticProperties.ExistingApplicationID); //Add some applications info CurrentPosition currentPosition = new CurrentPosition { Address1 = StaticProperties.TestString, City = StaticProperties.TestString, Country = StaticProperties.TestString, Department = StaticProperties.TestString, Institution = StaticProperties.TestString, Title = StaticProperties.TestString, Zip = StaticProperties.TestString, State = StaticProperties.TestString, ApplicationStepType = ApplicationStepType.CurrentPosition, AssociatedApplication = application }; Education education = new Education { ApplicationStepType = ApplicationStepType.Education, AssociatedApplication = application, Date = DateTime.Now, Discipline = StaticProperties.TestString, Institution = StaticProperties.TestString }; Reference reference = new Reference { AssociatedApplication = application }; Survey survey = new Survey { AssociatedApplication = application, Other = StaticProperties.TestString }; File file = new File { FileName = StaticProperties.TestString, }; FileType fileType = new FileType { ApplicationFile = true, FileTypeName = StaticProperties.TestString }; file.FileType = fileType; using (var ts = new TransactionScope()) { FileTypeBLL.EnsurePersistent(fileType); FileBLL.EnsurePersistent(file); application.CurrentPositions = new List <CurrentPosition> { currentPosition }; application.Education = new List <Education> { education }; application.References = new List <Reference> { reference }; application.Surveys = new List <Survey> { survey }; application.Files = new List <File> { file }; ApplicationBLL.EnsurePersistent(application); ts.CommitTransaction(); } }
public CollectionManager() { _collectionBLL = new CollectionBLL(); _applicationBLL = new ApplicationBLL(); }
/// <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); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { if (SelectedTab == 0) { const double progressStep = 25; // 100 / 4 Stopwatch stopWatchStep = new Stopwatch(); Stopwatch stopWatchGlobal = new Stopwatch(); try { stopWatchGlobal.Start(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(MessageManager.SetBusyMode), true); //Set culture for the new thread if (!string.IsNullOrEmpty(Setting.ReportingParameter.CultureName)) { var culture = new CultureInfo(Setting.ReportingParameter.CultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } //Get result for the Application stopWatchStep.Restart(); ApplicationBLL.BuildApplicationResult(ActiveConnection, SelectedApplication.Application); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgBuildApplicationResult, stopWatchStep.Elapsed); //Get result for the previous snapshot stopWatchStep.Restart(); SnapshotBLL.BuildSnapshotResult(ActiveConnection, SelectedSnapshot, true); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgBuildSnapshotResult, stopWatchStep.Elapsed); //Get result for the previuos snapshot if (PreviousSnapshot != null) { stopWatchStep.Restart(); SnapshotBLL.BuildSnapshotResult(ActiveConnection, PreviousSnapshot, false); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgBuildPreviousSnapshotResult, stopWatchStep.Elapsed); } //Launch generaion stopWatchStep.Restart(); GenerateReport(); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgReportGenerated, stopWatchStep.Elapsed); //Show final message and unlock the screen stopWatchGlobal.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <string, TimeSpan>(MessageManager.OnReportGenerated), ReportFileName, stopWatchGlobal.Elapsed); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(MessageManager.SetBusyMode), false); } catch (Exception ex) { System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <CastReportingException>(WorkerThreadException), ex); } } else { const double progressStep = 25; //100 / 4; Stopwatch stopWatchStep = new Stopwatch(); Stopwatch stopWatchGlobal = new Stopwatch(); List <Application> Apps = new List <Application>(); List <Snapshot> Snapshots = new List <Snapshot>(); try { stopWatchGlobal.Start(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(MessageManager.SetBusyMode), true); //GetActive Connection ActiveConnection = Setting?.GetActiveConnection(); //Get list of domains if (_ActiveConnection != null) { try { using (CastDomainBLL castDomainBLL = new CastDomainBLL(ActiveConnection)) { Apps = castDomainBLL.GetCommonTaggedApplications(SelectedTag); } } catch (Exception ex) { MessageManager.OnErrorOccured(ex); } } if (Apps == null) { return; } if (Apps.Count > 0) { Application[] SelectedApps = Apps.ToArray <Application>(); //Set culture for the new thread if (!string.IsNullOrEmpty(Setting?.ReportingParameter.CultureName)) { var culture = new CultureInfo(Setting.ReportingParameter.CultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } string[] SnapsToIgnore = null; //Get result for the Portfolio stopWatchStep.Restart(); string[] AppsToIgnorePortfolioResult = PortfolioBLL.BuildPortfolioResult(ActiveConnection, SelectedApps); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgBuildPortfolioResults, stopWatchStep.Elapsed); List <Application> N_Apps = new List <Application>(); //Remove from Array the Ignored Apps foreach (Application app in SelectedApps) { int intAppYes = 0; foreach (string s in AppsToIgnorePortfolioResult) { if (s == app.Name) { intAppYes = 1; break; } intAppYes = 0; } if (intAppYes == 0) { N_Apps.Add(app); } } Application[] N_SelectedApps = N_Apps.ToArray(); //GetActive Connection ActiveConnection = Setting?.GetActiveConnection(); //Get list of domains if (_ActiveConnection != null) { try { using (CastDomainBLL castDomainBLL = new CastDomainBLL(ActiveConnection)) { Snapshots = castDomainBLL.GetAllSnapshots(N_SelectedApps); } } catch (Exception ex) { MessageManager.OnErrorOccured(ex); } } List <Snapshot> N_Snaps = new List <Snapshot>(); //Get result for each app's latest snapshot if (Snapshots != null) { Snapshot[] SelectedApps_Snapshots = Snapshots.ToArray <Snapshot>(); //Get result for all snapshots in Portfolio stopWatchStep.Restart(); SnapsToIgnore = PortfolioSnapshotsBLL.BuildSnapshotResult(ActiveConnection, SelectedApps_Snapshots, true); stopWatchStep.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgBuildPortfSnapshotsResults, stopWatchStep.Elapsed); foreach (Snapshot snap in SelectedApps_Snapshots) { int intRemoveYes = 0; foreach (string s in SnapsToIgnore) { if (s == snap.Href) { intRemoveYes = 1; break; } intRemoveYes = 0; } if (intRemoveYes == 0) { N_Snaps.Add(snap); } } Snapshot[] N_SelectedApps_Snapshots = N_Snaps.ToArray(); //Launch generaion stopWatchStep.Restart(); GenerateReportPortfolio(N_SelectedApps, N_SelectedApps_Snapshots, AppsToIgnorePortfolioResult, SnapsToIgnore); stopWatchStep.Stop(); } System.Text.StringBuilder sb = new System.Text.StringBuilder(); if ((AppsToIgnorePortfolioResult.Length > 0) || (SnapsToIgnore?.Length > 0)) { sb.Append(Messages.msgIgnoredAppSnaps); if (AppsToIgnorePortfolioResult.Length > 0) { AppsToIgnorePortfolioResult = AppsToIgnorePortfolioResult.Distinct().ToArray(); sb.Append(Messages.msgIgnoredApplications + " "); for (int i = 0; i < AppsToIgnorePortfolioResult.Length; i++) { if (i == 0) { sb.Append(AppsToIgnorePortfolioResult[i]); } else { sb.Append("," + AppsToIgnorePortfolioResult[i]); } } } if (SnapsToIgnore?.Length > 0) { SnapsToIgnore = SnapsToIgnore.Distinct().ToArray(); sb.Append(Messages.msgIgnoredSnapshots + " "); for (int i = 0; i < SnapsToIgnore.Length; i++) { if (i == 0) { sb.Append(_ActiveConnection?.Url + "/" + SnapsToIgnore[i]); } else { sb.Append("," + _ActiveConnection?.Url + "/" + SnapsToIgnore[i]); } } } System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, sb + "", null); } System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgReportGenerated, stopWatchStep.Elapsed); //Show final message and unlock the screen stopWatchGlobal.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <string, TimeSpan>(MessageManager.OnReportGenerated), ReportFileName, stopWatchGlobal.Elapsed); } else { //Show final message and unlock the screen stopWatchGlobal.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgErrorGeneratingReport + " - " + Messages.msgReportErrorNoAAD, stopWatchGlobal.Elapsed); } System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(MessageManager.SetBusyMode), false); } catch (System.Net.WebException webEx) { LogHelper.Instance.LogErrorFormat ("Request URL '{0}' - Error execution : {1}" , "" , webEx.Message ); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(MessageManager.OnStepDone), progressStep, Messages.msgErrorGeneratingReport + " - " + webEx.Message + " - " + Messages.msgReportErrorNoRestAPI, stopWatchStep.Elapsed); stopWatchGlobal.Stop(); System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(MessageManager.SetBusyMode), false); } catch (Exception ex) { System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <CastReportingException>(WorkerThreadException), ex); } } }
/// <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); } } } }
public void Dispose() { _collectionBLL = null; _applicationBLL = null; }
/// <summary> /// Create a new user. /// </summary> /// <param name="username">User name.</param> /// <param name="password">Password.</param> /// <param name="email">Email address.</param> /// <param name="passwordQuestion">Security quesiton for password.</param> /// <param name="passwordAnswer">Security quesiton answer for password.</param> /// <param name="isApproved"></param> /// <param name="userID">User ID</param> /// <param name="status"></param> /// <returns>MembershipUser</returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { UserBLL userBLL = new UserBLL(); ApplicationBLL applicationBLL = new ApplicationBLL(); ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args.Cancel) { status = MembershipCreateStatus.InvalidPassword; return(null); } MembershipUser membershipUser = GetUser(username, false); if (membershipUser == null) { try { User creator = userBLL.GetUserByUserName(HttpContext.Current.User.Identity.Name); User user = new User(); user.UserID = Guid.NewGuid(); user.UserName = username; user.Password = EncodePassword(password); user.PasswordQuestion = passwordQuestion; user.PasswordAnswer = EncodePassword(passwordAnswer); user.IsApproved = isApproved; user.IsLockedOut = false; user.IsChangePassword = false; user.LastLoginDate = DateTime.Now; user.LastActivityDate = DateTime.Now; user.LastPasswordChangedDate = DateTime.Now; user.LastLockedOutDate = DateTime.Now; user.FailedPasswordAnswerAttemptCount = 0; user.FailedPasswordAnswerAttemptWindowStart = DateTime.Now; user.FailedPasswordAttemptCount = 0; user.FailedPasswordAttemptWindowStart = DateTime.Now; user.CreatedDate = DateTime.Now; user.CreatorUserID = creator.UserID; user.EditedDate = DateTime.Now; user.EditorUserID = creator.UserID; Guid ret = default(Guid); ret = userBLL.CreateNewUser(user); Application currentApplication = applicationBLL.GetApplicationByApplicationName(applicationName); if (currentApplication == null) // If Application does not exists create it { currentApplication.ApplicationName = applicationName; applicationBLL.CreateNewApplication(currentApplication); } if (ret != default(Guid)) { status = MembershipCreateStatus.Success; } else { status = MembershipCreateStatus.UserRejected; } } catch (SqlException e) { //Add exception handling here. status = MembershipCreateStatus.ProviderError; } return(GetUser(username, false)); } else { status = MembershipCreateStatus.DuplicateUserName; } return(null); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { if (SelectedTab == 0) { double progressStep = 100 / 4; Stopwatch stopWatchStep = new Stopwatch(); Stopwatch stopWatchGlobal = new Stopwatch(); try { stopWatchGlobal.Start(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(base.MessageManager.SetBusyMode), true); //Set culture for the new thread if (!string.IsNullOrEmpty(Setting.ReportingParameter.CultureName)) { var culture = new CultureInfo(Setting.ReportingParameter.CultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } //Get result for the Application stopWatchStep.Restart(); ApplicationBLL.BuildApplicationResult(ActiveConnection, SelectedApplication); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Build result for the application", stopWatchStep.Elapsed); //Get result for the previous snapshot stopWatchStep.Restart(); SnapshotBLL.BuildSnapshotResult(ActiveConnection, SelectedSnapshot, true); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Build result for the selected snapshot", stopWatchStep.Elapsed); //Get result for the previuos snapshot if (PreviousSnapshot != null) { stopWatchStep.Restart(); SnapshotBLL.BuildSnapshotResult(ActiveConnection, PreviousSnapshot, false); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Build result for the previous snapshot", stopWatchStep.Elapsed); } //Launch generaion stopWatchStep.Restart(); GenerateReport(); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Report generated", stopWatchStep.Elapsed); //Show final message and unlock the screen stopWatchGlobal.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <string, TimeSpan>(base.MessageManager.OnReportGenerated), ReportFileName, stopWatchGlobal.Elapsed); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(base.MessageManager.SetBusyMode), false); } catch (Exception ex) { App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <Exception>(WorkerThreadException), ex); } } else { List <Application> Apps = new List <Application>(); List <Snapshot> Snapshots = new List <Snapshot>(); //if (SelectedTag != null) //{ //GetActive Connection ActiveConnection = (Setting != null) ? Setting.GetActiveConnection() : null; //Get list of domains if (_ActiveConnection != null) { try { using (CastDomainBLL castDomainBLL = new CastDomainBLL(ActiveConnection)) { Apps = castDomainBLL.GetCommonTaggedApplications(SelectedTag); } } catch (Exception ex) { base.MessageManager.OnErrorOccured(ex); } } if (Apps != null) { Application[] SelectedApps = Apps.ToArray <Application>(); double progressStep = 100 / 4; Stopwatch stopWatchStep = new Stopwatch(); Stopwatch stopWatchGlobal = new Stopwatch(); try { stopWatchGlobal.Start(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(base.MessageManager.SetBusyMode), true); //Set culture for the new thread if (!string.IsNullOrEmpty(Setting.ReportingParameter.CultureName)) { var culture = new CultureInfo(Setting.ReportingParameter.CultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } string[] SnapsToIgnore = null; //Get result for the Portfolio stopWatchStep.Restart(); string[] AppsToIgnorePortfolioResult = PortfolioBLL.BuildPortfolioResult(ActiveConnection, SelectedApps); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Build result for the portfolio", stopWatchStep.Elapsed); 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(); //GetActive Connection ActiveConnection = (Setting != null) ? Setting.GetActiveConnection() : null; //Get list of domains if (_ActiveConnection != null) { try { using (CastDomainBLL castDomainBLL = new CastDomainBLL(ActiveConnection)) { Snapshots = castDomainBLL.GetAllSnapshots(N_SelectedApps); } } catch (Exception ex) { base.MessageManager.OnErrorOccured(ex); } } List <Snapshot> N_Snaps = new List <Snapshot>(); //Get result for each app's latest snapshot if (Snapshots != null) { Snapshot[] SelectedApps_Snapshots = Snapshots.ToArray <Snapshot>(); //Get result for all snapshots in Portfolio stopWatchStep.Restart(); SnapsToIgnore = PortfolioSnapshotsBLL.BuildSnapshotResult(ActiveConnection, SelectedApps_Snapshots, true); stopWatchStep.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Build result for snapshots in portfolio", stopWatchStep.Elapsed); 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(); //Launch generaion stopWatchStep.Restart(); GenerateReportPortfolio(N_SelectedApps, N_SelectedApps_Snapshots, AppsToIgnorePortfolioResult, SnapsToIgnore); stopWatchStep.Stop(); } System.Text.StringBuilder sb = new System.Text.StringBuilder(); if ((AppsToIgnorePortfolioResult.Count() > 0 && AppsToIgnorePortfolioResult != null) || (SnapsToIgnore.Count() > 0 && SnapsToIgnore != null)) { sb.Append("Some Applications or Snapshots were ignored during processing REST API."); if (AppsToIgnorePortfolioResult.Count() > 0 && AppsToIgnorePortfolioResult != null) { AppsToIgnorePortfolioResult = AppsToIgnorePortfolioResult.Distinct().ToArray(); sb.Append("Ignored Applications are: "); for (int i = 0; i < AppsToIgnorePortfolioResult.Count(); i++) { if (i == 0) { sb.Append(AppsToIgnorePortfolioResult[i].ToString()); } else { sb.Append("," + AppsToIgnorePortfolioResult[i].ToString()); } } } if (SnapsToIgnore.Count() > 0 && SnapsToIgnore != null) { SnapsToIgnore = SnapsToIgnore.Distinct().ToArray(); sb.Append(" Ignored Snapshots are: "); for (int i = 0; i < SnapsToIgnore.Count(); i++) { if (i == 0) { sb.Append(_ActiveConnection.Url + "/" + SnapsToIgnore[i].ToString()); } else { sb.Append("," + _ActiveConnection.Url + "/" + SnapsToIgnore[i].ToString()); } } } App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, sb.ToString() + "", null); } App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Report generated", stopWatchStep.Elapsed); //Show final message and unlock the screen stopWatchGlobal.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <string, TimeSpan>(base.MessageManager.OnReportGenerated), ReportFileName, stopWatchGlobal.Elapsed); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(base.MessageManager.SetBusyMode), false); } catch (System.Net.WebException webEx) { LogHelper.Instance.LogErrorFormat ("Request URL '{0}' - Error execution : {1}" , "" , webEx.Message ); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <double, string, TimeSpan>(base.MessageManager.OnStepDone), progressStep, "Error Generating Report - " + webEx.Message + " - Typically happens when Report Generator does not find REST API (in schema)", stopWatchStep.Elapsed); stopWatchGlobal.Stop(); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <bool>(base.MessageManager.SetBusyMode), false); } catch (Exception ex) { App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action <Exception>(WorkerThreadException), ex); } } } }