public bool IsCacheValid() { var file = ProtectedFile.GetCacheFile(_fileName); if (!File.Exists(file)) { return(false); } try { var json = JObject.Parse(File.ReadAllText(file)); if (Constants.FileVersion.Value != json.Value <string>("ver")) { ClearAll(); return(false); } return(true); } catch (Exception) { ClearAll(); return(false); } }
public void SaveRecentToken(TokenCacheInfo cacheInfo, string resource) { var file = ProtectedFile.GetCacheFile(GetRecentTokenFileName(resource)); var json = JObject.FromObject(cacheInfo); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(file), json.ToString()); }
public static bool CommitDefaultSettings(this ApplicationOptions settings, bool waitWindow = true) { try { if (waitWindow) { return((bool)WaitWindow.WaitWindow.Show(CommitDefaultSettings, @"Saving settings", settings)); } else { //write all new settings var protectedFile = new ProtectedFile(SettingsFile); protectedFile.WriteAllText(settings.ProfileToXml(), ProtectedSettings); return(true); } } catch (Exception ex) { LoggingHelpers.RecordException(ex.Message, @"CommitToDefaultError"); } //default return(false); }
public void ClearCache() { foreach (var filePath in Directory.GetFiles(ProtectedFile.GetCachePath(), "*token*", SearchOption.TopDirectoryOnly)) { File.Delete(filePath); } }
public bool IsCacheValid() { var file = ProtectedFile.GetCacheFile(_fileName); if (!File.Exists(file)) { return(false); } try { var json = JObject.Parse(File.ReadAllText(file)); if (Constants.FileVersion.Value != json.Value <string>("ver")) { ClearAll(); return(false); } AzureEnvironments unused; return(Enum.TryParse <AzureEnvironments>(json.Value <string>("env"), out unused)); } catch (Exception) { ClearAll(); return(false); } }
public void SaveRecentToken(TokenCacheInfo cacheInfo, string resource) { var file = ProtectedFile.GetCacheFile(resource == Constants.CSMResource ? _recentARMFileName : _recentAADFileName); var json = JObject.FromObject(cacheInfo); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(file), json.ToString()); }
public void ClearCache() { foreach (var filePath in Directory.GetFiles(Path.GetDirectoryName(ProtectedFile.GetCacheFile(_fileName)), "cache_tenants*", SearchOption.TopDirectoryOnly)) { File.Delete(filePath); } }
/// <summary> /// Generates a new random global GUID and if storeNew is true, it replaces the existing GUID in persistent storage. /// </summary> /// <param name="storeNew">Whether or not to replace the existing GUID in persistent storage</param> /// <returns></returns> public static Guid NewGlobalGuid(bool storeNew = true) { try { //generate a new GUID var newGuid = Guid.NewGuid(); //should we replace the existing GUID? if (storeNew) { //store the new GUID encrypted via WDPAPI var handler = new ProtectedFile(GuidFileLocation); handler.WriteAllText(newGuid.ToString()); } //return the newly generated GUID return(newGuid); } catch { //ignore all errors } //default (all zeroes) return(Guid.Empty); }
/// <summary> /// Load the global GUID from persistent storage; returns Guid.Empty on failure. /// </summary> /// <returns></returns> public static Guid StoredGlobalGuid() { try { if (File.Exists(GuidFileLocation)) { //decrypt and read the GUID from persistent storage var handler = new ProtectedFile(GuidFileLocation); var guidString = handler.ReadAllText(); //is it a valid string? if (!string.IsNullOrEmpty(guidString)) { //validate the GUID and return the GUID struct if successful if (Guid.TryParse(guidString, out var r)) { return(r); } } } } catch { //ignore all errors } //default (all zeroes) return(Guid.Empty); }
public void SaveEnvironment(AzureEnvironments azureEnvironment) { var json = new JObject(); json["ver"] = Constants.FileVersion.Value; json["env"] = azureEnvironment.ToString(); File.WriteAllText(ProtectedFile.GetCacheFile(_fileName), json.ToString()); }
public void ClearSavedEnvironment() { var filePath = ProtectedFile.GetCacheFile(_fileName); if (File.Exists(filePath)) { File.Delete(filePath); } }
public TokenCacheInfo GetRecentToken(string resource) { var file = ProtectedFile.GetCacheFile(resource == Constants.CSMResource ? _recentARMFileName : _recentAADFileName); if (!File.Exists(file)) { return(null); } return(JsonConvert.DeserializeObject <TokenCacheInfo>(ProtectedFile.ReadAllText(file))); }
public Dictionary <string, TenantCacheInfo> GetCache() { var file = ProtectedFile.GetCacheFile(_fileName); if (!File.Exists(file)) { return(new Dictionary <string, TenantCacheInfo>()); } return(JsonConvert.DeserializeObject <Dictionary <string, TenantCacheInfo> >(ProtectedFile.ReadAllText(file))); }
public AzureEnvironments GetSavedEnvironment() { var file = ProtectedFile.GetCacheFile(_fileName); if (File.Exists(file)) { return((AzureEnvironments)Enum.Parse(typeof(AzureEnvironments), File.ReadAllText(file))); } return(AzureEnvironments.Prod); }
public AzureEnvironments GetSavedEnvironment() { var file = ProtectedFile.GetCacheFile(_fileName); if (File.Exists(file)) { var json = JObject.Parse(File.ReadAllText(file)); return((AzureEnvironments)Enum.Parse(typeof(AzureEnvironments), json.Value <string>("env"))); } return(AzureEnvironments.Prod); }
public string GetSavedEnvironment() { var file = ProtectedFile.GetCacheFile(_fileName); if (File.Exists(file)) { var json = JObject.Parse(File.ReadAllText(file)); return(json.Value <string>("env")); } return(Utils.GetDefaultEnv()); }
public CustomTokenCache GetCache() { var file = ProtectedFile.GetCacheFile(_cacheFileName); if (!File.Exists(file)) { return(new CustomTokenCache()); } var state = ProtectedFile.ReadAllText(file); return(new CustomTokenCache(state)); }
public static string DecryptSettings() { try { var protectedFile = new ProtectedFile(SettingsFile); return(protectedFile.ReadAllText()); } catch (Exception ex) { LoggingHelpers.RecordException(ex.Message, @"SettingsDecryptionError"); } //default return(@""); }
public static string StoredToken() { try { if (!IsTokenStored || !TokenCachingEnabled) { return(string.Empty); } var protectedToken = new ProtectedFile(Final); var t = protectedToken.ReadAllText(); return(t.Length == 20 && !string.IsNullOrEmpty(t) ? t : string.Empty); //valid Plex tokens are always 20 characters in length. } catch (Exception) { //ignore any errors } //default return(string.Empty); }
public static bool SaveToken(string token, bool deleteIfPresent = true) { if (deleteIfPresent) { ClearStored(); } try { var protectedToken = new ProtectedFile(Final); if (TokenCachingEnabled) { protectedToken.WriteAllText(token); } return(true); } catch (Exception) { //ignore any errors } //default return(false); }
public void SaveCache(Dictionary <string, TenantCacheInfo> tenants) { var json = JObject.FromObject(tenants); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_fileName), json.ToString()); }
public void SaveEnvironment(AzureEnvironments azureEnvironment) { File.WriteAllText(ProtectedFile.GetCacheFile(_fileName), azureEnvironment.ToString()); }
public void SaveCache(CustomTokenCache cache) { var state = cache.GetState(); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_cacheFileName), state); }
public bool IsCacheValid() { var file = ProtectedFile.GetCacheFile(_fileName); return(File.Exists(file)); }