RavenDB backup fails - ravendb

I try to make backup for RavenDB. Especially for this I have console application
var req = WebRequest.Create("http://localhost:8081" + "/admin/backup");
req.Method = "POST";
req.UseDefaultCredentials = true;
req.PreAuthenticate = true;
req.Credentials = CredentialCache.DefaultCredentials;
string postData = "{ 'BackupLocation': 'H:\\\\projects\\\\backup\\\\test' }";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
req.ContentLength = byteArray.Length;
Stream dataStream = req.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = req.GetResponse();
response.Close();
But RavenDB creates several empty folders (in specified location) without anything.
What's wrong?
Edit
Log
2011-12-12 10:42:24.2343;Raven.Storage.Esent.Backup.BackupOperation;Error;Failed to complete backup;"System.IO.FileNotFoundException: Could not find file 'H:\projects\Servers\RavenDB\Data\Tempb35260cb5e394474acbb4c0d8cd3876b\Auto%2fPlaces%2fByPlaceCode.index'.
File name: 'H:\projects\Servers\RavenDB\Data\Tempb35260cb5e394474acbb4c0d8cd3876b\Auto%2fPlaces%2fByPlaceCode.index'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileInfo.get_Length()
at Raven.Database.Backup.DirectoryBackup.Prepare()
at Raven.Storage.Esent.Backup.BackupOperation.Execute(Object ignored)"
2011-12-12 10:42:24.2343;Raven.Storage.Esent.Backup.BackupOperation;Info;Failed to complete backup because: Could not find file 'H:\projects\Servers\RavenDB\Data\Tempb35260cb5e394474acbb4c0d8cd3876b\Auto%2fPlaces%2fByPlaceCode.index'.;
2011-12-12 10:42:24.2343;Raven.Storage.Esent.StorageActions.DocumentStorageActions;Debug;Document with key 'Raven/Backup/Status' was found;
2011-12-12 10:42:24.2343;Raven.Database.DocumentDatabase;Debug;Putting a document with key: Raven/Backup/Status and etag ;
2011-12-12 10:42:24.2343;Raven.Storage.Esent.StorageActions.DocumentStorageActions;Debug;Inserted a new document with key 'Raven/Backup/Status', update: True, ;
2011-12-12 10:42:24.2500;Raven.Storage.Esent.Backup.BackupOperation;Info;Backup completed;
2011-12-12 10:42:24.2500;Raven.Storage.Esent.StorageActions.DocumentStorageActions;Debug;Document with key 'Raven/Backup/Status' was found;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Auto/Places/ByPlaceCode;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.Index.Indexing;Debug;Indexed 0 documents for Auto/Places/ByPlaceCode;
2011-12-12 10:42:24.2500;Raven.Database.DocumentDatabase;Debug;Putting a document with key: Raven/Backup/Status and etag ;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Raven/DocumentCollections;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Raven/DocumentsByEntityName;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.Index.Indexing;Debug;Indexed 0 documents for Raven/DocumentsByEntityName;
2011-12-12 10:42:24.2500;Raven.Database.Indexing.Index.Indexing;Debug;Mapped 0 documents for Raven/DocumentCollections;
2011-12-12 10:42:24.2500;Raven.Storage.Esent.StorageActions.DocumentStorageActions;Debug;Inserted a new document with key 'Raven/Backup/Status', update: True, ;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Auto/Places/ByPlaceCode;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.Index.Indexing;Debug;Indexed 0 documents for Auto/Places/ByPlaceCode;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Raven/DocumentCollections;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.Index.Indexing;Debug;Mapped 0 documents for Raven/DocumentCollections;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.AbstractIndexingExecuter;Debug;Indexing 1 documents for index: Raven/DocumentsByEntityName;
2011-12-12 10:42:24.2656;Raven.Database.Indexing.Index.Indexing;Debug;Indexed 0 documents for Raven/DocumentsByEntityName;

Related

Error on HTTP response when exporting PDF file

