Example #1
0
        public static ExportFile ReadExportFile(string fragmentLockFilePath)
        {
            using (var stream = ResilientFileStreamOpener.OpenFile(fragmentLockFilePath))
            {
                try
                {
                    var rootJObject = JsonDeserializer.Deserialize(new StreamReader(stream)) as JsonObject;

                    if (rootJObject == null)
                    {
                        throw new InvalidDataException();
                    }

                    var version = ReadInt(rootJObject, "version", defaultValue: int.MinValue);
                    var exports = ReadObject(rootJObject.ValueAsJsonObject("exports"), ReadTargetLibrary);

                    return(new ExportFile(fragmentLockFilePath, version, exports));
                }
                catch (FileFormatException ex)
                {
                    throw ex.WithFilePath(fragmentLockFilePath);
                }
                catch (Exception ex)
                {
                    throw FileFormatException.Create(ex, fragmentLockFilePath);
                }
            }
        }
Example #2
0
 public static LockFile Read(string lockFilePath, bool patchWithExportFile = true)
 {
     using (var stream = ResilientFileStreamOpener.OpenFile(lockFilePath))
     {
         try
         {
             return(Read(lockFilePath, stream, patchWithExportFile));
         }
         catch (FileFormatException ex)
         {
             throw ex.WithFilePath(lockFilePath);
         }
         catch (Exception ex)
         {
             throw FileFormatException.Create(ex, lockFilePath);
         }
     }
 }
Example #3
0
 public static LockFile Read(string lockFilePath, bool designTime)
 {
     using (var stream = ResilientFileStreamOpener.OpenFile(lockFilePath))
     {
         try
         {
             return(new LockFileReader().ReadLockFile(lockFilePath, stream, designTime));
         }
         catch (FileFormatException ex)
         {
             throw ex.WithFilePath(lockFilePath);
         }
         catch (Exception ex)
         {
             throw FileFormatException.Create(ex, lockFilePath);
         }
     }
 }
Example #4
0
        private FileModelEntry <LockFile> AddLockFileEntry(string projectDirectory, FileModelEntry <LockFile> currentEntry)
        {
            if (currentEntry == null)
            {
                currentEntry = new FileModelEntry <LockFile>();
            }

            if (currentEntry.IsInvalid)
            {
                currentEntry.Reset();

                if (!File.Exists(Path.Combine(projectDirectory, LockFile.FileName)))
                {
                    return(currentEntry);
                }
                else
                {
                    currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName);

                    using (var fs = ResilientFileStreamOpener.OpenFile(currentEntry.FilePath, retry: 2))
                    {
                        try
                        {
                            currentEntry.Model = LockFileReader.Read(currentEntry.FilePath, fs);
                            currentEntry.UpdateLastWriteTimeUtc();
                        }
                        catch (FileFormatException ex)
                        {
                            throw ex.WithFilePath(currentEntry.FilePath);
                        }
                        catch (Exception ex)
                        {
                            throw FileFormatException.Create(ex, currentEntry.FilePath);
                        }
                    }
                }
            }

            return(currentEntry);
        }