예제 #1
0
        //处理寻路
        private void HandleSeek(SeekPathCom seekPathCom, SpeedCom speedCom)
        {
            //请求寻路
            if (seekPathCom.ReqSeek)
            {
                Vector2Int curPos  = seekPathCom.CurrPos;
                Vector2Int tarPos  = seekPathCom.TargetPos;
                MapData    mapData = TempConfig.GetMapData(seekPathCom.MapPos);

                //List<Vector2Int> path = AstarHelp.FindPath(curPos, tarPos, mapData.ObstaclePos);
                //seekPathCom.MovePath = path;

                TaskHelp.AddTaskTwoParam(seekPathCom, mapData, ExcuteFindPath, FinishFindPath);
                seekPathCom.ReqSeek = false;
            }

            if (seekPathCom.CurrPos.Equals(seekPathCom.TargetPos))
            {
                return;
            }
            if (seekPathCom.MovePath == null || seekPathCom.MovePath.Count <= 0)
            {
                return;
            }

            MoveFollowPath(seekPathCom.Trans, seekPathCom.MovePath, ref seekPathCom.CurrPathIndex, speedCom.MaxSpeed, seekPathCom);
            //HandleSeekMove(seekPathCom, speedCom, viewCom);
        }
예제 #2
0
        public void AppSettingsCannotLoadFromConfigSource()
        {
            using (var tempConfig = new TempConfig(TestData.EmptyConfig))
            {
                const string SubDirectory        = "Config";
                const string AppConfigFileName   = "tempAppConfig.config";
                string       tempConfigDirectory = Path.Combine(Path.GetDirectoryName(tempConfig.ConfigPath), SubDirectory);
                using (var tempDirectory = new TempDirectory(tempConfigDirectory))
                {
                    // set configSource and save the config
                    var config = ConfigurationManager.OpenExeConfiguration(tempConfig.ExePath);
                    config.AppSettings.SectionInformation.ConfigSource = Path.Combine(SubDirectory, AppConfigFileName);
                    config.Save();

                    // write temporary appConfig
                    var tempAppConfigPath = Path.Combine(tempConfigDirectory, AppConfigFileName);
                    File.WriteAllText(tempAppConfigPath, AppSettingsConfig);

                    // load config and test the appSettings
                    config = ConfigurationManager.OpenExeConfiguration(tempConfig.ExePath);
                    Assert.NotEmpty(config.AppSettings.Settings);
                    Assert.Equal("AppSettingsValue", config.AppSettings.Settings["AppSettingsKey"].Value);
                }
            }
        }
예제 #3
0
 public void RootSectionGroupNotNull()
 {
     using (var temp = new TempConfig(TestData.EmptyConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.NotNull(config.RootSectionGroup);
     }
 }
예제 #4
0
 public void UnspecifiedAssemblyStringTransformer()
 {
     using (var temp = new TempConfig(TestData.EmptyConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.Null(config.AssemblyStringTransformer);
     }
 }
예제 #5
0
 public void AppSettingsInvalidConfigSourcePath_Throws(string configPath)
 {
     using (var tempConfig = new TempConfig(TestData.EmptyConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(tempConfig.ExePath);
         Assert.ThrowsAny <Exception>(() => config.AppSettings.SectionInformation.ConfigSource = configPath);
     }
 }
예제 #6
0
 public void CreateExe()
 {
     using (var temp = new TempConfig(TestData.SimpleConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.NotNull(config);
         Assert.Equal(2, config.AppSettings.Settings.Count);
     }
 }
예제 #7
0
 public void EmptyDesignTimeAppSettings()
 {
     using (var temp = new TempConfig(TestData.EmptyConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.NotNull(config.AppSettings);
         Assert.Empty(config.AppSettings.Settings);
     }
 }
예제 #8
0
        public void SimpleCustomSectionMissingRequired()
        {
            using (var temp = new TempConfig(MissingRequiredData))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);

                Assert.Throws <ConfigurationErrorsException>(() => config.GetSection("simpleCustomSectionRequiredValue") as SimpleCustomSectionRequiredValue);
            }
        }
예제 #9
0
 public void SimpleCustomSectionWithData()
 {
     using (var temp = new TempConfig(SimpleCustomDataWithValue))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         SimpleCustomSection section = config.GetSection("simpleCustomSection") as SimpleCustomSection;
         Assert.NotNull(section);
         Assert.Equal("Foo", section.Test);
     }
 }
예제 #10
0
 public void SimpleCustomSectionExists()
 {
     using (var temp = new TempConfig(SimpleCustomData))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         SimpleCustomSection section = config.GetSection("simpleCustomSection") as SimpleCustomSection;
         Assert.NotNull(section);
         Assert.Equal(string.Empty, section.Test);
     }
 }
예제 #11
0
 public void UriSectionIdnIriParsing()
 {
     using (var temp = new TempConfig(UriSectionConfiguration))
     {
         var        config     = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         UriSection uriSection = (UriSection)config.GetSection("uri");
         Assert.Equal(UriIdnScope.All, uriSection.Idn.Enabled);
         Assert.Equal(true, uriSection.IriParsing.Enabled);
     }
 }
예제 #12
0
 public void SimpleCustomSectionWithDefault()
 {
     using (var temp = new TempConfig(DefaultAppliedData))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         SimpleCustomSectionDefaultValue section = config.GetSection("simpleCustomSectionDefaultValue") as SimpleCustomSectionDefaultValue;
         Assert.NotNull(section);
         Assert.Equal("Bar", section.Test);
     }
 }
