コード例 #1
0
ファイル: PackageInfo.cs プロジェクト: marcus-williams/RTVS
        /// <summary>
        /// Attempts to locate cached function list for the package
        /// </summary>
        /// <returns></returns>
        private IEnumerable <IPersistentFunctionInfo> TryRestoreFromCache()
        {
            var filePath = this.CacheFilePath;

            try {
                if (_fs.FileExists(filePath))
                {
                    var list = new List <IPersistentFunctionInfo>();
                    using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) {
                        using (var sr = new StreamReader(file)) {
                            var s = sr.ReadLine();
                            if (!s.EqualsOrdinal(VersionString))
                            {
                                return(null); // incompatible
                            }
                            while (!sr.EndOfStream)
                            {
                                s = sr.ReadLine().Trim();
                                if (!PersistentFunctionInfo.TryParse(s, out IPersistentFunctionInfo info))
                                {
                                    return(null);
                                }
                                list.Add(info);
                            }
                        }
                    }
                    return(list);
                }
            } catch (IOException) { } catch (UnauthorizedAccessException) { }
            return(null);
        }
コード例 #2
0
        public static bool TryParse(string s, out IPersistentFunctionInfo info)
        {
            info = null;

            var start = s.IndexOf('`');
            var end   = s.LastIndexOf('`');

            if (start < 0 || end < 0 || start >= end)
            {
                return(false);
            }
            if (!bool.TryParse(s.Substring(end + 1), out bool isInternal))
            {
                return(false);
            }
            info = new PersistentFunctionInfo(s.Substring(start + 1, end - start - 1), isInternal);
            return(true);
        }