private void Initialize()
        {
            _projectId = Guid.NewGuid().ToString();
            var buildPath = Path.Combine(Path.GetTempPath(), "RoslynPad", "Build", _projectId);

            try
            {
                Directory.CreateDirectory(buildPath);
                _buildPath = buildPath;
            }
            catch (Exception ex)
            {
                _telemetryProvider.ReportError(ex);
            }
        }
示例#2
0
        public NuGetViewModel(ITelemetryProvider telemetryProvider, IApplicationSettings appSettings)
        {
            try
            {
                var settings = LoadSettings();
                ConfigPath          = settings.ConfigFilePath;
                GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);

                DefaultCredentialServiceUtility.SetupDefaultCredentialService(NullLogger.Instance, nonInteractive: false);

                var sourceProvider = new PackageSourceProvider(settings);
                _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(sourceProvider);
            }
            catch (Exception e)
            {
                _initializationException = ExceptionDispatchInfo.Capture(e);

                ConfigPath          = string.Empty;
                GlobalPackageFolder = string.Empty;
            }

            Settings LoadSettings()
            {
                Settings?settings = null;

                const int retries = 3;

                for (var i = 1; i <= retries; i++)
                {
                    try
                    {
                        settings = new Settings(appSettings.GetDefaultDocumentPath(), "RoslynPad.nuget.config");
                    }
                    catch (NuGetConfigurationException ex)
                    {
                        if (i == retries)
                        {
                            telemetryProvider.ReportError(ex);
                            throw;
                        }
                    }
                }

                return(settings !);
            }
        }
        public void Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            try
            {
                InitializeInternal();

                IsInitialized = true;
            }
            catch (Exception e)
            {
                _telemetryProvider.ReportError(e);
            }
        }
        public async Task Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            try
            {
                await InitializeInternal().ConfigureAwait(true);

                IsInitialized = true;
            }
            catch (Exception e)
            {
                _telemetryProvider.ReportError(e);
            }
        }
示例#5
0
        public NuGetViewModel(ITelemetryProvider telemetryProvider)
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            try
            {
                ISettings settings;

                try
                {
                    settings = Settings.LoadDefaultSettings(
                        root: null,
                        configFileName: null,
                        machineWideSettings: new XPlatMachineWideSetting());
                }
                catch (NuGetConfigurationException ex)
                {
                    telemetryProvider.ReportError(ex);

                    // create default settings using a non-existent config file
                    settings = new Settings(nameof(RoslynPad));
                }

                GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);
                _configFilePaths    = SettingsUtility.GetConfigFilePaths(settings);
                _packageSources     = SettingsUtility.GetEnabledSources(settings);

                DefaultCredentialServiceUtility.SetupDefaultCredentialService(NullLogger.Instance, nonInteractive: false);

                var sourceProvider = new PackageSourceProvider(settings);
                _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(sourceProvider);
            }
            catch (Exception e)
            {
                _initializationException = ExceptionDispatchInfo.Capture(e);
            }
        }