Skip to content

Commit

Permalink
chore: combine projects move up a directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Feb 17, 2024
1 parent ed463a6 commit 23d1738
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 210 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
run: dotnet test --no-build

- name: Publish
run: dotnet publish SharpFM.App/SharpFM.App.csproj --runtime "${{ matrix.target }}" -c Debug
run: dotnet publish SharpFM/SharpFM.csproj --runtime "${{ matrix.target }}" -c Debug
6 changes: 3 additions & 3 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
shell: bash
run: |
tag=$(git describe --tags --abbrev=0)
release_name="SharpFM.App-$tag-${{ matrix.target }}"
release_name="SharpFM-$tag-${{ matrix.target }}"
# Build everything
dotnet publish SharpFM.App/SharpFM.App.csproj --runtime "${{ matrix.target }}" -c Release -o "$release_name"
dotnet publish SharpFM/SharpFM.csproj --runtime "${{ matrix.target }}" -c Release -o "$release_name"
# Pack files
if [ "${{ matrix.target }}" == "win-x64" ]; then
Expand All @@ -51,6 +51,6 @@ jobs:
- name: Publish
uses: softprops/action-gh-release@v1
with:
files: "SharpFM.App*"
files: "SharpFM*"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/SharpFM.App/bin/Debug/net8.0/win-x64/SharpFM.App.dll",
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/SharpFM.dll",
"args": [],
"cwd": "${workspaceFolder}/SharpFM.App",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.App/App.axaml → App.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SharpFM.App.App"
x:Class="SharpFM.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

Expand Down
4 changes: 2 additions & 2 deletions SharpFM.App/App.axaml.cs → App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using SharpFM.App.ViewModels;
using SharpFM.ViewModels;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;

namespace SharpFM.App;
namespace SharpFM;

public partial class App : Application
{
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.App/AvaloniaNLogSink.cs → AvaloniaNLogSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Avalonia.Logging;
using NLog;

namespace SharpFM.App;
namespace SharpFM;

/// <summary>
/// Avalonia Log Sink that writes to NLog Loggers.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

Contributions are welcome! As an open source project, any help we can get fixing bugs or adding features is always appreciated. In all cases, PRs will be reviewed with an eye toward future maintainability, so things like good comments, unit test coverage, and thorough design are importat considerations. If you decide to work on a bug or feature from our issue list, please be prepared to work through design or maintenance issues in the PR.
Contributions are welcome! As an open source project, any help we can get fixing bugs or adding features is always appreciated. In all cases, PRs will be reviewed with an eye toward future maintainability, so things like good comments and thorough design are important considerations. If you decide to work on a bug or feature from our issue list, please be prepared to work through design or maintenance issues in the PR.

## Features

Expand Down
3 changes: 1 addition & 2 deletions SharpFM.Core/FileMakerClip.cs → Core/FileMakerClip.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;

namespace SharpFM.Core;
namespace SharpFM;

public class FileMakerClip
{
Expand Down
139 changes: 139 additions & 0 deletions Core/FileMakerClipExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace SharpFM;

public static class FileMakerClipExtensions
{
/// <summary>
/// Create a class from scratch.
/// </summary>
public static string CreateClass(this FileMakerClip _clip, FileMakerClip? fieldProjectionLayout = null)
{
if (_clip == null) { return string.Empty; }

var fieldProjectionList = new List<string>();
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes.Single(ct => ct.KeyId == fieldProjectionLayout.ClipboardFormat).DisplayName == "Layout")
{
// a clip that is of type layout, only has name attribute (since the rest isn't available)
// and we only need the name to skip it down below
fieldProjectionList.AddRange(fieldProjectionLayout.Fields.Select(f => f.Name));
}
else
{
// otherwise include all fields
fieldProjectionList.AddRange(_clip.Fields.Select(f => f.Name));
}

return _clip.CreateClass(fieldProjectionList);
}

/// <summary>
/// Create a class from scratch.
/// </summary>
public static string CreateClass(this FileMakerClip _clip, IEnumerable<string> fieldProjectionList)
{
// Create a namespace: (namespace CodeGenerationSample)
var @namespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName("SharpFM.CodeGen")).NormalizeWhitespace();

// Add System using statement: (using System)
@namespace = @namespace.AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System")));
@namespace = @namespace.AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System.Runtime.Serialization")));

var dataContractAttribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName("DataContract"));

// Create a class: (class [_clip.Name])
var classDeclaration = SyntaxFactory.ClassDeclaration(_clip.Name);

// Add the public modifier: (public class [_clip.Name])
classDeclaration = classDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
classDeclaration = classDeclaration.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(dataContractAttribute)));

// add each field from the underling _clip as a public property with the data member attribute
List<PropertyDeclarationSyntax> fieldsToBeAddedAsProperties = new List<PropertyDeclarationSyntax>(_clip.Fields.Count());
// include the field projection
foreach (var field in _clip.Fields.Where(fmF => fieldProjectionList.Contains(fmF.Name)))
{
// filemaker to C# data type mapping
var propertyTypeCSharp = string.Empty;

switch (field.DataType)
{
case "Text":
propertyTypeCSharp = "string";
break;
case "Number":
propertyTypeCSharp = "int";
break;
case "Binary":
propertyTypeCSharp = "byte[]";
break;
case "Date":
propertyTypeCSharp = "DateTime";
break;
case "Time":
propertyTypeCSharp = "TimeSpan";
break;
case "TimeStamp":
propertyTypeCSharp = "DateTime";
break;
default:
propertyTypeCSharp = "string";
break;
}

if (field.NotEmpty == false && propertyTypeCSharp != "string")
{
propertyTypeCSharp += "?";
}

var propertyTypeSyntax = SyntaxFactory.ParseTypeName(propertyTypeCSharp);

var dataMemberAttribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName("DataMember"));

var propertyDeclaration = SyntaxFactory.PropertyDeclaration(propertyTypeSyntax, field.Name)
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
.AddAccessorListAccessors(
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)))
.NormalizeWhitespace(indentation: "", eol: " ")
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(dataMemberAttribute)))
.NormalizeWhitespace();

fieldsToBeAddedAsProperties.Add(propertyDeclaration);
}

// Add the field, the property and method to the class.
classDeclaration = classDeclaration.AddMembers(fieldsToBeAddedAsProperties.ToArray());

// Add the class to the namespace.
@namespace = @namespace.AddMembers(classDeclaration);

// Normalize and get code as string.
var code = @namespace.NormalizeWhitespace().ToFullString().FormatAutoPropertiesOnOneLine();

// Output new code to the console.
return code;
}


/// <summary>
/// https://stackoverflow.com/a/52339795/86860
/// </summary>
private static readonly Regex AutoPropRegex = new Regex(@"\s*\{\s*get;\s*set;\s*}\s");

/// <summary>
/// https://stackoverflow.com/a/52339795/86860
/// </summary>
/// <param name="str">Code string to format.</param>
/// <returns>The code string with auto properties formatted to a single line</returns>
private static string FormatAutoPropertiesOnOneLine(this string str)
{
return AutoPropRegex.Replace(str, " { get; set; }");
}
}
19 changes: 19 additions & 0 deletions Core/FileMakerField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

namespace SharpFM;

public class FileMakerField
{
public int FileMakerFieldId { get; set; }

public string Name { get; set; } = null!;

public string DataType { get; set; } = null!;

public string FieldType { get; set; } = null!;

public string? Comment { get; set; }

public bool NotEmpty { get; set; }

public bool Unique { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using AvaloniaEdit;
using AvaloniaEdit.Utils;

namespace SharpFM.App.Behaviors;
namespace SharpFM.Behaviors;

public class DocumentTextBindingBehavior : Behavior<TextEditor>
{
Expand Down
6 changes: 3 additions & 3 deletions SharpFM.App/MainWindow.axaml → MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Window
x:Class="SharpFM.App.MainWindow"
x:Class="SharpFM.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:behaviors="clr-namespace:SharpFM.App.Behaviors;assembly=SharpFM.App"
xmlns:behaviors="clr-namespace:SharpFM.Behaviors;assembly=SharpFM"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SharpFM.App.ViewModels"
xmlns:vm="using:SharpFM.ViewModels"
Icon="/Assets/noun-sharp-teeth-monster-4226695.small.png"
Title="SharpFM"
Width="700"
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.App/MainWindow.axaml.cs → MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using AvaloniaEdit.TextMate;
using TextMateSharp.Grammars;

namespace SharpFM.App;
namespace SharpFM;

public partial class MainWindow : Window
{
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.App/Models/Clip.cs → Models/Clip.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SharpFM.App.Models;
namespace SharpFM.Models;

/// <summary>
/// Clip Data Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;


namespace SharpFM.App.Models;
namespace SharpFM.Models;

/// <summary>
/// Clip Db Context
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.App/Program.cs → Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using NLog;
using System;

namespace SharpFM.App;
namespace SharpFM;

class Program
{
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ SharpFM has the option to persist clips between sessions by using the File menu

## App Icon

![Sharp FM](SharpFM.App/Assets/noun-sharp-teeth-monster-4226695.small.png)
![Sharp FM](SharpFM/Assets/noun-sharp-teeth-monster-4226695.small.png)

sharp teeth monster by Kanyanee Watanajitkasem from [Noun Project](https://thenounproject.com/browse/icons/term/sharp-teeth-monster/) (CC BY 3.0)
Loading

0 comments on commit 23d1738

Please sign in to comment.