コード例 #1
0
ファイル: GuidHandler.cs プロジェクト: mitchscobell/PlexDL
        /// <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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public void SaveCache(Dictionary <string, TenantCacheInfo> tenants)
        {
            var json = JObject.FromObject(tenants);

            ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_fileName), json.ToString());
        }
コード例 #7
0
        public void SaveCache(CustomTokenCache cache)
        {
            var state = cache.GetState();

            ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_cacheFileName), state);
        }