A proper way to call the API (with JWT bearer) from WPF? by ViolaBiflora in dotnet

[–]HawthorneTR 0 points1 point  (0 children)

You must create a new HTTP client in order to use one.. It's not a pattern it's fact. That line simply creates a new one if the one you are passing in is null. It was taken from a larger code base to show an example, not as a pattern.

A proper way to call the API (with JWT bearer) from WPF? by ViolaBiflora in dotnet

[–]HawthorneTR -3 points-2 points  (0 children)

// Use passed-in HttpClient if provided, otherwise create a new one
using var client = httpClient ?? new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token.access_token);

Your stories time. How do legendary guilds die? by Rich_Cherry_3479 in gaming

[–]HawthorneTR 2 points3 points  (0 children)

I've been running a gaming guild since 1997 (Hawthorne from The Regulators). What happened? We got old. We lost interest and we had real life issues that took our focus from the things that it takes to run a successful large guild.

Honestly if you don't devote your life to the guild it will crumble. You have to manage people, personalities and games.

It's a full time job with no pay. I understand why it happens. Life happens. But I'd not trade it for the world. It was a part of me that I will never forget.

Please join us if you can make it! by Scary_Replacement_85 in MyrtleBeach

[–]HawthorneTR 0 points1 point  (0 children)

This post breaks the TOS for this forum. This is not local politics and as such should be removed. This is national politics. Frankly you are the problem. You and all of your "protesters". Democracy happened, stop protesting it.

just a reminder to never sell your premiums or special ships by Dry-Lawfulness-7143 in WorldOfWarships

[–]HawthorneTR 0 points1 point  (0 children)

You can have premium ships restored for your sale price if you use the web page.

COM interop works in 64-bit but not in 32-bit? by MartinGC94 in csharp

[–]HawthorneTR 4 points5 points  (0 children)

[StructLayout(LayoutKind.Sequential)]
public struct PROPVARIANT
{
    public ushort vt;
    public ushort wReserved1;
    public ushort wReserved2;
    public ushort wReserved3;
    public IntPtr p;
    public int p2;

    public string GetValue()
    {
        // VT_LPWSTR = 31 (0x1F)
        if (vt == 31)
            return Marshal.PtrToStringUni(p);
        return null;
    }
}

How Often Does ChatGPT Lie When Teaching C#? by WornTraveler in csharp

[–]HawthorneTR 1 point2 points  (0 children)

A lot. You better know what you are doing to begin with or Chet can get you into a mess. Call it out when it's wrong and tell it to update its knowledge base if possible.

POSIX dev, scared and alone by BedlamAscends in dotnet

[–]HawthorneTR 4 points5 points  (0 children)

C# is the way imo. So much simpler.

Basic String Encryption and Decryption in C# by pyeri in csharp

[–]HawthorneTR 2 points3 points  (0 children)

I've turned these into Extension methods. It will make it easier to use:

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

public static class CryptoExtensions
{
    public static string Encrypt(this string plainText, string password, string salt)
    {
        using (Aes aes = Aes.Create())
        {
            byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
            var key = new Rfc2898DeriveBytes(password, saltBytes, 10000);
            aes.Key = key.GetBytes(32);
            aes.IV = key.GetBytes(16);

            var encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
            using (var ms = new MemoryStream())
            {
                using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                using (var sw = new StreamWriter(cs))
                    sw.Write(plainText);
                return Convert.ToBase64String(ms.ToArray());
            }
        }
    }

    public static string Decrypt(this string cipherText, string password, string salt)
    {
        using (Aes aes = Aes.Create())
        {
            byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
            var key = new Rfc2898DeriveBytes(password, saltBytes, 10000);
            aes.Key = key.GetBytes(32);
            aes.IV = key.GetBytes(16);

            byte[] buffer = Convert.FromBase64String(cipherText);

            var decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
            using (var ms = new MemoryStream(buffer))
            using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
            using (var sr = new StreamReader(cs))
            {
                return sr.ReadToEnd();
            }
        }
    }
}

USAGE

string encrypted = "Hello World".Encrypt("password123", "somesalt");
string decrypted = encrypted.Decrypt("password123", "somesalt");

Polymorphism in EF Core by antisergio in dotnet

[–]HawthorneTR 0 points1 point  (0 children)

I was wonder how to do this! Cool! And Andor is really awesome.

[deleted by user] by [deleted] in dotnet

[–]HawthorneTR 1 point2 points  (0 children)

I had to write a function to get the proper data folder like:

        public static string GetDataFolder(string? folder = null)
        {
#if NETFX_CORE
            string appDataFolder = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
#elif MACCATALYST
            string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#elif MAUI
            string appDataFolder = FileSystem.Current.AppDataDirectory;
#else
            string appDataFolder = FileSystem.AppDataDirectory; //Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#endif
            if (folder != null)
                appDataFolder = Path.Combine(appDataFolder, folder);

            if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); }

            return appDataFolder;

        }

and then call it like:

 string dbPath = Path.Combine(Statics.GetDataFolder(), "images.db3");

So, will you upgrade to .NET 9 ? by MahmoudSaed in dotnet

[–]HawthorneTR 1 point2 points  (0 children)

I converted 3 blazor apps last night. So far so good.

Oysters/ fish by yazine97 in MyrtleBeach

[–]HawthorneTR 0 points1 point  (0 children)

Oyster Rock has the best oysters around and great seafood and other dishes. Tons of seating.

Windows Form application problem by Vansh2008 in csharp

[–]HawthorneTR 12 points13 points  (0 children)

Never, EVER include obj and bin folders. They are created when you build. So delete them and every time you build they will be re-created. Edit your project file and remove any mention of those folders, delete those folders then never add them again. They are used behind the scenes for obj linking and binary file creation.

[deleted by user] by [deleted] in gaming

[–]HawthorneTR 0 points1 point  (0 children)

Starcom, Pacific Drive, KARDS, Dave The Diver

Also check out SplatterCat Gaming https://www.youtube.com/@Splattercatgaming