public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { SharedData sharedData = SharedData.SharedDataInstance; if (args.Kind == ActivationKind.Launch) { BackgroundTransfer backgroundTransfer = BackgroundTransfer.CreateBackgroundTransfer(); await backgroundTransfer.DiscoverActiveDownloadsAsync(); } //long-running startup tasks go here StorageFolder localFolder = ApplicationData.Current.LocalFolder; Views.MainPage._unsentMessagesFolder = await localFolder.CreateFolderAsync("UnsentMessages", CreationCollisionOption.OpenIfExists); Views.MainPage._sentMessagesFolder = await localFolder.CreateFolderAsync("SentMessages", CreationCollisionOption.OpenIfExists); Views.MainPage._receivedMessagesFolder = await localFolder.CreateFolderAsync("ReceivedMessages", CreationCollisionOption.OpenIfExists); Views.MainPage._draftMessagesFolder = await localFolder.CreateFolderAsync("DraftMessages", CreationCollisionOption.OpenIfExists); Views.MainPage._archivedMessagesFolder = await localFolder.CreateFolderAsync("ArchivedMessages", CreationCollisionOption.OpenIfExists); Views.MainPage._deletedMessagesFolder = await localFolder.CreateFolderAsync("DeletedMessages", CreationCollisionOption.OpenIfExists); Views.MainPage.LogsFolder = await localFolder.CreateFolderAsync("Logs", CreationCollisionOption.OpenIfExists); Views.MainPage._MetroLogsFolder = await localFolder.CreateFolderAsync("MetroLogs", CreationCollisionOption.OpenIfExists); SharedData.filesInInstalledLocation = await Package.Current.InstalledLocation.GetFilesAsync(); sharedData.BbsArray = await BBSDefinitions.OpenAsync(localFolder); //"ms-appx:///Assets/pdffile.pdf" sharedData.TncDeviceArray = await TNCDeviceArray.OpenAsync(localFolder); sharedData.ProfileArray = await ProfileArray.OpenAsync(localFolder); foreach (var tacticalCallsignType in _tacticalCallsignDataDictionary.Values) { tacticalCallsignType.TacticalCallsigns = await TacticalCallsigns.OpenAsync(tacticalCallsignType.FileName); } await AddressBook.Instance.OpenAsync(); await DistributionListArray.Instance.OpenAsync(); await ListViewParametersArray.Instance.OpenAsync(); NavigationService.Navigate(typeof(Views.MainPage)); await Task.CompletedTask; }
public App() { InitializeComponent(); EnteredBackground += App_EnteredBackground; Resuming += App_Resuming; //Suspending += App_SuspendingAsync; UnhandledException += OnAppUnhandledException; // Deferred execution until used. Check https://msdn.microsoft.com/library/dd642331(v=vs.110).aspx for further info on Lazy<T> class. _activationService = new Lazy <ActivationService>(CreateActivationService); LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new StreamingFileTarget()); GlobalCrashHandler.Configure(); // Write a FATAL entry, wait until all of the targets have finished writing, then call Application.Exit. TacticalCallsigns.CreateTacticalCallsignsData(); }
public async Task ProcessReceivedMessagesAsync() { if (_packetMessagesReceived.Count() > 0) { bool updateBulletinList = false; foreach (PacketMessage packetMessageOutpost in _packetMessagesReceived) { FormControlBase formControl = new MessageControl(); // test for packet form!! PacketMessage pktMsg = new PacketMessage() { BBSName = packetMessageOutpost.BBSName, TNCName = packetMessageOutpost.TNCName, MessageSize = packetMessageOutpost.MessageSize, MessageNumber = packetMessageOutpost.MessageNumber, ReceivedTime = packetMessageOutpost.ReceivedTime, CreateTime = DateTime.Now, Area = packetMessageOutpost.Area, // Save the original message for post processing (tab characters are lost in the displayed message) MessageBody = packetMessageOutpost.MessageBody, MessageState = MessageState.Locked, MessageOpened = false, MessageOrigin = MessageOriginHelper.MessageOrigin.Received, }; string[] msgLines = packetMessageOutpost.MessageBody.Split(new string[] { "\r\n", "\r" }, StringSplitOptions.None); // Check if base64 encoded int startOfMessage = 0; int startOfMessage1 = 0; int startOfMessage2 = 0; int endOfMessage = 0; bool dateFound = false; bool subjectFound = false; for (int k = 0; k < msgLines.Length; k++) { if (msgLines[k].StartsWith("Date:")) { dateFound = true; startOfMessage1 = k + 1; } if (msgLines[k].StartsWith("Subject:")) { subjectFound = true; startOfMessage2 = k + 1; } if (dateFound && subjectFound) { break; } } startOfMessage = Math.Max(startOfMessage1, startOfMessage2); endOfMessage = msgLines.Length - 1; try { // Process encoded message string message = ""; for (int j = startOfMessage; j <= endOfMessage; j++) { message += msgLines[j]; } const string outpostEncodedMarker = "!B64!"; if (message.StartsWith(outpostEncodedMarker)) { message = message.Substring(outpostEncodedMarker.Length); } byte[] messageText = Convert.FromBase64String(message); string decodedString = Encoding.UTF8.GetString(messageText); List <string> msgLinesList = msgLines.ToList(); msgLinesList.RemoveRange(startOfMessage, endOfMessage - startOfMessage + 1); string[] decodedMsgLines = decodedString.Split(new string[] { "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); msgLinesList.InsertRange(startOfMessage, decodedMsgLines); msgLines = msgLinesList.ToArray(); _logHelper.Log(LogLevel.Info, "This message was an encoded message"); } catch (FormatException) { // Not an encoded message //_logHelper.Log(LogLevel.Info, "Not an encoded message"); } catch (ArgumentOutOfRangeException) { _logHelper.Log(LogLevel.Error, "Argument out of range"); } bool toFound = false; subjectFound = false; string prefix = ""; for (int i = 0; i < Math.Min(msgLines.Length, 20); i++) { if (msgLines[i].StartsWith("From:")) { pktMsg.MessageFrom = NormalizeEmailField(msgLines[i].Substring(6)); } else if (!toFound && msgLines[i].StartsWith("To:")) { pktMsg.MessageTo = NormalizeEmailField(msgLines[i].Substring(4)); toFound = true; } else if (msgLines[i].StartsWith("Cc:")) { pktMsg.MessageTo += (", " + msgLines[i].Substring(4)); while (msgLines[i + 1].Length == 0) { i++; } if (msgLines[i + 1][0] == ' ') { pktMsg.MessageTo += msgLines[i + 1].TrimStart(new char[] { ' ' }); } } else if (!subjectFound && msgLines[i].StartsWith("Subject:")) { pktMsg.Subject = msgLines[i].Substring(9); if (pktMsg.Subject[3] == '-') { prefix = pktMsg.Subject.Substring(0, 3); } //pktMsg.MessageSubject = pktMsg.MessageSubject.Replace('\t', ' '); subjectFound = true; } else if (msgLines[i].StartsWith("Date:")) { pktMsg.JNOSDate = DateTime.Parse(msgLines[i].Substring(10, 21)); } else if (msgLines[i].StartsWith("# FORMFILENAME:")) { string html = ".html"; string formName = msgLines[i].Substring(16).TrimEnd(new char[] { ' ' }); formName = formName.Substring(0, formName.Length - html.Length); pktMsg.PacFormName = formName; formControl = FormsViewModel.CreateFormControlInstance(pktMsg.PacFormName); if (formControl is null) { _logHelper.Log(LogLevel.Error, $"Form {pktMsg.PacFormName} not found"); await ContentDialogs.ShowSingleButtonContentDialogAsync($"Form {pktMsg.PacFormName} not found"); return; } pktMsg.SenderMessageNumber = FormControlBase.GetOutpostValue(msgLines[i + 1]); pktMsg.FormProvider = FormProviders.PacForm; // TODO update with real provider //pktMsg.FormProvider = formControl.FormProvider; // TODO update with real provider break; } else if (msgLines[i].StartsWith("#T:")) { string[] fileNameString = msgLines[i].Split(new char[] { ' ', '.' }, StringSplitOptions.RemoveEmptyEntries); string formName = fileNameString[1]; formName.Trim(); pktMsg.PacFormName = formName; formControl = FormsViewModel.CreateFormControlInstance(pktMsg.PacFormName); if (formControl is null) { _logHelper.Log(LogLevel.Error, $"Form {pktMsg.PacFormName} not found"); await ContentDialogs.ShowSingleButtonContentDialogAsync($"Form {pktMsg.PacFormName} not found"); return; } pktMsg.SenderMessageNumber = FormControlBase.GetOutpostValue(msgLines[i + 2]); pktMsg.FormProvider = FormProviders.PacItForm; break; } } //pktMsg.MessageNumber = GetMessageNumberPacket(); // Filled in BBS connection pktMsg.PacFormType = formControl.PacFormType; //pktMsg.PacFormName = formControl.GetPacFormName(); pktMsg.PacFormName = formControl.FormControlName; pktMsg.FormControlType = formControl.FormControlType; pktMsg.FormFieldArray = formControl.ConvertFromOutpost(pktMsg.MessageNumber, ref msgLines, pktMsg.FormProvider); //if (pktMsg.ReceivedTime != null) //{ // DateTime dateTime = (DateTime)pktMsg.ReceivedTime; //} if (!pktMsg.CreateFileName()) { _logHelper.Log(LogLevel.Error, $"Error in Create FileName(), {pktMsg.MessageNumber}, {pktMsg.PacFormType}"); throw new Exception(); } AddressBook.Instance.UpdateLastUsedBBS(pktMsg.MessageFrom, prefix); _logHelper.Log(LogLevel.Info, $"Message number {pktMsg.MessageNumber} received"); // If the received message is a delivery confirmation, update receivers message number in the original sent message if (!string.IsNullOrEmpty(pktMsg.Subject) && pktMsg.Subject.Contains("DELIVERED:")) { await ProcessMessagesMarkedDeliveredAsync(pktMsg); } pktMsg.Save(SharedData.ReceivedMessagesFolder.Path); if (!string.IsNullOrEmpty(pktMsg.Area)) { updateBulletinList |= true; // Does this work with xscevent if (pktMsg.Area.ToLower() == "xscperm") { if (pktMsg.Subject.ToLower().Contains("scco packet frequencies")) { await BBSDefinitions.CreateFromBulletinAsync(pktMsg); } else if (pktMsg.Subject.ToLower().Contains("scco packet tactical calls")) { await TacticalCallsigns.CreatePacketTacticalCallsignsFromBulletinAsync(pktMsg); } } } // Do printing if requested if (!string.IsNullOrEmpty(pktMsg.Subject) && !pktMsg.Subject.Contains("DELIVERED:") && string.IsNullOrEmpty(pktMsg.Area) && SettingsViewModel.Instance.PrintReceivedMessages) { _logHelper.Log(LogLevel.Info, $"Message number {pktMsg.MessageNumber} to be printed"); pktMsg.Save(SharedData.PrintMessagesFolder.Path); SettingsViewModel settingsViewModel = SettingsViewModel.Instance; PrintQueue.Instance.AddToPrintQueue(pktMsg.FileName, settingsViewModel.ReceivedCopyNamesAsArray()); // Test await PrintQueue.Instance.PrintToDestinationsAsync(); //await Singleton<PrintQueue>.Instance.BackgroundPrintingTrigger.RequestAsync(); } } //RefreshDataGrid(); // Display newly added messages if (updateBulletinList) { await MainViewModel.Instance.UpdateDownloadedBulletinsAsync(); } } }
protected override async void OnLaunched(LaunchActivatedEventArgs args) { _logHelper.Log(LogLevel.Info, "--------------------------------------"); _logHelper.Log(LogLevel.Info, "Packet Messaging Application started"); StorageFolder localFolder = ApplicationData.Current.LocalFolder; Properties = await localFolder.ReadAsync <Dictionary <string, object> >(PropertiesDictionaryFileName) ?? new Dictionary <string, object>(); if (Properties is null) { Properties = new Dictionary <string, object>(); } //TacticalCallsArray = await localFolder.ReadAsync<int[]>(TacticalCallsArrayFileName); #if DEBUG SharedData.TestFilesFolder = await localFolder.CreateFolderAsync("TestFiles", CreationCollisionOption.OpenIfExists); // Shows how to process tasks that return a value //IAsyncOperation<StorageFolder>[] folders = new IAsyncOperation<StorageFolder>[] //{ // localFolder.CreateFolderAsync("TestFiles", CreationCollisionOption.OpenIfExists), //}; ////IAsyncOperation<StorageFolder> folders[0] = localFolder.CreateFolderAsync("TestFiles", CreationCollisionOption.OpenIfExists); //List<Task> folderTasks = new List<Task>() { folders[0].AsTask<StorageFolder>() }; //while (folderTasks.Count > 0) //{ // Task finishedTask = await Task.WhenAny(folderTasks); // string s = finishedTask.ToString(); // if (finishedTask == folders[0]) // { // SharedData.TestFilesFolder = folders[0].GetResults(); // } // folderTasks.Remove(finishedTask); //} #endif SharedData.MetroLogsFolder = await localFolder.CreateFolderAsync("MetroLogs", CreationCollisionOption.OpenIfExists); SharedData.ArchivedMessagesFolder = await localFolder.CreateFolderAsync("ArchivedMessages", CreationCollisionOption.OpenIfExists); SharedData.DeletedMessagesFolder = await localFolder.CreateFolderAsync("DeletedMessages", CreationCollisionOption.OpenIfExists); SharedData.DraftMessagesFolder = await localFolder.CreateFolderAsync("DraftMessages", CreationCollisionOption.OpenIfExists); SharedData.ReceivedMessagesFolder = await localFolder.CreateFolderAsync("ReceivedMessages", CreationCollisionOption.OpenIfExists); SharedData.SentMessagesFolder = await localFolder.CreateFolderAsync("SentMessages", CreationCollisionOption.OpenIfExists); SharedData.UnsentMessagesFolder = await localFolder.CreateFolderAsync("UnsentMessages", CreationCollisionOption.OpenIfExists); SharedData.PrintMessagesFolder = await localFolder.CreateFolderAsync("PrintMessages", CreationCollisionOption.OpenIfExists); //// Moved here for FormMenuIndexDefinitions.Instance.OpenAsync() //SharedData.Assemblies = new List<Assembly>(); //AppDomain currentDomain = AppDomain.CurrentDomain; //Assembly[] assemblies = currentDomain.GetAssemblies(); //foreach (Assembly assembly in assemblies) //{ // if (!assembly.FullName.Contains("FormControl")) // continue; // //_logHelper.Log(LogLevel.Info, $"Assembly: {assembly}"); // SharedData.Assemblies.Add(assembly); //} ////_logHelper.Log(LogLevel.Info, $"Assembly count: {SharedData.Assemblies.Count}"); foreach (TacticalCallsignData tacticalCallsignType in TacticalCallsigns.TacticalCallsignDataList) { //Task<TacticalCallsigns> taskFinished = TacticalCallsigns.OpenAsync(tacticalCallsignType.FileName); // taskFinished = TacticalCallsigns.OpenAsync(tacticalCallsignType.FileName); //tacticalCallsignType.TacticalCallsigns = taskFinished.Result; tacticalCallsignType.TacticalCallsigns = await TacticalCallsigns.OpenAsync(tacticalCallsignType.FileName); } //await UserCallsigns.OpenAsync(); // The following Open() must happen in the right order await TNCDeviceArray.Instance.OpenAsync(); await BBSDefinitions.Instance.OpenAsync(); //"ms-appx:///Assets/pdffile.pdf" await EmailAccountArray.Instance.OpenAsync(); await ProfileArray.Instance.OpenAsync(); List <Task> tasks = new List <Task> { UserAddressArray.Instance.OpenAsync(), DistributionListArray.Instance.OpenAsync(), HospitalRollCall.Instance.OpenAsync(), CustomFoldersArray.OpenAsync(), }; while (tasks.Count > 0) { Task finishedTask = await Task.WhenAny(tasks); tasks.Remove(finishedTask); } AddressBook.Instance.CreateAddressBook(); if (!args.PrelaunchActivated) { await ActivationService.ActivateAsync(args); } ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; SharedData.SettingsContainer = localSettings.CreateContainer("SettingsContainer", ApplicationDataCreateDisposition.Always); //SharedData.FilesInInstalledLocation = await Package.Current.InstalledLocation.GetFilesAsync(); //await UpdatePacFormsFiles.SyncPacFormFoldersAsync(); BulletinHelpers.CreateBulletinDictionaryFromFiles(); bool displayIdentity = Properties.TryGetValue("DisplayIdentityAtStartup", out object displayIdentityAtStartup); bool callsignExist = Properties.TryGetValue("UserCallsign", out object userCallsign); bool displayProfiles = Properties.TryGetValue("DisplayProfileOnStart", out object displayProfileOnStart); // Show Identity dialog if Call-sign is empty if (displayIdentity && (bool)displayIdentityAtStartup || !callsignExist || string.IsNullOrEmpty((string)userCallsign)) { NavigationService.Navigate(typeof(SettingsPage), 1); } else if (displayProfiles && (bool)displayProfileOnStart) { NavigationService.Navigate(typeof(SettingsPage), 2); } Utilities.SetApplicationTitle(); SharedData.Assemblies = new List <Assembly>(); AppDomain currentDomain = AppDomain.CurrentDomain; Assembly[] assemblies = currentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (!assembly.FullName.Contains("FormControl")) { continue; } //_logHelper.Log(LogLevel.Info, $"Assembly: {assembly}"); SharedData.Assemblies.Add(assembly); } await FormMenuIndexDefinitions.Instance.OpenAsync(); // Depends on SharedData.Assemblies //_logHelper.Log(LogLevel.Info, $"Assembly count: {SharedData.Assemblies.Count}"); }