コード例 #1
0
        protected override void ProcessDemo()
        {
            var firstSimpleConfiguration = SimpleConfiguration.GetInstance();
            var lastSimpleConfiguration  = SimpleConfiguration.GetInstance();

            Console.WriteLine(firstSimpleConfiguration == lastSimpleConfiguration);
        }
コード例 #2
0
        public DBAccess()
        {
            var config   = new Configuration();
            var settings = new SimpleConfiguration();

            config.AddAssembly("FragmentNetslumServer");

            config.DataBaseIntegration(db => {
                db.ConnectionString = "Server=" + settings.Get("dbhost") +
                                      ";Port=" + settings.Get("dbport") +
                                      ";Database=" + settings.Get("dbname") +
                                      ";User ID=" + settings.Get("dbuser") +
                                      ";Password="******"dbpass") +
                                      ";SslMode=none";
                db.Driver <MySqlDataDriver>();
                db.Dialect <MySQL5Dialect>();
            });

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            _encoding = Encoding.GetEncoding("Shift-JIS");

            _sessionFactory = config.BuildSessionFactory();



            //_messageOfTheDay = LoadMessageOfDay();
        }
コード例 #3
0
        public void TestBasicSetup1()
        {
            SimpleConfiguration config = new SimpleConfiguration(LoaderTypeEnum.FileLoader, new Dictionary <string, string>(), new Dictionary <string, string>());

            Assert.AreEqual(LoaderTypeEnum.FileLoader, config.LoaderType);
            Assert.AreEqual(0, config.FilterNames.Count);
            Assert.AreEqual(0, config.Filters.Count);
        }
コード例 #4
0
        // if you modify InitializeContainer you gotta go down below
        // and add it to the ConfigureServices() if you want WebAPI to care about
        // it otherwise tough cookies.
        private static IServiceCollection InitializeContainer()
        {
            return(new ServiceCollection()
                   .AddTransient <ILogger>((provider) =>
            {
                var cfg = new SimpleConfiguration();
                var logConfig = new LoggerConfiguration();

                // configure the sinks appropriately
                var sinks = cfg.Get("sinks")?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                if (sinks.Contains("console", StringComparer.OrdinalIgnoreCase))
                {
                    logConfig.WriteTo.Console();
                }
                if (sinks.Contains("file", StringComparer.OrdinalIgnoreCase))
                {
                    var path = cfg.Get("folder");
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    logConfig.WriteTo.File(
                        formatter: new JsonFormatter(),
                        path: path,
                        buffered: true,
                        flushToDiskInterval: TimeSpan.FromMinutes(1),
                        rollingInterval: RollingInterval.Hour,
                        rollOnFileSizeLimit: true,
                        retainedFileCountLimit: 31,
                        fileSizeLimitBytes: ONE_GIGABYTE,
                        encoding: Encoding.UTF8);
                }

                // set the minimum level
                var lobbyLogLevel = cfg.Get("lobbyloglevel");
                var apiLogLevel = cfg.Get("apiloglevel");
                logConfig.MinimumLevel.Is(Enum.Parse <LogEventLevel>(lobbyLogLevel));
                logConfig.MinimumLevel.Override("Microsoft.AspNetCore", Enum.Parse <LogEventLevel>(apiLogLevel))
                .Enrich.FromLogContext()
                .Enrich.WithExceptionDetails();
                return logConfig.CreateLogger();
            })
                   .AddSingleton <IClientProviderService, GameClientService>()
                   .AddSingleton <IClientConnectionService, ClientConnectionService>()
                   .AddSingleton <ILobbyChatService, LobbyChatService>()
                   .AddSingleton <IMailService, MailService>()
                   .AddSingleton <IBulletinBoardService, BulletinBoardService>()
                   .AddSingleton <INewsService, NewsService>()
                   .AddSingleton <IOpCodeProviderService, OpCodeProviderService>()
                   .AddSingleton <IRankingManagementService, RankingManagementService>()
                   .AddSingleton <IGuildManagementService, GuildManagementService>()
                   .AddTransient <GameClientAsync>()
                   .AddSingleton <SimpleConfiguration>()
                   .AddSingleton <Server>());
        }
