private async void OnLoadCommand(object parameter) //This method is going to be changed
        {
            if (!Banners.LoadingBannerVisible)
            {
                ManagedBookmarks ParsedBookmarks = new ManagedBookmarks();
                Banners.ShowLoadingBanner("Loading JSON, please wait...");
                SerializeCommand.RaiseCanExecuteChanged();
                Info.LoadText   = "Loading JSON...";
                ParsedBookmarks = await ChromeJSONConverter.ParseJSON(Json.Code);

                Info.LoadText             = "Load";
                Banners.LoadingBannerText = "JSON Loaded";
                LoadTimer.Start();



                if (ParsedBookmarks.RootFolder.Name != "")
                {
                    ChromeBookmarks.RootFolder           = ParsedBookmarks.RootFolder;
                    ChromeBookmarks.CurrentWorkingFolder = ParsedBookmarks.RootFolder;
                    ChromeBookmarks.CurrentWorkingFolderContextMenuText = $"Rename '{ParsedBookmarks.RootFolder.Name}'";
                    ChromeBookmarks.CurrentWorkingFolderPath            = ParsedBookmarks.RootFolder.Name;
                }
            }
            else
            {
                Info.LoadText = "Please Wait...";
            }
        }
示例#2
0
        public static HttpRequestMessage CreatePutCommandRequest(
            object command,
            Guid commandId,
            string basePath,
            ResolveMediaType resolveMediaType,
            SerializeCommand serializeCommand = null)
        {
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(resolveMediaType).IsNotNull();

            serializeCommand = serializeCommand ?? DefaultSerializeCommand;
            using (var writer = new StringWriter())
            {
                serializeCommand(writer, command);

                var httpContent = new StringContent(writer.ToString());
                var mediaType   = resolveMediaType(command.GetType(), "json");
                httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(mediaType);

                var request = new HttpRequestMessage(HttpMethod.Put, basePath + "/{0}".FormatWith(commandId))
                {
                    Content = httpContent
                };
                request.Headers.UserAgent.Add(UserAgent);
                request.Headers.Accept.Add(HttpProblemDetails.MediaTypeWithQualityHeaderValue);

                return(request);
            }
        }
        public PhonebookCommand ReadCommand(string line)
        {
            string commandType = line.Substring(0, line.IndexOf('(')).Trim();

            string commandArgs = line.Split('(', ')')[1].Trim();

            string[] args = commandArgs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < args.Length; i++)
            {
                args[i] = args[i].Trim();
            }

            Commands type;

            PhonebookCommand command = null;

            switch (commandType)
            {
            case "find": type = Commands.Find; command = new FindCommand(args); break;

            case "serialize": type = Commands.Serialize; command = new SerializeCommand(args); break;

            case "add": type = Commands.add; command = new AddCommand(args); break;

            default: type = Commands.Find; command = new FindCommand(args); break;
            }

            return(command);
        }
        public static async Task PutCommand(
            this HttpClient client,
            object command,
            Guid commandId,
            ResolveMediaType resolveMediaType,
            string basePath = null,
            Action<HttpRequestMessage> customizeRequest = null,
            SerializeCommand serializeCommand = null)
        {
            Ensure.That(client, "client").IsNotNull();
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(resolveMediaType, "resolveMediaType").IsNotNull();

            basePath = basePath ?? string.Empty;
            var request = CreatePutCommandRequest(command, commandId, basePath, resolveMediaType, serializeCommand);
            if(customizeRequest != null)
            {
                customizeRequest(request);
            }

            Logger.InfoFormat("Put Command {0}. Type: {1}", commandId, command.GetType());
            HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
            Logger.InfoFormat("Put Command {0}. Response: {1}", commandId, response.ReasonPhrase);

            await response.EnsureCommandSuccess();
        }
