public void GetsValuesForBuildConfigurationFromConfigurationEnvironment()
        {
            var config         = GetConfiguration();
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.Environment.Defaults.Add("SampleProp", "Hello Tests");
            config.Configuration.Environment.Configuration[config.BuildConfiguration] = new Dictionary <string, string>
            {
                { "SampleProp", "Hello Override" }
            };
            config.Configuration.AppSettings[config.ProjectName] = new List <SettingsConfig>(new[] { settingsConfig });

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp"));
            Assert.Equal(config.Configuration.Environment.Configuration[config.BuildConfiguration]["SampleProp"], mergedSecrets["SampleProp"]);
        }
 private void EnsureADSettingsEnforced()
 {
     if (this["ADServerSettings"] == null && !EnvironmentAnalyzer.IsWorkGroup())
     {
         this.waitHandle.WaitOne();
     }
 }
        public void OverridesConfigEnvironmentFromHostEnvironment()
        {
            var config         = GetConfiguration();
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp3",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.AppSettings[config.ProjectName]     = new List <SettingsConfig>(new[] { settingsConfig });
            config.Configuration.Environment.Defaults["SampleProp3"] = "Hello Config Environment";

            Environment.SetEnvironmentVariable("SampleProp3", nameof(OverridesConfigEnvironmentFromHostEnvironment), EnvironmentVariableTarget.Process);

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp3"));
            Assert.Equal(nameof(OverridesConfigEnvironmentFromHostEnvironment), mergedSecrets["SampleProp3"]);
        }
        public void GetsValuesFromJson(string filename)
        {
            var config         = GetConfiguration($"{nameof(GetsValuesFromJson)}-{Path.GetFileNameWithoutExtension(filename)}");
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.AppSettings[config.ProjectName] = new List <SettingsConfig>(new[] { settingsConfig });

            var secrets = new
            {
                SampleProp = "Hello Tests"
            };

            File.WriteAllText(Path.Combine(config.ProjectDirectory, filename), JsonSerializer.Serialize(secrets));

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp"));
            Assert.Equal(secrets.SampleProp, mergedSecrets["SampleProp"]);
        }
        public void ProcessesStandardTokenizedVariables()
        {
            var generator = CreateGenerator();
            var template  = File.ReadAllText(TemplateManifestPath);
            var match     = generator.GetMatches(template).Cast <Match>().FirstOrDefault();
            var config    = new TestBuildConfiguration
            {
                BuildConfiguration = "Test",
                ProjectDirectory   = Directory.GetCurrentDirectory(),
                SolutionDirectory  = Directory.GetCurrentDirectory()
            };
            var variables = EnvironmentAnalyzer.GatherEnvironmentVariables(config, true);

            foreach (var variable in variables)
            {
                _testOutputHelper.WriteLine($"  - {variable.Key}: {variable.Value}");
            }
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonConvert.DeserializeAnonymousType(processedTemplate, new
            {
                TemplatedParameter   = "",
                CustomTokenParameter = ""
            });

            Assert.Equal("%%CustomTokenParameter%%", json.CustomTokenParameter);
            Assert.Equal(nameof(AppManifestGeneratorFixture), json.TemplatedParameter);
        }
Ejemplo n.º 6
0
 public BuildConfig(string configuration, string projectDir)
 {
     BuildConfiguration = configuration;
     ProjectDirectory   = projectDir;
     SolutionDirectory  = EnvironmentAnalyzer.LocateSolution(projectDir);
     Configuration      = ConfigHelper.GetConfig(projectDir);
 }
Ejemplo n.º 7
0
        public static bool IsRemoteEnabled()
        {
            if (PSConnectionInfoSingleton.GetInstance().Type != OrganizationType.ToolOrEdge)
            {
                return(true);
            }
            if (EnvironmentAnalyzer.IsWorkGroup())
            {
                return(false);
            }
            string name   = "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\AdminTools";
            bool   result = true;

            try
            {
                using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(name))
                {
                    if (registryKey != null)
                    {
                        object value = registryKey.GetValue("EMC.RemotePowerShellEnabled");
                        if (value != null && string.Equals("false", value.ToString(), StringComparison.OrdinalIgnoreCase))
                        {
                            result = false;
                        }
                    }
                }
            }
            catch (SecurityException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            return(result);
        }
        private string LocateSolution(string solutionDirectory)
        {
            if (!string.IsNullOrEmpty(solutionDirectory) && Directory.EnumerateFiles(solutionDirectory, "*.sln").Any())
            {
                return(null);
            }

            return(EnvironmentAnalyzer.LocateSolution(ProjectDirectory));
        }
        internal override void ExecuteInternal(IBuildConfiguration config)
        {
            if (!EnvironmentAnalyzer.IsInGitRepo(config.ProjectDirectory))
            {
                Log.LogMessage($"The project {config.ProjectName} is not inside of an initialized git repository");
                return;
            }

            IGenerator generator = new ReleaseNotesGenerator(config, OutputPath);

            generator.Execute();
        }
