Skip to content

Commit

Permalink
TooManyProjectsException: (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
T-mp committed Jan 21, 2024
1 parent 755cc92 commit ed40f47
Show file tree
Hide file tree
Showing 79 changed files with 3,090 additions and 386 deletions.
2 changes: 1 addition & 1 deletion Test.Extensions.Logging/Test.Extensions.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

</Project>
13 changes: 6 additions & 7 deletions WebRaid.Abstraction.Tests/WebRaid.Abstraction.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions WebRaid.Abstraction/WebRaid.Abstraction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions WebRaid.CsWin32/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace WebRaid.CsWin32
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");

var sync = new SyncRootManager();
var connect = sync.Connect();

Console.WriteLine($"Pfad: {sync.Pfad}");

Console.ReadLine();
}
}
}
186 changes: 186 additions & 0 deletions WebRaid.CsWin32/SyncRootManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System.Runtime.InteropServices;
using System.Security.Principal;
using Vanara.Extensions;
using Vanara.PInvoke;
using Windows.Security.Cryptography;
using Windows.Storage;
using Windows.Storage.Provider;
using static Vanara.PInvoke.CldApi;

namespace WebRaid.CsWin32
{
public class SyncRootManager
{
public string Pfad=> SyncRootPath;
internal static readonly string SyncRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "TestCloud");
internal static readonly Guid StorageProviderId = Guid.Parse("BEE7B8DC-9699-4561-910D-D3B2F6A923A9");

internal const string CloudName = "Test Cloud";
internal const string StorageProviderAccount = "SomeAccount";

private readonly CF_CALLBACK_REGISTRATION[] _callbacks = [
new CF_CALLBACK_REGISTRATION
{
Type = CF_CALLBACK_TYPE.CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS,
Callback = new CF_CALLBACK((in CF_CALLBACK_INFO x, in CF_CALLBACK_PARAMETERS y) => CfExecutePlaceholdersFetch(new FileSystemItem
{
Id = Guid.NewGuid(),
RelativePath = "testFile.txt",
FileAttributes = System.IO.FileAttributes.Normal,
CreationTime = DateTime.Now,
LastAccessTime = DateTime.Now,
LastWriteTime = DateTime.Now,
Size = 15654654
}, x)),
},
new CF_CALLBACK_REGISTRATION
{
Type = CF_CALLBACK_TYPE.CF_CALLBACK_TYPE_NONE
}];

public CF_CONNECTION_KEY ConnectionKey { get; private set; }

public async Task Connect()
{
EnsureFeatureSupported();
EnsureSyncRootPathCreated();

StorageProviderSyncRootManager.Register(await CreateSyncRoot());

CfConnectSyncRoot(
SyncRootPath,
_callbacks,
nint.Zero,
CF_CONNECT_FLAGS.CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAGS.CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH,
out var connectionKey);

ConnectionKey = connectionKey;

CfUpdateSyncProviderStatus(ConnectionKey, CF_SYNC_PROVIDER_STATUS.CF_PROVIDER_STATUS_IDLE);
}

private static void EnsureFeatureSupported()
{
if (!StorageProviderSyncRootManager.IsSupported())
{
throw new NotSupportedException("Cloud API is not supported on this machine.");
}
}

private static void EnsureSyncRootPathCreated()
{
if (!Directory.Exists(SyncRootPath))
{
Directory.CreateDirectory(SyncRootPath);
}
}

private static async Task<StorageProviderSyncRootInfo> CreateSyncRoot()
{
StorageProviderSyncRootInfo syncRoot = new()
{
Id = GetSyncRootId(),
ProviderId = StorageProviderId,
Path = await StorageFolder.GetFolderFromPathAsync(SyncRootPath),
AllowPinning = true,
DisplayNameResource = CloudName,
HardlinkPolicy = StorageProviderHardlinkPolicy.Allowed,
HydrationPolicy = StorageProviderHydrationPolicy.Partial,
HydrationPolicyModifier = StorageProviderHydrationPolicyModifier.AutoDehydrationAllowed | StorageProviderHydrationPolicyModifier.StreamingAllowed,
InSyncPolicy = StorageProviderInSyncPolicy.FileLastWriteTime,
PopulationPolicy = StorageProviderPopulationPolicy.Full,
ProtectionMode = StorageProviderProtectionMode.Unknown,
Version = "1.0.0",
IconResource = "%SystemRoot%\\system32\\charmap.exe,0",
ShowSiblingsAsGroup = false,
RecycleBinUri = null,
Context = CryptographicBuffer.ConvertStringToBinary(GetSyncRootId(), BinaryStringEncoding.Utf8)
};

return syncRoot;

}

private static string GetSyncRootId()
=> $"{StorageProviderId}!{WindowsIdentity.GetCurrent().User}!{StorageProviderAccount}";

#region Placeholder creation
private static void CfExecutePlaceholdersFetch(FileSystemItem placeholder, CF_CALLBACK_INFO callbackInfo)
{
CF_OPERATION_INFO operationInfo = CreateOperationInfo(callbackInfo, CF_OPERATION_TYPE.CF_OPERATION_TYPE_TRANSFER_PLACEHOLDERS);
CF_PLACEHOLDER_CREATE_INFO nativePlaceholder = CreatePlaceholder(placeholder);

IntPtr placeholderArray = Marshal.AllocHGlobal(Marshal.SizeOf<CF_PLACEHOLDER_CREATE_INFO>());
Marshal.StructureToPtr(nativePlaceholder, placeholderArray, false);

CF_OPERATION_PARAMETERS.TRANSFERPLACEHOLDERS placeholdersFetchParameter = new()
{
PlaceholderArray = placeholderArray,
Flags = CF_OPERATION_TRANSFER_PLACEHOLDERS_FLAGS.CF_OPERATION_TRANSFER_PLACEHOLDERS_FLAG_DISABLE_ON_DEMAND_POPULATION,
PlaceholderCount = 1,
CompletionStatus = NTStatus.STATUS_SUCCESS,
PlaceholderTotalCount = 1,
};

CF_OPERATION_PARAMETERS opParams = CF_OPERATION_PARAMETERS.Create(placeholdersFetchParameter);

HRESULT result = CfExecute(operationInfo, ref opParams);
result.ThrowIfFailed();

Marshal.FreeHGlobal(placeholderArray);
Marshal.FreeHGlobal(nativePlaceholder.FileIdentity);
}

private static CF_PLACEHOLDER_CREATE_INFO CreatePlaceholder(FileSystemItem placeholder)
{
CF_PLACEHOLDER_CREATE_INFO cfInfo = new()
{
FileIdentity = Marshal.StringToHGlobalUni("a"),
FileIdentityLength = 2 * 2,
RelativeFileName = placeholder.RelativePath,
FsMetadata = new CF_FS_METADATA
{
FileSize = placeholder.Size,
BasicInfo = new Kernel32.FILE_BASIC_INFO
{
FileAttributes = (FileFlagsAndAttributes)placeholder.FileAttributes,
CreationTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.CreationTime.ToFileTime()),
LastWriteTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastWriteTime.ToFileTime()),
LastAccessTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastAccessTime.ToFileTime()),
ChangeTime = FileTimeExtensions.MakeFILETIME((ulong)placeholder.LastWriteTime.ToFileTime())
}
},
Flags = CF_PLACEHOLDER_CREATE_FLAGS.CF_PLACEHOLDER_CREATE_FLAG_MARK_IN_SYNC
};

