Ejemplo n.º 1
0
        public void CreateNewSpecialOrders(Supplier supplier, uint formaterId, string specialName, HandlerTypes handlerType)
        {
            var orderHandler = DbSession.Query <OrderHandler>().FirstOrDefault(t => t.Id == formaterId);

            if (DbSession.Query <SpecialHandler>().FirstOrDefault(t => t.Supplier.Id == supplier.Id && t.Handler.Id == formaterId) == null &&
                !OrderHandler.DefaultHandlerByType[handlerType].Contains(orderHandler.ClassName))
            {
                var handler = new SpecialHandler {
                    Supplier = supplier,
                    Handler  = DbSession.Query <OrderHandler>().FirstOrDefault(t => t.Id == formaterId)
                };
                // задаем имя по умолчанию
                var handlerName = specialName;
                // проверяем свободно ли имя и если нет, то ищем свободное
                if (DbSession.Query <SpecialHandler>().Count(t => t.Supplier.Id == supplier.Id && t.Name.ToLower() == handlerName) != 0)
                {
                    handlerName += DateTime.Now.ToString("yyMMdd");
                }
                int    i       = 1;
                string postfix = "";
                while (DbSession.Query <SpecialHandler>().Count(t => t.Supplier.Id == supplier.Id && t.Name.ToLower() == handlerName + postfix) != 0)
                {
                    postfix = "_" + i;
                    i++;
                }
                handler.Name = handlerName + postfix;
                DbSession.Save(handler);
                DbSession.Flush();
            }
        }
Ejemplo n.º 2
0
        public void Should_Provide_Many_Callbacks_By_Key()
        {
            var handler = new SpecialHandler();
            var bees    = handler.ResolveAll <Bee>();

            Assert.AreEqual(3, bees.Length);
        }
Ejemplo n.º 3
0
        public void Should_Provide_Callbacks_By_Key()
        {
            var handler = new SpecialHandler();
            var boo     = handler.Resolve <Boo>();

            Assert.IsNotNull(boo);
            Assert.IsTrue(boo.HasComposer);
        }
Ejemplo n.º 4
0
        public void Should_Handle_Callbacks_With_Keys()
        {
            var foo     = new Foo();
            var handler = new SpecialHandler();

            Assert.IsTrue(handler.Handle(foo, true));
            Assert.AreEqual(1, foo.Handled);
        }
        public void New(uint supplierId)
        {
            var supplier = DbSession.Load <Supplier>(supplierId);
            var handler  = new SpecialHandler(supplier);

            PropertyBag["handler"]  = handler;
            PropertyBag["supplier"] = supplier;
            ValidateAndSaveIfNeeded(handler);
        }
Ejemplo n.º 6
0
        public void Should_Resolve_All()
        {
            var custom  = new CustomHandler();
            var special = new SpecialHandler();
            var handler = custom + special;
            var objects = handler.ResolveAll <object>();

            CollectionAssert.Contains(objects, custom);
            CollectionAssert.Contains(objects, special);
            Assert.AreEqual(11, objects.Length);
        }
 private void ValidateAndSaveIfNeeded(SpecialHandler handler)
 {
     if (IsPost)
     {
         BindObjectInstance(handler, "handler");
         if (IsValid(handler))
         {
             DbSession.Save(handler);
             Notify("Сохранено");
             RedirectToAction("Index", new { supplierId = handler.Supplier.Id });
         }
     }
 }
Ejemplo n.º 8
0
        public void Should_Provide_Callbacks_With_Many_Keys()
        {
            var handler = new SpecialHandler();
            var baz1    = handler.Resolve <Baz <int> >();

            Assert.AreEqual(1, baz1.Stuff);
            var baz2 = handler.Resolve <Baz <string> >();

            Assert.AreEqual("Hello", baz2.Stuff);
            var baz3 = handler.Resolve <Baz <float> >();

            Assert.IsNull(baz3);
        }
