private static void LoadGlobalWebDavSession() { WebDav = new WebDav( UserConfig.Config.SyncService.RemoteURL, UserConfig.Config.SyncService.UserName, UserConfig.Config.SyncService.Password, UserConfig.Config.Program.IntervalTime, UserConfig.Config.Program.RetryTimes, UserConfig.Config.Program.TimeOut ); WebDav.TestAliveAsync().ContinueWith( (res) => Log.Write(res.Result.ToString()), System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted ); }
public override void UploadProfile(IWebDav webdav) { string remotePath = $"{SyncService.REMOTE_FILE_FOLDER}/{FileName}"; FileInfo file = new FileInfo(fullPath); if (file.Length <= maxFileSize) { Log.Write("PUSH file " + FileName); webdav.PutFile(remotePath, fullPath); } else { Log.Write("file is too large, skipped " + FileName); } SetMd5(GetMD5HashFromFile(fullPath)); webdav.PutText(SyncService.REMOTE_RECORD_FILE, this.ToJsonString()); }
public static async Task <Profile> CreateFromRemote(IWebDav webDav) { string httpReply = await webDav.GetTextAsync(SyncService.REMOTE_RECORD_FILE, 0, 0).ConfigureAwait(false); Log.Write("[PULL] json " + httpReply); JsonProfile jsonProfile; try { JavaScriptSerializer serializer = new JavaScriptSerializer(); jsonProfile = serializer.Deserialize <JsonProfile>(httpReply); } catch (ArgumentException) { Log.Write("Existed profile file's format is wrong"); throw new Exception("failed to connect remote server"); } ClipboardType type = StringToClipBoardType(jsonProfile.Type); return(GetProfileBy(type, jsonProfile, webDav)); }
public ImageProfile(JsonProfile jsonProfile, IWebDav webdav) : base(jsonProfile, webdav) { }
public abstract Task UploadProfileAsync(IWebDav webdav);
public abstract void UploadProfile(IWebDav webdav);
private static Profile GetProfileBy(ClipboardType type, JsonProfile jsonProfile, IWebDav webDav) { switch (type) { case ClipboardType.Text: return(new TextProfile(jsonProfile.Clipboard)); case ClipboardType.File: { if (FileIsImage(jsonProfile.File)) { return(new ImageProfile(jsonProfile, webDav)); } return(new FileProfile(jsonProfile, webDav)); } case ClipboardType.Image: return(new ImageProfile(jsonProfile, webDav)); } return(null); }
public override void UploadProfile(IWebDav webdav) { webdav.PutText(SyncService.REMOTE_RECORD_FILE, this.ToJsonString()); }
public override async Task UploadProfileAsync(IWebDav webdav) { await webdav.PutTextAsync(SyncService.REMOTE_RECORD_FILE, this.ToJsonString(), 0, 0).ConfigureAwait(false); }
public FileProfile(JsonProfile jsonProfile, IWebDav webDav) { FileName = jsonProfile.File; _webDav = webDav; SetMd5(jsonProfile.Clipboard); }
public override Task UploadProfileAsync(IWebDav webdav) { return(Task.CompletedTask); }
public override void UploadProfile(IWebDav webdav) { }