public void Configure(IResourceBuilder resourceBuilder)
        {
            resourceBuilder.Run("message-stream", "{?types,contextId}", ResourceType.Client, async (context, parameters) =>
            {
                var continueTask = new TaskCompletionSource<bool>();

                // Disable request compression
                var buffering = context.Features.Get<IHttpBufferingFeature>();
                if (buffering != null)
                {
                    buffering.DisableRequestBuffering();
                }

                var types = parameters.ParseEnumerable("types").ToArray();
                var contextId = parameters.ParseGuid("contextId");
                var filter = GetStreamFilter(types, contextId);

                var sse = await context.RespondWith(new ServerSentEventResponse());
                await sse.SetRetry(TimeSpan.FromSeconds(5));

                var unSubscribe = (IDisposable)null;
                unSubscribe = _senderSubject.Where(c =>  c.Event == "ping" || filter(c)).Subscribe(async t =>
                {
                    await _syncLock.WaitAsync();

                    try
                    {
                        try
                        {
                            await sse.SendData(data: $"[{t.Data}]", @event: t.Event);
                        }
                        catch (Exception)
                        {
                            continueTask.TrySetResult(true);
                            unSubscribe?.Dispose();  // TODO: Need to review this
                        }
                    }
                    finally 
                    {
                        _syncLock.Release();
                    }
                });

                context.RequestAborted.Register(() =>
                {
                    continueTask.SetResult(true);
                    unSubscribe.Dispose();
                });

                await continueTask.Task;
            });
        }
Beispiel #2
0
		/// <summary>
		///    Initializes a new instance of the <see cref="Stargate" /> class.
		/// </summary>
		/// <param name="options">The options.</param>
		/// <param name="resourceBuilder">The resource builder.</param>
		/// <param name="restSharp">The RestSharp factory.</param>
		/// <param name="converterFactory">The converter factory.</param>
		/// <param name="errorProvider">The error provider.</param>
		/// <param name="scannerConverter">The scanner converter.</param>
		public Stargate(IStargateOptions options, IResourceBuilder resourceBuilder, IRestSharpFactory restSharp, IMimeConverterFactory converterFactory,
			IErrorProvider errorProvider, IScannerOptionsConverter scannerConverter)
		{
			_resourceBuilder = resourceBuilder;
			_restSharp = restSharp;
			_errorProvider = errorProvider;
			_scannerConverter = scannerConverter;
			_client = _restSharp.CreateClient(options.ServerUrl);
			options.ContentType = string.IsNullOrEmpty(options.ContentType) ? DefaultContentType : options.ContentType;
			_converter = converterFactory.CreateConverter(options.ContentType);
			options.FalseRowKey = string.IsNullOrEmpty(options.FalseRowKey) ? DefaultFalseRowKey : options.FalseRowKey;
			Options = options;
		}
        public void Configure(IResourceBuilder resourceBuilder)
        {
            var appBuilder = resourceBuilder.AppBuilder;

            appBuilder.ModifyResponseWith(response => response.EnableCaching());

            appBuilder.ModifyResponseWith(res => res.EnableCors());

            appBuilder.UseFileServer(new FileServerOptions
            {
                RequestPath = "",
                EnableDefaultFiles = true,
                FileProvider =
                    new EmbeddedFileProvider(typeof (EmbeddedFileResource).GetTypeInfo().Assembly, BaseNamespace)
            });

            foreach (var registration in Register)
            {
                resourceBuilder.RegisterResource(registration.Key, registration.Value);
            }
        }
        public void Configure(IResourceBuilder resourceBuilder)
        {
            resourceBuilder.Run("context", "?contextId={contextId}{&types}", ResourceType.Client, async (context, parameters) =>
            {
                var contextId = parameters.ParseGuid("contextId");

                if (!contextId.HasValue)
                {
                    await context.RespondWith(new MissingParameterProblem("contextId")
                        .EnableCaching()
                        .EnableCors());
                    return;
                }

                var types = parameters.ParseEnumerable("types").ToArray();

                var list = await _storage.RetrieveByContextId(contextId.Value, types);

                await context.RespondWith(
                    new RawJson(list.ToJsonArray())
                    .EnableCaching()
                    .EnableCors());
            });
        }
 public CartonTypeResponseProcessor(IResourceBuilder <CartonType> resourceBuilder)
     : base(resourceBuilder, "carton-type", 1)
 {
 }
 public BuildPlanResponseProcessor(IResourceBuilder <ResponseModel <BuildPlan> > resourceBuilder)
     : base(resourceBuilder, "build-plan", 1)
 {
 }
