Пример #1
0
 protected TrainManagerBase(HostInterface host, BaseRenderer renderer, BaseOptions Options, FileSystem fileSystem)
 {
     currentHost    = host;
     Renderer       = renderer;
     CurrentOptions = Options;
     FileSystem     = fileSystem;
 }
Пример #2
0
        /// <summary>
        /// The operation to load in initial settings for this application.
        /// </summary>
        /// <param name="options">The options object which contains extra information
        /// which helps during the exeuction of this modus.</param>
        public static void Start(BaseOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            // Convert Options value to Settings.
            if (options.HasCulture)
            {
                Settings.Culture = CultureInfo.GetCultureInfo(options.Culture);
            }
            Settings.ShowDebug      = options.DebugMessages;
            Settings.DirectShutDown = options.AutoExit;
            // Read the Settings.
            string settingsFile = Settings.SettingsFile;

            if (Settings.FileManager.TryRead(settingsFile, out TempSettings settings))
            {
                settings.Finalise();
            }
            // Add previously refined files.
            string finalDir = Settings.ShapeFinalDir;

            if (!Directory.Exists(finalDir))
            {
                Directory.CreateDirectory(finalDir);
            }
            Settings.FileManager.AddDirectoryDirect(finalDir);
        }
Пример #3
0
        private async Task <int> OnExecute(BaseOptions baseOptions, XRayBuildOptions xrayBuildOptions, CancellationToken cancellationToken)
        {
            var config = new XRayBuilderConfig
            {
                UseSubdirectories   = baseOptions.UseSubdirectories.HasValue(),
                BaseOutputDirectory = baseOptions.BaseOutputDirectory.HasValue()
                    ? baseOptions.BaseOutputDirectory.Value()
                    : $"{AppDomain.CurrentDomain.BaseDirectory ?? Environment.CurrentDirectory}out",
                BuildForAndroid = baseOptions.Android.HasValue(),
                OutputToSidecar = baseOptions.OutputToSidecar.HasValue()
            };

            await using var container = _bootstrap(config);
            var logger = container.GetInstance <ILogger>();

            var bookPath = (string)baseOptions.Book.Value;

            if (bookPath == null || !File.Exists(bookPath))
            {
                logger.Log($"Book not found: {bookPath}");
                return(1);
            }

            var xrayBuildService = container.GetInstance <XRay>();
            var request          = new XRay.Request(
                bookPath: bookPath,
                dataUrl: xrayBuildOptions.DataUrl.Value() ?? SecondarySourceRoentgen.FakeUrl,
                includeTopics: xrayBuildOptions.IncludeTopics.HasValue(),
                splitAliases: xrayBuildOptions.SplitAliases.HasValue(),
                amazonTld: baseOptions.AmazonTld.Value());
            var xrayPath = await xrayBuildService.BuildAsync(request, cancellationToken);

            return(0);
        }
Пример #4
0
        public override void Initialize(HostInterface CurrentHost, BaseOptions CurrentOptions)
        {
            base.Initialize(CurrentHost, CurrentOptions);

            try
            {
                if (pickingShader == null)
                {
                    pickingShader = new Shader(this, "default", "picking", true);
                }
                pickingShader.Activate();
                pickingShader.Deactivate();
            }
            catch
            {
                Interface.AddMessage(MessageType.Error, false, "Initializing the touch shader failed- Falling back to legacy openGL.");
                Interface.CurrentOptions.IsUseNewRenderer = false;
                ForceLegacyOpenGL = true;
            }

            events               = new Events(this);
            overlays             = new Overlays(this);
            Touch                = new Touch(this);
            ObjectsSortedByStart = new int[] { };
            ObjectsSortedByEnd   = new int[] { };
            Program.FileSystem.AppendToLogFile("Renderer initialised successfully.");
        }
Пример #5
0
        /// <summary>Loads all interfaces this plugin supports.</summary>
        public void Load(Hosts.HostInterface Host, FileSystem.FileSystem FileSystem, BaseOptions Options, object RendererReference = null)
        {
            if (this.Texture != null)
            {
                this.Texture.Load(Host);
            }

            if (this.Sound != null)
            {
                this.Sound.Load(Host);
            }

            if (this.Object != null)
            {
                this.Object.Load(Host, FileSystem);
                this.Object.SetObjectParser(Options.CurrentXParser);
                this.Object.SetObjectParser(Options.CurrentObjParser);
            }

            if (this.Route != null)
            {
                //FIXME: Remove renderer reference
                this.Route.Load(Host, FileSystem, Options, RendererReference);
            }
        }