예제 #13
0
 public void UriSectionIdnIriParsing()
 {
     using (var temp = new TempConfig(PlatformDetection.IsFullFramework ? UriSectionConfiguration_NetFX : UriSectionConfiguration_Core))
     {
         var        config     = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         UriSection uriSection = (UriSection)config.GetSection("uri");
         Assert.Equal(UriIdnScope.All, uriSection.Idn.Enabled);
         Assert.Equal(true, uriSection.IriParsing.Enabled);
     }
 }
예제 #14
0
 public void SpecifiedAssemblyStringTransformerReturned()
 {
     using (var temp = new TempConfig(TestData.EmptyConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Func <string, string> transformer = s => s;
         config.AssemblyStringTransformer = transformer;
         Assert.Same(transformer, config.AssemblyStringTransformer);
     }
 }
예제 #15
0
 public void SimpleAppSettings()
 {
     using (var temp = new TempConfig(TestData.SimpleConfig))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.NotNull(config.AppSettings);
         Assert.Equal(2, config.AppSettings.Settings.Count);
         Assert.Equal("FooValue", config.AppSettings.Settings["FooKey"].Value);
         Assert.Equal("BarValue", config.AppSettings.Settings["BarKey"].Value);
     }
 }
예제 #16
0
 public void EmptySectionGroup()
 {
     using (var temp = new TempConfig(EmptySectionGroupConfiguration))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("emptySectionGroup");
         Assert.NotNull(sectionGroup);
         Assert.Empty(sectionGroup.Sections);
         Assert.Empty(sectionGroup.SectionGroups);
     }
 }
예제 #17
0
 public void SimpleSectionGroup()
 {
     using (var temp = new TempConfig(SimpleSectionGroupConfiguration))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("simpleSectionGroup");
         Assert.NotNull(sectionGroup);
         Assert.Equal(1, sectionGroup.Sections.Count);
         Assert.Equal("fooSection", sectionGroup.Sections[0].SectionInformation.Name);
         Assert.Equal("System.Configuration.NameValueSectionHandler, System", sectionGroup.Sections[0].SectionInformation.Type);
     }
 }
예제 #18
0
 public void UriSectionSchemeSettings()
 {
     using (var temp = new TempConfig(PlatformDetection.IsFullFramework ? UriSectionConfiguration_NetFX : UriSectionConfiguration_Core))
     {
         var        config     = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         UriSection uriSection = (UriSection)config.GetSection("uri");
         Assert.Equal(1, uriSection.SchemeSettings.Count);
         SchemeSettingElement schemeSettingElement = uriSection.SchemeSettings[0];
         Assert.Equal("ftp", schemeSettingElement.Name);
         Assert.Equal(GenericUriParserOptions.DontCompressPath, schemeSettingElement.GenericUriParserOptions);
     }
 }
예제 #19
0
        public void DesignTimeAppSettingsFailWithEmptyMachineConfig()
        {
            // If we've explicitly specified a machine config and it doesn't define the AppSettingsType we shouldn't be able
            // to get it (e.g. we haven't stubbed in overtop).
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                var config = ConfigurationManager.OpenMappedMachineConfiguration(new ConfigurationFileMap(temp.ConfigPath));
                Assert.NotNull(config);

                Assert.Null(config.AppSettings);
            }
        }
예제 #20
0
 public void SimpleConnectionString()
 {
     using (var temp = new TempConfig(SimpleConnectionStringConfiguration))
     {
         var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
         Assert.NotNull(config.ConnectionStrings);
         Assert.NotNull(config.ConnectionStrings.ConnectionStrings);
         ConnectionStringSettings connection = config.ConnectionStrings.ConnectionStrings["fooName"];
         Assert.Equal("fooName", connection.Name);
         Assert.Equal("fooConnectionString", connection.ConnectionString);
         Assert.Equal("fooProviderName", connection.ProviderName);
     }
 }
