Ami2
Ami2
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
I'm currently grappling with an issue while merging two Excel workbooks (array1 and array2). The challenge arises when I add sheets from array2 to array1 using the following code:
private byte[] MergeExcelWorksheets(byte[] array1, byte[] array2)
{
using (MemoryStream ms1 = new MemoryStream(array1))
using (MemoryStream ms2 = new MemoryStream(array2))
using (ExcelPackage package1 = new ExcelPackage(ms1))
using (ExcelPackage package2 = new ExcelPackage(ms2))
{
var workbook1 = package1.Workbook;
var workbook2 = package2.Workbook;

// Iterate through sheets in workbook2
foreach (var sourceSheet in workbook2.Worksheets)
{
if (!workbook1.Worksheets.Any(sheet => sheet.Name == sourceSheet.Name))
{
var clonedSheet = workbook1.Worksheets.Add(sourceSheet.Name, sourceSheet);
}
}

return package1.GetAsByteArray();
}
}
private byte[] MergeExcelWorksheets(byte[] array1, byte[] array2)
{
using (MemoryStream ms1 = new MemoryStream(array1))
using (MemoryStream ms2 = new MemoryStream(array2))
using (ExcelPackage package1 = new ExcelPackage(ms1))
using (ExcelPackage package2 = new ExcelPackage(ms2))
{
var workbook1 = package1.Workbook;
var workbook2 = package2.Workbook;

// Iterate through sheets in workbook2
foreach (var sourceSheet in workbook2.Worksheets)
{
if (!workbook1.Worksheets.Any(sheet => sheet.Name == sourceSheet.Name))
{
var clonedSheet = workbook1.Worksheets.Add(sourceSheet.Name, sourceSheet);
}
}

return package1.GetAsByteArray();
}
}
- I'm trying to merge two Excel workbooks (array1 and array2), and while the sheets from array1 are created successfully, they seem to be empty when additional sheets from array2 are added. The perplexing part is that the sheets from array2 are being integrated correctly, but the corresponding sheets from array1 appear to lose their data.
11 replies
CC#
Created by Ami2 on 6/3/2023 in #help
❔ Adding Google External Login to ABP Framework 6
Hello, I am new to security and currently working on an app built on ABP Framework 6 (React Native, .NET 6 Web API). The app already has a default setup for JWT token authentication provided by ABP Framework 6. Now, I want to add Google external login functionality to the app. After some research, I have come up with the following solution:
public async Task<string> CreateGoogleExternalUserAsync([Required] string accessToken)
{
try
{
var validationSettings = new GoogleJsonWebSignature.ValidationSettings
{
Audience = new List<string> { _configuration["Authentication:Google:ClientId"] }
};
var payload = await GoogleJsonWebSignature.ValidateAsync(accessToken, validationSettings);
var email = payload.Email;

// Create an account in your app using the retrieved information

// Generate JWT token

// Return the generated JWT token
}
catch (InvalidJwtException)
{
// Handle invalid access token
throw new AbpAuthorizationException();
}
}
public async Task<string> CreateGoogleExternalUserAsync([Required] string accessToken)
{
try
{
var validationSettings = new GoogleJsonWebSignature.ValidationSettings
{
Audience = new List<string> { _configuration["Authentication:Google:ClientId"] }
};
var payload = await GoogleJsonWebSignature.ValidateAsync(accessToken, validationSettings);
var email = payload.Email;

// Create an account in your app using the retrieved information

// Generate JWT token

// Return the generated JWT token
}
catch (InvalidJwtException)
{
// Handle invalid access token
throw new AbpAuthorizationException();
}
}
I have a couple of problems with this approach and would appreciate your help in addressing them: 1. JWT Generation: In the given code snippet, I need assistance in understanding whether I should generate a JWT token in this method or if there is a different approach I should follow. 2. Usage of ABP Framework 6 Tables: While exploring the database schema used by ABP Framework 6, I noticed the existence of tables like AbpUserLogins with a column named LoginProvider. I'm unsure whether I need to utilize any of these tables for the external login functionality. 3. Authentication Flow: I'm not sure if the reactive should initiate the authentication flow, get the access token, and send it to the backend, or if it should be the other way around. Could you please clarify the recommended approach for handling the authentication flow in this scenario?
2 replies
CC#
Created by Ami2 on 5/8/2023 in #help
❔ Calculating reading duration percentages for different time periods
I'm working on a project where I need to calculate the reading duration percentages for different time periods based on user reading data. The time periods include dawn, night, evening, morning, and afternoon. I have the start and end times for each reading session, and I want to determine the percentage of reading time spent in each period. I've already defined the time ranges for each period (e.g., dawn from 4:30am to 5:30am, night from 9pm onwards), and I need help with the logic to calculate the percentages. Additionally, there are cases where a reading session may span multiple periods (e.g., morning and afternoon). I'm using .NET 6 linq, and any guidance or code snippets on how to approach this calculation would be greatly appreciated.
var downStart = new TimeSpan(4, 30, 0); //4:30am
var morningStart = new TimeSpan(5, 30, 0); // 5:30am
var afternoonStart = new TimeSpan(12, 0, 0); // 12pm
var eveningStart = new TimeSpan(16, 0, 0); // 4pm
var nightStart = new TimeSpan(19, 0, 0); // 9pm
var downStart = new TimeSpan(4, 30, 0); //4:30am
var morningStart = new TimeSpan(5, 30, 0); // 5:30am
var afternoonStart = new TimeSpan(12, 0, 0); // 12pm
var eveningStart = new TimeSpan(16, 0, 0); // 4pm
var nightStart = new TimeSpan(19, 0, 0); // 9pm
public class ReadingSession
{
public DateTime StartAt {get;set;}
public DateTime EndAt {get;set;}
}
public class ReadingSession
{
public DateTime StartAt {get;set;}
public DateTime EndAt {get;set;}
}
3 replies