public static void PresentOptions(Action SuccessCallback, Action CancelCallback, IntPtr owner) { Action localhostrCallback = () => { Settings.Set("UploadType", UploadOptions.Localhostr); SuccessCallback(); }; Action LocalWebServerCallback = () => { Settings.Set("UploadType", UploadOptions.LocalWebServer); SuccessCallback(); }; Action DropboxCallback = () => { Settings.Set("UploadType", UploadOptions.Dropbox); Dropbox.Configure(SuccessCallback, CancelCallback); }; ShowUploadDialog("documents and photos", localhostrCallback, LocalWebServerCallback, DropboxCallback, CancelCallback, owner); }
public static void UploadFile(string filename, Action <UploadResult> Callback, Action CancelCallback) { Action localhostrCallback = () => { Settings.Set("UploadType", UploadOptions.Localhostr); Callback(Localhostr.UploadFile(filename)); }; Action LocalWebServerCallback = () => { Settings.Set("UploadType", UploadOptions.LocalWebServer); var file_guid = Guid.NewGuid() + "." + Path.GetExtension(filename); Program.LocalFileStorage[file_guid] = filename; string addr = LocalEndPoint; if (Settings.Get("UseFixedIPAddress", false)) { Trace.Write("Using Fixed IP Address"); addr = Settings.Get("FixedIPAddress", "[UnknownIP]"); } Callback(new UploadResult { Icon = "", // TODO icon URL = string.Format("http://{0}:{1}/{2}", addr, Settings.Get("HttpPort", 7780), file_guid) }); }; Action DropboxCallback = () => { Settings.Set("UploadType", UploadOptions.Dropbox); Action upload = () => { Callback(Dropbox.UploadFile(filename)); }; if (Dropbox.IsConfigured) { // configured, so do the uplod upload(); } else { Dropbox.Configure(() => { // configured, so do the upload upload(); }, CancelCallback); } }; if (Settings.Get("AskEachTime", true) || Settings.Get("UploadType", UploadOptions.NotSet) == UploadOptions.NotSet) { ShowUploadDialog(Path.GetFileName(filename), localhostrCallback, LocalWebServerCallback, DropboxCallback, CancelCallback, IntPtr.Zero); } else { switch (Settings.Get("UploadType", UploadOptions.NotSet)) { case UploadOptions.Localhostr: localhostrCallback(); break; case UploadOptions.LocalWebServer: LocalWebServerCallback(); break; case UploadOptions.Dropbox: DropboxCallback(); break; default: Trace.WriteLine("Invalid upload option!"); CancelCallback(); break; } } }