FiftyOne.Foundation.Mobile.Detection.WebProvider.GetTempFileName C# (CSharp) Method

GetTempFileName() static private method

Returns a temporary file name for the data file.
static private GetTempFileName ( ) : string
return string
        internal static string GetTempFileName()
        {
            var directoryInfo = Directory.CreateDirectory(
                Mobile.Configuration.Support.GetFilePath(Constants.TemporaryFilePath));
            var fileInfo = new FileInfo(Manager.BinaryFilePath);
            return Path.Combine(
                directoryInfo.FullName,
                String.Format("{0}.{1}.tmp",
                fileInfo.Name,
                Guid.NewGuid()));
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Downloads and updates the premium data file.
        /// </summary>
        internal static LicenceKeyResults Download(string[] licenceKeys)
        {
            var       status = LicenceKeyResults.InProgress;
            WebClient client = new WebClient();

            var compressedTempFile   = WebProvider.GetTempFileName();
            var uncompressedTempFile = String.Format("{0}.new", Manager.BinaryFilePath);

            try
            {
                // Wait until any other threads have finished executing.
                _autoDownloadUpdateSignal.WaitOne();

                // Download the data file to the compressed temporary file.
                status = DownloadFile(client, Manager.BinaryFilePath, compressedTempFile, licenceKeys);

                // Validate the MD5 hash of the download.
                if (status == LicenceKeyResults.InProgress)
                {
                    status = CheckedDownloadedFileMD5(client, compressedTempFile);
                }

                // Decompress the data file ready to create the data set.
                if (status == LicenceKeyResults.InProgress)
                {
                    status = Decompress(compressedTempFile, uncompressedTempFile);
                }

                // Validate that the data file can be used to create a provider.
                if (status == LicenceKeyResults.InProgress)
                {
                    status = ValidateDownloadedFile(uncompressedTempFile);
                }

                // Activate the data file downloaded for future use.
                if (status == LicenceKeyResults.InProgress)
                {
                    status = ActivateDownloadedFile(client, uncompressedTempFile);
                }
            }
            catch (Exception)
            {
                status = LicenceKeyResults.GenericFailure;
            }
            finally
            {
                File.Delete(compressedTempFile);
                File.Delete(uncompressedTempFile);
                client.Dispose();
                _autoDownloadUpdateSignal.Set();
            }
            return(status);
        }