public static GenRes SetMt(Uri uri, String fp, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "PROPPATCH"; req.PreAuthenticate = true; MemoryStream si = new MemoryStream(); { XmlDocument xmlo = new XmlDocument(); XmlElement elroot = xmlo.CreateElement("D", "propertyupdate", "DAV:"); xmlo.AppendChild(elroot); XmlElement elset = xmlo.CreateElement("D", "set", "DAV:"); elroot.AppendChild(elset); XmlElement elprop = xmlo.CreateElement("D", "prop", "DAV:"); elset.AppendChild(elprop); // http://code.google.com/p/sem-fs/source/browse/trunk/milton-api-patch/src/docs/vista/proppatch?spec=svn218&r=218 XmlElement elmt = xmlo.CreateElement("Z", "Win32LastModifiedTime", "urn:schemas-microsoft-com:"); elprop.AppendChild(elmt); elmt.AppendChild(xmlo.CreateTextNode(File.GetLastWriteTimeUtc(fp).ToString("r"))); StreamWriter wr = new StreamWriter(si); xmlo.Save(wr); } si.Position = 0; { req.ContentLength = si.Length; req.ContentType = "text/xml; charset=\"utf-8\""; req.SendChunked = true; using (Stream os = req.GetRequestStream()) { byte[] bin = new byte[4096]; while (true) { int r = si.Read(bin, 0, bin.Length); if (r < 1) { break; } os.Write(bin, 0, r); } } GenRes ret = new GenRes(); ret.baseUri = req.RequestUri; try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return(ret); } }
private void mDelSel_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "選択したファイル・フォルダを削除しますか?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { return; } foreach (Ent ent in lvF.SelectedItems.Cast <ListViewItem>().Select(p => (Ent)p.Tag)) { using (GenRes killed = DInfo.Delete(ent.FullUrl, conn)) { } } RefreshView(); }
private void bNewFolder_Click(object sender, EventArgs e) { String name = Interaction.InputBox("フォルダ名称", "", "", -1, -1); if (name.Length == 0) { return; } using (GenRes newf = DInfo.NewFolder(UUt.CombineFile(navi, name), conn)) { if (!newf.Success) { MessageBox.Show(this, "フォルダの作成に失敗しました:" + newf.err.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } RefreshView(); }
public static GenRes Upload2(Uri uri, String fp, ConnInfo conn, INoticeIO nio, WaitHandle cancel) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "PUT"; req.PreAuthenticate = true; using (FileStream si = File.OpenRead(fp)) { req.ContentLength = si.Length; req.ContentType = "application/octet-stream"; req.SendChunked = true; req.Pipelined = true; req.AllowWriteStreamBuffering = true; using (Stream os = req.GetRequestStream()) { byte[] bin = new byte[4096]; while (true) { nio.Notice(fp, si.Position, si.Length); if (cancel.WaitOne(0, false)) { break; } int r = si.Read(bin, 0, bin.Length); if (r < 1) { break; } os.Write(bin, 0, r); } } GenRes ret = new GenRes(); ret.baseUri = req.RequestUri; try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return(ret); } }
public static GenRes NewFolder(Uri uri, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "MKCOL"; req.PreAuthenticate = true; GenRes ret = new GenRes(); try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return(ret); }
private void mRenameSel_Click(object sender, EventArgs e) { foreach (Ent ent in lvF.SelectedItems.Cast <ListViewItem>().Select(p => (Ent)p.Tag)) { String newname = Interaction.InputBox("新しい名前", "", ent.Name, -1, -1); if (newname.Length == 0) { break; } using (GenRes moved = DInfo.Move(ent.FullUrl, new Uri(ent.SelfFullUrl, newname + "/"), conn)) { if (!moved.Success) { MessageBox.Show(this, "フォルダの移動に失敗しました:" + moved.err.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } RefreshView(); break; } }
public static GenRes Move(Uri uriFrm, Uri uriTo, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriFrm); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "MOVE"; req.PreAuthenticate = true; req.Headers["Destination"] = HttpUtility.UrlPathEncode(uriTo.ToString()); req.Headers["Overwrite"] = "F"; GenRes ret = new GenRes(); try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return(ret); }
public static GenRes Move(Uri uriFrm, Uri uriTo, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriFrm); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "MOVE"; req.PreAuthenticate = true; req.Headers["Destination"] = HttpUtility.UrlPathEncode(uriTo.ToString()); req.Headers["Overwrite"] = "F"; GenRes ret = new GenRes(); try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return ret; }
public static GenRes NewFolder(Uri uri, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "MKCOL"; req.PreAuthenticate = true; GenRes ret = new GenRes(); try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return ret; }
public static GenRes SetMt(Uri uri, String fp, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "PROPPATCH"; req.PreAuthenticate = true; MemoryStream si = new MemoryStream(); { XmlDocument xmlo = new XmlDocument(); XmlElement elroot = xmlo.CreateElement("D", "propertyupdate", "DAV:"); xmlo.AppendChild(elroot); XmlElement elset = xmlo.CreateElement("D", "set", "DAV:"); elroot.AppendChild(elset); XmlElement elprop = xmlo.CreateElement("D", "prop", "DAV:"); elset.AppendChild(elprop); // http://code.google.com/p/sem-fs/source/browse/trunk/milton-api-patch/src/docs/vista/proppatch?spec=svn218&r=218 XmlElement elmt = xmlo.CreateElement("Z", "Win32LastModifiedTime", "urn:schemas-microsoft-com:"); elprop.AppendChild(elmt); elmt.AppendChild(xmlo.CreateTextNode(File.GetLastWriteTimeUtc(fp).ToString("r"))); StreamWriter wr = new StreamWriter(si); xmlo.Save(wr); } si.Position = 0; { req.ContentLength = si.Length; req.ContentType = "text/xml; charset=\"utf-8\""; req.SendChunked = true; using (Stream os = req.GetRequestStream()) { byte[] bin = new byte[4096]; while (true) { int r = si.Read(bin, 0, bin.Length); if (r < 1) break; os.Write(bin, 0, r); } } GenRes ret = new GenRes(); ret.baseUri = req.RequestUri; try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return ret; } }
public static GenRes Upload(Uri uri, String fp, ConnInfo conn) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url); req.Credentials = conn.Auth; req.UserAgent = UA; req.Method = "PUT"; req.PreAuthenticate = true; using (FileStream si = File.OpenRead(fp)) { req.ContentLength = si.Length; req.ContentType = "application/octet-stream"; req.SendChunked = true; using (Stream os = req.GetRequestStream()) { byte[] bin = new byte[4096]; while (true) { int r = si.Read(bin, 0, bin.Length); if (r < 1) break; os.Write(bin, 0, r); } } GenRes ret = new GenRes(); ret.baseUri = req.RequestUri; try { ret.res = (HttpWebResponse)req.GetResponse(); } catch (WebException err) { ret.err = err; } return ret; } }
public UTRes UploadThem(String[] alfp, Uri baseUri) { foreach (String fp in alfp) { if (cancel.WaitOne(0, false)) { return(UTRes.Cancel); } Uri uriTo = UUt.CombineFile(baseUri, Path.GetFileName(fp)); using (HeadRes head = DInfo.Head(uriTo, conn)) { head.Dispose(); if (0 == (File.GetAttributes(fp) & FileAttributes.Directory)) { if (head.Exists) { switch (QueryOvwr(head.baseUri.ToString())) { case DialogResult.Yes: break; case DialogResult.No: continue; case DialogResult.Cancel: return(UTRes.Cancel); } } head.Dispose(); using (GenRes uploaded = DInfo.Upload2(uriTo, fp, conn, nio, cancel)) { if (cancel.WaitOne(0, true)) { using (GenRes rest = DInfo.Delete(uriTo, conn)) { } } } using (GenRes set = DInfo.SetMt(uriTo, fp, conn)) { } } else { Uri uriDir = UUt.CombineFile(baseUri, Path.GetFileName(fp)); if (!head.Exists) { using (GenRes newf = DInfo.NewFolder(uriTo, conn)) { if (!newf.Success) { continue; } } } switch (UploadThem(Directory.GetFileSystemEntries(fp), uriDir)) { case UTRes.Cancel: return(UTRes.Cancel); } } } } return(UTRes.Ok); }