コード例 #5
0
        public void TestBasicSetup3()
        {
            Dictionary <string, string> additional = new Dictionary <string, string>
            {
                { AdditionalSettingsEnum.FilePath.ToString(), TEST_FILE_PATH }
            };
            SimpleConfiguration config = new SimpleConfiguration(LoaderTypeEnum.FileLoader, new Dictionary <string, string>(), additional);

            Assert.AreEqual(LoaderTypeEnum.FileLoader, config.LoaderType);
            Assert.AreEqual(0, config.FilterNames.Count);
            Assert.AreEqual(0, config.Filters.Count);

            Assert.AreEqual(TEST_FILE_PATH, config.GetAdditionalSetting(AdditionalSettingsEnum.FilePath));
            Assert.AreEqual(TEST_FILE_PATH, config.GetAdditionalSetting("FilePath"));
        }
コード例 #6
0
        public void TestBasicSetup2()
        {
            Dictionary <string, string> filters = new Dictionary <string, string>
            {
                { FilterTypeEnum.Caller.ToString(), TEST_FILTER_CONTENT }
            };
            SimpleConfiguration config = new SimpleConfiguration(LoaderTypeEnum.FileLoader, filters, new Dictionary <string, string>());

            Assert.AreEqual(LoaderTypeEnum.FileLoader, config.LoaderType);

            Assert.AreEqual(1, config.FilterNames.Count);
            Assert.AreEqual(FilterTypeEnum.Caller.ToString(), config.FilterNames[0]);
            Assert.AreEqual(TEST_FILTER_CONTENT, config.Filters[FilterTypeEnum.Caller.ToString()]);
            Assert.AreEqual(1, config.Filters.Count);
        }