Пример #6
0
        private static async Task <int> Process(BaseOptions options)
        {
            ConfigureServices(options);
            var mediator = _serviceProvider.GetRequiredService <IMediator>();

            return(await mediator.Send(options));
        }
        public void InitializeTreils_AllRegionsInitializedInRange_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            for (var i = 0; i < options.NumberOfRegions; i++)
            {
                int velueOfFirstVerticeInRegion = antSystem.Treil[i].Single().Weight;
                Assert.IsTrue(velueOfFirstVerticeInRegion <= 8);
                Assert.IsTrue(velueOfFirstVerticeInRegion >= 0);
            }
        }
        public void SumOfWeight_AllZerosSet_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            var sumOfWeights = antSystem.WeightOfColonies.Sum();

            Assert.AreEqual(15, sumOfWeights);
        }
        public void CalculateProbability_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);
            mockGraph.Setup(prop => prop.PheromoneMatrix).Returns(new double[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            var probability = antSystem.CalculateProbability(1);

            Assert.AreEqual(probability[0], 0);
        }
        public void GetNextColony_AddVertex_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            antSystem.AddFreeVertexToTreil(0, antSystem.FreeVertices.First());

            var nextColonyIndex     = antSystem.GetNextColony();
            var nextColonyWeightSum = antSystem.WeightOfColonies[nextColonyIndex];

            for (int i = 0; i < options.NumberOfRegions; i++)
            {
                Assert.IsTrue(antSystem.WeightOfColonies[i] >= nextColonyWeightSum);
            }
        }
        public void SumaKriterijumaOptimalnosti_Initialized_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            Assert.IsNotNull(antSystem.EdgesWeightOfColonies);
            for (var i = 0; i < options.NumberOfRegions; i++)
            {
                Assert.AreEqual(0, antSystem.EdgesWeightOfColonies[i]);
            }
        }
Пример #12
0
 public EventHarvester(int confirmationsRequired, BaseOptions opts) : base(opts)
 {
     _blocksPerRound        = 20;
     _confirmationsRequired = Math.Max(2, confirmationsRequired);
     _lastBlock             = BigInteger.Zero;
     _lastSavedBlock        = BigInteger.Zero;
 }
        public SimCardsServiceTest(MockHttpClientFixture mockHttpClientFixture)
            : base(mockHttpClientFixture)
        {
            this.service = new SimCardsService();

            this.listOptions = new ListOptions
            {
                PageNumber = 1,
                PageSize   = 20,
            };

            this.baseOptions = new BaseOptions();
            this.baseOptions.AddExtraParam("include_sim_card_group", "true");

            this.requestOptions       = new RequestOptions();
            this.updateSimCardOptions = new UpdateSimCardOptions()
            {
                Id             = "001",
                SimCardGroupId = Guid.NewGuid(),
                Tags           = new List <string>()
                {
                    "personal",
                    "active-customers",
                },
            };

            this.simCardRegisterOptions = new SimCardRegisterOptions
            {
                RegistrationCodes = new string[]
                {
                    "0000000001",
                    "0000000002",
                    "0000000003",
                },
                SimCardGroupId = "6a09cdc3-8948-47f0-aa62-74ac943d6c58",
                Tags           = new string[]
                {
                    "personal",
                    "customers",
                    "active-customers",
                },
            };

            this.simCardBulkNetworkPreferenceUpdateOptions = new SimCardBulkNetworkPreferenceUpdateOptions
            {
                SimCardIds = new string[]
                {
                    "6b14e151-8493-4fa1-8664-1cc4e6d14158",
                    "6b14e151-8493-4fa1-8664-1cc4e6d14158",
                },
                MobileOperatorNetworksPreferences = new List <MobileOperatorNetworksPreferences>()
                {
                    new MobileOperatorNetworksPreferences()
                    {
                        MobileOperatorNetworkId = new Guid("6a09cdc3-8948-47f0-aa62-74ac943d6c58"),
                        Priority = 0,
                    },
                },
            };
        }
Пример #14
0
        public TelephonyCredentialServiceTest(MockHttpClientFixture mockHttpClientFixture)
            : base(mockHttpClientFixture)
        {
            this.service = new TelephonyCredentialService();

            this.listOptions = new ListOptions
            {
                PageNumber = 1,
                PageSize   = 20,
            };

            this.baseOptions = new BaseOptions();

            this.requestOptions = new RequestOptions();
            this.createOptions  = new TelephonyCredentialCreateOptions()
            {
                ConnectionId = "1234567890",
                ExpiresAt    = "2018-02-02T22:25:27.521Z",
                Name         = "admin",
            };

            this.updateOptions = new TelephonyCredentialUpdateOptions()
            {
                ConnectionId = "987654321",
                ExpiresAt    = "2018-02-02T22:25:27.521Z",
                Name         = "My Creds",
            };
        }
