Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Sync settings over wifi" #195

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions appLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "appLauncher", "appLauncher\appLauncher.csproj", "{825249DF-2022-4222-96A1-69A32AA4E16C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleAnalyticsv4SDK", "..\GoogleAnalyticsv4SDKFor.Net\GoogleAnalyticsv4SDK\GoogleAnalyticsv4SDK.csproj", "{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -49,6 +51,26 @@ Global
{825249DF-2022-4222-96A1-69A32AA4E16C}.Release|x86.ActiveCfg = Release|x86
{825249DF-2022-4222-96A1-69A32AA4E16C}.Release|x86.Build.0 = Release|x86
{825249DF-2022-4222-96A1-69A32AA4E16C}.Release|x86.Deploy.0 = Release|x86
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|ARM.ActiveCfg = Debug|ARM
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|ARM.Build.0 = Debug|ARM
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|ARM64.ActiveCfg = Debug|ARM64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|ARM64.Build.0 = Debug|ARM64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|x64.ActiveCfg = Debug|x64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|x64.Build.0 = Debug|x64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|x86.ActiveCfg = Debug|x86
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Debug|x86.Build.0 = Debug|x86
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|Any CPU.Build.0 = Release|Any CPU
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|ARM.ActiveCfg = Release|ARM
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|ARM.Build.0 = Release|ARM
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|ARM64.ActiveCfg = Release|ARM64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|ARM64.Build.0 = Release|ARM64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|x64.ActiveCfg = Release|x64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|x64.Build.0 = Release|x64
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|x86.ActiveCfg = Release|x86
{80207DE7-F5EF-4B47-9C81-E65DEA1D4832}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
237 changes: 34 additions & 203 deletions appLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
using appLauncher.Core.Helpers;
using appLauncher.Core.Model;
using appLauncher.Core.Pages;

using GoogleAnalyticsv4SDK.Helpers;
using GoogleAnalyticsv4SDK.Interfaces;

using Newtonsoft.Json;
using GoogleAnalyticsv4SDK.Validation;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Networking;
using Windows.Networking.Connectivity;
using Windows.Storage;
using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -35,16 +27,9 @@ namespace appLauncher
/// </summary>
sealed partial class App : Application
{
public GoogleAnalyticsEndpoints tracker;
public List<IEvent> recordingEvents = new List<IEvent>();
public BackgroundWorker UDPServer = new BackgroundWorker();
public BackgroundWorker TCPServer = new BackgroundWorker();
public BackgroundWorker UDPClient = new BackgroundWorker();
public BackgroundWorker TCPClient = new BackgroundWorker();
private bool isnetworkstatuschangedregistered = false;
private NetworkStatusChangedEventHandler networkstatuschangedhandler;


public static ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
public ExceptionEventCalls reportException;
public ScreenViewEventCalls reportScreenViews;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand All @@ -57,62 +42,28 @@ public App()
App.Current.UnhandledException += App_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;


}
private void OnNetworkStatusChange(object sender)
{
SettingsHelper.totalAppSettings.Sync = false;
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{


if (!profile.IsWlanConnectionProfile)
{

// SettingsHelper.totalAppSettings.Sync = false;
return;
}
// SettingsHelper.totalAppSettings.Sync = true;
if (!((App)Current).UDPServer.IsBusy)
{
((App)Current).UDPServer.RunWorkerAsync();
}
if (!((App)Current).UDPClient.IsBusy)
{
((App)Current).UDPClient.RunWorkerAsync();
}
if (!((App)Current).TCPServer.IsBusy)
{
((App)Current).TCPServer.RunWorkerAsync();
}

}
}

private void NetworkStatusChange()
{
networkstatuschangedhandler = new NetworkStatusChangedEventHandler(OnNetworkStatusChange);
if (isnetworkstatuschangedregistered == false)
{
NetworkInformation.NetworkStatusChanged += networkstatuschangedhandler;
isnetworkstatuschangedregistered = true;
}

}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
GoogleAnalyticsv4SDK.Events.Mobile.Execeptions exec = new GoogleAnalyticsv4SDK.Events.Mobile.Execeptions(e.Exception);
((App)Application.Current).recordingEvents.Add(exec);
tracker.SendEvent(recordingEvents, SettingsHelper.totalAppSettings.ClientID, false);
// Dictionary<string, string> result = new Dictionary<string, string>();
// result.Add("UnhandedExceptionmessage", e.Exception.Message);
// result.Add("StackTrace", e.Exception.StackTrace);
// result.Add("TargetSite", e.Exception.TargetSite.Name);
// result.Add("ExceptionSource", e.Exception.Source);
// result.AddRange((IEnumerable<KeyValuePair<string, string>>)e.Exception.Data);

}

private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
GoogleAnalyticsv4SDK.Events.Mobile.Execeptions exec = new GoogleAnalyticsv4SDK.Events.Mobile.Execeptions(e.Exception);
((App)Application.Current).recordingEvents.Add(exec);
tracker.SendEvent(recordingEvents, SettingsHelper.totalAppSettings.ClientID, false);
//Dictionary<string, string> result = new Dictionary<string, string>();
//result.Add("Unhandedmessage", e.Message);
//result.Add("UnhandedExceptionmessage", e.Exception.Message);
//result.Add("StackTrace", e.Exception.StackTrace);
//result.Add("TargetSite", e.Exception.TargetSite.Name);
//result.Add("ExceptionSource", e.Exception.Source);
//result.AddRange((IEnumerable<KeyValuePair<string, string>>)e.Exception.Data);

}

