コード例 #1
0
ファイル: Importer.cs プロジェクト: Minocula/MindTouch_Core
        private Yield WriteData_Helper(ImportItem item, Result result)
        {
            var          mimeType = MimeType.New(item.Request["@type"].AsText ?? MimeType.TEXT_XML.FullType);
            DreamMessage itemMessage;

            if (item.Data != null)
            {
                itemMessage = DreamMessage.Ok(mimeType, item.DataLength, item.Data);
            }
            else
            {
                var body = item.Request["body"];
                itemMessage = !body.IsEmpty ? DreamMessage.Ok(body.Elements) : DreamMessage.Ok();
            }
            foreach (var header in item.Request["header"])
            {
                itemMessage.Headers[header["@name"].AsText] = header["@value"].AsText;
            }
            var verb     = item.Request["@method"].AsText;
            var itemPlug = Plug.New(item.Request["@href"].AsUri)
                           .WithHeaders(_dekiApi.Headers)
                           .WithCredentials(_dekiApi.Credentials)
                           .WithCookieJar(_dekiApi.CookieJar)
                           .WithTimeout(TimeSpan.FromMinutes(30));
            DreamMessage response = null;

            yield return(itemPlug.Invoke(verb, itemMessage, new Result <DreamMessage>(TimeSpan.MaxValue)).Set(x => response = x));

            if (!response.IsSuccessful)
            {
                throw new DreamResponseException(response, string.Format("Request failed with {0} for {1}", response.Status, itemPlug.Uri));
            }
            result.Return();
            yield break;
        }
コード例 #2
0
ファイル: FilePackageReader.cs プロジェクト: heran/DekiWiki
 public Result<ImportItem> ReadData(ImportItem item, Result<ImportItem> result) {
     string file = _package[string.Format("map/item[@dataid='{0}']/@path", item.DataId)].AsText;
     string path = Path.Combine(_packageDirectory, file);
     if(!File.Exists(path)) {
         throw new FileNotFoundException(string.Format("Unable to locate file for dataid '{0}'", item.DataId), path);
     }
     FileStream fileStream = File.OpenRead(path);
     result.Return(item.WithData(fileStream, fileStream.Length));
     return result;
 }
コード例 #3
0
        private Yield ReadData_Helper(ImportItem item, Result <ImportItem> result)
        {
            if (_package == null)
            {
                yield return(Coroutine.Invoke(ReadPackage_Helper, new Result()));
            }
            string   file  = _package[string.Format("map/item[@dataid='{0}']/@path", item.DataId)].AsText;
            ZipEntry entry = _zipFile.GetEntry(file);

            result.Return(item.WithData(_zipFile.GetInputStream(entry), entry.Size));
            yield break;
        }
コード例 #4
0
        public Result <ImportItem> ReadData(ImportItem item, Result <ImportItem> result)
        {
            string file = _package[string.Format("map/item[@dataid='{0}']/@path", item.DataId)].AsText;
            string path = Path.Combine(_packageDirectory, file);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(string.Format("Unable to locate file for dataid '{0}'", item.DataId), path);
            }
            FileStream fileStream = File.OpenRead(path);

            result.Return(item.WithData(fileStream, fileStream.Length));
            return(result);
        }
コード例 #5
0
ファイル: Importer.cs プロジェクト: Minocula/MindTouch_Core
 public Result WriteDataAsync(ImportItem item, Result result)
 {
     return(Coroutine.Invoke(WriteData_Helper, item, result));
 }
コード例 #6
0
 private Yield ReadData_Helper(ImportItem item, Result<ImportItem> result) {
     if(_package == null) {
         yield return Coroutine.Invoke(ReadPackage_Helper, new Result());
     }
     string file = _package[string.Format("map/item[@dataid='{0}']/@path", item.DataId)].AsText;
     ZipEntry entry = _zipFile.GetEntry(file);
     result.Return(item.WithData(_zipFile.GetInputStream(entry), entry.Size));
     yield break;
 }
コード例 #7
0
 public Result<ImportItem> ReadData(ImportItem item, Result<ImportItem> result) {
     return Coroutine.Invoke(ReadData_Helper, item, result);
 }
コード例 #8
0
        public void Importer_can_send_ImportItem_with_xml_body_in_request_doc() {

            // Arrange
            var dekiApiUri = new XUri("http://mock/@api/deki");
            var importManifest = new XDoc("manifest");
            var item1Uri = dekiApiUri.At("foo", "bar", "abc");
            var importResponse = new XDoc("requests");
            var mock = MockPlug.Register(dekiApiUri);
            mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse));
            mock.Expect().Verb("POST").Uri(item1Uri).RequestDocument(new XDoc("item1").Elem("foo", "bar"));

            // Act
            Importer importer = Importer.CreateAsync(Plug.New(dekiApiUri), importManifest, 0, new Result<Importer>()).Wait();
            var item1 = new ImportItem(
                "abc",
                new XDoc("request")
                    .Attr("method", "POST")
                    .Attr("dataid", "abc")
                    .Attr("href", item1Uri)
                    .Start("body")
                        .Attr("type","xml")
                        .Start("item1").Elem("foo","bar").End()
                    .End(),
                new XDoc("manifest"),
                null,
                0);
            importer.WriteDataAsync(item1, new Result()).Wait();

            //Assert
            Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1)));
        }
コード例 #9
0
 private Yield WriteData_Helper(ImportItem item, Result result) {
     var mimeType = MimeType.New(item.Request["@type"].AsText ?? MimeType.TEXT_XML.FullType);
     DreamMessage itemMessage;
     if(item.Data != null) {
         itemMessage = DreamMessage.Ok(mimeType, item.DataLength, item.Data);
     } else {
         var body = item.Request["body"];
         itemMessage = !body.IsEmpty ? DreamMessage.Ok(body.Elements) : DreamMessage.Ok();
     }
     foreach(var header in item.Request["header"]) {
         itemMessage.Headers[header["@name"].AsText] = header["@value"].AsText;
     }
     var verb = item.Request["@method"].AsText;
     var itemPlug = Plug.New(item.Request["@href"].AsUri)
         .WithHeaders(_dekiApi.Headers)
         .WithCredentials(_dekiApi.Credentials)
         .WithCookieJar(_dekiApi.CookieJar)
         .WithTimeout(TimeSpan.FromMinutes(30));
     DreamMessage response = null;
     yield return itemPlug.Invoke(verb, itemMessage, new Result<DreamMessage>(TimeSpan.MaxValue)).Set(x => response = x);
     if(!response.IsSuccessful) {
         throw new DreamResponseException(response, string.Format("Request failed with {0} for {1}", response.Status, itemPlug.Uri));
     }
     result.Return();
     yield break;
 }
コード例 #10
0
 public Result WriteDataAsync(ImportItem item, Result result) {
     return Coroutine.Invoke(WriteData_Helper, item, result);
 }
コード例 #11
0
 public Result <ImportItem> ReadData(ImportItem item, Result <ImportItem> result)
 {
     return(Coroutine.Invoke(ReadData_Helper, item, result));
 }