コード例 #7
0
        public static SimpleConfiguration GetInstance()
        {
            if (_instance != null)
            {
                return(_instance);
            }
            lock (LockObject)
            {
                if (_instance == null)
                {
                    _instance = new SimpleConfiguration();
                }
            }

            return(_instance);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: ChiruclanDE/Cessenger
        private static struct_socket sock; // socket structure with client and server socket

        #endregion Fields

        #region Methods

        private static bool init_server()
        {
            try
            {
                TextWriter tmp = Console.Out; // save old output
                Console.SetOut(TextWriter.Null); // suppress output

                config = new SimpleConfiguration("cc_server.conf");
                crypt = new SimpleCryptography();
                cache = new SimpleCaching();

                Console.SetOut(tmp); // reenable console output

                cfg.logging.file.basename = config.GetKey("logging.file.basename");
                cfg.logging.file.prefix = config.GetKey("logging.file.prefix");
                cfg.logging.file.suffix = config.GetKey("logging.file.suffix");
                bool.TryParse(config.GetKey("logging.usedate"), out cfg.logging.usedate);
                logger = new Logging(cfg.logging.file.basename, cfg.logging.file.prefix, cfg.logging.file.suffix, cfg.logging.usedate);

                cfg.server.name = config.GetKey("server.name");
                uint.TryParse(config.GetKey("server.connection.limit"), out cfg.server.connection.limit);

                cfg.inet.address = config.GetKey("inet.address");
                ushort.TryParse(config.GetKey("inet.port"), out cfg.inet.port);

                cfg.mysql.username = config.GetKey("mysql.username");
                cfg.mysql.password = config.GetKey("mysql.password");
                cfg.mysql.hostname = config.GetKey("mysql.hostname");
                cfg.mysql.database = config.GetKey("mysql.database");
                ushort.TryParse(config.GetKey("mysql.port"), out cfg.mysql.port);

                db = new Database(cfg.mysql.hostname, cfg.mysql.port, cfg.mysql.username, cfg.mysql.password, cfg.mysql.database, logger);

                sock.address = cfg.inet.address;
                sock.port = cfg.inet.port;
                sock.server = new TcpListener(sock.endpoint);

                return true;
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nError:\n{0}", ex.Message);
                return false;
            }
        }
コード例 #9
0
        public void ReadConfigurationAttributesTest()
        {
            string inputXml = @"
                <SimpleConfiguration Name=""AAA"" MaxValue=""23"">
                </SimpleConfiguration>";

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(inputXml);

            IMappingStrategyFactory mappingStrategyFactory = new MappingStrategyFactory();
            IConfigurationReader    configurationReader    = new ConfigurationReader(xml.FirstChild, mappingStrategyFactory);

            SimpleConfiguration actual = configurationReader.ReadObject <SimpleConfiguration>();

            Assert.AreEqual(23, actual.MaxValue);
            Assert.AreEqual("AAA", actual.Name);
        }
コード例 #10
0
        public static IList <TargetFolderMRUEntry> AddAndGetFolders(OwaStoreObjectId folderId, UserContext userContext)
        {
            SimpleConfiguration <TargetFolderMRUEntry> simpleConfiguration = new SimpleConfiguration <TargetFolderMRUEntry>(userContext);

            simpleConfiguration.Load();
            bool flag = false;
            ReadOnlyCollection <TargetFolderMRUEntry> result = new ReadOnlyCollection <TargetFolderMRUEntry>(simpleConfiguration.Entries);

            while (simpleConfiguration.Entries.Count > 10)
            {
                simpleConfiguration.Entries.RemoveAt(10);
                flag = true;
            }
            int i = 0;

            while (i < simpleConfiguration.Entries.Count)
            {
                OwaStoreObjectId owaStoreObjectId = OwaStoreObjectId.CreateFromString(simpleConfiguration.Entries[i].FolderId);
                if (owaStoreObjectId.Equals(folderId))
                {
                    if (i == 0)
                    {
                        if (flag)
                        {
                            simpleConfiguration.Save();
                        }
                        return(result);
                    }
                    simpleConfiguration.Entries.RemoveAt(i);
                    break;
                }
                else
                {
                    i++;
                }
            }
            if (simpleConfiguration.Entries.Count == 10)
            {
                simpleConfiguration.Entries.RemoveAt(9);
            }
            simpleConfiguration.Entries.Insert(0, new TargetFolderMRUEntry(folderId));
            simpleConfiguration.Save();
            return(result);
        }
コード例 #11
0
        public org.semanticweb.owlapi.reasoner.OWLReasoner createReasoner(OWLOntology ontology)
        {
            var config = new SimpleConfiguration(progrMonitor);

            return(new com.clarkparsia.pellet.owlapiv3.PelletReasoner(ontology, config, BufferingMode.BUFFERING));
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: SimuPoLAS/Ofc
        public static void Main(string[] args)
        {
            // debug stuff
#if DEBUG
            if (args.Length == 0)
            {
                // input for arguments
                Console.Write("args: ");
                var input = Console.ReadLine();
                Console.Clear();

                // string builder for string operations
                var sb = new StringBuilder();

                // if not empty
                if (!string.IsNullOrWhiteSpace(input))
                {
                    var rargs     = new List <string>();
                    var inLiteral = false;
                    for (var i = 0; i < input.Length; i++)
                    {
                        var c = input[i];
                        if (inLiteral)
                        {
                            if (c == '"')
                            {
                                if (i != input.Length - 1 && input[i + 1] == '"')
                                {
                                    sb.Append('"');
                                }
                                else
                                {
                                    inLiteral = false;
                                }
                            }
                            else
                            {
                                sb.Append(c);
                            }
                        }
                        else
                        {
                            if (char.IsWhiteSpace(c))
                            {
                                if (sb.Length == 0)
                                {
                                    continue;
                                }
                                rargs.Add(sb.ToString());
                                sb.Length = 0;
                            }
                            else if (c == '"')
                            {
                                inLiteral = true;
                            }
                            else
                            {
                                sb.Append(c);
                            }
                        }
                    }
                    if (sb.Length != 0)
                    {
                        rargs.Add(sb.ToString());
                    }
                    args = rargs.ToArray();
                }

                // provide info
                Console.WriteLine($"calling with {args.Length} arguments");

                // show the arguments that will be passed over
                sb.Length = 0;
                sb.Append('[');
                var l = args.Length;
                for (var i = 0; i < l; i++)
                {
                    sb.Append($"\"{args[i]}\"{(i != l - 1 ? ", " : string.Empty)}");
                }
                sb.Append(']');
                Console.WriteLine(sb.ToString());
                Console.WriteLine();
            }
#endif

            try
            {
                BlockyAlgorithm.SetBlockfindingDebugConsoleEnabled(false);

                // initiate the parser
                IArgumentParser <CommandLineLayers> argumentParser = new ArgumentParser <CommandLineLayers>();
                argumentParser.Description = "A command line tool for compressing Open Foam (r) files.";
                argumentParser.Name        = "ofc.exe";

                // add validators
                argumentParser.Validator <int>(new FuncValidator((string v, ref object d) =>
                {
                    int value;
                    if (!int.TryParse(v, out value))
                    {
                        return(false);
                    }
                    d = value;
                    return(true);
                }));

                // add parser definitions
                argumentParser.NewLayer(CommandLineLayers.Help).AddOption(e => e.SetShortName('h').SetLongName("help").Description("Display this help message."));
                argumentParser.NewLayer(CommandLineLayers.Version).AddOption(e => e.SetLongName("version").Description("Display the current version of the tool."));

                argumentParser.NewLayer(CommandLineLayers.ListAlgorithms).Command("algorithms").Command("list", "Lists all available algorithms for compression/decompression.");

                argumentParser.NewLayer(CommandLineLayers.CompressDirectory).Command("compress").Command("directory", "Compress the specified directory.").Argument("input").Argument("output").Option("algorithm", e => e.SetName("name")).Option("rounding", e => e.SetName("digits").Type <int>()).Option('f').Option('r').Option('p').Option('s');
                argumentParser.NewLayer(CommandLineLayers.CompressFile).Command("compress").Command("file", "Compress the specified file.").Argument("input").Argument("output").Option("algorithm", e => e.SetName("name")).Option("rounding", e => e.SetName("digits").Type <int>()).Option('f').Option('s');

                argumentParser.NewLayer(CommandLineLayers.DecompressDirectory).Command("decompress").Command("directory", "Decompress the specified compressed directory.").Argument("input").Argument("output").Option("algorithm", e => e.SetName("name")).Option('f').Option('r').Option('p');
                argumentParser.NewLayer(CommandLineLayers.DecompressFile).Command("decompress").Command("file", "Decompress the specified compressed file or directory.").Argument("input").Argument("output").Option("algorithm", e => e.SetName("name")).Argument("data", true).Option('f');

                argumentParser.NewOption().SetLongName("rounding").Description("Enable rounding to the specified amount of digits.");
                argumentParser.NewOption().SetShortName('f').Description("Force overriding of files.");
                argumentParser.NewOption().SetShortName('r').Description("Enable recursive compression/decompression.");
                argumentParser.NewOption().SetShortName('p').Description("Enable parallel compression/decompression.");
                argumentParser.NewOption().SetShortName('s').Description("Treat anonymous lists as lists of one type.");

                // parse the arguments
                var result = argumentParser.Parse(args);

                var ok = false;
                // check if the parser succeeded
                if (result.Success)
                {
                    ok = true;
                    var             manager = new OfcActionManager();
                    IConfiguaration config  = new SimpleConfiguration();

                    // check for rounding
                    if (result.GetFlag("rounding"))
                    {
                        config["rounding"]         = true;
                        config["roundingDecimals"] = result.GetOption <int>("rounding");
                    }
                    if (result.GetFlag("s"))
                    {
                        config["simplealists"] = true;
                    }

                    // check is algorithm is supplied
                    string algorithm = null;
                    if (result.GetFlag("algorithm"))
                    {
                        var supposedAlgorithm = result.GetOption("algorithm") as string;
                        if (supposedAlgorithm == null || !AlgorithmHelper.IsValidAlgorithm(supposedAlgorithm))
                        {
                            Console.WriteLine("Invalid algorithm.\n");
                            Console.Write(argumentParser.GenerateHelp());
                            return;
                        }
                        algorithm = supposedAlgorithm;
                    }

                    switch (result.LayerId)
                    {
                    // Displays the CLI help
                    case CommandLineLayers.Help:
                        Console.Write(argumentParser.GenerateHelp());
                        break;

                    // Displays the current version
                    case CommandLineLayers.Version:
                        Console.WriteLine($"{argumentParser.Name} [v1.0]");
                        break;

                    // Compresses the specified file
                    case CommandLineLayers.CompressFile:
                        manager.AddCompressFileActionWithAlgorithm(algorithm, config, result[0], result[1]);
                        manager.Override = result['f'];
                        manager.Handle();
                        break;

                    // Compresses the specified directory
                    case CommandLineLayers.CompressDirectory:
                        manager.AddCompressDirectoryActionWithAlgorithm(algorithm, config, result[0], result[1], result['r']);
                        if (manager.Empty)
                        {
                            Console.WriteLine(" WARNING: input folder is empty");
                        }
                        manager.Override = result['f'];
                        manager.Parallel = result['p'];
                        manager.Handle();
                        break;

                    // Decompresses the specified file
                    case CommandLineLayers.DecompressFile:
                        manager.AddDecompressFileActionWithAlgorithm(algorithm, config, result[0], result[2] ?? Path.ChangeExtension(result[0], ActionUtils.DataFileExtention), result[1]);
                        manager.Handle();
                        break;

                    // Decompresses the specified directory
                    case CommandLineLayers.DecompressDirectory:
                        manager.AddDecompressDirectoryActionWithAlgorithm(algorithm, config, result[0], result[1], result['r']);
                        if (manager.Empty)
                        {
                            Console.WriteLine(" WARNING: input folder is empty");
                        }
                        manager.Override = result['f'];
                        manager.Parallel = result['p'];
                        manager.Handle();
                        break;

                    // List all available algorithms
                    case CommandLineLayers.ListAlgorithms:
                        var defaultAlgorithm = AlgorithmHelper.DefaultAlgorithm;
                        foreach (var name in AlgorithmHelper.RegisteredAlgorithmByName.OrderBy(e => e))
                        {
                            Console.WriteLine($" {(defaultAlgorithm == name ? "*" : " ")} {name}");
                        }
                        Console.WriteLine();
                        break;
                    }
                }

                // Write an error message
                if (ok)
                {
                    return;
                }
                Console.WriteLine("Invalid arguments.\n");
                Console.Write(argumentParser.GenerateHelp());
            }
            catch (Exception ex)
            {
                Console.WriteLine("fatal application error: \n" + ex);
            }
        }
コード例 #13
0
        public static void GetFolders(UserContext userContext, out OwaStoreObjectId[] folderIds, out string[] folderNames, out string[] folderClassNames, out int folderCount)
        {
            folderIds        = new OwaStoreObjectId[10];
            folderNames      = new string[10];
            folderClassNames = new string[10];
            folderCount      = 0;
            SimpleConfiguration <TargetFolderMRUEntry> simpleConfiguration = new SimpleConfiguration <TargetFolderMRUEntry>(userContext);

            simpleConfiguration.Load();
            bool flag = false;
            int  i    = 0;

            while (i < simpleConfiguration.Entries.Count)
            {
                if (i >= 10)
                {
                    break;
                }
                OwaStoreObjectId owaStoreObjectId = null;
                try
                {
                    owaStoreObjectId = OwaStoreObjectId.CreateFromString(simpleConfiguration.Entries[i].FolderId);
                }
                catch (OwaInvalidIdFormatException)
                {
                    simpleConfiguration.Entries.RemoveAt(i);
                    flag = true;
                    continue;
                }
                if (!userContext.IsPublicFoldersAvailable() && owaStoreObjectId.IsPublic)
                {
                    i++;
                }
                else
                {
                    Folder folder = null;
                    string text   = null;
                    string text2  = null;
                    try
                    {
                        folder = Utilities.GetFolder <Folder>(userContext, owaStoreObjectId, new PropertyDefinition[0]);
                        if (Utilities.IsFolderSegmentedOut(folder.ClassName, userContext))
                        {
                            i++;
                            continue;
                        }
                        text2 = folder.ClassName;
                        text  = Utilities.GetDisplayNameByFolder(folder, userContext);
                    }
                    catch (ObjectNotFoundException)
                    {
                        simpleConfiguration.Entries.RemoveAt(i);
                        flag = true;
                        continue;
                    }
                    catch (StorageTransientException)
                    {
                        i++;
                        continue;
                    }
                    finally
                    {
                        if (folder != null)
                        {
                            folder.Dispose();
                            folder = null;
                        }
                    }
                    folderIds[folderCount]        = owaStoreObjectId;
                    folderNames[folderCount]      = text;
                    folderClassNames[folderCount] = text2;
                    folderCount++;
                    i++;
                }
            }
            while (simpleConfiguration.Entries.Count > 10)
            {
                simpleConfiguration.Entries.RemoveAt(10);
                flag = true;
            }
            if (flag)
            {
                simpleConfiguration.Save();
            }
        }