return cfInfo;
}

private static CF_OPERATION_INFO CreateOperationInfo(in CF_CALLBACK_INFO CallbackInfo, CF_OPERATION_TYPE OperationType)
{
CF_OPERATION_INFO opInfo = new()
{
Type = OperationType,
ConnectionKey = CallbackInfo.ConnectionKey,
TransferKey = CallbackInfo.TransferKey,
CorrelationVector = CallbackInfo.CorrelationVector,
RequestKey = CallbackInfo.RequestKey
};

opInfo.StructSize = (uint)Marshal.SizeOf(opInfo);
return opInfo;
}

public class FileSystemItem
{
public Guid Id { get; set; }
public string RelativePath { get; set; }
public long Size { get; set; }
public System.IO.FileAttributes FileAttributes { get; set; }
public DateTimeOffset CreationTime { get; set; }
public DateTimeOffset LastWriteTime { get; set; }
public DateTimeOffset LastAccessTime { get; set; }
}
#endregion
}
}
16 changes: 16 additions & 0 deletions WebRaid.CsWin32/WebRaid.CsWin32.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Vanara.PInvoke.CldApi" Version="3.4.17" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion WebRaid.Main.WinService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
.UseWindowsService()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<WebRaid.Main.Startup>();
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>0.1.0-dev011</Version>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug'">
<BumpLabel>dev</BumpLabel>
<BumpLabelDigits>3</BumpLabelDigits>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration) == 'Release'">
<BumpPatch>True</BumpPatch>
<BumpResetLabel>dev</BumpResetLabel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="MSBump" Version="2.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebRaid.Main\WebRaid.Main.csproj" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions WebRaid.Main.WinService/WebRaid - Backup.Main.WinService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>0.1.0-dev011</Version>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug'">
<BumpLabel>dev</BumpLabel>
<BumpLabelDigits>3</BumpLabelDigits>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration) == 'Release'">
<BumpPatch>True</BumpPatch>
<BumpResetLabel>dev</BumpResetLabel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="MSBump" Version="2.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebRaid.Main\Server\WebRaid.Main.Server.csproj" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions WebRaid.Main.WinService/WebRaid.Main.WinService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>0.1.0-dev009</Version>
<TargetFramework>net6.0</TargetFramework>
<Version>0.1.0-dev029</Version>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Debug'">
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
<PackageReference Include="MSBump" Version="2.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
12 changes: 12 additions & 0 deletions WebRaid.Main/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.3",
"commands": [
"dotnet-ef"
]
}
}
}
10 changes: 10 additions & 0 deletions WebRaid.Main/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Loading

0 comments on commit ed40f47

Please sign in to comment.