public WebClient CreateAuthenticatedWebClient(string remoteUnicornUrl) { var client = new SuperWebClient(RequestTimeoutInMs); client.Headers.Add("Authenticate", CorrectAuthToken); return client; }
public WebClient CreateAuthenticatedWebClient(string remoteUnicornUrl) { var client = new SuperWebClient(RequestTimeoutInMs); client.Headers.Add("Authenticate", CorrectAuthToken); return(client); }
public WebClient CreateAuthenticatedWebClient(string remoteUnicornUrl) { var remoteUri = new Uri(remoteUnicornUrl); var client = new SuperWebClient(RequestTimeoutInMs); // we get a new challenge from the remote Unicorn, which is a unique known value to both parties var challenge = client.DownloadString(remoteUri.GetLeftPart(UriPartial.Path) + "?verb=Challenge"); // then we sign the request using our shared secret combined with the challenge and the URL, providing a unique verifiable hash for the request client.Headers.Add("X-MC-MAC", _signatureService.CreateSignature(challenge, remoteUnicornUrl, Enumerable.Empty <SignatureFactor>()).SignatureHash); // the Unicorn server needs to know the challenge we are using. It makes sure that it issued the challenge before validating it. client.Headers.Add("X-MC-Nonce", challenge); return(client); }
public async Task <SuperWebClient> UploadObject(string container, string remotePath, string localPath, string signature, string maxFileSize, string expires, Action <object, SWCTransferProgressChangedEventArgs> transferProgressChangedCallback, Action <object, SWCTransferCompletedEventArgs> transferCompletedCallback) { SuperWebClient mwc = new SuperWebClient(); /* * mwc.TransferProgressChanged += new SuperWebClient.TransferProgressChangedHandler(transferProgressChangedCallback); * mwc.TransferCompleted += new SuperWebClient.TransferCompletedHandler(transferCompletedCallback); */ mwc.AddValue("max_file_size", maxFileSize); mwc.AddValue("max_file_count", "1"); mwc.AddValue("expires", expires); mwc.AddValue("redirect", ""); mwc.AddValue("signature", signature); mwc.AddValue("name", Path.GetFileName(localPath)); mwc.AddFile("file1", localPath); await mwc.MultipartUploadTaskAsync(this.endpoint + "/" + container + "/" + remotePath); return(mwc); }
public void Process(UnicornSyncBeginPipelineArgs args) { var serializationProvider = args.Configuration.Resolve <ISerializationProvider>(); var logger = args.Configuration.Resolve <ILogger>(); var remotingSerializationProvider = serializationProvider as IRemotingSerializationProvider; if (remotingSerializationProvider == null) { return; } // get package if (string.IsNullOrWhiteSpace(remotingSerializationProvider.RemoteUrl)) { logger.Error("Remoting URL was not set on " + remotingSerializationProvider.GetType().Name + "; cannot update remote."); args.AbortPipeline(); return; } if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host.Equals(new Uri(remotingSerializationProvider.RemoteUrl).Host, StringComparison.OrdinalIgnoreCase)) { logger.Warn("Remoting: Remote URL was local instance - skipping this configuration as it is by definition already synced."); args.SyncIsHandled = true; return; } var lastLoaded = GetLastLoadedTime(args.Configuration.Name); // if you pass the force parameter, we do not use the history engine differential sync if (remotingSerializationProvider.DisableDifferentialSync || (HttpContext.Current != null && HttpContext.Current.Request.QueryString["force"] != null)) { lastLoaded = _unsyncedDateTimeValue; } var url = string.Format("{0}?c={1}&ts={2}", remotingSerializationProvider.RemoteUrl, args.Configuration.Name, lastLoaded); var webClient = new SuperWebClient(); // TODO; add signature to request RemotingPackage package = null; try { logger.Info("Remoting: Downloading updated items from {0} newer than {1}".FormatWith(remotingSerializationProvider.RemoteUrl, lastLoaded.ToLocalTime())); var tempFileName = HostingEnvironment.MapPath("~/temp/" + Guid.NewGuid() + ".zip"); try { webClient.DownloadFile(url, tempFileName); using (var stream = File.OpenRead(tempFileName)) { package = RemotingPackage.FromStream(stream); } } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } WritePackageToProvider(package, args.Configuration); if (package.Manifest.Strategy == RemotingStrategy.Differential) { logger.Info("Remoting: received differential package with {0} changes. Replaying instead of sync.".FormatWith(package.Manifest.HistoryEntries.Length)); var replayer = new DifferentialPackageReplayer(package); if (!replayer.Replay(logger)) { logger.Error("Remoting package replay signalled an error. Aborting."); args.AbortPipeline(); return; } else { args.SyncIsHandled = true; } } else { logger.Info("Remoting: received full package from remote. Deployed and executing sync."); } SetLastLoadedTime(args.Configuration.Name, package.Manifest.LastSynchronized); } finally { // clean up temp files if (package != null) { package.Dispose(); } } }
public void Process(UnicornSyncBeginPipelineArgs args) { var serializationProvider = args.Configuration.Resolve<ISerializationProvider>(); var logger = args.Configuration.Resolve<ILogger>(); var remotingSerializationProvider = serializationProvider as IRemotingSerializationProvider; if (remotingSerializationProvider == null) return; // get package if (string.IsNullOrWhiteSpace(remotingSerializationProvider.RemoteUrl)) { logger.Error("Remoting URL was not set on " + remotingSerializationProvider.GetType().Name + "; cannot update remote."); args.AbortPipeline(); return; } if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host.Equals(new Uri(remotingSerializationProvider.RemoteUrl).Host, StringComparison.OrdinalIgnoreCase)) { logger.Warn("Remoting: Remote URL was local instance - skipping this configuration as it is by definition already synced."); args.SyncIsHandled = true; return; } var lastLoaded = GetLastLoadedTime(args.Configuration.Name); // if you pass the force parameter, we do not use the history engine differential sync if (remotingSerializationProvider.DisableDifferentialSync || (HttpContext.Current != null && HttpContext.Current.Request.QueryString["force"] != null)) { lastLoaded = _unsyncedDateTimeValue; } var url = string.Format("{0}?c={1}&ts={2}", remotingSerializationProvider.RemoteUrl, args.Configuration.Name, lastLoaded); var webClient = new SuperWebClient(); // TODO; add signature to request RemotingPackage package = null; try { logger.Info("Remoting: Downloading updated items from {0} newer than {1}".FormatWith(remotingSerializationProvider.RemoteUrl, lastLoaded.ToLocalTime())); var tempFileName = HostingEnvironment.MapPath("~/temp/" + Guid.NewGuid() + ".zip"); try { webClient.DownloadFile(url, tempFileName); using (var stream = File.OpenRead(tempFileName)) { package = RemotingPackage.FromStream(stream); } } finally { if (File.Exists(tempFileName)) File.Delete(tempFileName); } WritePackageToProvider(package, args.Configuration); if (package.Manifest.Strategy == RemotingStrategy.Differential) { logger.Info("Remoting: received differential package with {0} changes. Replaying instead of sync.".FormatWith(package.Manifest.HistoryEntries.Length)); var replayer = new DifferentialPackageReplayer(package); if (!replayer.Replay(logger)) { logger.Error("Remoting package replay signalled an error. Aborting."); args.AbortPipeline(); return; } else args.SyncIsHandled = true; } else { logger.Info("Remoting: received full package from remote. Deployed and executing sync."); } SetLastLoadedTime(args.Configuration.Name, package.Manifest.LastSynchronized); } finally { // clean up temp files if(package != null) package.Dispose(); } }
public WebClient CreateAuthenticatedWebClient(string remoteUnicornUrl) { var remoteUri = new Uri(remoteUnicornUrl); var client = new SuperWebClient(RequestTimeoutInMs); // we get a new challenge from the remote Unicorn, which is a unique known value to both parties var challenge = client.DownloadString(remoteUri.GetLeftPart(UriPartial.Path) + "?verb=Challenge"); // then we sign the request using our shared secret combined with the challenge and the URL, providing a unique verifiable hash for the request client.Headers.Add("X-MC-MAC", _signatureService.CreateSignature(challenge, remoteUnicornUrl, Enumerable.Empty<SignatureFactor>())); // the Unicorn server needs to know the challenge we are using. It makes sure that it issued the challenge before validating it. client.Headers.Add("X-MC-Nonce", challenge); return client; }