Ejemplo n.º 10
0
 internal override bool HasViewPermissionForPage(string pageName)
 {
     if (EnvironmentAnalyzer.IsWorkGroup() || !base.ProfileBuilder.CanEnableUICustomization())
     {
         return(true);
     }
     if (this.pageToReaderTaskMapping.ContainsKey(pageName))
     {
         return((from c in this.readerTaskProfileList
                 where this.pageToReaderTaskMapping[pageName].Contains(c.Name)
                 select c).Any((ReaderTaskProfile c) => c.HasPermission()));
     }
     return(true);
 }
Ejemplo n.º 11
0
        internal static string GetCurrentConnectedServerName()
        {
            string result = string.Empty;

            if (WinformsHelper.IsRemoteEnabled())
            {
                result = PSConnectionInfoSingleton.GetInstance().ServerName;
            }
            else
            {
                result = EnvironmentAnalyzer.GetLocalServerName();
            }
            return(result);
        }
 public RunspaceServerSettingsPresentationObject CreateRunspaceServerSettingsObject()
 {
     if (EnvironmentAnalyzer.IsWorkGroup() || OrganizationType.Cloud == PSConnectionInfoSingleton.GetInstance().Type || this.ADServerSettings == null)
     {
         return(null);
     }
     if (this.ADServerSettings != null)
     {
         lock (this.syncRoot)
         {
             return(this.ADServerSettings.Clone() as RunspaceServerSettingsPresentationObject);
         }
     }
     return(null);
 }
        internal void EnforceADSettings()
        {
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <ExchangeADServerSettings>(0L, "-->ExchangeSystemManagerSettings.EnforceAdSettings: {0}", this);
            if (this["ADServerSettings"] == null && !EnvironmentAnalyzer.IsWorkGroup() && OrganizationType.Cloud != PSConnectionInfoSingleton.GetInstance().Type)
            {
                try
                {
                    try
                    {
                        using (MonadConnection monadConnection = new MonadConnection("timeout=30", new CommandInteractionHandler(), null, PSConnectionInfoSingleton.GetInstance().GetMonadConnectionInfo()))
                        {
                            monadConnection.Open();
                            LoggableMonadCommand loggableMonadCommand = new LoggableMonadCommand("Get-ADServerSettingsForLogonUser", monadConnection);
                            object[]             array = loggableMonadCommand.Execute();
                            if (array != null && array.Length > 0)
                            {
                                RunspaceServerSettingsPresentationObject runspaceServerSettingsPresentationObject = array[0] as RunspaceServerSettingsPresentationObject;
                                this.ADServerSettings              = runspaceServerSettingsPresentationObject;
                                this.OrganizationalUnit            = runspaceServerSettingsPresentationObject.RecipientViewRoot;
                                this.ForestViewEnabled             = runspaceServerSettingsPresentationObject.ViewEntireForest;
                                this.GlobalCatalog                 = runspaceServerSettingsPresentationObject.UserPreferredGlobalCatalog;
                                this.ConfigurationDomainController = runspaceServerSettingsPresentationObject.UserPreferredConfigurationDomainController;
                                if (runspaceServerSettingsPresentationObject.UserPreferredDomainControllers != null && runspaceServerSettingsPresentationObject.UserPreferredDomainControllers.Count != 0)
                                {
                                    this.DomainController = runspaceServerSettingsPresentationObject.UserPreferredDomainControllers[0];
                                }
                            }
                            else
                            {
                                this.SetDefaultSettings();
                            }
                        }
                    }
                    catch (Exception)
                    {
                        this.SetDefaultSettings();
                    }
                    goto IL_11A;
                }
                finally
                {
                    this.waitHandle.Set();
                }
            }
            this.waitHandle.Set();
IL_11A:
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <ExchangeADServerSettings>(0L, "<--ExchangeSystemManagerSettings.EnforceAdSettings: {0}", this);
        }
        public void ProcessesStandardTokenizedVariables()
        {
            var generator         = CreateGenerator();
            var template          = File.ReadAllText(TemplateManifestPath);
            var match             = generator.GetMatches(template).FirstOrDefault();
            var variables         = EnvironmentAnalyzer.GatherEnvironmentVariables(Directory.GetCurrentDirectory(), true);
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonConvert.DeserializeAnonymousType(processedTemplate, new
            {
                TemplatedParameter   = "",
                CustomTokenParameter = ""
            });

            Assert.Equal("%%CustomTokenParameter%%", json.CustomTokenParameter);
            Assert.Equal(nameof(AppManifestGeneratorFixture), json.TemplatedParameter);
        }
