コード例 #1
0
        private SiteInfo LoadSiteInfoFromFile(string domain)
        {
            if (!SiteInfo.IsValidDomain(domain))
            {
                return(null);
            }

            string fileName = GetFullSiteInfoFileName(domain);

            if (!File.Exists(fileName))
            {
                return(null);
            }

            int retryCount = 3;

            do
            {
                try
                {
                    using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            string st = reader.ReadToEnd();
                            return(SiteInfo.DeserializeFromJson(st));
                        }
                    }
                }
                catch (IOException)
                {
                    retryCount--;

                    if (retryCount == 0)
                    {
                        return(null);
                    }

                    Thread.Sleep(2);
                }
                catch
                {
                    return(null);
                }
            }while (retryCount > 0);

            return(null);
        }