示例#5
0
        public static async Task PutCommand(
            this HttpClient client,
            object command,
            Guid commandId,
            ResolveMediaType resolveMediaType,
            string basePath = null,
            Action <HttpRequestMessage> customizeRequest = null,
            SerializeCommand serializeCommand            = null)
        {
            Ensure.That(client, "client").IsNotNull();
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(resolveMediaType, "resolveMediaType").IsNotNull();

            basePath = basePath ?? string.Empty;
            var request = CreatePutCommandRequest(command, commandId, basePath, resolveMediaType, serializeCommand);

            if (customizeRequest != null)
            {
                customizeRequest(request);
            }

            Logger.InfoFormat("Put Command {0}. Type: {1}", commandId, command.GetType());
            HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            Logger.InfoFormat("Put Command {0}. Response: {1}", commandId, response.ReasonPhrase);

            await response.EnsureCommandSuccess();
        }
        public void CanDeserialize()
        {
            var command = new SerializeCommand();

            this.SystemUnderTest.DeserializeInto(serialization, command);
            Assert.Equal("Fozzy", command.Name);
            Assert.Equal(new DateTime(2015, 10, 31), command.DateCreated);
        }
        public void CanSerializeIntoJson()
        {
            var command = new SerializeCommand {
                Name = "Fozzy", DateCreated = new DateTime(2015, 10, 31)
            };
            var result = this.SystemUnderTest.Serialize(command);

            Assert.Equal(serialization, result);
        }
示例#8
0
        public static void Main(string[] args)
        {
            //string fileToLoad = "drugfile_forparsing";
            string fileToLoad = "input_BNF_ertapenem";

            SetJsonConverter();
            string           path             = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            ParseCommand     command          = new ParseCommand(path + "\\" + fileToLoad + ".json");
            DrugsInput       parsedInput      = command.Execute();
            SerializeCommand serializeCommand = new SerializeCommand(parsedInput);
            string           resultJson       = serializeCommand.Execute();

            WriteJsonToFile(resultJson);
        }
示例#9
0
        public CategoryDataViewModel()
        {
            CategoricalDatas = new ObservableCollection <CategoryData>();
            CategoricalDatas.Add(new CategoryData("Gear", 5));
            CategoricalDatas.Add(new CategoryData("Motor", 10));
            CategoricalDatas.Add(new CategoryData("Bearing", 15));
            CategoricalDatas.Add(new CategoryData("Switch", 20));
            CategoricalDatas.Add(new CategoryData("Plug", 20));
            CategoricalDatas.Add(new CategoryData("Cord", 35));
            CategoricalDatas.Add(new CategoryData("Fuse", 40));
            CategoricalDatas.Add(new CategoryData("Pump", 20));
            CategoricalDatas.Add(new CategoryData("Leak", 15));
            CategoricalDatas.Add(new CategoryData("Seals", 40));

            SerializedChartContainer   = new SerializedChartContainer();
            DeserializedChartContainer = new DeserializedChartContainer();

            SerializeCommand = new SerializeCommand(this);
            LoadOpacity      = 0.5;
            ChartVisibility  = Visibility.Collapsed;
        }
示例#10
0
        public async Task Can_invoke_command_over_http()
        {
            var resolver            = new CommandHandlerResolver(new CommandModule());
            var commandMediaTypeMap = new CommandMediaTypeMap(new CommandMediaTypeWithQualifierVersionFormatter())
            {
                { typeof(Command).FullName.ToLower(), typeof(Command) }
            };

            // 1. Create the serializer
            var jsonSerializer = new JsonSerializer();
            var settings       = new CommandHandlingSettings(resolver, commandMediaTypeMap)
            {
                // 2. Customize the deserialization
                DeserializeCommand = (commandReader, type) =>
                {
                    using (var reader = new JsonTextReader(commandReader))
                    {
                        return(jsonSerializer.Deserialize(reader, type));
                    }
                }
            };
            var middleware = CommandHandlingMiddleware.HandleCommands(settings);

            // 3. Customize the serialization
            SerializeCommand serializeCommand = (writer, command) =>
            {
                jsonSerializer.Serialize(writer, command);
            };

            // 3. Create an embedded HttpClient. This allows invoking of the
            //    HttpPipeline in-memory without a server / listener.
            using (HttpClient client = middleware.CreateEmbeddedClient())
            {
                // 3. This is as close as you can get to simulating a real client call
                //    without needing real server.
                //    Can use this to do acceptance testing also.
                await client.PutCommand(new Command(), Guid.NewGuid(), commandMediaTypeMap, serializeCommand : serializeCommand);
            }
        }