Ejemplo n.º 15
0
        public void ProcessCustomTokenizedVariables()
        {
            var config = GetConfiguration();

            config.BuildConfiguration            = "Test";
            config.ProjectDirectory              = config.SolutionDirectory = Directory.GetCurrentDirectory();
            config.Configuration.Manifests.Token = @"%%";
            var generator = CreateGenerator(config);

            var template          = File.ReadAllText(TemplateManifestPath);
            var match             = generator.GetMatches(template).Cast <Match>().FirstOrDefault();
            var variables         = EnvironmentAnalyzer.GatherEnvironmentVariables(config, true);
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonSerializer.Deserialize <TestManifest>(processedTemplate);

            Assert.Equal(nameof(AppManifestGeneratorFixture), json.CustomTokenParameter);
            Assert.Equal("$TemplatedParameter$", json.TemplatedParameter);
        }
Ejemplo n.º 16
0
        public void Execute(GeneratorExecutionContext context)
        {
            _context = context;

            if (!TryGet(context, "MSBuildProjectName", ref _projectName) ||
                !TryGet(context, "MSBuildProjectDirectory", ref _projectDirectory) ||
                !TryGet(context, "RootNamespace", ref _rootNamespace) ||
                !TryGet(context, "Configuration", ref _buildConfiguration) ||
                !TryGet(context, "TargetFrameworkIdentifier", ref _targetFrameworkAssembly) ||
                !TryGet(context, "IntermediateOutputPath", ref _intermediateOutputDir))
            {
                return;
            }

            SolutionDirectory  = EnvironmentAnalyzer.LocateSolution(ProjectDirectory);
            _configurationPath = ConfigHelper.GetConfigurationPath(ProjectDirectory);
            Config             = ConfigHelper.GetConfig(_configurationPath);

            try
            {
                Generate();
            }
            catch (System.Exception ex)
            {
                if (Config.Debug)
                {
                    context.ReportDiagnostic
                        (Diagnostic.Create(
                            new DiagnosticDescriptor(
                                "MBT500",
                                "DEBUG - Unhandled Error",
                                "An Unhandled Generator Error Occurred: {0} - {1}",
                                "DEBUG",
                                DiagnosticSeverity.Error,
                                true),
                            null,
                            ex.Message, ex.StackTrace));
                }
            }
        }
        public override bool Execute()
        {
            var variables = EnvironmentAnalyzer.GatherEnvironmentVariables(ProjectDirectory, true);

            string message;

            if (variables.Any())
            {
                message = $"Found {variables.Count} Environment Variables\n";
                foreach (var variable in variables)
                {
                    message += $"    {variable.Key}: {variable.Value}\n";
                }
            }
            else
            {
                message = "There doesn't seem to be any Environment Variables... something is VERY VERY Wrong...";
            }

            Log.LogMessage(Microsoft.Build.Framework.MessageImportance.High, message);

            return(true);
        }
Ejemplo n.º 18
0
        internal static bool IsConnectedWithLocalServer()
        {
            string localServerName = EnvironmentAnalyzer.GetLocalServerName();

            return(WinformsHelper.IsCurrentConnectedServer(localServerName));
        }
Ejemplo n.º 19
0
        ///<summary> Modifiers Evaluate method used for the Planners vessel simulation in the VAB/SPH </summary>
        public static double Evaluate(EnvironmentAnalyzer env, VesselAnalyzer va, ResourceSimulator sim, List <string> modifiers)
        {
            double k = 1.0;

            foreach (string mod in modifiers)
            {
                switch (mod)
                {
                case "zerog":
                    k *= env.zerog ? 1.0 : 0.0;
                    break;

                case "landed":
                    k *= env.landed ? 1.0 : 0.0;
                    break;

                case "breathable":
                    k *= env.breathable ? 1.0 : 0.0;
                    break;

                case "non_breathable":
                    k *= env.breathable ? 0.0 : 1.0;
                    break;

                case "temperature":
                    k *= env.temp_diff;
                    break;

                case "radiation":
                    k *= Math.Max(Radiation.Nominal, (env.landed ? env.surface_rad : env.magnetopause_rad) + va.emitted);
                    break;

                case "shielding":
                    k *= 1.0 - va.shielding;
                    break;

                case "volume":
                    k *= va.volume;
                    break;

                case "surface":
                    k *= va.surface;
                    break;

                case "living_space":
                    k /= va.living_space;
                    break;

                case "comfort":
                    k /= va.comforts.factor;
                    break;

                case "pressure":
                    k *= va.pressurized ? 1.0 : Settings.PressureFactor;
                    break;

                case "poisoning":
                    k *= !va.scrubbed ? 1.0 : Settings.PoisoningFactor;
                    break;

                case "per_capita":
                    k /= (double)Math.Max(va.crew_count, 1);
                    break;

                default:
                    k *= sim.Resource(mod).amount;
                    break;
                }
            }
            return(k);
        }
