本文整理汇总了C#中ICloudFileSystemEntry.GetPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C# ICloudFileSystemEntry.GetPropertyValue方法的具体用法?C# ICloudFileSystemEntry.GetPropertyValue怎么用?C# ICloudFileSystemEntry.GetPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICloudFileSystemEntry
的用法示例。
在下文中一共展示了ICloudFileSystemEntry.GetPropertyValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OfGoogleDocsKind
public static bool OfGoogleDocsKind(ICloudFileSystemEntry entry)
{
var kind = entry.GetPropertyValue(GoogleDocsConstants.KindProperty);
return kind.Equals("document") || kind.Equals("presentation") || kind.Equals("spreadsheet") || kind.Equals("drawing");
}
示例2: CopyResource
public override bool CopyResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry copyTo)
{
if (entry.Name.Equals("/"))
return false;
if (entry is ICloudDirectoryEntry)
{
// skydrive allowes to copy only files so we will recursively create/copy entries
var newEntry = CreateResource(session, entry.Name, copyTo) as ICloudDirectoryEntry;
return newEntry != null && (entry as ICloudDirectoryEntry).Aggregate(true, (current, subEntry) => current && CopyResource(session, subEntry, newEntry));
}
String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String data = String.Format("{{destination: \"{0}\"}}", copyTo.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String json = SkyDriveRequestHelper.PerformRequest(session, uri, "COPY", data, false);
if (json != null && !SkyDriveJsonParser.ContainsError(json, false))
{
var copyToBase = copyTo as BaseDirectoryEntry;
if (copyToBase != null)
copyToBase.AddChild(entry as BaseFileEntry);
return true;
}
return false;
}
示例3: CreateDownloadStream
public override Stream CreateDownloadStream(IStorageProviderSession session, ICloudFileSystemEntry entry)
{
if (entry is ICloudDirectoryEntry)
throw new ArgumentException("Download operation can be perform for files only");
String uri = String.Format("{0}/{1}/content", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
uri = SkyDriveRequestHelper.SignUri(session, uri);
var request = WebRequest.Create(uri);
var response = request.GetResponse();
((BaseFileEntry)entry).Length = response.ContentLength;
return new BaseFileEntryDownloadStream(response.GetResponseStream(), entry);
}
示例4: RenameResource
public override bool RenameResource(IStorageProviderSession session, ICloudFileSystemEntry entry, String newName)
{
if (entry.Name.Equals("/") || newName.Contains("/"))
return false;
String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String data = String.Format("{{name: \"{0}\"}}", newName);
String json = SkyDriveRequestHelper.PerformRequest(session, uri, "PUT", data, false);
if (!SkyDriveJsonParser.ContainsError(json, false))
{
var entryBase = entry as BaseFileEntry;
if (entryBase != null)
entryBase.Name = newName;
return true;
}
return false;
}
示例5: MoveResource
public override bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry entry, ICloudDirectoryEntry moveTo)
{
if (entry.Name.Equals("/"))
return false;
String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String data = String.Format("{{destination: \"{0}\"}}", moveTo.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String json = SkyDriveRequestHelper.PerformRequest(session, uri, "MOVE", data, false);
if (!SkyDriveJsonParser.ContainsError(json, false))
{
var parent = entry.Parent as BaseDirectoryEntry;
if (parent != null)
parent.RemoveChildById(entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
var moveToBase = moveTo as BaseDirectoryEntry;
if (moveToBase != null)
moveToBase.AddChild(entry as BaseFileEntry);
return true;
}
return false;
}
示例6: RefreshResource
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
{
//not refresh if resource was requested recently
var timestamp = resource.GetPropertyValue(SkyDriveConstants.TimestampKey);
var refreshNeeded = DateTime.Parse(timestamp, CultureInfo.InvariantCulture) + TimeSpan.FromSeconds(5) < DateTime.UtcNow;
if (refreshNeeded)
{
//Request resource by ID and then update properties from requested
var current = RequestResource(session, resource.GetPropertyValue(SkyDriveConstants.InnerIDKey), null);
SkyDriveHelpers.CopyProperties(current, resource);
}
var directory = resource as ICloudDirectoryEntry;
if (directory != null && !refreshNeeded && directory.HasChildrens == nChildState.HasNotEvaluated)
RefreshDirectoryContent(session, directory);
}
示例7: DeleteResource
public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry)
{
String uri = String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
String json = SkyDriveRequestHelper.PerformRequest(session, uri, "DELETE", null, true);
if (!SkyDriveJsonParser.ContainsError(json, false))
{
var parent = entry.Parent as BaseDirectoryEntry;
if (parent != null)
parent.RemoveChildById(entry.GetPropertyValue(SkyDriveConstants.InnerIDKey));
return true;
}
return false;
}
示例8: CreateDownloadStream
public override Stream CreateDownloadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry)
{
var url = fileSystemEntry.GetPropertyValue(GoogleDocsConstants.DownloadUrlProperty);
var format = GoogleDocsResourceHelper.GetStreamExtensionByKind(fileSystemEntry.GetPropertyValue(GoogleDocsConstants.KindProperty));
if (!String.IsNullOrEmpty(format))
{
url = String.Format("{0}&exportFormat={1}", url, format);
if (format.Equals("docx"))
url += "&format=" + format;
}
var request = CreateWebRequest(session, url, "GET", null, true);
var response = (HttpWebResponse)request.GetResponse();
if (fileSystemEntry.Length > 0)
{
return new BaseFileEntryDownloadStream(response.GetResponseStream(), fileSystemEntry);
}
var isChukedEncoding = string.Equals(response.Headers.Get("Transfer-Encoding"), "Chunked", StringComparison.OrdinalIgnoreCase);
if (!isChukedEncoding)
{
((BaseFileEntry)fileSystemEntry).Length = response.ContentLength;
return new BaseFileEntryDownloadStream(response.GetResponseStream(), fileSystemEntry);
}
var tempBuffer = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, 8096, FileOptions.DeleteOnClose);
response.GetResponseStream().CopyTo(tempBuffer);
tempBuffer.Flush();
tempBuffer.Seek(0, SeekOrigin.Begin);
return tempBuffer;
}
示例9: CreateUploadSession
public override IResumableUploadSession CreateUploadSession(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, long bytesToTransfer)
{
WebRequest request;
if (GoogleDocsResourceHelper.IsResorceId(fileSystemEntry.Id))
{
//request for update
request = CreateWebRequest(session, fileSystemEntry.GetPropertyValue(GoogleDocsConstants.ResEditMediaProperty), "PUT", null, true);
request.Headers.Add("If-Match", "*");
}
else
{
//request for create
request = CreateWebRequest(session, fileSystemEntry.Parent.GetPropertyValue(GoogleDocsConstants.ResCreateMediaProperty) + "?convert=false", "POST", null, true);
}
if (GoogleDocsResourceHelper.OfGoogleDocsKind(fileSystemEntry))
{
((BaseFileEntry)fileSystemEntry).Name = Path.GetFileNameWithoutExtension(fileSystemEntry.Name);
}
GoogleDocsXmlParser.WriteAtom(request, GoogleDocsXmlParser.EntryElement(GoogleDocsXmlParser.TitleElement(fileSystemEntry.Name)));
request.Headers.Add("X-Upload-Content-Type", Common.Net.MimeMapping.GetMimeMapping(fileSystemEntry.Name));
request.Headers.Add("X-Upload-Content-Length", bytesToTransfer.ToString(CultureInfo.InvariantCulture));
var response = request.GetResponse();
var uploadSession = new ResumableUploadSession(fileSystemEntry, bytesToTransfer);
uploadSession["Location"] = response.Headers["Location"];
uploadSession.Status = ResumableUploadSessionStatus.Started;
return uploadSession;
}
示例10: RenameResource
public override bool RenameResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, string newName)
{
if (String.IsNullOrEmpty(newName) || GoogleDocsResourceHelper.IsNoolOrRoot(fsentry))
return false;
var url = String.Format(GoogleDocsConstants.GoogleDocsResourceUrlFormat, fsentry.Id.ReplaceFirst("_", "%3a"));
var request = CreateWebRequest(session, url, "PUT", null);
request.Headers.Add("If-Match", fsentry.GetPropertyValue(GoogleDocsConstants.EtagProperty));
GoogleDocsXmlParser.WriteAtom(request, GoogleDocsXmlParser.EntryElement(GoogleDocsXmlParser.TitleElement(newName)));
try
{
var response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
//check if extension added
if (!(fsentry is ICloudDirectoryEntry) && String.IsNullOrEmpty(Path.GetExtension(newName)))
newName = newName + Path.GetExtension(fsentry.Name);
(fsentry as BaseFileEntry).Name = newName;
return true;
}
}
catch (WebException)
{
}
return false;
}
示例11: RefreshResource
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
{
if (resource == null)
return;
if (resource.Id.Equals(GoogleDocsConstants.RootFolderId))
{
RefreshDirectoryContent(session, resource as BaseDirectoryEntry);
return;
}
var resourceUrl = String.Format(GoogleDocsConstants.GoogleDocsResourceUrlFormat, resource.Id.ReplaceFirst("_", "%3a"));
var request = CreateWebRequest(session, resourceUrl, "GET", null);
request.Headers.Add("If-None-Match", resource.GetPropertyValue(GoogleDocsConstants.EtagProperty));
try
{
var response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode != HttpStatusCode.NotModified)
{
var s = response.GetResponseStream();
var xml = new StreamReader(s).ReadToEnd();
GoogleDocsResourceHelper.UpdateResourceByXml(session, out resource, xml);
}
var dirEntry = resource as BaseDirectoryEntry;
if (dirEntry == null || dirEntry.HasChildrens == nChildState.HasChilds)
return;
RefreshDirectoryContent(session, dirEntry);
}
catch (WebException)
{
}
}
示例12: RefreshResource
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
{
var path = GetResourceUrlInternal(session, DropBoxResourceIDHelpers.GetResourcePath(resource));
int code;
var res = DropBoxRequestParser.RequestResourceByUrl(path, this, session, out code);
if (res.Length == 0)
throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
// build the entry and subchilds
DropBoxRequestParser.UpdateObjectFromJsonString(res, resource as BaseFileEntry, this, session);
var hash = resource.GetPropertyValue("hash");
if (!string.IsNullOrEmpty(hash))
{
DropBoxRequestParser.Addhash(path, hash, res, session);
}
}
示例13: CreateUploadStream
public override Stream CreateUploadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry, long uploadSize)
{
String url;
bool update = false;
String type = GetMimeType(fileSystemEntry.Name);
if (GoogleDocsResourceHelper.IsResorceId(fileSystemEntry.Id)) //update existent
{
var ext = GoogleDocsResourceHelper.GetExtensionByKind(fileSystemEntry.GetPropertyValue(GoogleDocsConstants.KindProperty));
if (!String.IsNullOrEmpty(ext))
{
//for google docs kind we previously add an extension that don't needed anymore
var index = fileSystemEntry.Name.IndexOf('.' + ext, StringComparison.Ordinal);
(fileSystemEntry as BaseFileEntry).Name = fileSystemEntry.Name.Substring(0, index);
}
url = fileSystemEntry.GetPropertyValue(GoogleDocsConstants.ResEditMediaProperty);
update = true;
if (String.IsNullOrEmpty(url))
throw new HttpException(403, "User not authorize to update resource");
}
else
{
url = fileSystemEntry.Parent.GetPropertyValue(GoogleDocsConstants.ResCreateMediaProperty) + "?convert=false";
}
//first initiate resumable upload request
var initRequest = CreateWebRequest(session, url, update ? "PUT" : "POST", null);
initRequest.Headers.Add("X-Upload-Content-Length", uploadSize.ToString(CultureInfo.InvariantCulture));
initRequest.Headers.Add("X-Upload-Content-Type", type);
if (update)
{
initRequest.Headers.Add("If-Match", "*");
}
GoogleDocsXmlParser.WriteAtom(initRequest, GoogleDocsXmlParser.EntryElement(null, GoogleDocsXmlParser.TitleElement(fileSystemEntry.Name)));
var response = initRequest.GetResponse();
//secondly create request to obtained url
var uplRequest = CreateWebRequest(session, response.Headers["Location"], "PUT", null);
uplRequest.ContentLength = uploadSize;
uplRequest.ContentType = type;
uplRequest.Headers.Add("Content-Range", String.Format("bytes {0}-{1}/{2}", 0, uploadSize - 1, uploadSize));
var wrStream = new WebRequestStream(uplRequest.GetRequestStream(), uplRequest, null);
wrStream.PushPostDisposeOperation(CommitUploadOperation, session, uplRequest, fileSystemEntry);
return wrStream;
}
示例14: CreateDownloadStream
public override Stream CreateDownloadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry)
{
var url = fileSystemEntry.GetPropertyValue(GoogleDocsConstants.DownloadUrlProperty);
var format = GoogleDocsResourceHelper.GetExtensionByKind(fileSystemEntry.GetPropertyValue(GoogleDocsConstants.KindProperty));
if (!String.IsNullOrEmpty(format))
{
url = String.Format("{0}&exportFormat={1}&format={1}", url, format);
}
var request = CreateWebRequest(session, url, "GET", null, true);
MemoryStream stream = null;
try
{
var response = request.GetResponse();
using (var rs = response.GetResponseStream())
{
stream = new MemoryStream();
rs.CopyTo(stream);
stream.Seek(0, SeekOrigin.Begin);
}
}
catch (WebException)
{
}
return stream;
}