コード例 #1
0
ファイル: VsVimHost.cs プロジェクト: aesire/VsVim
 internal static void Initialize(IVimGlobalSettings globalSettings, IVimApplicationSettings vimApplicationSettings)
 {
     var settingsSource = new SettingsSource(vimApplicationSettings);
     globalSettings.AddCustomSetting(UseEditorIndentName, UseEditorIndentName, settingsSource);
     globalSettings.AddCustomSetting(UseEditorDefaultsName, UseEditorDefaultsName, settingsSource);
     globalSettings.AddCustomSetting(UseEditorTabAndBackspaceName, UseEditorTabAndBackspaceName, settingsSource);
 }
コード例 #2
0
        /// <summary>
        /// Performs custom arg validation for the utility, after invoking the base class parser.
        /// </summary>
        /// <param name="Settings">A settings instance to parse</param>
        /// <param name="CmdLineArgs">Command-line args array</param>
        /// <returns>True if args are valid, else False</returns>

        public new static bool Parse(SettingsSource Settings, string[] CmdLineArgs = null)
        {
            if (AppSettingsBase.Parse(Settings, CmdLineArgs))
            {
                if (!Type.Value.In("delimited", "fixed"))
                {
                    ParseErrorMessage = "Invalid value specified for the -type arg";
                    return(false);
                }
                if (Header.Initialized && Type.Value == "fixed" && !Header.Value.In("trunc", "fit"))
                {
                    ParseErrorMessage = "Invalid value specified for the -header arg";
                    return(false);
                }
                if (Tbl.Initialized && Tbl.Value.Contains("."))
                {
                    if (Tbl.Value.Split('.').Length != 2)
                    {
                        ParseErrorMessage = "Accepted table name forms are \"tablename\" and \"schemaname.tablename\"";
                        return(false);
                    }
                }
                if (Delimiter.Initialized)
                {
                    if (!Delimiter.Value.In("pipe", "comma", "tab"))
                    {
                        ParseErrorMessage = "Invalid value specified for the -delimiter arg";
                        return(false);
                    }
                }
                if (JobID.Initialized && !JobID.Value.IsGuid())
                {
                    ParseErrorMessage = "-jobid arg must be a GUID (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)";
                    return(false);
                }
                if (SQLTimeout.Initialized)
                {
                    float Timeout;
                    if (!float.TryParse(SQLTimeout.Value, out Timeout))
                    {
                        ParseErrorMessage = "Uable to parse the specified SQL timeout value as a decimal value: " + SQLTimeout.Value;
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Saves the settings in their current state to the passed source.
        /// </summary>
        /// <param name="Src">Supported sources. See the SettingsSource enum</param>

        public static void Save(SettingsSource Src)
        {
            switch (Src)
            {
            case SettingsSource.Registry:
                SaveRegistrySettings();
                break;

            case SettingsSource.SettingsFile:
                SaveFileSettings();
                break;

            default:
                throw new ParseException(string.Format("Unsupport Operation: Attempt to save an unsupported settings source: {0}", Src));
            }
        }
コード例 #4
0
            private void SetValue(string name, object value)
            {
                SettingsSource
                .SetValue <object>(name, value, value =>
                {
                    switch (Type.GetTypeCode(typeof(T)))
                    {
                    case TypeCode.String:
                        return((string)value);

                    default:
                        return(JsonConvert
                               .SerializeObject(value));
                    }
                });
            }
コード例 #5
0
            private object GetValue(string name)
            {
                return(SettingsSource
                       .GetValue <object>(name, null, value =>
                {
                    switch (Type.GetTypeCode(typeof(T)))
                    {
                    case TypeCode.String:
                        return value;

                    default:
                        return JsonConvert
                        .DeserializeObject <T>(value);
                    }
                }));
            }
コード例 #6
0
        public static void Main()
        {
            try
            {
                SettingsSource source = SelectFrameworkConfigSource();
                RunConsumer(GetSettings(source), GetSessionService(source));
            }
            catch (Exception e)
            {
                if (Log.IsErrorEnabled)
                {
                    Log.Error($"Error running the Consumer.\n{ExceptionUtils.InferErrorResponseMessage(e)}", e);
                }
            }

            Console.WriteLine("Press any key to continue ...");
            Console.ReadKey();
        }
コード例 #7
0
        private static IFrameworkSettings GetSettings(SettingsSource source)
        {
            IFrameworkSettings settings;

            switch (source)
            {
            case SettingsSource.Database:
                settings = new ConsumerSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb")));
                break;

            case SettingsSource.File:
                settings = SettingsManager.ConsumerSettings;
                break;

            default:
                settings = SettingsManager.ConsumerSettings;
                break;
            }
            return(settings);
        }
コード例 #8
0
            private object?GetValue(string name)
            {
                return(SettingsSource
                       .GetValue <object?>(name, null, value =>
                {
                    var type = typeof(T);
                    var underlyingType = Nullable.GetUnderlyingType(type) ?? type;

                    switch (Type.GetTypeCode(underlyingType))
                    {
                    case TypeCode.String:
                        return (string)value;

                    case TypeCode.Object:
                        try
                        {
                            return JsonConvert
                            .DeserializeObject <T>(value);
                        }
                        catch
                        {
                            return null;
                        }

                    default:
                        var converter = TypeDescriptor
                                        .GetConverter(underlyingType);

                        try
                        {
                            return converter
                            .ConvertFromInvariantString(value);
                        }
                        catch
                        {
                            return null;
                        }
                    }
                }));
            }
コード例 #9
0
        /// <summary>
        /// Parses the passed source for settings. Override to add custom parsing (i.e. valid values, ranges, etc)
        /// </summary>
        /// <param name="Src"></param>
        /// <param name="CmdLineArgs"></param>
        /// <remarks>
        /// If the settings were previously parsed from another source then the second parse operation overwrites
        /// the first for settings that are defined in both sources.
        /// </remarks>
        /// <returns></returns>

        public static bool Parse(SettingsSource Src, string[] CmdLineArgs = null)
        {
            switch (Src)
            {
            case SettingsSource.Registry:
                if (!ParseRegistry())
                {
                    return(false);
                }
                break;

            case SettingsSource.SettingsFile:
                if (!ParseSettingsFile())
                {
                    return(false);
                }
                break;

            case SettingsSource.CommandLine:
                if (!ParseCommandLine(CmdLineArgs))
                {
                    return(false);
                }
                break;
            }

            foreach (Setting s in SettingsDict.Values)
            {
                if (s.ArgType == Setting.ArgTyp.StopIfProvided && s.Initialized)
                {
                    return(true);
                }
                if (s.ArgType == Setting.ArgTyp.Mandatory && !s.Initialized)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #10
0
            private object?GetValue(string name)
            {
                string?stringValue = SettingsSource.GetValue(name);

                Type type           = typeof(T);
                Type underlyingType = Nullable.GetUnderlyingType(type) ?? type;

                switch (Type.GetTypeCode(underlyingType))
                {
                case TypeCode.String:
                    return(stringValue);

                case TypeCode.Object:
                    try
                    {
                        return(JsonConvert
                               .DeserializeObject <T>(stringValue));
                    }
                    catch
                    {
                        return(null);
                    }

                default:
                    TypeConverter converter = TypeDescriptor
                                              .GetConverter(underlyingType);

                    try
                    {
                        return(converter
                               .ConvertFromInvariantString(stringValue));
                    }
                    catch
                    {
                        return(null);
                    }
                }
            }
コード例 #11
0
        protected static ISessionService GetSessionService(SettingsSource source)
        {
            ISessionService sessionService;

            switch (source)
            {
            case SettingsSource.Database:
                DbContext dbContext = new SessionDbContext("name=FrameworkConfigDb");
                IRepository <Session, Guid>    repository = new Repository <Session, Guid>(dbContext);
                IObjectService <Session, Guid> service    = new ObjectService <Session, Guid>(repository);
                sessionService = new SessionService(service);
                break;

            case SettingsSource.File:
                sessionService = SessionsManager.ConsumerSessionService;
                break;

            default:
                sessionService = SessionsManager.ConsumerSessionService;
                break;
            }

            return(sessionService);
        }
コード例 #12
0
 public override void VimCreated(IVim vim)
 {
     _vim = vim;
     SettingsSource.Initialize(vim.GlobalSettings, _vimApplicationSettings);
 }
コード例 #13
0
 private static void OnSettingsChanged([CallerMemberName] string propertyName = null)
 {
     SettingsSource.SaveState();
     SettingsChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
 }
コード例 #14
0
        public static void Main()
        {
            Console.WriteLine();
            Console.WriteLine("********************************************************************************");
            Console.WriteLine();
            Console.WriteLine("To run this Event Consumer demo, the following steps are required.");
            Console.WriteLine();
            Console.WriteLine("  1) In the demo Consumer project:");
            Console.WriteLine("    1.1) Set the consumer.environment.template.applicationKey app setting to Sif3DemoEventConsumer.");
            Console.WriteLine("    1.2) Configure the consumer.environment.url app setting to reference the BROKERED environment endpoint - http://localhost:59586/api/environments/environment.");
            Console.WriteLine("    1.3) Configure the EventConsumerApp to be the Startup object for the project.");
            Console.WriteLine();
            Console.WriteLine("  2) In the demo Consumer project:");
            Console.WriteLine("    2.1) Set the provider.environmentType app setting to BROKERED.");
            Console.WriteLine("    2.2) Configure the provider.environment.url app setting to reference the BROKERED environment endpoint - http://localhost:59586/api/environments/environment.");
            Console.WriteLine("    2.3) This EventConsumerApp needs to be configured to be the Startup object for this project.");
            Console.WriteLine();
            Console.WriteLine("  3) Run the demo Broker instead of the EnvironmentProvider.");
            Console.WriteLine();
            Console.WriteLine("  4) Run the demo Provider.");
            Console.WriteLine();
            Console.WriteLine("  5) Run the demo Consumer.");
            Console.WriteLine();
            Console.WriteLine("********************************************************************************");

            try
            {
                SettingsSource     source         = SelectFrameworkConfigSource();
                IFrameworkSettings settings       = GetSettings(source);
                ISessionService    sessionService = GetSessionService(source);
                var consumer = new StudentPersonalEventConsumer(
                    settings.ApplicationKey,
                    settings.InstanceId,
                    settings.UserToken,
                    settings.SolutionId,
                    settings,
                    sessionService);
                consumer.Start("Sif3DemoZone1", "DEFAULT");

                if (Log.IsInfoEnabled)
                {
                    Log.Info("Started the Event Consumer.");
                }

                Console.WriteLine(
                    "Press any key to stop the Event Consumer (may take several seconds to complete) ...");
                Console.ReadKey();

                consumer.Stop();

                if (Log.IsInfoEnabled)
                {
                    Log.Info("Stopped the Event Consumer.");
                }
            }
            catch (Exception e)
            {
                if (Log.IsErrorEnabled)
                {
                    Log.Error($"Error running the Event Consumer.\n{ExceptionUtils.InferErrorResponseMessage(e)}", e);
                }
            }

            Console.WriteLine("Press any key to continue ...");
            Console.ReadKey();
        }