Exemplo n.º 1
0
        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
                );
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 public ImageProfile(JsonProfile jsonProfile, IWebDav webdav) : base(jsonProfile, webdav)
 {
 }
Exemplo n.º 5
0
 public abstract Task UploadProfileAsync(IWebDav webdav);
Exemplo n.º 6
0
 public abstract void UploadProfile(IWebDav webdav);
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 public override void UploadProfile(IWebDav webdav)
 {
     webdav.PutText(SyncService.REMOTE_RECORD_FILE, this.ToJsonString());
 }
Exemplo n.º 9
0
 public override async Task UploadProfileAsync(IWebDav webdav)
 {
     await webdav.PutTextAsync(SyncService.REMOTE_RECORD_FILE, this.ToJsonString(), 0, 0).ConfigureAwait(false);
 }
Exemplo n.º 10
0
 public FileProfile(JsonProfile jsonProfile, IWebDav webDav)
 {
     FileName = jsonProfile.File;
     _webDav  = webDav;
     SetMd5(jsonProfile.Clipboard);
 }
Exemplo n.º 11
0
 public override Task UploadProfileAsync(IWebDav webdav)
 {
     return(Task.CompletedTask);
 }
Exemplo n.º 12
0
 public override void UploadProfile(IWebDav webdav)
 {
 }