コード例 #1
0
        private void OpenQuery()
        {
            string          json  = string.Empty;
            QueryExpression query = null;

            try
            {
                HermesService Hermes  = new HermesService();
                Request       request = Hermes.GetTestRequest();
                json = request.ParseTree;

                SerializationService serializer = new SerializationService();
                query = serializer.FromJson(json);
            }
            catch (Exception ex)
            {
                Z.Notify(new Notification()
                {
                    Title = CONST_ModuleDialogsTitle, Content = Z.GetErrorText(ex)
                });
                return;
            }

            try
            {
                string path = GetQueryFilePath();
                using (StreamWriter writer = new StreamWriter(path, false))
                {
                    writer.Write(json);
                }
                //using (StreamReader reader = new StreamReader(path))
                //{
                //    json = reader.ReadToEnd();
                //}
                ProcessStartInfo psi = new ProcessStartInfo(@"notepad.exe")
                {
                    Arguments       = $"\"{path}\"",
                    UseShellExecute = false,
                    CreateNoWindow  = true
                };
                Process.Start(psi);
            }
            catch (Exception ex)
            {
                Z.Notify(new Notification()
                {
                    Title = CONST_ModuleDialogsTitle, Content = Z.GetErrorText(ex)
                });
            }

            //Z.ClearRightRegion(this.regionManager);
            //IRegion rightRegion = this.regionManager.Regions[RegionNames.RightRegion];
            //if (rightRegion == null) return;
            //queryVM = new QueryExpressionViewModel(null, query);
            //QueryExpressionView queryView = new QueryExpressionView(queryVM);
            //rightRegion.Add(queryView);
        }
コード例 #2
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Method == "GET" || context.Request.Method == "POST")
            {
                //if (routes.Count == 0)
                //{
                routes = Metadata.GetRequests();
                //}

                Request request = null;
                string  json    = string.Empty;

                _logger.LogInformation("Request path: {0}", context.Request.Path);

                if (routes.TryGetValue(context.Request.Path, out request))
                {
                    json = request.ParseTree;
                    QueryExpression query = Serializer.FromJson(json);

                    JObject parameters = this.ReadParameters(context);
                    if (parameters != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        this.SetParameters(parameters, query);
                    }

                    QueryExecutor executor = new QueryExecutor(query);
                    try
                    {
                        var result = executor.Build().ExecuteAsRowData();
                        json = JsonConvert.SerializeObject(result);
                    }
                    catch (Exception ex)
                    {
                        json = Program.GetErrorText(ex);
                    }
                }
                else
                {
                    _logger.LogInformation("Requested path not found.");
                    _logger.LogInformation("Available paths are:");
                    foreach (string route in routes.Keys)
                    {
                        _logger.LogInformation(route);
                    }
                }

                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(json);
            }
            else
            {
                await _next(context);
            }
        }
コード例 #3
0
ファイル: MacroTests.cs プロジェクト: jraghu24/Rraghu
        public void Can_Create_And_Serialize_Then_Deserialize_Macro()
        {
            // Arrange
            var serviceStackSerializer = new ServiceStackJsonSerializer();
            var serializationService   = new SerializationService(serviceStackSerializer);

            var macro = new Macro
            {
                Alias         = "test",
                CacheByPage   = false,
                CacheByMember = false,
                DontRender    = true,
                Name          = "Test",
                Xslt          = "/xslt/testMacro.xslt",
                UseInEditor   = false
            };

            macro.Properties = new List <IMacroProperty>();
            macro.Properties.Add(new MacroProperty {
                Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number()
            });
            macro.Properties.Add(new MacroProperty {
                Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text()
            });

            // Act
            var    json       = serializationService.ToStream(macro);
            string jsonString = json.ResultStream.ToJsonString();

            var deserialized = serializationService.FromJson <Macro>(jsonString);

            var    stream        = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
            object o             = serializationService.FromStream(stream, typeof(Macro));
            var    deserialized2 = o as IMacro;

            // Assert
            Assert.That(json.Success, Is.True);
            Assert.That(jsonString, Is.Not.Empty);
            Assert.That(deserialized, Is.Not.Null);
            Assert.That(deserialized2, Is.Not.Null);
            Assert.That(deserialized.Name, Is.EqualTo(macro.Name));
            Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias));
            Assert.That(deserialized2.Name, Is.EqualTo(macro.Name));
            Assert.That(deserialized2.Alias, Is.EqualTo(macro.Alias));
        }
コード例 #4
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Method == "GET" || context.Request.Method == "POST")
            {
                //if (routes.Count == 0)
                //{
                routes = Metadata.GetRequests();
                //}

                Request request = null;
                string  json    = string.Empty;

                if (routes.TryGetValue(context.Request.Path, out request))
                {
                    json = request.ParseTree;
                    QueryExpression query = Serializer.FromJson(json);

                    JObject parameters = this.ReadParameters(context);
                    if (parameters != null && query.Parameters != null && query.Parameters.Count > 0)
                    {
                        this.SetParameters(parameters, query);
                    }

                    QueryExecutor executor = new QueryExecutor(query);
                    try
                    {
                        var result = executor.Build().ExecuteAsRowData();
                        json = JsonConvert.SerializeObject(result);
                    }
                    catch (Exception ex)
                    {
                        json = Program.GetErrorText(ex);
                    }
                }
                //context.Response.StatusCode = 500;

                context.Response.StatusCode  = 200;
                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(json);
            }
            //context.Response.StatusCode = 200;
            await _next(context);
        }