Ejemplo n.º 9
0
        public void Should_Provide_Many_Callbacks_Explicitly()
        {
            var handler = new SpecialHandler();
            var baz     = handler.Resolve <Baz>();

            Assert.IsInstanceOfType(baz, typeof(SuperBaz));
            Assert.IsFalse(baz.HasComposer);
            var bazs = handler.ResolveAll <Baz>();

            Assert.AreEqual(2, bazs.Length);
            Assert.IsInstanceOfType(bazs[0], typeof(SuperBaz));
            Assert.IsFalse(bazs[0].HasComposer);
            Assert.IsInstanceOfType(bazs[1], typeof(Baz));
            Assert.IsFalse(bazs[1].HasComposer);
        }
Ejemplo n.º 10
0
        public void Should_Provide_Many_Callbacks_Implicitly()
        {
            var handler = new SpecialHandler();
            var bar     = handler.Resolve <Bar>();

            Assert.IsNotNull(bar);
            Assert.IsFalse(bar.HasComposer);
            Assert.AreEqual(1, bar.Handled);
            var bars = handler.ResolveAll <Bar>();

            Assert.AreEqual(2, bars.Length);
            Assert.AreEqual(1, bars[0].Handled);
            Assert.IsFalse(bars[0].HasComposer);
            Assert.AreEqual(2, bars[1].Handled);
            Assert.IsFalse(bars[1].HasComposer);
        }
Ejemplo n.º 11
0
        public SimpleApiPage(Color elementColor, string title, string handle)
        {
            if (WebApiHandleStore.Handles.Any(h => h.HandleId.Equals(handle)))
            {
                ILogManager.Log($"API Handler with the same name [{handle}] already exists. The page will not be registered.", this.ToString(), LogType.Error);
                return;
            }

            if (HttpHandleStore.Handles.Any(h => h.Value.Path.Equals(handle)))
            {
                ILogManager.Log($"Http handle with the same name [{handle}] already exists. The page will not be registered.", this.ToString(), LogType.Error);
                return;
            }


            this.Title        = title;
            this.Handle       = handle;
            this.ElementColor = elementColor;
            this.Handler      = new ApiHandleHolder(handle);
            WebApiHandleStore.Add(this.Handler);
            // compile page
            this.Html = SimpleApiPageSplicerConstant.Page.Replace(SimpleApiPageSplicerConstant.ReplaceInTitle, title);
            this.Html = this.Html.Replace(SimpleApiPageSplicerConstant.ReplaceInColor, GetColor());
            this.Html = this.Html.Replace(SimpleApiPageSplicerConstant.ReplaceInPort, IConfigurationStore.GetByType <RequiemConfig>().ApiPort.ToString());
            this.Html = this.Html.Replace(SimpleApiPageSplicerConstant.ReplaceInHandle, handle);
            using (var ms = new MemoryStream())
            {
                using var headers = new HttpResponseHeaders(this.Html.Length, ResponseStatusCode.Ok200, new IResponseField[] {
                    new FieldAcceptRanges(HttpConstant.AcceptRanges),
                    new FieldServer(HttpConstant.ServerName),
                    new FieldContentType("text/html")
                }, "HTTP/1.1");
                var h = headers.Compile();
                ms.Write(h.Item1, 0, h.Item2);
                ms.Write(Encoding.UTF8.GetBytes(this.Html));
                this.HtmlBytes = ms.ToArray();
            }
            var webHandle = new SpecialHandler(handle, async(client) =>
            {
                await client.SafeWriteAsync(this.HtmlBytes);
            });

            HttpHandleStore.AddHandler(webHandle);
        }