Beispiel #7
0
 public RootProductResponseProcessor(IResourceBuilder <ResponseModel <RootProduct> > resourceBuilder)
     : base(resourceBuilder, "root-product", 1)
 {
 }
Beispiel #8
0
        private void Build(IModelContext context, ICodeWriter w, IResourceBuilder resBuilder)
        {
            w.Write("//------------------------------------------------------------------------------");
            w.Write("// <auto-generated>");
            w.Write("//     This code was generated by a tool.");
            w.Write("//");
            w.Write("//     Changes to this file may cause incorrect behavior and will be lost if");
            w.Write("//     the code is regenerated.");
            w.Write("// </auto-generated>");
            w.Write("//------------------------------------------------------------------------------");
            w.Write();
            var resourcesName          = Path.GetFileNameWithoutExtension(Path.GetFileName(ResFile));
            Func <string, string>  res = s => string.Format("{0}.{1}", resourcesName, resBuilder.Add(s));
            Func <double?, string> num = d => d.HasValue ? d.Value.ToString(CultureInfo.InvariantCulture) : "null";

            using (w.Block("namespace {0}", NameSpace))
            {
                var ioDevices = context.Get <io_devices>().OrderBy(d => d.name).ToArray();

                #region IoDevices

                foreach (var ioDevice in ioDevices)
                {
                    using (w.Block("public sealed partial class {0} : PHmiClient.Tags.IoDeviceBase", ioDevice.name))
                    {
                        var digitalTags = ioDevice.dig_tags.OrderBy(t => t.name).ToArray();
                        var numericTags = ioDevice.num_tags.OrderBy(t => t.name).ToArray();
                        using (w.Block("public {0}() : base({1}, \"{0}\")", ioDevice.name, ioDevice.id))
                        {
                            foreach (var t in digitalTags)
                            {
                                w.Write("{0} = AddDigitalTag({1}, \"{0}\", () => {2});",
                                        t.name, t.id, res(t.description));
                            }
                            foreach (var t in numericTags)
                            {
                                w.Write("{0} = AddNumericTag({1}, \"{0}\", () => {2}, () => {3}, () => {4}, {5}, {6});",
                                        t.name, t.id, res(t.description), res(t.format),
                                        res(t.eng_unit), num(t.eng_min), num(t.eng_max));
                            }
                        }
                        foreach (var t in digitalTags)
                        {
                            w.Write();
                            w.Write("public PHmiClient.Tags.IDigitalTag {0} {{ get; private set; }}", t.name);
                        }
                        foreach (var t in numericTags)
                        {
                            w.Write();
                            w.Write("public PHmiClient.Tags.INumericTag {0} {{ get; private set; }}", t.name);
                        }
                    }
                    w.Write();
                }

                #endregion

                var alarmCategories = context.Get <alarm_categories>().OrderBy(c => c.name).ToArray();

                #region AlarmCategories

                foreach (var category in alarmCategories)
                {
                    using (w.Block("public sealed partial class {0} : PHmiClient.Alarms.AlarmCategoryBase", category.name))
                    {
                        using (w.Block("public {0}() : base({1}, \"{0}\", () => {2})", category.name, category.id, res(category.description)))
                        {
                            foreach (var alarmTag in category.alarm_tags.ToArray())
                            {
                                w.Write("AddAlarmInfo({0}, () => {1}, () => {2});", alarmTag.id, res(alarmTag.location), res(alarmTag.description));
                            }
                        }
                    }
                    w.Write();
                }

                #endregion

                var trendsCategories = context.Get <trend_categories>().OrderBy(c => c.name).ToArray();

                #region TrendsCategories

                foreach (var category in trendsCategories)
                {
                    using (w.Block("public sealed partial class {0} : PHmiClient.Trends.TrendsCategoryBase", category.name))
                    {
                        var trendTags = category.trend_tags.OrderBy(t => t.name).ToArray();
                        using (w.Block("public {0}() : base({1}, \"{0}\", {2})", category.name, category.id, category.period))
                        {
                            foreach (var t in trendTags)
                            {
                                w.Write("{0} = AddTrendTag({1}, \"{0}\", () => {2}, () => {3}, () => {4}, {5}, {6});",
                                        t.name, t.id, res(t.description), res(t.num_tags.format),
                                        res(t.num_tags.eng_unit), num(t.num_tags.eng_min), num(t.num_tags.eng_max));
                            }
                        }

                        foreach (var t in trendTags)
                        {
                            w.Write();
                            w.Write("public PHmiClient.Trends.ITrendTag {0} {{ get; private set; }}", t.name);
                        }
                    }
                    w.Write();
                }

                #endregion

                var logs = context.Get <logs>().OrderBy(l => l.name).ToArray();

                var settings = context.Get <settings>().Single();
                using (w.Block("public sealed partial class PHmi : PHmiClient.PHmiSystem.PHmiBase"))
                {
                    using (w.Block("public PHmi() : this(\"{0}\")", settings.server))
                    {
                    }
                    w.Write();
                    using (w.Block("public PHmi(string server) : this(server, \"{0}\")", settings.guid))
                    {
                    }
                    w.Write();
                    using (w.Block("public PHmi(string server, string guid) : base(server, guid)"))
                    {
                        foreach (var ioDevice in ioDevices)
                        {
                            w.Write("{0} = AddIoDevice(new {0}());", ioDevice.name);
                        }
                        foreach (var category in alarmCategories)
                        {
                            w.Write("{0} = AddAlarmCategory(new {0}());", category.name);
                        }
                        foreach (var category in trendsCategories)
                        {
                            w.Write("{0} = AddTrendsCategory(new {0}());", category.name);
                        }
                        foreach (var log in logs)
                        {
                            w.Write("{0} = AddLog({1}, \"{0}\");", log.name, log.id);
                        }
                    }
                    foreach (var ioDevice in ioDevices)
                    {
                        w.Write();
                        w.Write("public {0} {0} {{ get; private set; }}", ioDevice.name);
                    }
                    foreach (var category in alarmCategories)
                    {
                        w.Write();
                        w.Write("public {0} {0} {{ get; private set; }}", category.name);
                    }
                    foreach (var category in trendsCategories)
                    {
                        w.Write();
                        w.Write("public {0} {0} {{ get; private set; }}", category.name);
                    }
                    foreach (var log in logs)
                    {
                        w.Write();
                        w.Write("public PHmiClient.Logs.LogAbstract {0} {{ get; private set; }}", log.name);
                    }
                }
            }
        }
 public PartFailsResponseProcessor(IResourceBuilder <IEnumerable <PartFail> > resourceBuilder)
     : base(resourceBuilder, "part-fails", 1)
 {
 }
Beispiel #10
0
 public TqmsCategoriesResponseProcessor(
     IResourceBuilder <IEnumerable <TqmsCategory> > resourceBuilder)
     : base(resourceBuilder, "tqms-categories", 1)
 {
 }
Beispiel #11
0
 public ProductionTriggerLevelStateResponseProcessor(IResourceBuilder <ResponseModel <ProductionTriggerLevel> > resourceBuilder)
     : base(resourceBuilder, new List <MediaRange> {
     new MediaRange("application/vnd.linn.application-state+json;version=1")
 })
 {
 }
Beispiel #12
0
 public PcasRevisionsResponseProcessor(IResourceBuilder <IEnumerable <PcasRevision> > resourceBuilder)
     : base(resourceBuilder, "pcas-revisions", 1)
 {
 }
Beispiel #13
0
 public EmployeesResponseProcessor(IResourceBuilder <IEnumerable <Employee> > resourceBuilder)
     : base(resourceBuilder, "employees", 1)
 {
 }
Beispiel #14
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     ResourceWriter  = new Mock <IResourceWriter>();
     ResourceBuilder = new ResourceBuilder(ResourceWriter.Object);
 }
Beispiel #15
0
 public AddressResponseProcessor(IResourceBuilder <Address> resourceBuilder)
     : base(resourceBuilder, "addresses", 1)
 {
 }
 public TransferableStockListResponseProcessor(IResourceBuilder <IEnumerable <TransferableStock> > resourceBuilder)
     : base(resourceBuilder, "transferable-stock", 1)
 {
 }
 public static IResourceBuilder Property(this IResourceBuilder source, string name, string displayName)
 {
     return(source.Property(name, displayName, null, null));
 }
 public PartFailSuppliersResponseProcessor(IResourceBuilder <IEnumerable <PartFailSupplierView> > resourceBuilder)
     : base(resourceBuilder, "part-fail-suppliers", 1)
 {
 }
 public PartTemplatesResponseProcessor(IResourceBuilder <IEnumerable <PartTemplate> > resourceBuilder)
     : base(resourceBuilder, "linnapps-part-templates", 1)
 {
 }
 public BoardFailTypeResponseProcessor(IResourceBuilder <BoardFailType> resourceBuilder)
     : base(resourceBuilder, "board-fail-type", 1)
 {
 }
 public ImportBookCpcNumbersResponseProcessor(
     IResourceBuilder <IEnumerable <ImportBookCpcNumber> > resourceBuilder)
     : base(resourceBuilder, "linnapps-import-books-cpc-numbers", 1)
 {
 }
 public TurnoverBandProposalJsonResponseProcessor(IResourceBuilder <TurnoverBandProposal> resourceBuilder)
     : base(resourceBuilder, "sales.accounts-turnover-band-proposal", 1)
 {
 }
 public ProductRangesResponseProcessor(IResourceBuilder <IEnumerable <ProductRange> > resourceBuilder)
     : base(resourceBuilder, "product-ranges", 1)
 {
 }
 public RetailerDemListJsonResponseProcessor(IResourceBuilder <RetailerDemList> resourceBuilder)
     : base(resourceBuilder, "retailer-dem-list", 1)
 {
 }
 public LabelTypesResponseProcessor(IResourceBuilder <IEnumerable <LabelType> > resourceBuilder)
     : base(resourceBuilder, "label-types", 1)
 {
 }
 public RootProductJsonResponseProcessor(IResourceBuilder <RootProduct> resourceBuilder)
     : base(resourceBuilder, "retailer-dem-list-product", 1)
 {
 }
 public UndoAmendmentDetailsJsonResultProcessor(IEnumerable <ISerializer> serializers, IResourceBuilder <UndoAmendmentDetails> builder)
     : base(serializers, builder)
 {
 }
 public ManufacturingRouteResponseProcessor(IResourceBuilder <ResponseModel <ManufacturingRoute> > resourceBuilder)
     : base(resourceBuilder, "manufacturing-route", 1)
 {
 }
 public SalesOutletsResponseProcessor(IResourceBuilder <IEnumerable <SalesOutlet> > resourceBuilder)
     : base(resourceBuilder, "sales-outlets", 1)
 {
 }
Beispiel #30
0
 public IdAndNameResponseProcessor(IResourceBuilder <IdAndName> resourceBuilder)
     : base(resourceBuilder, "id-and-name", 1)
 {
 }
 public SalesOutletResponseProcessor(IResourceBuilder <SalesOutlet> resourceBuilder)
     : base(resourceBuilder, "sales-outlet", 1)
 {
 }
Beispiel #32
0
 public PartsResponseProcessor(IResourceBuilder <IEnumerable <Part> > resourceBuilder)
     : base(resourceBuilder, "linnapps-parts", 1)
 {
 }
 public BuildPlansResponseProcessor(IResourceBuilder <ResponseModel <IEnumerable <BuildPlan> > > resourceBuilder)
     : base(resourceBuilder, "build-plans", 1)
 {
 }
Beispiel #34
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     ResourceWriter = new Mock<IResourceWriter>();
     ResourceBuilder = new ResourceBuilder(ResourceWriter.Object);
 }
Beispiel #35
0
 public ComponentCountResponseProcessor(IResourceBuilder <ComponentCount> resourceBuilder)
     : base(resourceBuilder, "component-count", 1)
 {
 }