예제 #1
0
        private async Task ReadFirmwareDictionary(bool fDownloadScratchDocuments)
        {
            using (var releaser = await _fwDictLock.LockAsync())
            {
                try
                {
                    var content = File.ReadAllText(GetFirmwareDictionaryPath());

                    _firmwareDictionary = JsonConvert.DeserializeObject <FirmwareDictionary>(content);

                    if (fDownloadScratchDocuments)
                    {
                        await UpdateDownloadableAssets();
                    }
                }
                catch (FileNotFoundException)
                {
                    _firmwareDictionary = null;
                }
                catch (Exception ex)
                {
                    _firmwareDictionary = null;
                    _tc.TrackException(ex);
                }
            }
        }
예제 #2
0
        private async Task UpdateFirmwareDictionaryFromInstallation()
        {
            var    destPath = GetFirmwareDictionaryPath();
            string sourcePath;

            sourcePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                sourcePath = ApplicationDeployment.CurrentDeployment.DataDirectory;
            }
            else
            {
                sourcePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            }
            sourcePath = Path.Combine(sourcePath, @"Assets\Installation\Dictionary", GetFirmwareDictionaryFileName());

            var lastWrite = File.GetLastWriteTime(destPath);

            // Missing files use a year of 1601 instead of DateTime.MinValue. Treat anything
            //   before 2015 as a missing file, because unless I start time traveling, that is
            //   an invalid file.
            if (lastWrite.Year < 2015)
            {
                try
                {
                    // We've never retrieved the file - go get a copy unconditionally
                    // Use a temp file because DownloadFile will create a zero-length file if there is an error retrieving the web content
                    File.Copy(sourcePath, destPath, true);
                    await ReadFirmwareDictionary(true);
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                    _firmwareDictionary = null;
                }
            }
            else
            {
                try
                {
                    // The file exists locally - get it only if it is newer on the server
                    var destLastWrite   = File.GetLastWriteTimeUtc(destPath);
                    var sourceLastWrite = File.GetCreationTimeUtc(sourcePath);

                    if (destLastWrite < sourceLastWrite)
                    {
                        File.Copy(sourcePath, destPath, true);
                        await ReadFirmwareDictionary(true);
                    }
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                }
                if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                {
                    throw new Exception("Unable to load firmware dictionary from install dir. Program cannot start");
                }
            }
        }
예제 #3
0
        private async Task ReadFirmwareDictionary(bool fDownloadScratchDocuments)
        {
            using (var releaser = await _fwDictLock.LockAsync())
            {
                try
                {
                    var content = File.ReadAllText(GetFirmwareDictionaryPath());

                    _firmwareDictionary = JsonConvert.DeserializeObject<FirmwareDictionary>(content);

                    if (fDownloadScratchDocuments)
                        await UpdateDownloadableAssets();
                }
                catch (FileNotFoundException fnfex)
                {
                    _firmwareDictionary = null;
                }
                catch (Exception ex)
                {
                    _firmwareDictionary = null;
                    _tc.TrackException(ex);
                }
            }
        }