I've been stuck with this question for a while, already tried several variations of the code but always with the same error. The error is "Server cannot set content type after HTTP headers have been sent."
I create my pdf with pdfptables, I suspect it is trying to export before it generates the Document but I have no clue. This is the last part of the code:
string filename = String.Format("productionstagereport-{0}", DateTime.Now.ToString("yyyyMMdd"));
MemoryStream ms = new MemoryStream();
Document document = new Document(PageSize.A4.Rotate());
document.Open();
foreach (PdfPTable content in masterTable)
document.Add(content);
document.Close();
PdfWriter writer = PdfWriter.GetInstance(document, ms);
writer.Close();
Response.ContentType = "pdf/application";
Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".pdf");
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
Response.Flush();

/AF reference to file embedded into a PDF with iTextSharp

I am struggling to include into the PDF Catalog an "/AF" reference to an Embedded File object just added by the iTextSharp library. The following code works, but the string literal PdfLiteral("[2 0 R]") is unbearable, because the reference to an embedded file may of course have any other number than "2 0":
PdfReader reader = new PdfReader("C:\\ZUGFeRD\\zugferd_2p1_EN16931_Einfach_stripped.pdf");
FileStream outputstream = new FileStream("C:\\ZUGFeRD\\zugferd_2p1_EN16931_Einfach2.pdf", FileMode.Create);
PdfStamper stamp = new PdfStamper(reader, outputstream);
PdfWriter writer = stamp.Writer;
byte[] bytes = System.IO.File.ReadAllBytes("C:\\ZUGFeRD\\factur-x.xml");
// Sample spec: Desc(factur-x.xml) / EF <</ UF 4 0 R / F 4 0 R >>/ Type / Filespec / AFRelationship / Alternative / F(factur-x.xml) / UF(factur - x.xml)
PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(writer, "", "factur-x.xml", bytes, false, "text/xml", null);
fs.Put(PdfName.AFRELATIONSHIP, new PdfName("Source"));
stamp.AddFileAttachment("factur-x.xml", fs);
stamp.Writer.ExtraCatalog.Put(PdfName.AF, new PdfLiteral("[2 0 R]"));
stamp.Close();
How can I write it better?

AES-GCM decryption error iaik.cms.CMSException: Unable to decrypt encrypted content-encryption key: Invalid padding

I am using following code to encrypt data using AES-GCM:
// the stream to which to write the EnvelopedData
ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
EnvelopedDataOutputStream envelopedData;
// wrap EnvelopedData into a ContentInfo
ContentInfoOutputStream contentInfoStream =
new ContentInfoOutputStream(ObjectID.cms_envelopedData, resultStream);
// create a new EnvelopedData object encrypted with AES
try {
envelopedData = new EnvelopedDataOutputStream(contentInfoStream,
(AlgorithmID)AlgorithmID.aes256_GCM.clone());
} catch (NoSuchAlgorithmException ex) {
throw new CMSException("No implementation for AES.");
}
// create the recipient infos
RecipientInfo[] recipients = new RecipientInfo[1];
// user1 is the first receiver
recipients[0] = new KeyTransRecipientInfo(signCert,
(AlgorithmID)AlgorithmID.rsaEncryption.clone());
// specify the recipients of the encrypted message
envelopedData.setRecipientInfos(recipients);
//int blockSize = 2048; // in real world we would use a block size like 2048
// write in the data to be encrypted
//byte[] buffer = new byte[blockSize];
byte[] buffer = new byte[16];
//byte[] buffer;
int bytesRead;
while ((bytesRead = inputstream.read(buffer)) != -1) {
envelopedData.write(buffer, 0, bytesRead);
}
But while trying to decrypt the same using following code:
EnvelopedDataStream enveloped_data = new EnvelopedDataStream(is);
enveloped_data.setupCipher(privateSignKey, 0);
InputStream decrypted = enveloped_data.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ByteStreams.copy(decrypted, os);
os.close();
I am getting following error:
iaik.cms.CMSException: Unable to decrypt encrypted content-encryption key: Invalid padding!
I am not sure of block size to be used, this might be a reason for the error, but not sure.
Moreover, if I compare my encrypted file with that of a correct one, I see following difference:
My encrypted data:
OBJECT IDENTIFIER 2.16.840.1.101.3.4.1.46 aes256-GCM (NIST Algorithm)
SEQUENCE (1 elem)
OCTET STRING (12 byte) FE5729470184A04A5AA30158
Correct data:
OBJECT IDENTIFIER 2.16.840.1.101.3.4.1.46 aes256-GCM (NIST Algorithm)
SEQUENCE (2 elem)
OCTET STRING (12 byte) CA985F7EAFB709DF711DCA2A
INTEGER 16
Could you please help us in getting this to work?