Пример #15
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            var rnd = new Random(Environment.TickCount);

            //var options = new BaseOptions(numberOfIterations: 10, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            //var graph = new BasicGraph(BasicEdges, BasicVertexWeights);
            //graph.InitializeGraph();
            //var aspg = new Aspg(options, graph, rnd);
            //var resultBasic = aspg.GetQuality();

            var options    = new BaseOptions(numberOfIterations: 50, numberOfRegions: 2, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var dataLoader = new FileLoader("Graphs/myciel4.col");
            var graph      = new DimacsGraph(dataLoader);

            graph.InitializeGraph();
            var aspg        = new AspgUnweighted(options, graph, rnd);
            var resultBasic = aspg.GetQuality();

            //var parallelOptimisationOptoins =
            //    new OptionsParallelOptimisation(numberOfIterations: 10, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D, numberOfInterSections: 5);
            //var graph = new Graph(AdvancedVertexWeights, AdvancedEdges);
            //graph.InitializeGraph();
            //var aspgParallelOptimisation = new AspgParallelOptimisation(parallelOptimisationOptoins, graph, rnd);
            //var resultParallelOptimisation = aspgParallelOptimisation.GetQuality();

            //var parallelOptimisationWithInheritanceOptoins =
            //    new OptionsParallelOptimisation(numberOfIterations: 10, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D, numberOfInterSections: 5);
            //var graph = new Graph(AdvancedVertexWeights, AdvancedEdges);
            //graph.InitializeGraph();
            //var aspgParallelOptimisationWithInheritance = new AspgParallelOptimisationWithInheritance(parallelOptimisationWithInheritanceOptoins,
            //    graph, rnd);
            //var resultParallelOptimisationWithInheritance = aspgParallelOptimisationWithInheritance.GetQuality();
        }
Пример #16
0
        /// <summary>Creates an <see cref="HttpContent"/> for a given options class.</summary>
        /// <param name="options">The options class.</param>
        /// <returns>The <see cref="HttpContent"/>.</returns>
        public static HttpContent CreateHttpContent(BaseOptions options)
        {
            // If options is null, we create an empty FormUrlEncodedContent because we still
            // want to send the Content-Type header.
            if (options == null)
            {
                return(new FormUrlEncodedContent(new List <KeyValuePair <string, string> >()));
            }

            var flatParams = FlattenParamsValue(options, null);

            // If all parameters have been encoded as strings, then the content can be represented
            // with application/x-www-form-url-encoded encoding. Otherwise, use
            // multipart/form-data encoding.
            if (flatParams.All(kvp => kvp.Value is string))
            {
                var flatParamsString = flatParams
                                       .Select(kvp => new KeyValuePair <string, string>(kvp.Key, kvp.Value as string));
                return(new FormUrlEncodedContent(flatParamsString));
            }
            else
            {
                return(new MultipartFormDataContent(flatParams));
            }
        }
        public void AddFreeVertexToTreil_AddVertex_Success()
        {
            var random          = new Random(1);
            var options         = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var verticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };
            var mockGraph = new Mock <IGraph>();

            mockGraph.SetupGet(prop => prop.NumberOfVertices).Returns(verticesWeights.Count);
            mockGraph.SetupGet(prop => prop.VerticesWeights).Returns(verticesWeights);
            mockGraph.Setup(prop => prop.EdgesWeights).Returns(new int[verticesWeights.Count, verticesWeights.Count]);

            var antSystem = new WeightedAntSystemFragment(random, options, mockGraph.Object);

            antSystem.AddFreeVertexToTreil(0, antSystem.FreeVertices.First());

            Assert.AreEqual(2, antSystem.Treil[0].Count);
            Assert.AreEqual(1, antSystem.Treil[1].Count);
            Assert.AreEqual(1, antSystem.Treil[2].Count);
            Assert.AreEqual(4, antSystem.PassedVertices.Count);
        }