예제 #4
0
        private async Task UpdateFirmwareDictionaryFromInternet()
        {
            var destPath = GetFirmwareDictionaryPath();
            var uriString = Constants.S4NHost + Constants.FirmwarePath + GetFirmwareDictionaryFileName();
            var uri = new Uri(uriString);

            var lastWrite = File.GetLastWriteTime(destPath);
            // Missing files use a year of 1601 instead of DateTime.MinValue. Treat anything
            //   before 2015 as a missing file, because unless I start time traveling, that is
            //   an invalid file.
            if (lastWrite.Year < 2015)
            {
                try
                {
                    // We've never retrieved the file - go get a copy unconditionally
                    // Use a temp file because DownloadFile will create a zero-length file if there is an error retrieving the web content
                    var tempFile = Path.GetTempFileName();
                    var client = new WebClient();
                    client.DownloadFile(uri, tempFile);
                    File.Copy(tempFile, destPath, true);
                    await ReadFirmwareDictionary(true);
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                    _firmwareDictionary = null;
                }
            }
            else
            {
                try
                {
                    // The file exists locally - get it only if it is newer on the server
                    var comparisonTime = lastWrite.ToUniversalTime();
                    var req = (HttpWebRequest)WebRequest.Create(uri);
                    req.IfModifiedSince = comparisonTime;
                    using (var response = (HttpWebResponse)await req.GetResponseAsync())
                    {
                        using (var sr = new StreamReader(response.GetResponseStream()))
                        {
                            var body = sr.ReadToEnd();
                            File.WriteAllText(destPath, body);
                        }
                    }
                    await ReadFirmwareDictionary(true);
                }
                catch (WebException wex)
                {
                    if (wex.Response != null)
                    {
                        var status = ((HttpWebResponse)wex.Response).StatusCode;
                        if (status == HttpStatusCode.NotModified)
                        {
                            // no big deal - we have the latest copy
                        }
                        else
                        {
                            // error - file not updated
                            _tc.TrackException(wex);
                        }
                    }
                    else
                    {
                        // error - file not updated
                        _tc.TrackException(wex);
                    }
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                }

                if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                {
                    await UpdateFirmwareDictionaryFromInstallation();
                    if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                        throw new Exception("Unable to load firmware dictionary from web or install dir. Program cannot start");
                }
            }
        }
예제 #5
0
        private async Task UpdateFirmwareDictionaryFromInstallation()
        {
            var destPath = GetFirmwareDictionaryPath();
            string sourcePath;

            if (ApplicationDeployment.IsNetworkDeployed)
                sourcePath = ApplicationDeployment.CurrentDeployment.DataDirectory;
            else
                sourcePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            sourcePath = Path.Combine(sourcePath, @"Assets\Installation\Dictionary", GetFirmwareDictionaryFileName());

            var lastWrite = File.GetLastWriteTime(destPath);
            // Missing files use a year of 1601 instead of DateTime.MinValue. Treat anything
            //   before 2015 as a missing file, because unless I start time traveling, that is
            //   an invalid file.
            if (lastWrite.Year < 2015)
            {
                try
                {
                    // We've never retrieved the file - go get a copy unconditionally
                    // Use a temp file because DownloadFile will create a zero-length file if there is an error retrieving the web content
                    File.Copy(sourcePath, destPath, true);
                    await ReadFirmwareDictionary(true);
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                    _firmwareDictionary = null;
                }
            }
            else
            {
                try
                {
                    // The file exists locally - get it only if it is newer on the server
                    var destLastWrite = File.GetLastWriteTimeUtc(destPath);
                    var sourceLastWrite = File.GetCreationTimeUtc(sourcePath);

                    if (destLastWrite < sourceLastWrite)
                    {
                        File.Copy(sourcePath, destPath, true);
                        await ReadFirmwareDictionary(true);
                    }
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                }
                if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                    throw new Exception("Unable to load firmware dictionary from install dir. Program cannot start");
            }
        }
