This commit is contained in:
Alan Rynne 2022-04-28 17:05:34 +02:00
Родитель 850b7360b2
Коммит 5126ea1c6a
7 изменённых файлов: 634 добавлений и 0 удалений

290
dotnet/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,290 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
.DS_Store
CHECKLIST.md
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
.vscode/
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

Просмотреть файл

@ -0,0 +1,135 @@
using System;
using Speckle.Core.Credentials;
using Speckle.Core.Api;
using System.Threading;
using System.Collections.Generic;
using Speckle.Core.Transports;
namespace CSharpStarter
{
class Program
{
// Running this program will pull the latest commit from the main branch
// of the specified stream and duplicate it inside a different branch.
// (branch should exist already or the program will fail)
static void Main(string[] args)
{
// The id of the stream to work with (we're assuming it already exists in your default account's server)
var streamId = "c1800d795b";
// The name of the branch we'll send data to.
var branchName = "processed";
// Get default account on this machine
// If you don't have Speckle Manager installed download it from https://speckle-releases.netlify.app
var defaultAccount = AccountManager.GetDefaultAccount();
// Or get all the accounts and manually choose the one you want
// var accounts = AccountManager.GetAccounts();
// var defaultAccount = accounts.ToList().FirstOrDefault();
// Authenticate using the account
var client = new Client(defaultAccount);
// Now we can start using the client
// Get the main branch with it's latest commit reference
var branch = client.BranchGet(streamId, "main", 1).Result;
// Get the id of the object referenced in the commit
var hash = branch.commits.items[0].referencedObject;
// Create the server transport for the specified stream.
var transport = new ServerTransport(defaultAccount, streamId);
// Receive the object
var receivedBase = Operations.Receive(hash, transport).Result;
// Process the object however you'd like
Console.WriteLine("Received object:" + receivedBase);
// Sending the object will return it's unique identifier.
var newHash = Operations.Send(receivedBase, new List<ITransport> { transport }).Result;
// Create a commit in `processed` branch (it must previously exist)
var commitId = client.CommitCreate(new CommitCreateInput()
{
branchName = branchName,
message = "Automatic commit created by AEC Tech Demo C# console app.",
objectId = newHash,
streamId = streamId,
sourceApplication = "AEC Tech C# Script"
}).Result;
Console.WriteLine($"Successfully created commit with id: {commitId}");
// Remember to dispose of the client once you've finished with it.
client.Dispose();
}
static void ReactToCommit(string[] args)
{
// Get default account on this machine
var defaultAccount = AccountManager.GetDefaultAccount();
var client = new Client(defaultAccount);
var streamId = "42c06de34f";
var branch = client.BranchGet(streamId, "main", 1).Result;
var hash = branch.commits.items[0].referencedObject;
var exit = false;
client.OnCommitCreated += OnCommitCreated;
// Subscribe to commits created on the stream.
client.SubscribeCommitCreated(streamId);
// HACK: This is a super hacky way to get a C# console app to wait for an event to happen.
// YOU SHOULD NOT DO THIS IN A PRODUCTION APPLICATION 🤣
Console.WriteLine("Waiting for commit created event...");
while (!exit)
{
// Exit if ESC is pressed
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)
{
exit = true;
}
else
{
Thread.Sleep(500);
Console.WriteLine("Still waiting...");
}
}
// Remember to dispose of the client once you've finished with it.
client.Dispose();
}
public static void OnCommitCreated(object sender, Speckle.Core.Api.SubscriptionModels.CommitInfo e)
{
// Ignore commits from any branch other than 'main'
if (e.branchName != "main") return;
Console.WriteLine("Commit was created in Main! Processing data...");
// Create the server transport for the specified stream.
var transport = new ServerTransport(defaultAccount, streamId);
// Receive the object
var receivedBase = Operations.Receive(hash, transport).Result;
var newHash = Operations.Send(receivedBase, new List<ITransport> { transport }).Result;
// Create a commit in `processed` branch (it must previously exist)
var commitId = client.CommitCreate(new CommitCreateInput()
{
branchName = "processed",
message = "Automatic commit created by AEC Tech Demo C# console app.",
objectId = newHash,
streamId = streamId,
sourceApplication = "C#"
}).Result;
Console.WriteLine($"Successfully created commit with id: {commitId}");
exit = true;
}
}
}