Пример #18
0
        private static int FormatProjectFiles(BaseOptions options)
        {
            var slnFile = new SolutionFile(options.SolutionFile);

            foreach (var project in slnFile.Projects)
            {
                // Load the XML data
                var xmlFile = XDocument.Load(project.FilePath);
                // Find each itemgroup
                if (xmlFile.Root == null)
                {
                    continue;
                }
                foreach (var itemGroup in xmlFile.Root.Descendants("ItemGroup"))
                {
                    var packageReferences = itemGroup.Descendants("PackageReference").OrderBy(e => e.Name.LocalName)
                                            .ToList();
                    // Remove and re-add to order
                    foreach (var reference in packageReferences)
                    {
                        reference.Remove();
                    }
                    foreach (var reference in packageReferences)
                    {
                        itemGroup.Add(reference);
                    }

                    // TODO - Allow for other save formats
                    xmlFile.Save(project.FilePath);
                }
            }

            return(0);
        }
        protected override int RunAction(BaseOptions options)
        {
            var assembly        = Assembly.GetExecutingAssembly();
            var assemblyVersion = assembly.GetName().Version;

            Log.Information("Version = [{0}]", assemblyVersion);
            return(0);
        }
Пример #20
0
 public BasketController(
     IHttpClient httpClient,
     IOptions <BaseOptions> options, IBasketServices basketServices)
 {
     _httpClient     = httpClient;
     _basketServices = basketServices;
     _options        = options.Value;
 }
Пример #21
0
        public override void Initialize(HostInterface CurrentHost, BaseOptions CurrentOptions)
        {
            base.Initialize(CurrentHost, CurrentOptions);

            redAxisVAO   = RegisterBox(Color128.Red);
            greenAxisVAO = RegisterBox(Color128.Green);
            blueAxisVAO  = RegisterBox(Color128.Blue);
        }
Пример #22
0
        static void Main(string[] args)
        {
            var rnd = new Random(Environment.TickCount);

            Func <AnalyzeData, DimacsGraph> graphFunc = data =>
            {
                var dataLoader = new FileLoader(data.GraphFilePath);
                var graph      = new DimacsGraph(dataLoader);
                graph.InitializeGraph();

                return(graph);
            };

            var analyzeData = AnalyzeDataAccess.GetAnalyzeData();

            while (analyzeData != null)
            {
                var startDate  = DateTime.UtcNow;
                var inputGraph = graphFunc(analyzeData);

                //var fileWriter = new FileWriter("graph.json");
                //var exportGraph = new GephiFileExport(fileWriter);

                var graphOptions = new BaseOptions(analyzeData.NumberOfIterations, analyzeData.NumberOfPartitions, analyzeData.Alfa,
                                                   analyzeData.Beta, analyzeData.Ro, analyzeData.Delta);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(graphOptions);

                var aspg        = new AspgUnweighted(graphOptions, inputGraph, rnd);
                var resultBasic = aspg.GetQuality();

                var analyzeResult = new AnalyzeResult
                {
                    AnalyzeID         = analyzeData.ID,
                    BestCost          = resultBasic.BestCost,
                    BestCostIteration = resultBasic.BestCostIteration,
                    Duration          = resultBasic.ElapsedMilliseconds,
                    StartDate         = startDate,
                    EndDate           = DateTime.UtcNow
                };

                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine(analyzeResult);

                AnalyzeDataAccess.SaveAnalyzeResult(analyzeResult);

                analyzeData = AnalyzeDataAccess.GetAnalyzeData();
            }

            //var options = new BaseOptions(numberOfIterations: 10, numberOfRegions: 2, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            //var dataLoader = new FileLoader("C.txt");
            //var graph = new DimacsGraph(dataLoader);
            //graph.InitializeGraph();
            //var aspg = new AspgUnweighted(options, graph, rnd);
            //var resultBasic = aspg.GetQuality();
            //var globlaCost = resultBasic.BestCost;
        }
Пример #23
0
 public RabbitMqBus(IMediator mediator, BaseOptions options, ILogManager logManager, IServiceScopeFactory serviceScopeFactory)
 {
     _mediator            = mediator;
     _handlers            = new Dictionary <string, List <Type> >();
     _eventTypes          = new List <Type>();
     _options             = options;
     _logManager          = logManager;
     _serviceScopeFactory = serviceScopeFactory;
 }
Пример #24
0
        private static HttpContent BuildContent(HttpMethod method, BaseOptions options)
        {
            if (method != HttpMethod.Post && method.ToString() != "PATCH")
            {
                return(null);
            }

            return(FormEncoder.CreateHttpContent(options));
        }
