I'm developing a function to verify if the ISO has Joliet extension.
I use DiscUtils to create the ISO file as follow
CDBuilder builder = new CDBuilder();
builder.UseJoliet = true;
builder.VolumeIdentifier = "A_SAMPLE_DISK";
builder.AddFile("x/x.png", #"C:\Users\Circle\Pictures\Image 1.png");
builder.Build(#"C:\temp\sample.iso");
However, when I read the ISO file. It doesn't be recognized as Joliet
using (FileStream isoStream = File.Open(#"C:\temp\sample.iso", FileMode.Open))
{
CDReader cd = new CDReader(isoStream, true);
if (cd.ActiveVariant == Iso9660Variant.Joliet)
{
// Never enter here
}
}
Not sure which part I did wrong. Any suggestions?
You don't appear to be doing it wrong; however the code won't ever set that ActiveVariant.
If you look at the underlying code, it seems to switch the ActiveVariant to Iso9660Variant.Iso9660 for joliet extensions for the purposes of that field. I don't know the reason for that - it might be a bug, it might have some other esoteric reason for doing it based on some other code in the project.
I've added a couple of comments to the code, and reproduced it here.
case Iso9660Variant.Joliet:
if (svdPos != 0) // <-- Joliet is always a supplementary table.
{
data.Position = svdPos;
data.Read(buffer, 0, IsoUtilities.SectorSize);
SupplementaryVolumeDescriptor volDesc = new SupplementaryVolumeDescriptor(buffer, 0);
Context = new IsoContext { VolumeDescriptor = volDesc, DataStream = _data };
RootDirectory = new ReaderDirectory(Context,
new ReaderDirEntry(Context, volDesc.RootDirectory));
ActiveVariant = Iso9660Variant.Iso9660; // <-- set active variant to base Iso9660
}
break;
Related
Hello i was able to upload multiple files in multiple threads when i was using WindowsAzure.Storage 2.0.4.0. but i have recently upgraded my library to 9.3.3.
Now i am facing error in setting my multiple threads to upload my file. Please have a look at my code and tell me that where i am missing. Although i have searched to set the parallel threads but its not setting the threads of the blob as it was setting before.
public void UploadBlobAsync(Microsoft.WindowsAzure.StorageClient.CloudBlob
blob, string LocalFile)
{
Microsoft.WindowsAzure.StorageCredentialsAccountAndKey account = blob.ServiceClient.Credentials as Microsoft.WindowsAzure.StorageCredentialsAccountAndKey;
ICloudBlob blob2 = new CloudBlockBlob(blob.Attributes.Uri, new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(blob.ServiceClient.Credentials.AccountName, account.Credentials.ExportBase64EncodedKey()));
UploadBlobAsync(blob2, LocalFile);
}
public void UploadBlobAsync(ICloudBlob blob, string LocalFile)
{
// The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems.
// A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client.
// Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called.
lock (WorkingLock)
{
if (!Working)
Working = true;
else
throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.");
}
// Attempt to open the file first so that we throw an exception before getting into the async work
using (FileStream fstemp = new FileStream(LocalFile, FileMode.Open, FileAccess.Read)) { }
// Create an async op in order to raise the events back to the client on the correct thread.
asyncOp = AsyncOperationManager.CreateOperation(blob);
TransferType = TransferTypeEnum.Upload;
m_Blob = blob;
m_FileName = LocalFile;
var file = new FileInfo(m_FileName);
long fileSize = file.Length;
FileStream fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
ProgressStream pstream = new ProgressStream(fs);
pstream.ProgressChanged += pstream_ProgressChanged;
pstream.SetLength(fileSize);
m_Blob.ServiceClient.ParallelOperationThreadCount = 10; //This Line is giving an error that is does not contain the definition.
m_Blob.StreamWriteSizeInBytes = GetBlockSize(fileSize);
asyncresult = m_Blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream));
}
m_Blob.ServiceClient.ParallelOperationThreadCount = 10; is giving the error that it does not contain the definition. As i tried to find the work around but couldn't. I fount the code on Microsoft forum but it didn't help much.
Updated code of uploading azure blob storage multiple files in multi-threaded way here is the snippet of updated code which can be integrated in my previous code.
//Replace
m_Blob.ServiceClient.ParallelOperationThreadCount = 10
//with
BlobRequestOptions options = new BlobRequestOptions
{
ParallelOperationThreadCount = 8,
DisableContentMD5Validation = true,
StoreBlobContentMD5 = false
};
//Replace
asyncresult = m_Blob.BeginUploadFromStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream));
//with
asyncresult = m_Blob.BeginUploadFromStream(pstream,null,options,null,BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream));
I am using JSReport in order to generate reports in .netCore2; In the below method the view is returned to the user and report is saved in specified directory;
public IActionResult ImageDownload()
{
HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf)
.Configure((r) => r.Template.Phantom = new Phantom
{
Format = PhantomFormat.A4,
Orientation = PhantomOrientation.Portrait
}).OnAfterRender( (r) =>
{
var streamIo = r.Content; // streamIo is of type System.IO
streamIo.CopyTo(System.IO.File.OpenWrite("C:GeneratedReports\\myReport.pdf"));
streamIo.Seek(0, SeekOrigin.Begin);
}
);
var dp = new Classes.DataProvider();
var lstnames = dp.GetRegisteredNames();
var lst = lstnames.ToArray<string>();
return View("Users", lst);
}
Once the view is returned a new browser opens displaying the pdf report. Also the same pdf will be saved in the webserver in the given directory; The problem is that the created report in the directory seems to be locked, I cannot copy it, open it... unless I close the .net solution. Any explanation of what's happening here?
You FileStream isn't closed when OnAfterRender has completed meaning no other app can open/access it. Try changing the code to put a using block around the File.OpenWrite call to contain a using statement for the FileStream e.g.
public IActionResult ImageDownload()
{
HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf)
.Configure((r) => r.Template.Phantom = new Phantom
{
Format = PhantomFormat.A4,
Orientation = PhantomOrientation.Portrait
}).OnAfterRender( (r) =>
{
var streamIo = r.Content; // streamIo is of type System.IO
using(var fs = System.IO.File.OpenWrite("C:GeneratedReports\\myReport.pdf"))
{
streamIo.CopyTo(fs);
}
streamIo.Seek(0, SeekOrigin.Begin);
}
);
var dp = new Classes.DataProvider();
var lstnames = dp.GetRegisteredNames();
var lst = lstnames.ToArray<string>();
return View("Users", lst);
}
This thread seems not helping me.
What I want to do is to read a excel .xlsx file contents to replace values of some cells and return the new file contents to the client. But the original file should remain as is. I don't want to save the new file to the system - it's not a solution.
Here is the code:
string excelFilePath = this.Server.MapPath("~/App_Data/Test.xlsx");
var fileStream = System.IO.File.Open(excelFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
Excel.IExcelDataReader exReder = Excel.ExcelReaderFactory.CreateOpenXmlReader(fileStream);
System.Data.DataSet dataSet = null;
using (exReder)
{
dataSet = exReder.AsDataSet();
}
if (dataSet == null)
{
throw new ArgumentNullException("Cannot Make Data Set");
}
dataSet.Tables[0].Rows[0].ItemArray = new[] { "Microsoft", "Test", "ASP.NET" };
bool hasChanges = dataSet.HasChanges(); // true
dataSet.AcceptChanges();
bool hasChanges2 = dataSet.HasChanges(); // false
var dataReader = dataSet.CreateDataReader(dataSet.Tables[0]);
TextReader textReader = dataReader.GetTextReader(1); // 1 is ordinal no matter what I pass it throws an exception
byte[] results = System.Text.Encoding.UTF8.GetBytes(textReader.ReadToEnd());
return this.File(results, System.Net.Mime.MediaTypeNames.Application.Octet);
I am using http://exceldatareader.codeplex.com/ package
dataReader.GetTextReader(1); always throws an exception. How to make this text reader? Or just get the bytes after the change?
Consider using the Microsoft provided Excel.Interop .net libraries. They are natively designed to perform these functions. Here's a dotnetperls blog on this:
Currently I found a workaround with http://epplus.codeplex.com/ .
I have recently started using C# over the past year so I'm somewhat new to this, but can usually hack through things with some effort, but this one is eluding me. We use TestTrack for development bug/issue tracking at our company. I've created a custom windows forms app to be the front-end to TestTrack for one of our departments. It connects using SOAP. I'm not using WPF/WCF and don't want to go that route. I'm having difficulty finding any examples of how to correctly encode a file for attachment that is a PDF. The code below does actually create an attachment in TestTrack to an already-existing issue, but when you try to open it in TestTrack, it pops up an error message that says "Insufficient Data For An Image". The example below does work if you're wanting to add a text file to TestTrack using SOAP. I'm wanting to know what I need to change below so that I can get a PDF file into TestTrack and then be able to open it in the TestTrack application without the error mentioned above. Thanks in advance for any input/help.
public void getAttachments(long lSession, CDefect def)
{
ttsoapcgi cgiengine = new ttsoapcgi();
// Lock the defect for edit.
CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);
string attachment = "c:\\TEST\\TEST_PDF.PDF";
CFileAttachment file = new CFileAttachment();
file.mstrFileName = Path.GetFileName(attachment);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
StreamReader reader = new StreamReader(attachment);
file.mstrFileName = Path.GetFileName(attachment);
file.mpFileData = enc.GetBytes(reader.ReadToEnd());
reader.Close();
CReportedByRecord reprec = lockedDefect.reportedbylist[0];
CFileAttachment[] afile = reprec.attachmentlist;
if (afile == null)
{
lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
lockedDefect.reportedbylist[0].attachmentlist[0] = file;
}
// Save our changes.
cgiengine.saveDefect(lSession, lockedDefect);
}
}
Here is the modified method that allowed me to attach a PDF to SOAP and get it into TestTrack as an attachment to an issue:
public void getAttachments(long lSession, CDefect def)
{
ttsoapcgi cgiengine = new ttsoapcgi();
// Lock the defect for edit.
CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);
string attachment = "c:\\TEST\\TEST_PDF.PDF";
CFileAttachment file = new CFileAttachment();
file.mpFileData = File.ReadAllBytes(attachment);
file.mstrFileName = Path.GetFileName(attachment);
CReportedByRecord reprec = lockedDefect.reportedbylist[0];
CFileAttachment[] afile = reprec.attachmentlist;
if (afile == null)
{
lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
lockedDefect.reportedbylist[0].attachmentlist[0] = file;
}
// Save our changes.
cgiengine.saveDefect(lSession, lockedDefect);
}
I need to turn a text into speech and then save it as wav file.
The following C# code uses the System.Speech namespace in the .Net framework.
It is necessary to reference the namespace before using it, because it is not automatically referenced by Visual Studio.
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Volume = 100;
ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
ss.SetOutputToWaveFile(#"C:\MyAudioFile.wav");
ss.Speak("Hello World");
I hope this is relevant and helpful.
This is from a few moments' play, so caveat emptor. Worked well for me. I did notice that SpFileStream (which doesn't implement IDisposable, thus the try/finally) prefers absolute paths to relative. C#.
SpFileStream fs = null;
try
{
SpVoice voice = new SpVoice();
fs = new SpFileStream();
fs.Open(#"c:\hello.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
voice.AudioOutputStream = fs;
voice.Speak("Hello world.", SpeechVoiceSpeakFlags.SVSFDefault);
}
finally
{
if (fs != null)
{
fs.Close();
}
}
And as I've found for how to change output format, we code something like this :
SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(6, AudioBitsPerSample.Sixteen, AudioChannel.Mono);
//Same code comes here
ss.SetOutputToWaveFile(#"C:\MyAudioFile.wav",info);
That's pretty easy and comprehensible.
Cool .net