Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work when publishe with AoT option #246

Open
R0CH1TV opened this issue Sep 11, 2024 · 0 comments
Open

Doesn't work when publishe with AoT option #246

R0CH1TV opened this issue Sep 11, 2024 · 0 comments

Comments

@R0CH1TV
Copy link

R0CH1TV commented Sep 11, 2024

Description:
Works fine when you run from visual studio (Release/Debug) mode, but when you try to call Mega function after published with AoT profile just fails

what are you trying to do

*Snippet from code

using CG.Web.MegaApiClient;

public static void UploadToMegaWithProgress(string zipFilePath, int mode)
{
string zipFileName = Path.GetFileName(zipFilePath);
string uploadDirectoryName = mode == 0 ? memoryDumpDirectory : crashReportDirectory;

 MegaApiClient client = new MegaApiClient();
 client.Login(megaEmail, megaPassword);

 INode root = client.GetNodes().Single(n => n.Type == NodeType.Root);

 INode uploadDirectory = EnsureDirectoryExists(client, root, uploadDirectoryName);

 using (var fileStream = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 32 * 1024))
 {
     long totalBytes = fileStream.Length;
     long uploadedBytes = 0;
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();

     int lastUpdate = 0;
     int progressLinesStart = Console.CursorTop;
     bool uploadComplete = false;


     client.UploadAsync(fileStream, zipFileName, uploadDirectory, null, null, CancellationToken.None).Wait();

     uploadedBytes = fileStream.Length;

     double percentage = Math.Min((double)uploadedBytes / totalBytes * 100, 100);
     double speed = uploadedBytes / stopwatch.Elapsed.TotalSeconds;

     TimeSpan timeElapsed = stopwatch.Elapsed;
     double timeLeftSeconds = (totalBytes - uploadedBytes) / speed;
     TimeSpan timeLeft = TimeSpan.FromSeconds(timeLeftSeconds);

     string timeElapsedFormatted = string.Format("{0:D2}:{1:D2}:{2:D2}", timeElapsed.Hours, timeElapsed.Minutes, timeElapsed.Seconds);
     string timeLeftFormatted = string.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);

     string progressBar = GenerateProgressBar(percentage, 25);
     string formattedSpeed = FormatBytes(speed) + "/s";
     string formattedUploaded = FormatBytes(uploadedBytes);
     string formattedTotal = FormatBytes(totalBytes);

     string secondLine = $"[{progressBar}] {percentage:F2}%";
     string thirdLine = $"{formattedUploaded} / {formattedTotal} - {formattedSpeed}";
     string fourthLine = $"Time Elapsed: {timeElapsedFormatted} - Time Left: {timeLeftFormatted}";

     Console.SetCursorPosition(0, progressLinesStart + 1);
     Console.Write(secondLine.PadRight(Console.WindowWidth));
     Console.SetCursorPosition(0, progressLinesStart + 2);
     Console.Write(thirdLine.PadRight(Console.WindowWidth));
     Console.SetCursorPosition(0, progressLinesStart + 3);
     Console.Write(fourthLine.PadRight(Console.WindowWidth));

     if (uploadedBytes == totalBytes && !uploadComplete)
     {
         uploadComplete = true;
         fileStream.Close();

         Console.WriteLine();

         if (File.Exists(zipFilePath))
         {
             File.Delete(zipFilePath);
             Console.WriteLine($"File {zipFileName} deleted successfully.");
         }

         Messages.DumpCompleted(zipFileName);
     }

     stopwatch.Stop();
 }

 client.Logout();

}

MegaApiClient Version:
Lasted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant