public static void PresentModal(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); using (ProfileViewingDialog dlg = new ProfileViewingDialog(profile)) dlg.ShowDialog(); }
private static string GetContainerPath(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); return String.Format("{0}.{1}", profile.RemoteHost, ContainerSuffix); }
public override void VerifyProfile(RoamingProfile profile) { try { Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceVerbose, "Testing roaming profile...", TraceCategory); FtpWebRequest ftpRequest = FtpRequestFactory.CreateTestRequest(profile); using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse()) { Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceVerbose, String.Format("Ftp request response is: '{0}' ({1}).", ftpResponse.StatusCode, ftpResponse.StatusDescription), TraceCategory); if (ftpResponse.StatusCode != FtpStatusCode.PathnameCreated) { Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceError, String.Format("Unexpected ftp request response. Expected '{0}', but got '{1}'. Check profile settings. Throwing...", FtpStatusCode.PathnameCreated.ToString(), ftpResponse.StatusCode), TraceCategory); throw new SyncException(Resources.ExceptionMsg_SyncTestFailed); } Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceVerbose, "Sync test successful.", TraceCategory); } } catch (SyncException) { throw; } catch (Exception e) { throw new SyncException(e.Message, e); } }
public SaveEventArgs(RoamingProfile profile, RoamingProfile originalProfile, ProfileEditor.EditingMode mode) { if (profile == null) throw new ArgumentNullException("profile"); this.profile = profile; this.originalProfile = originalProfile; this.commitMode = mode; }
public ProvisioningContainer(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); this.profile = profile; Contents = new ContentCollection(); }
public static HttpWebRequest CreateWebRequest(RoamingProfile profile, Uri remoteUri) { HttpWebRequest request = WebRequest.Create(remoteUri) as HttpWebRequest; if (request == null) throw new FormatException(Resources.ExceptionMsg_RemoteUriNotSupported); return request; }
private void PerformLocalSiteSync(RoamingProfile profile) { using (Stream dbStream = File.Create(Context.ProfilePath)) { // TODO if (!Adapter.PullFile(profile, profile.RemoteHost, dbStream)) throw new Exception(); } }
public override void SyncRemoteSite(RoamingProfile profile) { base.SyncRemoteSite(profile); if (!CanSyncRemoteSite) return; Context.Manifest.Publish(profile); }
public override void SyncLocalSite(RoamingProfile profile) { string remoteLegacyManifestPath = profile.RemoteHost + LegacyManifestExtension; if (Adapter.FileExists(profile, remoteLegacyManifestPath)) throw new DeltaSyncException(Resources.ExceptionMsg_LegacyManifestFound); base.SyncLocalSite(profile); }
public static bool PresentModal(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); using (ProfileEditingDialog dlg = new ProfileEditingDialog(profile)) { dlg.ShowDialog(); return dlg.ProfileChanged; } }
private void ProfileEditor_Save(object sender, ProfileEditor.SaveEventArgs e) { RoamingConfiguration configuration = RoamiePlugin.Singleton.RoamingContext.Configuration; ProfileCollection profiles = configuration.ProfileManager.Profiles; profiles.Add((CreatedProfile = e.Profile)); configuration.Save(); Close(); }
public virtual void SyncRemoteSite(RoamingProfile profile) { if (!CanSyncRemoteSite) { // TODO Log //Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceInfo, "Sandbox mode is active, no synchronization required.", ""); NonSyncShutdown(); } else if (Context.IsInState(RoamingState.ForceFullSync)) { PerformRemoteSiteSync(profile); } }
public void Publish(RoamingProfile profile) { ISiteAdapter adapter = profile.GetProvider().Adapter; using (MemoryStream containerStream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(containerStream, this); containerStream.Seek(0, SeekOrigin.Begin); ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_PublishingContent, SignificantProgress.Running); adapter.PushFile(profile, containerStream, GetRemoteManifestPath(profile), true); } }
public bool FileExists(RoamingProfile profile, string remotePath) { try { HttpWebRequest req = HttpRequestFactory.CreateWebRequest(profile, new Uri(remotePath)); using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) return resp.StatusCode == HttpStatusCode.OK; } catch { return false; } }
public override void SyncLocalSite(RoamingProfile profile) { base.SyncLocalSite(profile); DeltaEngine.Initialize(Context.ProfilePath); string remoteDeltaPath = GetRemoteDeltaPath(profile); if (!Adapter.FileExists(profile, remoteDeltaPath)) return; using (Stream deltaStream = DeltaEngine.CreateLocalDeltaFile()) Adapter.PullFile(profile, remoteDeltaPath, deltaStream); DeltaEngine.ApplyDelta(); }
public bool FileExists(RoamingProfile profile, string remotePath) { try { FtpWebRequest req = FtpRequestFactory.CreateRequest(WebRequestMethods.Ftp.DownloadFile, profile, new Uri(remotePath)); using (FtpWebResponse resp = (FtpWebResponse)req.GetResponse()) { bool exists = (resp.StatusCode == FtpStatusCode.OpeningData || resp.StatusCode == FtpStatusCode.DataAlreadyOpen); return exists; } } catch (Exception) { // TODO Log return false; } }
public static FtpWebRequest CreateRequest(string method, RoamingProfile profile, Uri remoteAddress) { FtpWebRequest ftpRequest = WebRequest.Create(remoteAddress) as FtpWebRequest; if (ftpRequest == null) throw new FormatException(Resources.ExceptionMsg_RemoteUriNotSupported); ftpRequest.Credentials = new NetworkCredential(profile.UserName, profile.Password); ftpRequest.UseBinary = true; ftpRequest.Proxy = null; ftpRequest.Method = method; ftpRequest.UsePassive = true; ftpRequest.KeepAlive = false; ftpRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceVerbose, "Ftp request created: " + String.Format("Url = '{0}', Method = '{1}', UsePassive = '{2}', UserName = '******', CachePolicy = '{4}'.", remoteAddress, method, ftpRequest.UsePassive, profile.UserName, ftpRequest.CachePolicy), FtpProvider.TraceCategory); return ftpRequest; }
public override void SyncRemoteSite(RoamingProfile profile) { base.SyncRemoteSite(profile); if (!CanSyncRemoteSite) return; string remoteDeltaPath = GetRemoteDeltaPath(profile); if (!UseDeltaSync) { Adapter.DeleteFile(profile, remoteDeltaPath); return; } ProgressMediator.ChangeProgress("Computing delta, this may take a while...", SignificantProgress.Running); using (Stream deltaStream = DeltaEngine.ComputeDelta()) Adapter.PushFile(profile, deltaStream, remoteDeltaPath, false); }
public override void SyncLocalSite(RoamingProfile profile) { base.SyncLocalSite(profile); try { Container = ProvisioningContainer.Load(profile); Container.Deploy(); } catch { ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_CannotGetAttachedContainer); Container = new ProvisioningContainer(profile); } finally { if (Container != null) Container.Dispose(); } }
public static Manifest Load(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); ISiteAdapter adapter = profile.GetProvider().Adapter; string remoteManifestPath = GetRemoteManifestPath(profile); if (!adapter.FileExists(profile, remoteManifestPath)) return new Manifest(); using (MemoryStream containerStream = new MemoryStream()) { adapter.PullFile(profile, remoteManifestPath, containerStream); BinaryFormatter formatter = new BinaryFormatter(); Manifest container = (Manifest)formatter.Deserialize(containerStream); return container; } }
public override void VerifyProfile(RoamingProfile profile) { try { HttpWebRequest request = HttpRequestFactory.CreateWebRequest(profile); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode != HttpStatusCode.OK || response.ContentType.ToLowerInvariant().StartsWith("text/htm")) throw new SyncException(Resources.ExceptionMsg_SyncTestFailed_NotFound); } } catch (SyncException) { throw; } catch (Exception e) { throw new SyncException(Resources.ExceptionMsg_SyncTestFailed, e); } }
public void PushFile(RoamingProfile profile, Stream sourceStream, string remotePath, bool reliable) { Uri remoteUri = new Uri(remotePath); Uri tempRemoteUri = (reliable ? new Uri(remotePath + ".tmp") : remoteUri); // First upload new database as *.tmp file (to preserve original database if the transfer fails) FtpWebRequest ftpRequest = FtpRequestFactory.CreateRequest(WebRequestMethods.Ftp.UploadFile, profile, tempRemoteUri); using (Stream remoteStream = ftpRequest.GetRequestStream(), protectedStream = new MemoryStream()) { ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_CompressingEncrypting, SignificantProgress.Running); StreamUtility.CompressAndEncrypt(sourceStream, protectedStream, profile.DatabasePassword); ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_Uploading, SignificantProgress.Stopped); protectedStream.Seek(0, SeekOrigin.Begin); StreamUtility.CopyStream(protectedStream, remoteStream, progress => ProgressMediator.ChangeProgress(null, progress)); } GetAndVerifyFtpResponse(ftpRequest, FtpStatusCode.ClosingData, true); if (reliable) { ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_Finishing, SignificantProgress.Running); // Now delete any previous existing *.dat profiles DeleteFile(profile, remoteUri); // Lastly rename *.tmp to *.dat ftpRequest = FtpRequestFactory.CreateRequest(WebRequestMethods.Ftp.Rename, profile, tempRemoteUri); ftpRequest.RenameTo = remoteUri.Segments[remoteUri.Segments.Length - 1]; GetAndVerifyFtpResponse(ftpRequest, FtpStatusCode.FileActionOK, true); } ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_Completed, SignificantProgress.Complete); }
public bool PullFile(RoamingProfile profile, string remotePath, Stream outputStream) { FtpWebRequest ftpFileRequest = FtpRequestFactory.CreateRequest(WebRequestMethods.Ftp.DownloadFile, profile, new Uri(remotePath)); int? fileSize = FtpRequestFactory.GetFileSize(ftpFileRequest); if (fileSize.GetValueOrDefault() <= 0) { // TODO Log //Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceError, "The FTP SIZE response says the remote file length is 0 bytes. This indicates the file is corrupted. Aborting download.", "Roamie"); return false; } using (FtpWebResponse ftpFileResponse = (FtpWebResponse) ftpFileRequest.GetResponse()) { using (Stream remoteStream = ftpFileResponse.GetResponseStream(), downloadedStream = new MemoryStream()) { ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_DownloadingDb, SignificantProgress.Running); var source = new UndisposableStream(remoteStream, fileSize); var progressCallback = (fileSize != null ? (progress => ProgressMediator.ChangeProgress(null, progress)) : (StreamUtility.ProgressCallback) null); StreamUtility.CopyStream(source, downloadedStream, progressCallback); ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_DecryptingDecompressing, SignificantProgress.Running); downloadedStream.Seek(0, SeekOrigin.Begin); StreamUtility.DecryptAndDecompress(downloadedStream, outputStream, profile.DatabasePassword); outputStream.Seek(0, SeekOrigin.Begin); } } ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_Completed, SignificantProgress.Complete); return true; }
public bool PullFile(RoamingProfile profile, string remotePath, Stream outputStream) { HttpWebRequest request = HttpRequestFactory.CreateWebRequest(profile, new Uri(remotePath)); if (!String.IsNullOrEmpty(profile.UserName)) request.Credentials = new NetworkCredential(profile.UserName, profile.Password); using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { long? fileSize = response.ContentLength > 0 ? response.ContentLength : (long?) null; if (fileSize.GetValueOrDefault() <= 0) return false; using (Stream remoteStream = response.GetResponseStream(), downloadedStream = new MemoryStream()) { ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_DownloadingDb, SignificantProgress.Running); var source = new UndisposableStream(remoteStream, fileSize); var progressCallback = (fileSize != null ? (progress => ProgressMediator.ChangeProgress(null, progress)) : (StreamUtility.ProgressCallback) null); StreamUtility.CopyStream(source, downloadedStream, progressCallback); ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_CompressingEncrypting, SignificantProgress.Running); downloadedStream.Seek(0, SeekOrigin.Begin); StreamUtility.DecryptAndDecompress(downloadedStream, outputStream, profile.DatabasePassword); outputStream.Seek(0, SeekOrigin.Begin); } } ProgressMediator.ChangeProgress(Resources.Text_UI_LogText_Completed, SignificantProgress.Complete); return true; }
public override void SyncRemoteSite(RoamingProfile profile) { base.SyncRemoteSite(profile); if (!CanSyncRemoteSite) return; if (Container == null || Container.Contents.Count == 0) return; try { Container.Publish(); Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceInfo, "Attached files synchronization completed.", RoamiePlugin.TraceCategory); } catch (Exception e) { Trace.WriteLineIf(RoamiePlugin.TraceSwitch.TraceInfo, "Attached files synchronization failed. " + e, RoamiePlugin.TraceCategory); } finally { Container.Dispose(); } }
private ProfileEditingDialog(RoamingProfile profile) : base(profile) { InitializeComponent(); }
public override void SyncLocalSite(RoamingProfile profile) { Context.Manifest = Manifest.Load(profile); base.SyncLocalSite(profile); }
public static ProvisioningContainer Load(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); ISiteAdapter adapter = profile.GetProvider().Adapter; string containerPath = GetContainerPath(profile); if (!adapter.FileExists(profile, containerPath)) return new ProvisioningContainer(profile); using (MemoryStream containerStream = new MemoryStream()) { adapter.PullFile(profile, containerPath, containerStream); BinaryFormatter formatter = new BinaryFormatter(); ProvisioningContainer container = (ProvisioningContainer)formatter.Deserialize(containerStream); container.profile = profile; return container; } }
public override void SyncRemoteSite(RoamingProfile profile) { Provider.NonSyncShutdown(); Provider.RemoveLocalSiteData(); }
// TODO Into separate class! public static void TestModal(RoamingProfile profile) { if (profile == null) throw new ArgumentNullException("profile"); try { RunModal(delegate { profile.GetProvider().VerifyProfile(profile); return null; }); MessageBox.Show(Resources.MsgBox_Text_TestSuccessful, Resources.MsgBox_Title_TestSuccessful, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { } }