Skip to content

Commit

Permalink
Merge branch 'master' into VS2022
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaTy authored Apr 5, 2022
2 parents 55e33db + 8d9f38e commit 3829e62
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Tests/Cosmos.TestRunner.TestController/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void AreEqual(double expected, double actual, string message, [Cal
if (!xResult)
{
TestController.Debugger.Send($"Expected value: '{expected}' " + BitConverter.ToString(BitConverter.GetBytes(expected)));
TestController.Debugger.Send($"Actual value: '{actual}' " + BitConverter.ToString(BitConverter.GetBytes(expected)));
TestController.Debugger.Send($"Actual value: '{actual}' " + BitConverter.ToString(BitConverter.GetBytes(actual)));
TestController.Debugger.Send($"Diff: {xResult}");
}
IsTrue(xResult, message, file, line);
Expand Down
1 change: 1 addition & 0 deletions source/Cosmos.Build.Builder/Cosmos.Build.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="1.16.30" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NuGet.Common" />
<PackageReference Include="NuGet.Configuration" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.6.0" />
Expand Down
68 changes: 68 additions & 0 deletions source/Cosmos.Build.Builder/Services/HasteBinClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Cosmos.Build.Builder.Services
{
//https://gist.github.com/jwoff78/f8babb48922132ea20d37ef4aa8aa1dd
public class HasteBinClient
{
private static HttpClient _httpClient;
private string _baseUrl;

static HasteBinClient()
{
_httpClient = new HttpClient();
}

public HasteBinClient(string baseUrl)
{
_baseUrl = baseUrl;
}

public async Task<HasteBinResult> Post(string content)
{
string fullUrl = _baseUrl;
if (!fullUrl.EndsWith("/"))
{
fullUrl += "/";
}
string postUrl = $"{fullUrl}documents";

var request = new HttpRequestMessage(HttpMethod.Post, new Uri(postUrl));
request.Content = new StringContent(content);
HttpResponseMessage result = await _httpClient.SendAsync(request).ConfigureAwait(false);

if (result.IsSuccessStatusCode)
{
string json = await result.Content.ReadAsStringAsync();
HasteBinResult hasteBinResult = JsonConvert.DeserializeObject<HasteBinResult>(json);

if (hasteBinResult?.Key != null)
{
hasteBinResult.FullUrl = $"{fullUrl}{hasteBinResult.Key}";
hasteBinResult.IsSuccess = true;
hasteBinResult.StatusCode = 200;
return hasteBinResult;
}
}

return new HasteBinResult()
{
FullUrl = fullUrl,
IsSuccess = false,
StatusCode = (int)result.StatusCode
};
}
}

// Define other methods and classes here
public class HasteBinResult
{
public string Key { get; set; }
public string FullUrl { get; set; }
public bool IsSuccess { get; set; }
public int StatusCode { get; set; }
}
}
28 changes: 28 additions & 0 deletions source/Cosmos.Build.Builder/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal sealed class MainWindowViewModel : ViewModelBase

public ICommand CopyCommand { get; }

public ICommand PostPaste { get; }

public bool CloseWhenCompleted
{
get => _closeWhenCompleted;
Expand Down Expand Up @@ -61,6 +63,8 @@ public MainWindowViewModel(

CopyCommand = new RelayCommand(CopyLogToClipboard);

PostPaste = new RelayCommand(PostPasteCommand);

CloseWhenCompleted = true;

_logger = new MainWindowLogger(this);
Expand All @@ -70,6 +74,8 @@ public MainWindowViewModel(

private void CopyLogToClipboard(object parameter) => Clipboard.SetText(BuildLog());

private void PostPasteCommand(object parameter) => InternalPostPaste();

private string BuildLog()
{
var log = @"
Expand All @@ -93,6 +99,28 @@ Build Log
return log;
}

private void InternalPostPaste()
{
try
{
string baseUrl = "https://www.toptal.com/developers/hastebin/";
var hasteBinClient = new HasteBinClient(baseUrl);
HasteBinResult result = hasteBinClient.Post(BuildLog()).Result;

if (result.IsSuccess)
{
Views.MessageBox.Show($"link:{baseUrl}{result.Key}");
}
else
{
Views.MessageBox.Show($"Failed, status code was {result.StatusCode}");
}
} catch (Exception e)
{
Views.MessageBox.Show(e.Message);
}
}

private async Task BuildAsync()
{
_logger.NewSection("Checking Dependencies...");
Expand Down
9 changes: 7 additions & 2 deletions source/Cosmos.Build.Builder/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<Grid DockPanel.Dock="Bottom" Height="46">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
Expand All @@ -38,11 +39,15 @@
Content="Copy log" Width="96" Height="46"
Padding="10,10,10,10"/>

<CheckBox Grid.Column="2"
<Button Grid.Column="1"
Command="{Binding PostPaste}"
Content="Publish on Hastebin" Height="46" MaxWidth="200"
Padding="10,10,10,10" Margin="0,0,319,0" HorizontalAlignment="Right" Width="147"/>

<CheckBox Grid.Column="3"
IsChecked="{Binding CloseWhenCompleted}"
Content="Close when finished" Height="39" Margin="0,0,20,7" />
</Grid>

<Rectangle DockPanel.Dock="Top"
Height="5" />
<TextBlock DockPanel.Dock="Top"
Expand Down
23 changes: 22 additions & 1 deletion source/Cosmos.Build.Builder/Views/MessageBox.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Documents;

namespace Cosmos.Build.Builder.Views
{
Expand All @@ -7,15 +8,35 @@ public partial class MessageBox : Window
public MessageBox(string Content)
{
InitializeComponent();
lblMain.Text = Content;
if (Content.StartsWith("link:"))
{
Content = Content.Replace("link:", "");
var hlink = new Hyperlink();
hlink.Inlines.Add(Content);
hlink.NavigateUri = new System.Uri(Content);
hlink.RequestNavigate += (sender, e) =>
{
System.Diagnostics.Process.Start(e.Uri.ToString());
};
lblMain.Text = "";
lblMain.Inlines.Add("Click me: ");
lblMain.Inlines.Add(hlink);
}
else
{
lblMain.Text = Content;
}

}

public static void Show(string Content)
{
var window = new MessageBox(Content);

//this workarounds a bug that when the main window is minimized then brought to front, the message box is no longer visible
window.Topmost = true;
window.ShowDialog();

}

private void Button_Click(object sender, RoutedEventArgs e)
Expand Down
18 changes: 18 additions & 0 deletions source/Cosmos.Core_Plugs/MathImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public static double Sin(double d)
{
throw new NotImplementedException();
}

[PlugMethod(Assembler = typeof(MathTanASM))]
public static double Tan(double d)
{
throw new NotImplementedException();
}
}

class MathRoundASM : AssemblerMethod
Expand Down Expand Up @@ -63,4 +69,16 @@ public override void AssembleNew(Assembler aAssembler, object aMethodInfo)
XS.FPU.FloatStoreAndPop(ESP, isIndirect: true, size: RegisterSize.Long64);
}
}

class MathTanASM : AssemblerMethod
{
public override void AssembleNew(Assembler aAssembler, object aMethodInfo)
{
XS.FPU.FloatLoad(EBP, destinationIsIndirect: true, displacement: 8, size: RegisterSize.Long64);
XS.FPU.FloatTan();
XS.Sub(ESP, 8);
XS.FPU.FloatPop();
XS.FPU.FloatStoreAndPop(ESP, isIndirect: true, size: RegisterSize.Long64);
}
}
}
10 changes: 0 additions & 10 deletions source/Cosmos.System2_Plugs/System/MathImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,16 +1219,6 @@ public static double Sqrt(double x)

#endregion Sqrt

#region Tan

public static double Tan(double x)
{
if (double.IsNegativeInfinity(x) || double.IsInfinity(x)) return double.NaN;
return Math.Sin(x) / Math.Cos(x);
}

#endregion Tan

#region Tanh

public static double Tanh(double x)
Expand Down
Loading

0 comments on commit 3829e62

Please sign in to comment.