Ejemplo n.º 20
0
        internal override bool HasPermissionForProperty(string propertyName, bool canUpdate)
        {
            if (EnvironmentAnalyzer.IsWorkGroup() || !base.ProfileBuilder.CanEnableUICustomization())
            {
                return(true);
            }
            ColumnProfile columnProfile = (from DataColumn c in base.Table.Columns
                                           where c.ColumnName == propertyName
                                           select c).First <DataColumn>().ExtendedProperties["ColumnProfile"] as ColumnProfile;
            string dataObjectName = columnProfile.DataObjectName;
            IEnumerable <ReaderTaskProfile> source = from c in this.readerTaskProfileList
                                                     where c.DataObjectName == dataObjectName
                                                     select c;
            ReaderTaskProfile readerTaskProfile = null;

            if (source.Count <ReaderTaskProfile>() > 0)
            {
                readerTaskProfile = source.First <ReaderTaskProfile>();
            }
            if (readerTaskProfile != null && !readerTaskProfile.HasPermission())
            {
                return(false);
            }
            if (canUpdate)
            {
                if (columnProfile.IgnoreChangeTracking)
                {
                    return(true);
                }
                IEnumerable <SaverTaskProfile> source2 = from c in this.saverTaskProfileList
                                                         where (c.Runner as Saver).GetConsumedDataObjectName() == dataObjectName && !string.IsNullOrEmpty(dataObjectName)
                                                         select c;
                SaverTaskProfile saverTaskProfile = null;
                if (source2.Count <SaverTaskProfile>() > 0)
                {
                    saverTaskProfile = source2.First <SaverTaskProfile>();
                }
                if (saverTaskProfile == null)
                {
                    IEnumerable <SaverTaskProfile> enumerable = from c in this.saverTaskProfileList
                                                                where (from p in c.ParameterProfileList
                                                                       where p.Reference == propertyName
                                                                       select p).Count <ParameterProfile>() > 0
                                                                select c;
                    using (IEnumerator <SaverTaskProfile> enumerator = enumerable.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            SaverTaskProfile saverTaskProfile2 = enumerator.Current;
                            if (!saverTaskProfile2.HasPermission(columnProfile.MappingProperty))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
                if (saverTaskProfile != null && !saverTaskProfile.HasPermission(columnProfile.MappingProperty))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 21
0
 public MicrosoftExchangeSnapIn()
 {
     GC.KeepAlive(ManagementGuiSqmSession.Instance);
     base.RootNode = new ToolboxNode(EnvironmentAnalyzer.IsWorkGroup());
 }
        public override bool Execute()
        {
//#if DEBUG
//            if (!System.Diagnostics.Debugger.IsAttached)
//                System.Diagnostics.Debugger.Launch();
//#endif
            LocateSolution();
            BuildToolsConfigFilePath = ConfigHelper.GetConfigurationPath(ProjectDir);
            MigrateSecretsToSettings();
            //ValidateConfigSchema();

            var crossTargetingProject = IsCrossTargeting();
            var platform       = TargetFrameworkIdentifier.GetTargetPlatform();
            var isPlatformHead = platform != Platform.Unsupported;
            var configuration  = ConfigHelper.GetConfig(BuildToolsConfigFilePath);

            // Only run these tasks for Android and iOS projects if they're not explicitly disabled
            EnableArtifactCopy        = !crossTargetingProject && IsEnabled(configuration?.ArtifactCopy) && isPlatformHead;
            EnableAutomaticVersioning = !crossTargetingProject && configuration.AutomaticVersioning is not null && configuration.AutomaticVersioning.Behavior != VersionBehavior.Off && isPlatformHead;
            EnableImageProcessing     = !crossTargetingProject && IsEnabled(configuration?.Images) && (platform == Platform.iOS || platform == Platform.Android);
            EnableTemplateManifests   = !crossTargetingProject && IsEnabled(configuration?.Manifests) && isPlatformHead;
            EnableReleaseNotes        = IsEnabled(configuration?.ReleaseNotes) && isPlatformHead && EnvironmentAnalyzer.IsInGitRepo(ProjectDir);

            // Only run this if it's not disabled and there are SCSS files
            EnableScssToCss = IsEnabled(configuration?.Css) && Directory.EnumerateFiles(ProjectDir, "*.scss", SearchOption.AllDirectories).Any();

            // Only run this if it is there is a configuration that enables it... or there is are secrets with no config
            EnableSecrets = ShouldEnableSecrets(configuration);

            return(true);
        }