FiftyOne.Foundation.Mobile.Detection.WebProvider.GetDataFileDate C# (CSharp) Метод

GetDataFileDate() статический приватный Метод

Creates a stream data set for the file provided and returns the published data of the file. Throws an exception if there's a problem accessing the file.
static private GetDataFileDate ( string fileName ) : DateTime?
fileName string
Результат DateTime?
        internal static DateTime? GetDataFileDate(string fileName)
        {
            try
            {
                using (var reader = new BinaryReader(File.OpenRead(fileName)))
                {
                    using (var dataSet = new DataSet(File.GetLastWriteTimeUtc(fileName), DataSet.Modes.File))
                    {
                        CommonFactory.LoadHeader(dataSet, reader);
                        return dataSet.Published;
                    }
                }
            }
            catch(Exception ex)
            {
                EventLog.Info(String.Format(
                    "Exception getting data file date from file '{0}'",
                    fileName));
                EventLog.Debug(ex);
                return null;
            }
        }

Usage Example

Пример #1
0
        private static LicenceKeyResults ActivateDownloadedFile(WebClient client, string uncompressedTempFile)
        {
            var status = LicenceKeyResults.Success;

            // Rename the current master file to a temp file so enable the new
            // master file to take it's place and to rollback if there's a problem.
            var tempCopyofCurrentMaster = String.Format("{0}.tmp", BinaryFile.FullName);

            try
            {
                // Both the MD5 hash was good and the provider was created.
                // Save the data and force the factory to reload.

                if (BinaryFile.Exists)
                {
                    // Keep a copy of the old data in case we need to go back to it.
                    File.Move(BinaryFile.FullName, tempCopyofCurrentMaster);
                }

                // Copy the new file to the master file.
                File.Move(uncompressedTempFile, BinaryFile.FullName);

                // Get the published date from the new data file.
                var publishedDate = WebProvider.GetDataFileDate(BinaryFile.FullName);

                // Sets the last modified time of the file downloaded to the one
                // provided in the HTTP header, or if not valid then the published
                // date of the data set.
                DateTime lastModified;
                if (DateTime.TryParseExact(
                        client.ResponseHeaders[HttpResponseHeader.LastModified],
                        "R",
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.AssumeUniversal,
                        out lastModified) == false)
                {
                    lastModified = publishedDate.Value;
                }
                BinaryFile.LastWriteTimeUtc = lastModified.ToUniversalTime();

                EventLog.Info(String.Format(
                                  "Automatically updated binary data file '{0}' with version " +
                                  "published on the '{1:d}'.",
                                  BinaryFile.FullName,
                                  publishedDate));
            }
            catch (Exception ex)
            {
                if (BinaryFile.Exists == false)
                {
                    File.Move(tempCopyofCurrentMaster, BinaryFile.FullName);
                }
                EventLog.Warn(ex);
                status = LicenceKeyResults.WriteDataFile;
            }
            finally
            {
                File.Delete(tempCopyofCurrentMaster);
            }

            return(status);
        }