本文整理汇总了C#中IStorageProviderSession类的典型用法代码示例。如果您正苦于以下问题:C# IStorageProviderSession类的具体用法?C# IStorageProviderSession怎么用?C# IStorageProviderSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IStorageProviderSession类属于命名空间,在下文中一共展示了IStorageProviderSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshDirectoryContent
public void RefreshDirectoryContent(IStorageProviderSession session, BaseDirectoryEntry entry)
{
if (entry == null)
return;
var url = String.Format(GoogleDocsConstants.GoogleDocsContentsUrlFormat, entry.Id.ReplaceFirst("_", "%3a"));
var parameters = new Dictionary<string, string> { { "max-results", "1000" } };
try
{
while (!String.IsNullOrEmpty(url))
{
var request = CreateWebRequest(session, url, "GET", parameters);
var response = (HttpWebResponse)request.GetResponse();
var rs = response.GetResponseStream();
var feedXml = new StreamReader(rs).ReadToEnd();
var childs = GoogleDocsXmlParser.ParseEntriesXml(session, feedXml);
entry.AddChilds(childs);
url = GoogleDocsXmlParser.ParseNext(feedXml);
}
}
catch (WebException)
{
}
}
示例2: RefreshDirectoryContent
public void RefreshDirectoryContent(IStorageProviderSession session, ICloudDirectoryEntry directory)
{
String uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, directory.Id);
uri = SignUri(session, uri);
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
using (var rs = response.GetResponseStream())
{
if (rs == null)
throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
String json = new StreamReader(rs).ReadToEnd();
var childs = SkyDriveJsonParser.ParseListOfEntries(session, json)
.Select(x => x as BaseFileEntry).Where(x => x != null).ToArray();
if (childs.Length == 0 || !(directory is BaseDirectoryEntry))
throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotRetrieveDirectoryList);
var directoryBase = directory as BaseDirectoryEntry;
directoryBase.AddChilds(childs);
}
}
示例3: RemoveResource
public bool RemoveResource(IStorageProviderSession session, ICloudFileSystemEntry resource, RemoveMode mode)
{
String url;
Dictionary<String, String> parameters = null;
if (mode == RemoveMode.FromParentCollection)
{
var pId = (resource.Parent != null ? resource.Parent.Id : GoogleDocsConstants.RootFolderId).ReplaceFirst("_", "%3a");
url = String.Format("{0}/{1}/contents/{2}", GoogleDocsConstants.GoogleDocsFeedUrl, pId, resource.Id.ReplaceFirst("_", "%3a"));
}
else
{
url = String.Format(GoogleDocsConstants.GoogleDocsResourceUrlFormat, resource.Id.ReplaceFirst("_", "%3a"));
parameters = new Dictionary<string, string> {{"delete", "true"}};
}
var request = CreateWebRequest(session, url, "DELETE", parameters);
request.Headers.Add("If-Match", "*");
try
{
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
return true;
}
catch (WebException)
{
}
return false;
}
示例4: RequestResource
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
{
//declare the requested entry
ICloudFileSystemEntry fsEntry = null;
// lets have a look if we are on the root node
if (parent == null)
{
// just create the root entry
fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent);
}
else
{
// ok we have a parent, let's retrieve the resource
// from his child list
fsEntry = parent.GetChild(Name, false);
}
// now that we create the entry just update the chuld
if (fsEntry != null && fsEntry is ICloudDirectoryEntry)
RefreshResource(session, fsEntry as ICloudDirectoryEntry);
// go ahead
return fsEntry;
}
示例5: DeleteResource
public override bool DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry)
{
// get the creds
ICredentials creds = ((GenericNetworkCredentials) session.SessionToken).GetCredential(null, null);
// generate the loca path
String uriPath = GetResourceUrl(session, entry, null);
// removed the file
if (entry is ICloudDirectoryEntry)
{
// we need an empty directory
foreach (ICloudFileSystemEntry child in (ICloudDirectoryEntry) entry)
{
DeleteResource(session, child);
}
// remove the directory
return _ftpService.FtpDeleteEmptyDirectory(uriPath, creds);
}
else
{
// remove the file
return _ftpService.FtpDeleteFile(uriPath, creds);
}
}
示例6: RefreshResource
public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
{
// nothing to do for files
if (!(resource is ICloudDirectoryEntry))
return;
// Refresh schild
RefreshChildsOfDirectory(session, resource as ICloudDirectoryEntry);
}
示例7: GetAccountInfo
public DropBoxAccountInfo GetAccountInfo(IStorageProviderSession session)
{
// request the json object via oauth
int code;
var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxGetAccountInfo, session.ServiceConfiguration), this, session, out code);
// parse the jason stuff
return new DropBoxAccountInfo(res);
}
示例8: RefreshResource
public void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
{
var cached = FsCache.Get(GetSessionKey(session), GetCacheKey(session, null, resource), null) as ICloudDirectoryEntry;
if (cached == null || cached.HasChildrens == nChildState.HasNotEvaluated)
{
_service.RefreshResource(session, resource);
FsCache.Add(GetSessionKey(session), GetCacheKey(session, null, resource), resource);
}
}
示例9: BaseFileEntry
public BaseFileEntry(String Name, long Length, DateTime Modified, IStorageProviderService service, IStorageProviderSession session)
{
this.Name = Name;
this.Length = Length;
this.Modified = Modified;
_service = new CachedServiceWrapper(service); //NOTE: Caching
_session = session;
IsDeleted = false;
}
示例10: PerformRequest
public static String PerformRequest(IStorageProviderSession session, String uri, String method, String data, bool signUri, int countAttempts)
{
if (String.IsNullOrEmpty(method))
method = "GET";
if (!String.IsNullOrEmpty(data) && method == "GET")
return null;
if (signUri)
uri = SignUri(session, uri);
int attemptsToComplete = countAttempts;
while (attemptsToComplete > 0)
{
WebRequest request = WebRequest.Create(uri);
request.Method = method;
request.Timeout = 5000;
if (!signUri)
request.Headers.Add("Authorization", "Bearer " + GetValidToken(session).AccessToken);
if (!String.IsNullOrEmpty(data))
{
byte[] bytes = Encoding.UTF8.GetBytes(data);
request.ContentType = "application/json";
request.ContentLength = bytes.Length;
using (var rs = request.GetRequestStream())
{
rs.Write(bytes, 0, bytes.Length);
}
}
try
{
WebResponse response = request.GetResponse();
using (var rs = response.GetResponseStream())
{
if (rs != null)
{
return new StreamReader(rs).ReadToEnd();
}
}
return null;
}
catch (WebException exception)
{
attemptsToComplete--;
if (exception.Response != null && ((HttpWebResponse)exception.Response).StatusCode == HttpStatusCode.NotFound)
return null;
}
}
return null;
}
示例11: RequestResource
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, String nameOrID, ICloudDirectoryEntry parent)
{
/* In this method name could be either requested resource name or it's ID.
* In first case just refresh the parent and then search child with an appropriate.
* In second case it does not matter if parent is null or not a parent because we use only resource ID. */
if (SkyDriveHelpers.IsResourceID(nameOrID) || nameOrID.Equals("/") && parent == null)
//If request by ID or root folder requested
{
String uri =
SkyDriveHelpers.IsResourceID(nameOrID)
? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, nameOrID)
: SkyDriveConstants.RootAccessUrl;
uri = SignUri(session, uri);
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
using (var rs = response.GetResponseStream())
{
if (rs != null)
{
String json = new StreamReader(rs).ReadToEnd();
ICloudFileSystemEntry entry = SkyDriveJsonParser.ParseSingleEntry(session, json);
return entry;
}
}
}
else
{
String uri =
parent != null
? String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.Id)
: SkyDriveConstants.RootAccessUrl + "/files";
uri = SignUri(session, uri);
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
using (var rs = response.GetResponseStream())
{
if (rs != null)
{
String json = new StreamReader(rs).ReadToEnd();
var entry = SkyDriveJsonParser.ParseListOfEntries(session, json).FirstOrDefault(x => x.Name.Equals(nameOrID));
if (entry != null && parent != null && parent is BaseDirectoryEntry)
(parent as BaseDirectoryEntry).AddChild(entry as BaseFileEntry);
return entry;
}
}
}
return null;
}
示例12: RequestResource
public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
{
// build path
String path;
if (Name.Equals("/"))
path = session.ServiceConfiguration.ServiceLocator.LocalPath;
else if (parent == null)
path = Path.Combine(path = session.ServiceConfiguration.ServiceLocator.LocalPath, Name);
else
path = new Uri(GetResourceUrl(session, parent, Name)).LocalPath;
// check if file exists
if (File.Exists(path))
{
// create the fileinfo
FileInfo fInfo = new FileInfo(path);
BaseFileEntry bf = new BaseFileEntry(fInfo.Name, fInfo.Length, fInfo.LastWriteTimeUtc, this, session) {Parent = parent};
// add to parent
if (parent != null)
(parent as BaseDirectoryEntry).AddChild(bf);
// go ahead
return bf;
}
// check if directory exists
else if (Directory.Exists(path))
{
// build directory info
DirectoryInfo dInfo = new DirectoryInfo(path);
// build bas dir
BaseDirectoryEntry dir = CreateEntryByFileSystemInfo(dInfo, session, parent) as BaseDirectoryEntry;
if (Name.Equals("/"))
dir.Name = "/";
// add to parent
if (parent != null)
(parent as BaseDirectoryEntry).AddChild(dir);
// refresh the childs
RefreshChildsOfDirectory(session, dir);
// go ahead
return dir;
}
else
return null;
}
示例13: UpdateObjectFromJsonString
public static BaseFileEntry UpdateObjectFromJsonString(String jsonMessage, BaseFileEntry objectToUpdate, IStorageProviderService service, IStorageProviderSession session)
{
// verify if we have a directory or a file
var jc = new JsonHelper();
if (!jc.ParseJsonMessage(jsonMessage))
throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidFileOrDirectoryName);
var isDir = jc.GetBooleanProperty("is_dir");
// create the entry
BaseFileEntry dbentry;
Boolean bEntryOk;
if (isDir)
{
if (objectToUpdate == null)
dbentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session);
else
dbentry = objectToUpdate as BaseDirectoryEntry;
bEntryOk = BuildDirectyEntry(dbentry as BaseDirectoryEntry, jc, service, session);
}
else
{
if (objectToUpdate == null)
dbentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session);
else
dbentry = objectToUpdate;
bEntryOk = BuildFileEntry(dbentry, jc);
}
// parse the childs and fill the entry as self
if (!bEntryOk)
throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService);
// set the is deleted flag
try
{
// try to read the is_deleted property
dbentry.IsDeleted = jc.GetBooleanProperty("is_deleted");
}
catch (Exception)
{
// the is_deleted proprty is missing (so it's not a deleted file or folder)
dbentry.IsDeleted = false;
}
// return the child
return dbentry;
}
示例14: ParseSingleEntry
private static ICloudFileSystemEntry ParseSingleEntry(IStorageProviderSession session, String json, JsonHelper parser)
{
if (json == null)
return null;
if (parser == null)
parser = CreateParser(json);
if (ContainsError(json, false, parser))
return null;
BaseFileEntry entry;
var type = parser.GetProperty("type");
if (!IsFolderType(type) && !IsFileType(type))
return null;
var id = parser.GetProperty("id");
var name = parser.GetProperty("name");
var parentID = parser.GetProperty("parent_id");
var uploadLocation = parser.GetProperty("upload_location");
var updatedTime = Convert.ToDateTime(parser.GetProperty("updated_time")).ToUniversalTime();
if (IsFolderType(type))
{
int count = parser.GetPropertyInt("count");
entry = new BaseDirectoryEntry(name, count, updatedTime, session.Service, session) {Id = id};
}
else
{
var size = Convert.ToInt64(parser.GetProperty("size"));
entry = new BaseFileEntry(name, size, updatedTime, session.Service, session) {Id = id};
}
entry[SkyDriveConstants.UploadLocationKey] = uploadLocation;
if (!String.IsNullOrEmpty(parentID))
{
entry.ParentID = SkyDriveConstants.RootIDRegex.IsMatch(parentID) ? "/" : parentID;
}
else
{
entry.Name = "/";
entry.Id = "/";
}
entry[SkyDriveConstants.InnerIDKey] = id;
entry[SkyDriveConstants.TimestampKey] = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
return entry;
}
示例15: CreateDirectoryEntry
/// <summary>
///
/// </summary>
/// <param name="session"></param>
/// <param name="Name"></param>
/// <param name="modifiedDate"></param>
/// <param name="parent"></param>
/// <returns></returns>
public static ICloudDirectoryEntry CreateDirectoryEntry(IStorageProviderSession session, string Name, DateTime modifiedDate, ICloudDirectoryEntry parent)
{
// build up query url
var newObj = new BaseDirectoryEntry(Name, 0, modifiedDate, session.Service, session);
// case the parent if possible
if (parent != null)
{
var objparent = parent as BaseDirectoryEntry;
objparent.AddChild(newObj);
}
return newObj;
}