示例#1
0
        private static ExternalAnnotationsCache TryGetCacheFromDisk()
        {
            try
            {
                if (File.Exists(CachePath))
                {
                    using (FileStream stream = File.OpenRead(CachePath))
                    {
                        using (new CodeTimer("ExternalAnnotationsCache:Read"))
                        {
                            var service = new MsgPackSerializationService();
                            var result  = service.ReadObject <ExternalAnnotationsCache>(stream);

                            if (result.ExternalAnnotations.Any())
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (IOException)
            {
            }

            return(null);
        }
示例#2
0
        private static void TrySaveToDisk([NotNull] ExternalAnnotationsCache cache)
        {
            try
            {
                EnsureDirectoryExists();

                using (FileStream stream = File.Create(CachePath))
                {
                    using (new CodeTimer("ExternalAnnotationsCache:Write"))
                    {
                        var service = new MsgPackSerializationService();
                        service.WriteObject(cache, stream);
                    }
                }
            }
            catch (IOException)
            {
                // When MSBuild runs in parallel, another process may be writing the cache file at the same time.
            }
        }