How to extract embedded files and attachment from PDF using PdfSharp?

Is it possible to extract embedded files and attachment from PDF using PdfSharp? if yes how can we achieve it.
Thanks in advance
Seems like PDFSharp is not supporting attachments directly but you may try to implement attachments extraction support: you need to look for /FS streams inside PDF document described in PDF Reference 1.7 in Section 3.10.3 and in note 94 in Appendix H.
you may try Apose.pdf, it works perfect for extract embedded files and attachment from PDF.
Try the following.
Document pdfDocument = new Document(#"C:\tmp\AddAttachment_out.pdf");
// Get embedded files collection
EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles;
Console.WriteLine("Total files : {0}", embeddedFiles.Count);
int count = 1;
// Loop through the collection to get all the attachments
foreach (FileSpecification fileSpecification in embeddedFiles)
{
Console.WriteLine("Name: {0}", fileSpecification.Name);
Console.WriteLine("Description: {0}",
fileSpecification.Description);
Console.WriteLine("Mime Type: {0}", fileSpecification.MIMEType);
// Check if parameter object contains the parameters
/*if (fileSpecification.Params != null)
{
Console.WriteLine("CheckSum: {0}",
fileSpecification.Params.CheckSum);
Console.WriteLine("Creation Date: {0}",
fileSpecification.Params.CreationDate);
Console.WriteLine("Modification Date: {0}",
fileSpecification.Params.ModDate);
Console.WriteLine("Size: {0}", fileSpecification.Params.Size);
}*/
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0,
fileContent.Length);
FileStream fileStream = new FileStream("C:\\Tmp\\" + count + "_out" + ".pdf",
FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Close();
count += 1;
}

Uploading big files to SkyDrive folder from Windows Phone 8

I'm trying to upload big files to SkyDrive from Windows Phone 8 device.
In order to avoid OurOfMemory exception I have to write file bytes manually (without SDK) to request stream with AllowWriteStreamBuffering = false
var putUrl = string.Format("https://apis.live.net/v5.0/{0}/files/{1}?suppress_response_codes=true&suppress_redirects=true&overwrite=true&access_token={2}", _folderId, fileName, _session.AccessToken);
var webRequest = (HttpWebRequest) WebRequest.Create(putUrl);
webRequest.ContentType = string.Empty;//Empty is required for PUT method.
webRequest.Method = "PUT";
webRequest.AllowWriteStreamBuffering = false;
webRequest.ContentLength = fileStream.Length;
webRequest.BeginGetRequestStream(iar =>
{
using (var requestStream = webRequest.EndGetRequestStream(iar))
{
var buffer = new byte[1024*100];
var read = 0;
while ((read = fileStream.Read(buffer, 0, buffer.Length)) <= buffer.Length)
{
requestStream.Write(buffer, 0, read); //!!!IT HANGS HERE WITHOUT ANY ERROR!!!
if (read < buffer.Length)
break;
}
}
}, webRequest);
It works fine for small and medium files (<50MB) but uploading hangs at requestStream.Write (at different percentage, sometime it is 30%, sometimes 50%) and wouldn't continue execution for large files (100-500 MB).
I appreciate any help.
Thanks,
Alexey Strakh