Exemplo n.º 1
0
        public static async Task <BBSDefinitions> OpenAsync(StorageFolder localFolder1)
        {
            BBSDefinitions bbsDataArray = null;

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                var storageItem = await localFolder.TryGetItemAsync(bbsFileName);

                if (storageItem == null)
                {
                    // Copy the file from the install folder to the local folder
                    var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

                    var storageFile = await folder.GetFileAsync(bbsFileName);

                    if (storageFile != null)
                    {
                        await storageFile.CopyAsync(localFolder, bbsFileName, Windows.Storage.NameCollisionOption.FailIfExists);
                    }
                }

                StorageFile file = await localFolder.GetFileAsync(bbsFileName);

                using (FileStream reader = new FileStream(file.Path, FileMode.Open))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(BBSDefinitions));
                    bbsDataArray = (BBSDefinitions)serializer.Deserialize(reader);
                }
            }
            catch (FileNotFoundException e)
            {
                Debug.WriteLine($"Open BBSData file failed: {e.Message}");
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error opening {e.Message} {e}");
            }
            return(bbsDataArray);
        }
Exemplo n.º 2
0
        public static BBSDefinitions CreateFromBulletin(ref PacketMessage bbsBulletin)
        {
            string bulletin = bbsBulletin.MessageBody;

            if (bulletin == null)
            {
                return(null);
            }

            int start  = 0;
            int start2 = 0;

            bulletin = bulletin.Substring(start);

            start   = bulletin.IndexOf("---------");
            start2 += start;
            string bbsInfo = bulletin.Substring(start);

            start   = bbsInfo.IndexOf("\n");
            start2 += start;
            bbsInfo = bbsInfo.Substring(start + 1);
            int end = bbsInfo.IndexOf('*');

            bbsInfo = bbsInfo.Substring(0, end);

            BBSData bbsData;
            var     lines    = bbsInfo.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int     bbsCount = lines.Length;

            BBSData[] bbsdataArray = new BBSData[lines.Length + 1];
            int       i            = 0;

            for (; i < lines.Length; i++)
            {
                var callsign = lines[i].Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                bbsData             = new BBSData();
                bbsData.Name        = callsign[0];
                bbsData.ConnectName = callsign[1];
                bbsData.Frequency1  = callsign[2];
                bbsData.Frequency2  = callsign[3];
                bbsData.Selected    = false;

                bbsdataArray[i] = bbsData;
            }
            // Location
            bbsInfo = bulletin.Substring(start2 + end);
            start   = bbsInfo.IndexOf("---------");
            bbsInfo = bbsInfo.Substring(start);
            start   = bbsInfo.IndexOf("\n");
            bbsInfo = bbsInfo.Substring(start + 1);
            string description = "Santa Clara County ARES/RACES PacketSystem. ";

            lines = bbsInfo.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            for (i = 0; i < bbsCount; i++)
            {
                var callsign = lines[i].Split(new string[] { ",", "      ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
                bbsdataArray[i].Description = description + callsign[1];
            }
            bbsdataArray[0].Selected = true;

            // Add training BBS
            bbsData             = new BBSData();
            bbsData.Name        = "W5XSC";
            bbsData.ConnectName = "W5XSC-1";
            bbsdataArray[i]     = bbsData;

            BBSDefinitions bbsDefinitions = new BBSDefinitions();

            bbsDefinitions.RevisionTime = bbsBulletin.JNOSDate;
            bbsDefinitions.BBSDataArray = bbsdataArray;

            return(bbsDefinitions);
        }