public bool InitBackup() { ServerUrl = ServerUrl.TrimEnd('/'); store = new DocumentStore { Url = ServerUrl, DefaultDatabase = Database, ApiKey = ApiKey }; store.Initialize(); var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }"; var url = "/admin/backup"; if (Incremental) { url += "?incremental=true"; } var req = CreateRequest(url, "POST"); req.Write(json); try { Console.WriteLine("Sending json {0} to {1}", json, ServerUrl); var response = req.ReadResponseJson(); Console.WriteLine(response); } catch (Exception exc) { Console.WriteLine(exc.Message); return(false); } return(true); }
public bool InitBackup() { ServerUrl = ServerUrl.TrimEnd('/'); var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }"; var uriString = ServerUrl + "/admin/backup"; if (Incremental) { uriString += "?incremental=true"; } var req = WebRequest.Create(uriString); req.Method = "POST"; req.UseDefaultCredentials = true; req.PreAuthenticate = true; req.Credentials = CredentialCache.DefaultCredentials; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.WriteLine(json); streamWriter.Flush(); } try { Console.WriteLine("Sending json {0} to {1}", json, ServerUrl); using (var resp = req.GetResponse()) using (var reader = new StreamReader(resp.GetResponseStream())) { var response = reader.ReadToEnd(); Console.WriteLine(response); } } catch (WebException we) { var response = we.Response as HttpWebResponse; if (response == null) { Console.WriteLine(we.Message); return(false); } Console.WriteLine(response.StatusCode + " " + response.StatusDescription); using (var reader = new StreamReader(response.GetResponseStream())) { Console.WriteLine(reader.ReadToEnd()); return(false); } } catch (Exception exc) { Console.WriteLine(exc.Message); return(false); } return(true); }
public void Move(string moveWhat, string moveTo) { string fullMoveTo = ServerUrl.TrimEnd("/".ToCharArray()) + moveTo.TrimEnd("/".ToCharArray()) + "/" + Path.GetFileName(moveWhat); IDictionary <string, string> headers = new Dictionary <string, string> { { "Destination", fullMoveTo } }; SendRequest(moveWhat, "MOVE", null, null, headers); }
public void Copy(string copyWhat, string copyTo) { string fullCopyToUrl = ServerUrl.TrimEnd("/".ToCharArray()) + copyTo.TrimEnd("/".ToCharArray()) + "/" + Path.GetFileName(copyWhat); IDictionary <string, string> headers = new Dictionary <string, string> { { "Destination", fullCopyToUrl } }; SendRequest(copyWhat, "COPY", null, null, headers); }
public bool InitBackup() { ServerUrl = ServerUrl.TrimEnd('/'); var json = @"{ ""BackupLocation"": """ + BackupPath.Replace("\\", "\\\\") + @""" }"; var req = WebRequest.Create(ServerUrl + "/admin/backup"); req.Method = "POST"; req.UseDefaultCredentials = true; req.PreAuthenticate = true; req.Credentials = CredentialCache.DefaultCredentials; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.WriteLine(json); streamWriter.Flush(); } try { Console.WriteLine(string.Format("Sending json {0} to {1}", json, ServerUrl)); using (var resp = req.GetResponse()) using (var reader = new StreamReader(resp.GetResponseStream())) { var response = reader.ReadToEnd(); Console.WriteLine(response); } } catch (Exception exc) { Console.WriteLine(exc.Message); return(false); } return(true); }
public bool InitBackup() { ServerUrl = ServerUrl.TrimEnd('/'); try //precaution - to show error properly just in case { var serverUri = new Uri(ServerUrl); if ((String.IsNullOrWhiteSpace(serverUri.PathAndQuery) || serverUri.PathAndQuery.Equals("/")) && String.IsNullOrWhiteSpace(Database)) { Database = Constants.SystemDatabase; } var serverHostname = serverUri.Scheme + Uri.SchemeDelimiter + serverUri.Host + ":" + serverUri.Port; store = new DocumentStore { Url = serverHostname, DefaultDatabase = Database, ApiKey = ApiKey }; store.Initialize(); } catch (Exception exc) { Console.WriteLine(exc.Message); try { store.Dispose(); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } return(false); } var backupRequest = new { BackupLocation = BackupPath.Replace("\\", "\\\\"), DatabaseDocument = new DatabaseDocument { Id = Database } }; var json = RavenJObject.FromObject(backupRequest).ToString(); var url = "/admin/backup"; if (Incremental) { url += "?incremental=true"; } try { var req = CreateRequest(url, "POST"); req.WriteAsync(json).Wait(); Console.WriteLine("Sending json {0} to {1}", json, ServerUrl); var response = req.ReadResponseJson(); Console.WriteLine(response); } catch (Exception exc) { Console.WriteLine(exc.Message); return(false); } return(true); }
private async Task ExtractDeviceInitInfo() { try { var fileName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location); var codeLength = AppConstants.RelayCodeLength + 2; for (var i = 0; i < fileName.Length; i++) { var guid = string.Join("", fileName.Skip(i).Take(36)); if (Guid.TryParse(guid, out _)) { OrganizationID = guid; return; } var codeSection = string.Join("", fileName.Skip(i).Take(codeLength)); if (codeSection.StartsWith("[") && codeSection.EndsWith("]") && !string.IsNullOrWhiteSpace(ServerUrl)) { var relayCode = codeSection.Substring(1, 4); using (var httpClient = new HttpClient()) { var response = await httpClient.GetAsync($"{ServerUrl}/api/relay/{relayCode}").ConfigureAwait(false); if (response.IsSuccessStatusCode) { var serializer = new JavaScriptSerializer(); var organizationId = await response.Content.ReadAsStringAsync(); OrganizationID = organizationId; break; } } } } if (!string.IsNullOrWhiteSpace(OrganizationID) && !string.IsNullOrWhiteSpace(ServerUrl)) { using (var httpClient = new HttpClient()) { var serializer = new JavaScriptSerializer(); var brandingUrl = $"{ServerUrl.TrimEnd('/')}/api/branding/{OrganizationID}"; using (var response = await httpClient.GetAsync(brandingUrl).ConfigureAwait(false)) { var responseString = await response.Content.ReadAsStringAsync(); _brandingInfo = serializer.Deserialize <BrandingInfo>(responseString); } } } } catch (Exception ex) { Logger.Write(ex); } finally { ApplyBranding(_brandingInfo); } }