Esempio n. 1
0
        protected override Task PutAttachment(AttachmentExportInfo attachmentExportInfo)
        {
            if (attachmentExportInfo != null)
            {
                var url     = ("/static/" + attachmentExportInfo.Key).NoCache();
                var request = commands.CreateRequest(url, "PUT");
                if (attachmentExportInfo.Metadata != null)
                {
                    foreach (var header in attachmentExportInfo.Metadata)
                    {
                        switch (header.Key)
                        {
                        case "Content-Type":
                            // request.httpClient.DefaultHeaders = header.Value.Value<string>();
                            break;

                        default:
                            // request.Headers.Add(header.Key, StripQuotesIfNeeded(header.Value));
                            break;
                        }
                    }
                }

                return(request
                       .ExecuteWriteAsync(attachmentExportInfo.Data));
            }

            return(FlushBatch());
        }
 public async Task PutAttachment(AttachmentExportInfo attachmentExportInfo)
 {
     if (attachmentExportInfo != null)
     {
         await Store.AsyncDatabaseCommands.PutAttachmentAsync(attachmentExportInfo.Key, null, attachmentExportInfo.Data, attachmentExportInfo.Metadata).ConfigureAwait(false);
     }
 }
Esempio n. 3
0
        protected override Task PutAttachment(AttachmentExportInfo attachmentExportInfo)
        {
            if (attachmentExportInfo != null)
            {
                var request = CreateRequest("/static/" + attachmentExportInfo.Key, "PUT");
                if (attachmentExportInfo.Metadata != null)
                {
                    foreach (var header in attachmentExportInfo.Metadata)
                    {
                        switch (header.Key)
                        {
                        case "Content-Type":
                            request.WebRequest.ContentType = header.Value.Value <string>();
                            break;

                        default:
                            request.WebRequest.Headers.Add(header.Key, StripQuotesIfNeeded(header.Value));
                            break;
                        }
                    }
                }

                request.Write(attachmentExportInfo.Data);
                request.ExecuteRequest();
            }

            return(new CompletedTask());
        }
 public async Task PutAttachment(RavenConnectionStringOptions dst, AttachmentExportInfo attachmentExportInfo)
 {
     if (attachmentExportInfo != null)
     {
         await Store.AsyncDatabaseCommands.PutAttachmentAsync(attachmentExportInfo.Key, null, attachmentExportInfo.Data, attachmentExportInfo.Metadata);
     }
 }
Esempio n. 5
0
 protected override void PutAttachment(AttachmentExportInfo attachmentExportInfo)
 {
     // we filter out content length, because getting it wrong will cause errors
     // in the server side when serving the wrong value for this header.
     // worse, if we are using http compression, this value is known to be wrong
     // instead, we rely on the actual size of the data provided for us
     attachmentExportInfo.Metadata.Remove("Content-Length");
     _database.PutStatic(attachmentExportInfo.Key, null, new MemoryStream(attachmentExportInfo.Data), attachmentExportInfo.Metadata);
 }
        public Task PutAttachment(RavenConnectionStringOptions dst, AttachmentExportInfo attachmentExportInfo)
        {
            if (attachmentExportInfo != null)
            {
                // we filter out content length, because getting it wrong will cause errors
                // in the server side when serving the wrong value for this header.
                // worse, if we are using http compression, this value is known to be wrong
                // instead, we rely on the actual size of the data provided for us
                attachmentExportInfo.Metadata.Remove("Content-Length");
                database.Attachments.PutStatic(attachmentExportInfo.Key, null, attachmentExportInfo.Data,
                                               attachmentExportInfo.Metadata);
            }

            return(new CompletedTask());
        }
        private async Task <Etag> ExportAttachments(ISmugglerDatabaseOperations exportOperations, ISmugglerDatabaseOperations importOperations, SmugglerDatabaseOptions databaseOptions)
        {
            Etag lastEtag   = databaseOptions.StartAttachmentsEtag;
            int  totalCount = 0;

            while (true)
            {
                try
                {
                    if (databaseOptions.Limit - totalCount <= 0)
                    {
                        await importOperations.PutAttachment(null).ConfigureAwait(false); // force flush

                        ShowProgress("Done with reading attachments, total: {0}", totalCount);
                        return(lastEtag);
                    }
                    var maxRecords  = Math.Min(databaseOptions.Limit - totalCount, databaseOptions.BatchSize);
                    var attachments = await exportOperations.GetAttachments(totalCount, lastEtag, maxRecords).ConfigureAwait(false);

                    if (attachments.Count == 0)
                    {
                        var databaseStatistics = await exportOperations.GetStats().ConfigureAwait(false);

                        if (lastEtag == null)
                        {
                            lastEtag = Etag.Empty;
                        }
                        if (lastEtag.CompareTo(databaseStatistics.LastAttachmentEtag) < 0)
                        {
                            lastEtag = EtagUtil.Increment(lastEtag, maxRecords);
                            ShowProgress("Got no results but didn't get to the last attachment etag, trying from: {0}",
                                         lastEtag);
                            continue;
                        }
                        ShowProgress("Done with reading attachments, total: {0}", totalCount);
                        return(lastEtag);
                    }

                    totalCount += attachments.Count;
                    ShowProgress("Reading batch of {0,3} attachments, read so far: {1,10:#,#;;0}", attachments.Count, totalCount);

                    foreach (var attachment in attachments)
                    {
                        var attachmentData = await exportOperations.GetAttachmentData(attachment).ConfigureAwait(false);

                        if (attachmentData == null)
                        {
                            continue;
                        }

                        var attachmentToExport = new AttachmentExportInfo
                        {
                            Key      = attachment.Key,
                            Metadata = attachment.Metadata,
                            Data     = new MemoryStream(attachmentData)
                        };

                        if (databaseOptions.StripReplicationInformation)
                        {
                            attachmentToExport.Metadata = StripReplicationInformationFromMetadata(attachmentToExport.Metadata);
                        }

                        await importOperations.PutAttachment(attachmentToExport).ConfigureAwait(false);

                        lastEtag = attachment.Etag;
                    }
                }
                catch (Exception e)
                {
                    ShowProgress("Got Exception during smuggler export. Exception: {0}. ", e.Message);
                    ShowProgress("Done with reading attachments, total: {0}", totalCount, lastEtag);
                    throw new SmugglerExportException(e.Message, e)
                          {
                              LastEtag = lastEtag,
                          };
                }
            }
        }