Пример #25
0
 /// <summary>Called when the plugin is loaded.</summary>
 /// <param name="host">The host that loaded the plugin.</param>
 /// <param name="fileSystem"></param>
 /// <param name="Options"></param>
 /// <param name="rendererReference"></param>
 public override void Load(HostInterface host, FileSystem fileSystem, BaseOptions Options, object rendererReference)
 {
     CurrentHost         = host;
     FileSystem          = fileSystem;
     CurrentOptions      = Options;
     Parser.knownRoutes  = new Dictionary <string, RouteProperties>();
     Parser.knownModules = new List <string>();
     RoutePropertiesDatabaseParser.LoadRoutePropertyDatabase(ref Parser.knownRoutes, ref Parser.knownModules);
 }
Пример #26
0
        public void GetQuality_Success()
        {
            var options = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);
            var graph   = new BasicGraph(null, null);
            var rnd     = new Random(Environment.TickCount);
            var aspg    = new Aspg(options, graph, rnd);

            //var quality = aspg.GetQuality();
        }
Пример #27
0
        public static int GetCountDetails(AmqpMessageHandler handler, BaseOptions opts)
        {
            var managementClient = new ManagementClient(opts.ConnectionString);
            var queue            = managementClient.GetQueueRuntimeInfoAsync(opts.Queue).GetAwaiter().GetResult();

            // write to stdout for piping
            Console.Out.WriteLine(JsonConvert.SerializeObject(queue.MessageCountDetails));
            return(EXIT_SUCCESS);
        }
Пример #28
0
        public static string ApplyAllParameters <T>(this Service <T> service, BaseOptions obj, string url, bool isListMethod = false)
            where T : IStripeEntity
        {
            // store the original url from the service call into requestString (e.g. https://api.stripe.com/v1/accounts/account_id)
            // before the stripe attributes get applied. all of the attributes that will get passed to stripe will be applied to this string,
            // don't worry - if the request is a post, the Requestor will take care of moving the attributes to the post body
            var requestString = url;

            // obj = the options object passed from the service
            if (obj != null)
            {
                RequestStringBuilder.CreateQuery(ref requestString, obj);

                foreach (KeyValuePair <string, string> pair in obj.ExtraParams)
                {
                    var key = WebUtility.UrlEncode(pair.Key);
                    RequestStringBuilder.ApplyParameterToRequestString(ref requestString, key, pair.Value);
                }

                foreach (var value in obj.Expand)
                {
                    RequestStringBuilder.ApplyParameterToRequestString(ref requestString, "expand[]", value);
                }
            }

            if (service != null)
            {
                // expandable properties
                var propertiesToExpand = service.GetType()
                                         .GetRuntimeProperties()
                                         .Where(p => p.Name.StartsWith("Expand") && p.PropertyType == typeof(bool))
                                         .Where(p => (bool)p.GetValue(service, null))
                                         .Select(p => p.Name);

                foreach (var propertyName in propertiesToExpand)
                {
                    string expandPropertyName = propertyName.Substring("Expand".Length);
                    expandPropertyName = Regex.Replace(expandPropertyName, "([a-z])([A-Z])", "$1_$2").ToLower();

                    if (isListMethod)
                    {
                        expandPropertyName = "data." + expandPropertyName;
                    }

                    requestString = ApplyParameterToUrl(requestString, "expand[]", expandPropertyName);

                    // note: I had no idea you could expand properties beyond the first level (up to 4 before stripe throws an exception).
                    // something to consider adding to the project.
                    //
                    // example:
                    // requestString = ApplyParameterToUrl(requestString, "expand[]", "data.charge.dispute.charge.dispute.charge.dispute");
                }
            }

            return(requestString);
        }
Пример #29
0
        public static string CreateQueryString(BaseOptions options)
        {
            var flatParams = FlattenParamsValue(options, null)
                             .Where(kvp => kvp.Value is string)
                             .Select(kvp => new KeyValuePair <string, string>(
                                         kvp.Key,
                                         kvp.Value as string));

            return(CreateQueryString(flatParams));
        }
Пример #30
0
 /// <summary>Called when the plugin is loaded.</summary>
 /// <param name="host">The host that loaded the plugin.</param>
 /// <param name="fileSystem"></param>
 /// <param name="Options"></param>
 /// <param name="trainManagerReference"></param>
 public override void Load(HostInterface host, FileSystem fileSystem, BaseOptions Options, object trainManagerReference)
 {
     CurrentHost    = host;
     FileSystem     = fileSystem;
     CurrentOptions = Options;
     if (trainManagerReference is TrainManagerBase)
     {
         TrainManager = (TrainManagerBase)trainManagerReference;
     }
 }