Ejemplo n.º 12
0
        public ApiGraphPage(string handle, string title, ApiGraph[] graphs, byte width)
        {
            this.ApiHandle = handle;
            this.Title     = title;
            this.Graphs    = graphs;

            var graphCodeStr             = new List <string>();
            var graphCodeHandles         = new List <string>();
            var declareVariablesInScript = new List <string>();

            foreach (var graph in graphs)
            {
                graphCodeStr.Add(graph.Code);
                graphCodeHandles.Add(graph.GraphCtx);
                declareVariablesInScript.Add(graph.Variable);
            }

            var script = GraphPageSplicer.SpliceMainScript(
                IConfigurationStore.GetByType <RequiemConfig>().ApiPort,
                handle,
                declareVariablesInScript.ToArray(),
                graphCodeStr.ToArray(),
                graphCodeHandles.ToArray());

            this.Code    = GraphPageSplicer.SpliceFinalHtml(script, title, graphCodeHandles.ToArray(), width);
            using var ms = new MemoryStream();

            using var headers = new HttpResponseHeaders(Code.Length, ResponseStatusCode.Ok200, new IResponseField[]
            {
                new FieldAcceptRanges("bytes"),
                new FieldContentType("text/html"),
                new FieldServer(HttpConstant.ServerName)
            }, "HTTP/1.1");
            this.Header = headers.Compile();
            ms.Write(Header.Item1, 0, Header.Item2);
            ms.Write(Encoding.UTF8.GetBytes(this.Code));
            this.Stream = ms.ToArray();
            var httpHandle = new SpecialHandler(handle, async(ctx) => await ctx.SafeWriteAsync(Stream));

            HttpHandleStore.AddHandler(httpHandle);
            this.Api = new ApiHandleHolder(handle);
            WebApiHandleStore.Add(this.Api);
        }
 public SimplePageHandler(string name, TableSite site)
 {
     this.Site   = site;
     this.Handle = new SpecialHandler(name, async(holder) =>
     {
         var document      = Encoding.UTF8.GetBytes(Site.GetLatest());
         using var headers = new HttpResponseHeaders(document.Length, ResponseStatusCode.Ok200, new IResponseField[]
         {
             new FieldServer(HttpConstant.ServerName),
             new FieldAcceptRanges(HttpConstant.AcceptRanges),
             new FieldContentType("text/html")
         }, "HTTP/1.1");
         var h = headers.Compile();
         if (!await holder.SafeWriteAsync(h.Item1, h.Item2))
         {
             return;
         }
         await holder.SafeWriteAsync(document);
     });
     HttpHandleStore.AddHandler(this.Handle);
 }
Ejemplo n.º 14
0
        public ApiConsolePage(Color boxColor, string title, string handle, string placeholder)
        {
            this.Handle      = handle;
            this.Title       = title;
            this.Placeholder = placeholder;
            this.BoxColor    = boxColor;

            this.Html = ApiConsolePageSplicer.Html.Replace(ApiConsolePageSplicer.ReplaceInTitle, title);
            this.Html = this.Html.Replace(ApiConsolePageSplicer.ReplaceInColor, GetColor());
            this.Html = this.Html.Replace(ApiConsolePageSplicer.ReplaceInPort, IConfigurationStore.GetByType <RequiemConfig>().ApiPort.ToString());
            this.Html = this.Html.Replace(ApiConsolePageSplicer.ReplaceInHandle, handle);
            this.Html = this.Html.Replace(ApiConsolePageSplicer.ReplaceInMainPlaceholder, placeholder);

            this.Handler = new ApiHandleHolder(handle);
            WebApiHandleStore.Add(this.Handler);

            using (var ms = new MemoryStream())
            {
                using var headers = new HttpResponseHeaders(this.Html.Length, ResponseStatusCode.Ok200, new IResponseField[]
                {
                    new FieldAcceptRanges(HttpConstant.AcceptRanges),
                    new FieldServer(HttpConstant.ServerName),
                    new FieldContentType("text/html")
                }, "HTTP/1.1");
                var h = headers.Compile();
                ms.Write(h.Item1, 0, h.Item2);
                ms.Write(Encoding.UTF8.GetBytes(this.Html));
                this.HtmlBytes = ms.ToArray();
            }
            var webHandle = new SpecialHandler(handle, async(client) =>
            {
                await client.SafeWriteAsync(this.HtmlBytes);
            });

            HttpHandleStore.AddHandler(webHandle);
        }