Просмотреть файл

@ -0,0 +1,25 @@
# AEC C# Starter
> If you're trying to run this you should have the .NetCore3.1 Runtime installed
## Running
This is a `dotnet core 3.1` console app, so just run:
```shell
dotnet run
```
## Creating your own
This is quite simple, just create a new console app:
```
dotnet new console -f netcoreapp3.1
```
And then add `Speckle.Core` as a dependency
```
dotnet add package Speckle.Core --version 2.1.22
```

Просмотреть файл

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Speckle.Core" Version="2.5.2" />
<PackageReference Include="Speckle.Objects" Version="2.5.2" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,104 @@
using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using DesktopUI2.Models;
using DesktopUI2.Models.Filters;
using DesktopUI2.Models.Settings;
using DesktopUI2.ViewModels;
namespace Speckle.DesktopUIStarter
{
public class ConnectorBindingsStarter : DesktopUI2.ConnectorBindings
{
public override string GetActiveViewName()
{
Console.WriteLine("GetActiveViewName was called");
return "Default";
}
public override List<MenuItem> GetCustomStreamMenuItems()
{
return new List<MenuItem>{
new MenuItem{Header = "First"},
new MenuItem{Header = "Second"},
new MenuItem{Header = "Third"},
};
}
public override string GetDocumentId()
{
return new Guid().ToString();
}
public override string GetDocumentLocation()
{
return "./";
}
public override string GetFileName()
{
return "Fake File Name";
}
public override string GetHostAppName()
{
return "Speckle DUI Starter";
}
public override string GetHostAppNameVersion()
{
return "1.0";
}
public override List<string> GetObjectsInView()
{
// TODO
return new List<string>();
}
public override List<string> GetSelectedObjects()
{
// TODO
return new List<string>();
}
public override List<ISelectionFilter> GetSelectionFilters()
{
// TODO
return new List<ISelectionFilter>();
}
public override List<ISetting> GetSettings()
{
// TODO
return new List<ISetting>();
}
public override List<StreamState> GetStreamsInFile()
{
return new List<StreamState>();
}
public override Task<StreamState> ReceiveStream(StreamState state, ProgressViewModel progress)
{
throw new System.NotImplementedException();
}
public override void SelectClientObjects(string args)
{
// TODO
}
public override Task<string> SendStream(StreamState state, ProgressViewModel progress)
{
throw new System.NotImplementedException();
}
public override void WriteStreamsToFile(List<StreamState> streams)
{
throw new System.NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
using Avalonia;
using Avalonia.ReactiveUI;
using System.IO;
namespace Speckle.DesktopUIStarter
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
{
// to debug the VS previewer
// 1. open another instanc of the project in VS
// 2. uncomment the lines below
// 3. close and reopen the problematic XAML window
//Debugger.Launch();
//while (!Debugger.IsAttached)
// Thread.Sleep(100);
return AppBuilder.Configure<DesktopUI2.App>()
.UsePlatformDetect()
.With(new X11PlatformOptions { UseGpu = false })
.With(new AvaloniaNativePlatformOptions { UseGpu = false, UseDeferredRendering = true })
.With(new MacOSPlatformOptions { ShowInDock = false, DisableDefaultApplicationMenuItems = true, DisableNativeMenus = true })
.With(new Win32PlatformOptions { AllowEglInitialization = true, EnableMultitouch = false })
.With(new SkiaOptions { MaxGpuResourceSizeBytes = 8096000 })
.LogToTrace()
.UseReactiveUI();
}
}
}

Просмотреть файл

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<WarningLevel>1</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
<PackageReference Include="Speckle.DesktopUI" Version="2.5.2" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
</Project>