예제 #21
0
        public void CustomSectionCollection()
        {
            using (var temp = new TempConfig(SimpleCollection))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                SimpleCollectionSection section = config.GetSection("simpleCollectionSection") as SimpleCollectionSection;
                Assert.NotNull(section);

                Assert.Equal(2, section.Foods.Count);
                Assert.Equal("Pear", section.Foods["Fruit"].Value);
                Assert.Equal("Cashew", section.Foods["Nut"].Value);
            }
        }
예제 #22
0
        public void AddToAppSettings_NoSave()
        {
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotNull(config.AppSettings);
                Assert.Empty(config.AppSettings.Settings);

                config.AppSettings.Settings.Add("NewKey", "NewValue");
                Assert.NotEmpty(config.AppSettings.Settings);
                Assert.Equal("NewValue", config.AppSettings.Settings["NewKey"].Value);

                config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.Empty(config.AppSettings.Settings);
            }
        }
        public void EnsureInitWithDifferentOrderHostParams()
        {
            string assemblyName = PlatformDetection.IsNetFramework ? "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" : "System.Configuration.ConfigurationManager";

            // InternalConfigFactory allows you to specify your own host / hostInitParams
            // Ensure ImplictMachineConfigHost can init within this process and not throw an Invalid cast exception
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                string typeName = "System.Configuration.Internal.InternalConfigConfigurationFactory, " + assemblyName;

                Type type          = Type.GetType(typeName, true);
                var  configFactory = (IInternalConfigConfigurationFactory)Activator.CreateInstance(type, true);
                var  config        = configFactory.Create(typeof(TempConfigurationHost), "test", new ConfigurationFileMap(temp.ConfigPath), "test");

                Assert.NotNull(config);
            }
        }
예제 #24
0
        public void AppSettingsCannotLoadFromUser()
        {
            // By default you can't load a section from a user config file- validating that appSettings falls in this bucket
            using (var machine = new TempConfig(TestData.ImplicitMachineConfig))
                using (var exe = new TempConfig(TestData.EmptyConfig))
                    using (var user = new TempConfig(TestData.SimpleConfig))
                    {
                        ExeConfigurationFileMap map = new ExeConfigurationFileMap
                        {
                            MachineConfigFilename     = machine.ConfigPath,
                            ExeConfigFilename         = exe.ConfigPath,
                            RoamingUserConfigFilename = user.ConfigPath
                        };

                        var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoaming);

                        Assert.Throws <ConfigurationErrorsException>(() => config.AppSettings);
                    }
        }
예제 #25
0
        public void CreateExe()
        {
            // Normally the "built-in" configuration section types come from the machine wide config.
            // Core doesn't have one that it installs, adding appSettings explicitly for now.
            const string SimpleConfig =
                @"<?xml version='1.0' encoding='utf-8' ?>
<configuration>
  <appSettings>
    <add key='Setting1' value='May 5, 2014'/>
    <add key='Setting2' value='May 6, 2014'/>
  </appSettings>
</configuration>";

            using (var temp = new TempConfig(SimpleConfig))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotNull(config);
                Assert.Equal(2, config.AppSettings.Settings.Count);
            }
        }
예제 #26
0
        public void AddToAppSettings_SaveFull()
        {
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotNull(config.AppSettings);
                Assert.Empty(config.AppSettings.Settings);

                config.AppSettings.Settings.Add("A", "1");
                Assert.NotEmpty(config.AppSettings.Settings);
                Assert.NotNull(config.AppSettings.Settings["A"]);
                Assert.Equal("1", config.AppSettings.Settings["A"].Value);

                config.Save(ConfigurationSaveMode.Full);

                config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotEmpty(config.AppSettings.Settings);
                Assert.NotNull(config.AppSettings.Settings["A"]);
                Assert.Equal("1", config.AppSettings.Settings["A"].Value);
            }
        }
