Bloxy.DeviceConfiguration.Save C# (CSharp) Method

Save() public method

public Save ( string fileName ) : void
fileName string
return void
        public void Save(string fileName)
        {
            if (File.Exists(fileName)) File.Delete(fileName);
              var writer = File.CreateText(fileName);

              writer.WriteLine("BDAddr=" + this.BDAddr.ToString("X12"));
              writer.WriteLine("RemoteName=" + this.RemoteName);
              writer.WriteLine("DeviceClass=" + this.DeviceClass.ToString("X06"));
              writer.WriteLine("PageScanRepetitionMode=" + this.PageScanRepetitionMode.ToString("X02"));
              writer.WriteLine("ClockOffset=" + this.ClockOffset.ToString("X04"));
              writer.Close();
        }

Usage Example

Example #1
0
        private static bool _CreateConfiguration(string fileName)
        {
            //Do an inquiry scan, find a device, and save its information
            Logger.WriteLine(String.Format("Configuration file '{0}' does not exist.", fileName));
            Logger.WriteLine("Performing inquiry scan...");

            var devices = Properties.Adapter.DoInquiryScan(INQUIRY_TIMEOUT_SECS);

            Logger.WriteLine(String.Format("Found {0} devices:", devices.Count));
            var list = new Dictionary <int, InquiryInfo>();

            for (int i = 1; i < devices.Count + 1; i++)
            {
                var name = Properties.Adapter.GetRemoteName(devices[i - 1]);
                Logger.WriteLine(String.Format("\t{0}: {1} - {2}", i.ToString(), devices[i - 1].BDAddr.ToString("X12"), name));

                list.Add(i, new InquiryInfo(devices[i - 1], name));
            }

            while (true)
            {
                Logger.WriteLine("Enter the index of the device you want to use (or 'x' to quit): ");
                var selected = Console.ReadKey().KeyChar;
                Logger.WriteLine();

                //HACK: Yeah, I know this would freak out with more than 9 devices...
                if (selected == 'x')
                {
                    return(false);
                }
                else if (list.ContainsKey(selected - 0x30))
                {
                    var item = list[selected - 0x30];

                    //Build the configuration
                    var file = new DeviceConfiguration();
                    file.BDAddr                 = item.Result.BDAddr;
                    file.RemoteName             = item.RemoteName;
                    file.DeviceClass            = item.Result.DeviceClass;
                    file.PageScanRepetitionMode = item.Result.PageScanRepetitionMode;
                    file.ClockOffset            = item.Result.ClockOffset;

                    //Write it out
                    Logger.WriteLine(String.Format("Saving configuration file '{0}'...", fileName));
                    file.Save(fileName);

                    break;
                }
                else
                {
                    Logger.WriteLine("Invalid selection, try again.");
                }
            }

            return(true);
        }
All Usage Examples Of Bloxy.DeviceConfiguration::Save