示例#11
0
        public static Task PutCommand(
            this HttpClient client,
            object command,
            Guid commandId,
            CommandMediaTypeMap commandMediaTypeMap,
            string basePath = null,
            Action <HttpRequestMessage> customizeRequest = null,
            SerializeCommand serializeCommand            = null)
        {
            Ensure.That(client, "client").IsNotNull();
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(commandMediaTypeMap, "commandMediaTypeMap").IsNotNull();

            return(PutCommand(
                       client,
                       command,
                       commandId,
                       commandMediaTypeMap.GetMediaType,
                       basePath,
                       customizeRequest,
                       serializeCommand));
        }
        public static Task PutCommand(
            this HttpClient client,
            object command,
            Guid commandId,
            CommandMediaTypeMap commandMediaTypeMap,
            string basePath = null,
            Action<HttpRequestMessage> customizeRequest = null,
            SerializeCommand serializeCommand = null)
        {
            Ensure.That(client, "client").IsNotNull();
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(commandMediaTypeMap, "commandMediaTypeMap").IsNotNull();

            return PutCommand(
                client,
                command,
                commandId,
                commandMediaTypeMap.GetMediaType,
                basePath,
                customizeRequest,
                serializeCommand);
        }
示例#13
0
        public void ValidDrugInput_Serialize_Success()
        {
            // Arrange
            IList <Drug> drugs = new List <Drug> {
                DrugFactory.GetDrug("testname1", "testIndication1", "testRoute"),
                DrugFactory.GetDrug("testname2", "testIndication2", "testRoute")
            };
            DrugsInput input = new DrugsInput {
                Drugs = drugs
            };
            SerializeCommand command = new SerializeCommand(input);

            // Act
            var result = command.Execute();

            // Assert
            Assert.Contains("testname1", result);
            Assert.Contains("testIndication1", result);
            Assert.Contains("testname2", result);
            Assert.Contains("testIndication2", result);
            Assert.DoesNotContain("testRoute", result);
            Assert.Contains("TestRoute", result);
        }
 private void LoadTimer_Tick(object sender, EventArgs e)
 {
     LoadTimer.Stop();
     Banners.HideLoadingBanner();
     SerializeCommand.RaiseCanExecuteChanged();
 }
        public static HttpRequestMessage CreatePutCommandRequest(
            object command,
            Guid commandId,
            string basePath,
            ResolveMediaType resolveMediaType,
            SerializeCommand serializeCommand = null)
        {
            Ensure.That(command, "command").IsNotNull();
            Ensure.That(commandId, "commandId").IsNotEmpty();
            Ensure.That(resolveMediaType).IsNotNull();

            serializeCommand = serializeCommand ?? DefaultSerializeCommand;
            using(var writer = new StringWriter())
            {
                serializeCommand(writer, command);

                var httpContent = new StringContent(writer.ToString());
                var mediaType = resolveMediaType(command.GetType(), "json");
                httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(mediaType);

                var request = new HttpRequestMessage(HttpMethod.Put, basePath + "/{0}".FormatWith(commandId))
                {
                    Content = httpContent
                };
                request.Headers.UserAgent.Add(UserAgent);
                request.Headers.Accept.Add(HttpProblemDetails.MediaTypeWithQualityHeaderValue);

                return request;
            }
        }