using H.Pipes;
using InABox.Core;
using InABox.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WampSharp.V2;
using WampSharp.V2.Realm;
namespace PRSRecordingNotes
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class ScreenRecorderWindow : Window
{
public PipeClient _client { get; private set; }
//IWampHost _host = null;
//IWampHostedRealm _realm = null;
//IWampSubject _subject = null;
//IDisposable _subscription = null;
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
public ScreenRecorderWindow()
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(CoreUtils.SyncfusionLicense(SyncfusionVersion.v19_4));
InitializeComponent();
HotKeyManager.Initialize();
HotKeyManager.RegisterHotKey(
Key.F6,
() => {
ResumeRecording(false);
return true;
}
);
Move.Source = Properties.Resources.target.AsBitmapImage();
_client = new PipeClient("PRSScreenRecorder",".");
_client.MessageReceived += (o, args) =>
{
ServerMessage(args.Message);
};
_client.ConnectAsync();
//_host = new WampSharp.V2.DefaultWampHost("ws://127.0.0.1:8001/prs");
//_host.Open();
//_realm = _host.RealmContainer.GetRealmByName("PRS");
//_realm.SessionCreated += _realm_SessionCreated;
//_realm.SessionClosed += _realm_SessionClosed;
//_subject = _realm.Services.GetSubject("ScreenRecording");
//_subscription = _subject.Subscribe(
// x =>
// {
// String command = x.Arguments[0].Deserialize();
// if (String.Equals(command, "EDIT"))
// Dispatcher.Invoke(() => { EditNotes(); });
// else if (String.Equals(command, "QUIT"))
// Dispatcher.Invoke(() => { System.Windows.Application.Current.Shutdown(); });
// }
//);
Hide();
}
private void ServerMessage(string message)
{
if (String.Equals(message, "EDIT"))
Dispatcher.Invoke(() => { EditNotes(); });
else if (String.Equals(message, "QUIT"))
Dispatcher.Invoke(() => { System.Windows.Application.Current.Shutdown(); });
}
private void _realm_SessionClosed(object sender, WampSessionCloseEventArgs e)
{
}
private void _realm_SessionCreated(object sender, WampSessionCreatedEventArgs e)
{
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
public void EditNotes()
{
Buttons.Visibility = Visibility.Visible;
Show();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
ResumeRecording(true);
}
private void Resume_Click(object sender, RoutedEventArgs e)
{
ResumeRecording(false);
}
private void ResumeRecording(bool hide)
{
if (hide)
Hide();
Buttons.Visibility = Visibility.Collapsed;
_client.WriteAsync("RESUME");
//_subject.OnNext(new WampEvent() { Arguments = new[] { "RESUME" } });
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
}
//bool bMoving = false;
//Point offset;
private void Move_MouseDown(object sender, MouseButtonEventArgs e)
{
//offset = e.GetPosition(this);
//bMoving = true;
this.DragMove();
}
private void Move_MouseUp(object sender, MouseButtonEventArgs e)
{
//bMoving = false;
}
private void Move_MouseMove(object sender, MouseEventArgs e)
{
//if (!bMoving)
// return;
//var current = e.GetPosition(this);
//Left = current.X - offset.X;
//Top = current.Y - offset.Y;
}
/// Brings main window to foreground.
public void BringToForeground()
{
//if (this.WindowState == WindowState.Minimized || this.Visibility == Visibility.Hidden)
//{
// this.Show();
// this.WindowState = WindowState.Normal;
//}
//// According to some sources these steps gurantee that an app will be brought to foreground.
//this.Activate();
//this.Topmost = true;
//this.Topmost = false;
//this.Focus();
}
}
}