예제 #27
0
        public void AddToAppSettings_Save()
        {
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotNull(config.AppSettings);
                Assert.Empty(config.AppSettings.Settings);

                config.AppSettings.Settings.Add("NewKey", "NewValue");
                Assert.NotEmpty(config.AppSettings.Settings);
                Assert.Equal("NewValue", config.AppSettings.Settings["NewKey"].Value);

                config.Save();

                // Make sure we didn't serialize the implicit machine.config
                Assert.False(File.Exists(new ConfigurationFileMap().MachineConfigFilename));

                config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                Assert.NotEmpty(config.AppSettings.Settings);
                Assert.Equal("NewValue", config.AppSettings.Settings["NewKey"].Value);
            }
        }
        public void MsdnRootSample()
        {
            // https://msdn.microsoft.com/en-us/library/system.configuration.keyvalueconfigurationcollection(v=vs.110).aspx
            using (var temp = new TempConfig(TestData.EmptyConfig))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);
                AppSettingsSection configSection = (AppSettingsSection)config.GetSection("appSettings");
                Assert.Equal("appSettings", configSection.SectionInformation.Name);
                KeyValueConfigurationElement    myAdminKeyVal  = new KeyValueConfigurationElement("myAdminTool", "admin.aspx");
                KeyValueConfigurationCollection configSettings = config.AppSettings.Settings;
                Assert.Equal(0, configSettings.AllKeys.Length);
                config.AppSettings.Settings.Add(myAdminKeyVal);
                Assert.False(configSection.SectionInformation.IsLocked);
                config.Save();

                KeyValueConfigurationCollection settings =
                    config.AppSettings.Settings;
                foreach (KeyValueConfigurationElement keyValueElement in settings)
                {
                    Assert.Equal("myAdminTool", keyValueElement.Key);
                    Assert.Equal("admin.aspx", keyValueElement.Value);
                }
            }
        }
예제 #29
0
        public void ReadConfigSectionsFromFile()
        {
            using (var temp = new TempConfig(DiagnosticsTestData.Sample))
            {
                var config = ConfigurationManager.OpenExeConfiguration(temp.ExePath);

                ConfigurationSection section = config.GetSection("system.diagnostics");
                Assert.NotNull(section);
                Assert.Equal("SystemDiagnosticsSection", section.GetType().Name);

                ConfigurationElementCollection collection;
                ConfigurationElement[]         items;

                // Verify Switches
                collection = (ConfigurationElementCollection)GetPropertyValue("Switches");
                Assert.Equal("SwitchElementsCollection", collection.GetType().Name);
                Assert.Equal(1, collection.Count);
                items = new ConfigurationElement[1];
                collection.CopyTo(items, 0);
                Assert.Equal("sourceSwitch", items[0].ElementInformation.Properties["name"].Value.ToString());
                Assert.Equal("Error", items[0].ElementInformation.Properties["value"].Value.ToString());

                // Verify SharedListeners
                collection = (ConfigurationElementCollection)GetPropertyValue("SharedListeners");
                Assert.Equal("SharedListenerElementsCollection", collection.GetType().Name);
                Assert.Equal(1, collection.Count);
                items = new ConfigurationElement[1];
                collection.CopyTo(items, 0);
                Assert.Equal("myListener", items[0].ElementInformation.Properties["name"].Value.ToString());
                Assert.Equal("System.Diagnostics.TextWriterTraceListener", items[0].ElementInformation.Properties["type"].Value.ToString());
                Assert.Equal("myListener.log", items[0].ElementInformation.Properties["initializeData"].Value.ToString());

                // Verify Sources
                collection = (ConfigurationElementCollection)GetPropertyValue("Sources");
                Assert.Equal("SourceElementsCollection", GetPropertyValue("Sources").GetType().Name);
                Assert.Equal(1, collection.Count);
                items = new ConfigurationElement[1];
                collection.CopyTo(items, 0);
                Assert.Equal("TraceSourceApp", items[0].ElementInformation.Properties["name"].Value.ToString());
                Assert.Equal("sourceSwitch", items[0].ElementInformation.Properties["switchName"].Value.ToString());
                Assert.Equal("System.Diagnostics.SourceSwitch", items[0].ElementInformation.Properties["switchType"].Value);

                ConfigurationElementCollection listeners = (ConfigurationElementCollection)items[0].ElementInformation.Properties["listeners"].Value;
                Assert.Equal("ListenerElementsCollection", listeners.GetType().Name);
                Assert.Equal(2, listeners.Count);
                ConfigurationElement[] listenerItems = new ConfigurationElement[2];
                listeners.CopyTo(listenerItems, 0);
                Assert.Equal("console", listenerItems[0].ElementInformation.Properties["name"].Value.ToString());
                Assert.Equal("System.Diagnostics.ConsoleTraceListener", listenerItems[0].ElementInformation.Properties["type"].Value.ToString());
                Assert.Equal("myListener", listenerItems[1].ElementInformation.Properties["name"].Value.ToString());

                ConfigurationElement filter = (ConfigurationElement)listenerItems[0].ElementInformation.Properties["filter"].Value;
                Assert.Equal("FilterElement", filter.GetType().Name);
                Assert.Equal("System.Diagnostics.EventTypeFilter", filter.ElementInformation.Properties["type"].Value.ToString());
                Assert.Equal("Error", filter.ElementInformation.Properties["initializeData"].Value.ToString());

                object GetPropertyValue(string propertyName) => section.GetType().
                GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance).
                GetValue(section);
            }
        }
예제 #30
0
 private void Awake()
 {
     TempConfig.Init();
 }