Exemplo n.º 1
0
        public static int FindHighestUsedMesageNumber()
        {
            string msgNoPrefix;

            if (IdentityViewModel.Instance.UseTacticalCallsign)
            {
                msgNoPrefix = IdentityViewModel.Instance.TacticalMsgPrefix;
            }
            else
            {
                msgNoPrefix = IdentityViewModel.Instance.UserMsgPrefix;
            }

            if (string.IsNullOrEmpty(msgNoPrefix))
            {
                return(0);
            }

            List <int> msgNumbers = new List <int>();

            Task <int>[] taskArray = { Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.ArchivedMessagesFolder.Path, msgNoPrefix)),
                                       Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.DeletedMessagesFolder.Path,  msgNoPrefix)),
                                       Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.DraftMessagesFolder.Path,    msgNoPrefix)),
                                       Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.ReceivedMessagesFolder.Path, msgNoPrefix)),
                                       Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.SentMessagesFolder.Path,     msgNoPrefix)),
                                       Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(SharedData.UnsentMessagesFolder.Path,   msgNoPrefix)), };

            var results = new int[taskArray.Length];

            for (int i = 0; i < taskArray.Length; i++)
            {
                msgNumbers.Add(taskArray[i].Result);
            }

            // Get message numbers from custom folders
            CustomFoldersArray _customFoldersInstance = CustomFoldersArray.Instance;
            List <Task <int> > taskList = new List <Task <int> >();

            foreach (string path in _customFoldersInstance.CustomStorageFolderPathList)
            {
                taskList.Add(Task <int> .Factory.StartNew(() => FindHighestUsedMesageNumberInFolder(path, msgNoPrefix)));
            }

            results = new int[taskList.Count];
            for (int i = 0; i < taskList.Count; i++)
            {
                msgNumbers.Add(taskList[i].Result);
            }

            msgNumbers.Sort();

            //_logHelper.Log(LogLevel.Info, $"msgNumbers: {msgNumbers.Last()}");

            return(msgNumbers.Last());
        }
Exemplo n.º 2
0
        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}");
        }