Esempio n. 8
0
 protected abstract Task PutAttachment(AttachmentExportInfo attachmentExportInfo);
Esempio n. 9
0
		protected override void PutAttachment(AttachmentExportInfo attachmentExportInfo)
		{
			// we filter out content length, because getting it wrong will cause errors 
			// in the server side when serving the wrong value for this header.
			// worse, if we are using http compression, this value is known to be wrong
			// instead, we rely on the actual size of the data provided for us
			attachmentExportInfo.Metadata.Remove("Content-Length");
			_database.PutStatic(attachmentExportInfo.Key, null, new MemoryStream(attachmentExportInfo.Data), attachmentExportInfo.Metadata);
		}
Esempio n. 10
0
 protected abstract Task PutAttachment(RavenConnectionStringOptions dst, AttachmentExportInfo attachmentExportInfo);
Esempio n. 11
0
		protected abstract void PutAttachment(AttachmentExportInfo attachmentExportInfo);
Esempio n. 12
0
		protected abstract Task PutAttachment(AttachmentExportInfo attachmentExportInfo);
Esempio n. 13
0
		protected override Task PutAttachment(RavenConnectionStringOptions dst ,AttachmentExportInfo attachmentExportInfo)
		{
			if (attachmentExportInfo != null)
			{
				var request = CreateRequest(dst, "/static/" + attachmentExportInfo.Key, "PUT");
				if (attachmentExportInfo.Metadata != null)
				{
					foreach (var header in attachmentExportInfo.Metadata)
					{
						switch (header.Key)
						{
							case "Content-Type":
								request.WebRequest.ContentType = header.Value.Value<string>();
								break;
							default:
								request.WebRequest.Headers.Add(header.Key, StripQuotesIfNeeded(header.Value));
								break;
						}
					}
				}

				request.Write(attachmentExportInfo.Data);
				request.ExecuteRequest();
			}

			return new CompletedTask();
		}
Esempio n. 14
0
 protected abstract void PutAttachment(AttachmentExportInfo attachmentExportInfo);
Esempio n. 15
0
		protected override void PutAttachment(AttachmentExportInfo attachmentExportInfo)
		{
			var request = CreateRequest("/static/" + attachmentExportInfo.Key, "PUT");
			if (attachmentExportInfo.Metadata != null)
			{
				foreach (var header in attachmentExportInfo.Metadata)
				{
					switch (header.Key)
					{
						case "Content-Type":
							request.WebRequest.ContentType = header.Value.Value<string>();
							break;
						default:
							request.WebRequest.Headers.Add(header.Key, StripQuotesIfNeeded(header.Value));
							break;
					}
				}
			}

			request.Write(attachmentExportInfo.Data);
			request.ExecuteRequest();

		}
Esempio n. 16
0
		protected override Task PutAttachment(RavenConnectionStringOptions dst, AttachmentExportInfo attachmentExportInfo)
		{
			if (attachmentExportInfo != null)
			{
				// we filter out content length, because getting it wrong will cause errors 
				// in the server side when serving the wrong value for this header.
				// worse, if we are using http compression, this value is known to be wrong
				// instead, we rely on the actual size of the data provided for us
				attachmentExportInfo.Metadata.Remove("Content-Length");
				database.Attachments.PutStatic(attachmentExportInfo.Key, null, attachmentExportInfo.Data,
									attachmentExportInfo.Metadata);
			}

			return new CompletedTask();
		}
Esempio n. 17
0
		protected override Task PutAttachment(AttachmentExportInfo attachmentExportInfo)
		{
			if (attachmentExportInfo != null)
			{
				var url = ("/static/" + attachmentExportInfo.Key).NoCache();
				var request = commands.CreateRequest(url, "PUT");
				if (attachmentExportInfo.Metadata != null)
				{
					foreach (var header in attachmentExportInfo.Metadata)
					{
						switch (header.Key)
						{
							case "Content-Type":
								request.ContentType = header.Value.Value<string>();
								break;
							default:
								request.Headers[header.Key] = StripQuotesIfNeeded(header.Value);
								break;
						}
					}
				}

				return request
					.ExecuteWriteAsync(attachmentExportInfo.Data);
			}

			return FlushBatch();
		}
Esempio n. 18
0
 protected abstract Task PutAttachment(RavenConnectionStringOptions dst, AttachmentExportInfo attachmentExportInfo);