Expand All @@ -126,38 +77,29 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
try
{
UDPServer.WorkerSupportsCancellation = true;
UDPServer.DoWork += UDPServer_DoWork;
UDPClient.WorkerSupportsCancellation = true;
UDPClient.DoWork += UDPClient_DoWork;
TCPServer.WorkerSupportsCancellation = true;
TCPServer.DoWork += TCPServer_DoWork;
TCPClient.WorkerSupportsCancellation = true;
TCPClient.DoWork += TCPClient_DoWork;


//Extends view into status bar/title bar, depending on the device used.
await SettingsHelper.LoadAppSettingsAsync();
tracker = new GoogleAnalyticsEndpoints(SettingsHelper.totalAppSettings.MeasurementID, SettingsHelper.totalAppSettings.APISecret);
reportScreenViews = new ScreenViewEventCalls(SettingsHelper.totalAppSettings.MeasurementID, SettingsHelper.totalAppSettings.APISecret, SettingsHelper.totalAppSettings.ClientID);
reportException = new ExceptionEventCalls(SettingsHelper.totalAppSettings.MeasurementID, SettingsHelper.totalAppSettings.APISecret, SettingsHelper.totalAppSettings.ClientID);
ApplicationView appView = ApplicationView.GetForCurrentView();
appView.SetPreferredMinSize(new Size(360, 360));
appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
IObservableMap<string, string> qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
SettingsHelper.SetApplicationResources();
OnNetworkStatusChange(new object());
NetworkStatusChange();

////if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop")
////{
//// appView.TitleBar.ButtonBackgroundColor = Colors.Transparent;
//// appView.TitleBar.BackgroundColor = Colors.Transparent;
//// CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
////}
if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop")
{
appView.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appView.TitleBar.BackgroundColor = Colors.Transparent;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
}

////if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile")
////{
//// ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile")
{
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

////}
}


Frame rootFrame = Window.Current.Content as Frame;
Expand Down Expand Up @@ -199,117 +141,6 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)

}
}

private void TCPClient_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// throw new NotImplementedException();
}

private void TCPClient_DoWork(object sender, DoWorkEventArgs e)
{
if (SettingsHelper.totalAppSettings.RemoteIP != null)
{
TcpClient client = new TcpClient();
client.ConnectAsync(SettingsHelper.totalAppSettings.RemoteIP.Address, 13000);
using (var stream = client.GetStream())
{
string content = JsonConvert.SerializeObject(SettingsHelper.totalAppSettings);
byte[] sendbody = Encoding.UTF8.GetBytes(content);
stream.WriteAsync(sendbody, 0, sendbody.Length);
}
}
}

private void TCPServer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{

}

private void TCPServer_DoWork(object sender, DoWorkEventArgs e)
{
TcpListener listener = new TcpListener(IPAddress.Any, 13000);
Task.Factory.StartNew(async () =>
{
listener.Start();
while (true)
{

TcpClient a = await listener.AcceptTcpClientAsync();
NetworkStream b = a.GetStream();
byte[] message = new byte[1024];
string test = string.Empty;
using (var stream = a.GetStream())
{
int ab = b.Read(message, 0, message.Length);
if (ab == 0)
{
return;
}
test += Encoding.UTF8.GetString(message, 0, ab);
SettingsHelper.totalAppSettings = JsonConvert.DeserializeObject<GlobalAppSettings>(test);
}
listener.Stop();
}
});
}

private void UDPClient_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
throw new NotImplementedException();
}

private async void UDPClient_DoWork(object sender, DoWorkEventArgs e)
{
UdpClient client = new UdpClient();
Task.Factory.StartNew(async () =>
{
while (true)
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Broadcast, 32123);
IReadOnlyList<HostName> hosts = NetworkInformation.GetHostNames();
byte[] data = Encoding.UTF8.GetBytes(hosts.ToString());
var a = await client.SendAsync(data, data.Length, ipep);
if (a > -1)
{
break;
}
}
});

}

private void UDPServer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// throw new NotImplementedException();
}

private void UDPServer_DoWork(object sender, DoWorkEventArgs e)
{
UdpClient server = new UdpClient();

//start listening for messages and copy the messages back to the client
Task.Factory.StartNew(async () =>
{
while (true)
{
var remoteEP = new IPEndPoint(IPAddress.Any, 32123);
UdpReceiveResult data = await server.ReceiveAsync();
var hosts = NetworkInformation.GetHostNames();
var es = Encoding.UTF8.GetString(data.Buffer);
if (es != hosts.ToString())
{
SettingsHelper.totalAppSettings.RemoteIP = data.RemoteEndPoint;
Console.WriteLine(data.RemoteEndPoint.Address);
Console.WriteLine(es);
break;
}


}
});
UDPServer.Dispose();
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions appLauncher/Core/Helpers/GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;

using Windows.Foundation;
Expand All @@ -13,7 +12,6 @@ namespace appLauncher.Core.Helpers
{
public static class GlobalVariables
{
public static IPEndPoint endPoint { get; set; }
public static int _appsPerScreen { get; private set; }
public static DraggedItem _Itemdragged { get; set; } = new DraggedItem();
public static int _columns { get; set; }
Expand Down
Loading