public Crawler Fetch() { if (!IsExternalIPAddress(SourceUrl)) { State = "INVALID_URL"; return(this); } var request = new HttpClient(); try { ServerUrl = PathFormatter.Format(Path.GetFileName(SourceUrl), Config.GetString("catcherPathFormat")); var savePath = Path.Combine(WebRootPath, ServerUrl.Replace('/', Path.DirectorySeparatorChar)); if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } var stream = request.GetStreamAsync(SourceUrl).Result; using (var fs = new FileStream(savePath, FileMode.OpenOrCreate)) { stream.CopyToAsync(fs).Wait(); } State = "SUCCESS"; return(this); } catch (Exception e) { State = e.Message; return(this); } }
private string GetFullPath(string cloudPath, string cloudFileName) { string serverUrl = ServerUrl.Replace("/dispatcherv2", ""); return(serverUrl + "/downloader/bc/g/" + _bc.Client.AppId + "/u/" + _bc.Client.AuthenticationService.ProfileId + "/f/" + cloudPath + "/" + cloudFileName); }
public Crawler Fetch() { var request = HttpWebRequest.Create(this.SourceUrl) as HttpWebRequest; using (var response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { State = "Url returns " + response.StatusCode + ", " + response.StatusDescription; return(this); } if (response.ContentType.IndexOf("image") == -1) { State = "Url is not an image"; return(this); } ServerUrl = PathFormatter.Format(Path.GetFileName(this.SourceUrl), Config.GetString("catcherPathFormat")); var savePath = Server.MapPath("/") + ServerUrl.Replace("/", "\\"); //Server.MapPath(ServerUrl); if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } try { var stream = response.GetResponseStream(); var reader = new BinaryReader(stream); byte[] bytes; using (var ms = new MemoryStream()) { byte[] buffer = new byte[4096]; int count; while ((count = reader.Read(buffer, 0, buffer.Length)) != 0) { ms.Write(buffer, 0, count); } bytes = ms.ToArray(); } File.WriteAllBytes(savePath, bytes); State = "SUCCESS"; } catch (Exception e) { State = "抓取错误:" + e.Message; } return(this); } }
public override MsDataFileImpl OpenMsDataFile(bool simAsSpectra, int preferOnlyMsLevel) { var account = FindMatchingAccount(Settings.Default.RemoteAccountList) as UnifiAccount; if (account == null) { throw new RemoteServerException(string.Format(Resources.UnifiUrl_OpenMsDataFile_Cannot_find_account_for_username__0__and_server__1__, Username, ServerUrl)); } // ReSharper disable NonLocalizedString string serverUrl = ServerUrl.Replace("://", "://" + account.Username + ":" + account.Password + "@"); serverUrl += "/unifi/v1/sampleresults(" + Id + ")?"; serverUrl += "identity=" + Uri.EscapeDataString(account.IdentityServer) + "&scope=" + Uri.EscapeDataString(account.ClientScope) + "&secret=" + Uri.EscapeDataString(account.ClientSecret); // ReSharper restore NonLocalizedString return(new MsDataFileImpl(serverUrl, 0, LockMassParameters, simAsSpectra, requireVendorCentroidedMS1: CentroidMs1, requireVendorCentroidedMS2: CentroidMs2, ignoreZeroIntensityPoints: true, preferOnlyMsLevel: preferOnlyMsLevel)); }
public override MsDataFileImpl OpenMsDataFile(bool simAsSpectra, int preferOnlyMsLevel, IEnumerable <MsDataFileImpl.PrecursorMzAndIonMobilityWindow> precursorMzAndIonMobilityWindows, bool ignoreZeroIntensityPoints) { var account = FindMatchingAccount(Settings.Default.RemoteAccountList) as UnifiAccount; if (account == null) { throw new RemoteServerException(string.Format(Resources.UnifiUrl_OpenMsDataFile_Cannot_find_account_for_username__0__and_server__1__, Username, ServerUrl)); } // ReSharper disable LocalizableElement string serverUrl = ServerUrl.Replace("://", "://" + account.Username + ":" + account.Password + "@"); serverUrl += "/unifi/v1/sampleresults(" + Id + ")?"; serverUrl += "identity=" + Uri.EscapeDataString(account.IdentityServer) + "&scope=" + Uri.EscapeDataString(account.ClientScope) + "&secret=" + Uri.EscapeDataString(account.ClientSecret); // ReSharper restore LocalizableElement return(new MsDataFileImpl(serverUrl, 0, LockMassParameters, simAsSpectra, requireVendorCentroidedMS1: CentroidMs1, requireVendorCentroidedMS2: CentroidMs2, ignoreZeroIntensityPoints: ignoreZeroIntensityPoints, preferOnlyMsLevel: preferOnlyMsLevel, combineIonMobilitySpectra: false, // CONSIDER: 3-array ims for unifi? precursorMzAndIonMobilityWindows: precursorMzAndIonMobilityWindows)); }
public override void Open() { base.Open(); if (base.CallOptionsValue != null) { CallOptions = new SfdcConnect.ApexObjects.CallOptions(); CallOptions.Actor = base.CallOptionsValue.Actor; CallOptions.client = base.CallOptionsValue.client; CallOptions.DidUnderstand = base.CallOptionsValue.DidUnderstand; CallOptions.EncodedMustUnderstand = base.CallOptionsValue.EncodedMustUnderstand; CallOptions.EncodedMustUnderstand12 = base.CallOptionsValue.EncodedMustUnderstand12; CallOptions.EncodedRelay = base.CallOptionsValue.EncodedRelay; CallOptions.MustUnderstand = base.CallOptionsValue.MustUnderstand; CallOptions.Relay = base.CallOptionsValue.Relay; CallOptions.Role = base.CallOptionsValue.Role; } if (base.SessionHeaderValue != null) { SessionHeader = new SfdcConnect.ApexObjects.SessionHeader(); SessionHeader.Actor = base.SessionHeaderValue.Actor; SessionHeader.sessionId = base.SessionHeaderValue.sessionId; SessionHeader.DidUnderstand = base.SessionHeaderValue.DidUnderstand; SessionHeader.EncodedMustUnderstand = base.SessionHeaderValue.EncodedMustUnderstand; SessionHeader.EncodedMustUnderstand12 = base.SessionHeaderValue.EncodedMustUnderstand12; SessionHeader.EncodedRelay = base.SessionHeaderValue.EncodedRelay; SessionHeader.MustUnderstand = base.SessionHeaderValue.MustUnderstand; SessionHeader.Relay = base.SessionHeaderValue.Relay; SessionHeader.Role = base.SessionHeaderValue.Role; } Uri url = new Uri(ServerUrl); this.Url = ServerUrl.Replace("Soap/u/", "Soap/s/");// + this.ApiEndPoint.Segments[this.ApiEndPoint.Segments.Length - 1]; }