예제 #6
0
        private async Task UpdateFirmwareDictionaryFromInternet()
        {
            var destPath  = GetFirmwareDictionaryPath();
            var uriString = Constants.S4NHost + Constants.FirmwarePath + GetFirmwareDictionaryFileName();
            var uri       = new Uri(uriString);

            var lastWrite = File.GetLastWriteTime(destPath);

            // Missing files use a year of 1601 instead of DateTime.MinValue. Treat anything
            //   before 2015 as a missing file, because unless I start time traveling, that is
            //   an invalid file.
            if (lastWrite.Year < 2015)
            {
                try
                {
                    // We've never retrieved the file - go get a copy unconditionally
                    // Use a temp file because DownloadFile will create a zero-length file if there is an error retrieving the web content
                    var tempFile = Path.GetTempFileName();
                    var client   = new WebClient();
                    client.DownloadFile(uri, tempFile);
                    File.Copy(tempFile, destPath, true);
                    await ReadFirmwareDictionary(true);
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                    _firmwareDictionary = null;
                }
            }
            else
            {
                try
                {
                    // The file exists locally - get it only if it is newer on the server
                    var comparisonTime = lastWrite.ToUniversalTime();
                    var req            = (HttpWebRequest)WebRequest.Create(uri);
                    req.IfModifiedSince = comparisonTime;
                    using (var response = (HttpWebResponse)await req.GetResponseAsync())
                    {
                        using (var sr = new StreamReader(response.GetResponseStream()))
                        {
                            var body = sr.ReadToEnd();
                            File.WriteAllText(destPath, body);
                        }
                    }
                    await ReadFirmwareDictionary(true);
                }
                catch (WebException wex)
                {
                    if (wex.Response != null)
                    {
                        var status = ((HttpWebResponse)wex.Response).StatusCode;
                        if (status == HttpStatusCode.NotModified)
                        {
                            // no big deal - we have the latest copy
                        }
                        else
                        {
                            // error - file not updated
                            _tc.TrackException(wex);
                        }
                    }
                    else
                    {
                        // error - file not updated
                        _tc.TrackException(wex);
                    }
                }
                catch (Exception ex)
                {
                    _tc.TrackException(ex);
                }

                if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                {
                    await UpdateFirmwareDictionaryFromInstallation();

                    if (_firmwareDictionary == null || _firmwareDictionary.Boards.Count == 0)
                    {
                        throw new Exception("Unable to load firmware dictionary from web or install dir. Program cannot start");
                    }
                }
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            var MicrosoftSpot431LibraryId = Guid.Parse("e98b4d8f-6f47-4663-bbae-bbe6fc8a019f");
            var ghiSdkLibraryId = Guid.Parse("9dea3dc3-6e24-45c4-9d1f-79cc35020e34");
            var brainPad431LibraryId = Guid.Parse("26571886-8ec7-4d55-9d43-c418545f2169");

            var dict = new FirmwareDictionary();

            //
            // Firmware Images
            //
            var brainPadImage = new FirmwareImage()
            {
                Id = Guid.Parse("b335f011-7604-4984-9418-33c9ce00d3ae"),
                Name = "BrainPad",
                AppName = "BrainPadFirmataApp",
                AppVersion = new Version(1, 0, 0, 0),
                Description = "This firmware unlocks all of the features of the GHI Electronics BrainPad",
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
                ConfigurationExtension = null,
                ImageCreatedBy = "Pervasive Digital LLC",
                ImageSupportUrl = "mailto:[email protected]",
            };
            dict.Images.Add(brainPadImage);

            //
            // Assemblies
            //
            var assm = new FirmwareAssembly()
            {
                Id = Guid.Parse("99d20fa1-895e-49b6-9a4f-45e4e08ff106"),
                Filename = "Microsoft.SPOT.Graphics.pe",
                IsLittleEndian = true,
                LibraryId = MicrosoftSpot431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id = Guid.Parse("a39662ef-143e-4cb4-9f75-22f0ea1b404b"),
                Filename = "Microsoft.SPOT.Hardware.USB.pe",
                IsLittleEndian = true,
                LibraryId = MicrosoftSpot431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id = Guid.Parse("302fe463-f90c-4a03-9554-e8af4903f516"),
                Filename = "GHI.Hardware.pe",
                IsLittleEndian = true,
                LibraryId = ghiSdkLibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id = Guid.Parse("62239dee-07d4-4447-997f-fa3808e250bd"),
                Filename = "FirmataRuntime.pe",
                IsLittleEndian = true,
                LibraryId = brainPad431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id = Guid.Parse("5b61839a-bc8b-4328-800b-e3372a7262e2"),
                Filename = "BrainPadFirmataApp.pe",
                IsLittleEndian = true,
                LibraryId = brainPad431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            //
            // Boards
            //

            var board = new FirmwareHost()
            {
                Id = Guid.Parse("6a9bdb56-8005-428d-9f29-8c425d9614b0"),
                Name = "BrainPad",
                ProductImageName = "BrainPad.jpg",
                Manufacturer = "GHI Electronics",
                Description = "Hardware for STEM education",
                UsbName = "G30_G30",
                BuildInfoContains = "GHI Electronics",
                OEM = 0xff,
                SKU = 0xffff,
            };
            board.CompatibleImages.Add(brainPadImage.Id);
            dict.Boards.Add(board);

            var content = JsonConvert.SerializeObject(dict, Formatting.Indented);
            File.WriteAllText("dict.json", content);
        }
예제 #8
0
        static void Main(string[] args)
        {
            var MicrosoftSpot431LibraryId = Guid.Parse("e98b4d8f-6f47-4663-bbae-bbe6fc8a019f");
            var ghiSdkLibraryId           = Guid.Parse("9dea3dc3-6e24-45c4-9d1f-79cc35020e34");
            var brainPad431LibraryId      = Guid.Parse("26571886-8ec7-4d55-9d43-c418545f2169");

            var dict = new FirmwareDictionary();

            //
            // Firmware Images
            //
            var brainPadImage = new FirmwareImage()
            {
                Id                     = Guid.Parse("b335f011-7604-4984-9418-33c9ce00d3ae"),
                Name                   = "BrainPad",
                AppName                = "BrainPadFirmataApp",
                AppVersion             = new Version(1, 0, 0, 0),
                Description            = "This firmware unlocks all of the features of the GHI Electronics BrainPad",
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
                ConfigurationExtension = null,
                ImageCreatedBy         = "Pervasive Digital LLC",
                ImageSupportUrl        = "mailto:[email protected]",
            };

            dict.Images.Add(brainPadImage);

            //
            // Assemblies
            //
            var assm = new FirmwareAssembly()
            {
                Id                     = Guid.Parse("99d20fa1-895e-49b6-9a4f-45e4e08ff106"),
                Filename               = "Microsoft.SPOT.Graphics.pe",
                IsLittleEndian         = true,
                LibraryId              = MicrosoftSpot431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };

            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id                     = Guid.Parse("a39662ef-143e-4cb4-9f75-22f0ea1b404b"),
                Filename               = "Microsoft.SPOT.Hardware.USB.pe",
                IsLittleEndian         = true,
                LibraryId              = MicrosoftSpot431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id                     = Guid.Parse("302fe463-f90c-4a03-9554-e8af4903f516"),
                Filename               = "GHI.Hardware.pe",
                IsLittleEndian         = true,
                LibraryId              = ghiSdkLibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id                     = Guid.Parse("62239dee-07d4-4447-997f-fa3808e250bd"),
                Filename               = "FirmataRuntime.pe",
                IsLittleEndian         = true,
                LibraryId              = brainPad431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            assm = new FirmwareAssembly()
            {
                Id                     = Guid.Parse("5b61839a-bc8b-4328-800b-e3372a7262e2"),
                Filename               = "BrainPadFirmataApp.pe",
                IsLittleEndian         = true,
                LibraryId              = brainPad431LibraryId,
                TargetFrameworkVersion = new Version(4, 3, 1, 0),
            };
            dict.Assemblies.Add(assm);
            brainPadImage.RequiredAssemblies.Add(assm.Id);

            //
            // Boards
            //

            var board = new FirmwareHost()
            {
                Id                = Guid.Parse("6a9bdb56-8005-428d-9f29-8c425d9614b0"),
                Name              = "BrainPad",
                ProductImageName  = "BrainPad.jpg",
                Manufacturer      = "GHI Electronics",
                Description       = "Hardware for STEM education",
                UsbName           = "G30_G30",
                BuildInfoContains = "GHI Electronics",
                OEM               = 0xff,
                SKU               = 0xffff,
            };

            board.CompatibleImages.Add(brainPadImage.Id);
            dict.Boards.Add(board);

            var content = JsonConvert.SerializeObject(dict, Formatting.Indented);

            File.WriteAllText("dict.json", content);
        }