Exemple #1
0
        /// <summary>
        /// Writes the profile using the specified file provider
        /// </summary>
        /// <param name="provider">The file provider used to save the profile</param>
        public void Save(IFileProvider provider, bool serializeCache = true)
        {
            foreach (string env in AzureEnvironment.PublicEnvironments.Keys)
            {
                EnvironmentTable.Remove(env);
            }

            try
            {
                TryRemoveContext(Constants.DefaultValue);
                string contents     = ToString(serializeCache);
                string diskContents = string.Empty;
                diskContents = provider.CreateReader().ReadToEnd();

                if (diskContents != contents)
                {
                    var writer = provider.CreateWriter();
                    writer.Write(contents);
                    writer.Flush();

                    // When writing to a stream, ensure that the file is truncated
                    // so that previous data is overwritten
                    provider.Stream.SetLength(provider.Stream.Position);
                }
            }
            finally
            {
                // Adding back predefined environments
                foreach (AzureEnvironment env in AzureEnvironment.PublicEnvironments.Values)
                {
                    EnvironmentTable[env.Name] = env;
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Reads settings from disk using the specified <see cref="IFileProvider"/>.
 /// </summary>
 /// <param name="fileProvider">The file provider that allows access to settings contents.</param>
 private void Load(IFileProvider fileProvider)
 {
     using (fileProvider)
     {
         string contents = fileProvider.CreateReader().ReadToEnd();
         if (TryDeserializeObject <GraphSettings>(contents, out GraphSettings contextSettings, new GraphSettingsConverter()))
         {
             Initialize(contextSettings);
         }
Exemple #3
0
        private void Load(IFileProvider provider)
        {
            this.ProfilePath = provider.FilePath;
            string contents = provider.CreateReader().ReadToEnd();
            LegacyAzureRmProfile oldProfile;
            AzureRmProfile       profile = null;

            if (!(SafeDeserializeObject <LegacyAzureRmProfile>(contents, out oldProfile) &&
                  oldProfile.TryConvert(out profile)) &&
                !SafeDeserializeObject <AzureRmProfile>(contents, out profile, new AzureRmProfileConverter(false)))
            {
                return;
            }

            Initialize(profile);
        }