private bool SaveSiteInfoToFile(SiteInfo siteInfo, bool overwrite) { if (siteInfo == null) { return(false); } if (!SiteInfo.IsValidDomain(siteInfo.Domain)) { return(false); } string fileName = GetFullSiteInfoFileName(siteInfo.Domain); if (!overwrite && File.Exists(fileName)) { return(false); } int retryCount = 3; do { try { using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { using (var writer = new StreamWriter(stream)) { writer.Write(siteInfo.SerializeToJson()); } } return(true); } catch (IOException) { retryCount--; if (retryCount == 0) { return(false); } Thread.Sleep(2); } catch { return(false); } }while (retryCount > 0); return(true); }