/// <summary>
        /// Writes the file json.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileData">The file data.</param>
        /// <exception cref="AzureDevOpsMgmt.Exceptions.EmptyIdFoundException">The ID Field is Empty</exception>
        /// <exception cref="EmptyIdFoundException">An input account contained an empty token ID.</exception>
        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception>
        /// <exception cref="T:System.UnauthorizedAccessException">The caller does not have the required permission.</exception>
        public static void WriteFileJson(string fileName, AzureDevOpsAccountCollection fileData)
        {
            if (fileData.PatTokens.Any(p => p.Id == Guid.Empty))
            {
                throw new EmptyIdFoundException(EventMessages.TOKEN_ID_CANNOT_BE_EMPTY_GUID);
            }

            FileHelpers.WriteFileJson(fileName, (object)fileData);
        }
        /// <summary>
        /// Loads the account data.
        /// </summary>
        /// <returns>Account configuration collection.</returns>
        private AzureDevOpsAccountCollection LoadAccountData()
        {
            AzureDevOpsAccountCollection accountData;

            if (!File.Exists(FileHelpers.GetConfigFilePath(FileNames.AccountData)))
            {
                var dirInfo = new DirectoryInfo(FileHelpers.GetConfigFilePath(FileNames.AccountData));

                if (dirInfo.Parent != null && !dirInfo.Parent.Exists)
                {
                    dirInfo.Parent.Create();
                }

                accountData = new AzureDevOpsAccountCollection
                {
                    Accounts  = new ObservableCollection <AzureDevOpsAccount>(),
                    PatTokens = new ObservableCollection <AzureDevOpsPatToken>()
                };

                accountData.Init();

                FileHelpers.WriteFileJson(FileNames.AccountData, accountData);
            }
            else
            {
                accountData = FileHelpers.ReadFileJson <AzureDevOpsAccountCollection>(FileNames.AccountData);
                accountData.Init();

#pragma warning disable 618,612
                if (accountData.Accounts.Any(a => a.TokenId != null))
#pragma warning restore 618,612
                {
                    accountData = this.MigrateTokenIdToTokenList(accountData);
                }
            }

            return(accountData);
        }
        /// <summary>
        /// Migrates the token identifier to token list.
        /// </summary>
        /// <param name="accountsCollection">The accounts collection.</param>
        /// <returns>The Azure DevOps Account Collection.</returns>
        private AzureDevOpsAccountCollection MigrateTokenIdToTokenList(AzureDevOpsAccountCollection accountsCollection)
        {
            var updatedAccounts = new List <AzureDevOpsAccount>();

#pragma warning disable 618,612
            foreach (AzureDevOpsAccount account in accountsCollection.Accounts.Where(a => a.TokenId != null))
#pragma warning restore 618,612
            {
                account.MigrateTokenToLinkedTokens();

                updatedAccounts.Add(account);
            }

            if (updatedAccounts.Any())
            {
                foreach (var account in updatedAccounts)
                {
                    accountsCollection.PerformAccountUpdate(account);
                }
            }

            return(accountsCollection);
        }