public static IEnumerable <MultipartFormParameter> ApiParameter(ConverterType from, ConverterType to, string template, string csl) { if (from != ConverterType.Undefined) { yield return(CreateField("from", from.ToString().ToLower())); yield return(CreateField("ext", from.GetExtension())); } if (to != ConverterType.Undefined) { yield return(CreateField("to", to.ToString().ToLower())); } if (!string.IsNullOrWhiteSpace(template)) { yield return(CreateField("template", template)); } if (!string.IsNullOrWhiteSpace(csl)) { yield return(CreateField("csl", csl)); } }
private static async Task ImportFile(WorkspaceViewModel workspace, string fileName, ConverterType target) { string targetFileName = Path.GetFileNameWithoutExtension(fileName) + target.GetExtension(); targetFileName = Path.Combine(workspace.Item.RelativeName, targetFileName); string from = Path.GetExtension(fileName); if (string.IsNullOrEmpty(from)) { throw new InvalidDataException("Could not determine import file type"); } string url = WebUtility.BuildConvertUrl(); using (var req = await WebUtility.PostRequest(url, BuildParameters(fileName, target).Concat(MultipartFormParameter.CreateFile("content", fileName)))) { byte[] content = await req.Content.ReadAsByteArrayAsync(); var item = await workspace.Item.Data.CreateNewFile(targetFileName, null, content); var itemViewModel = workspace.Item.AddChild(item); workspace.SelectedItem = itemViewModel; } }