FileStream security error - air

I am developing multithreaded application in Adobe Air 3.6 with Flex 4.6. I am using FileStream class inside the Worker thread which is created in separate SWF file. When I declare the variable like this:
var FS:FileStream = new FileStream();
It throws the following error without any further detail:
SecurityError: file
Using FileStream class on Main thread works fine. Is there any workaround to this?
Thanks.

Set createWorker attribute 'giveAppPrivileges' = true.
_worker = WorkerDomain.current.createWorker(Workers.myWorker,**true**);

Related

UWP SyncFusion SfDataGrid Serialization Exception

I'm trying to make use of the SfDataGrid component in my UWP app and have everything working just fine in debug mode. When I switched over to release mode to regression test the app before publishing to the Windows store the app throws an exception during grid serialization.
I have an SfDataGrid defined with 4 text columns, 1 numeric column and 1 template column. The template column just includes a delete button so that the user to can remove the row.
I have a method to return the serialization options as follows:
private SerializationOptions GetGridSerializationOptions()
{
return new SerializationOptions
{
SerializeFiltering = false,
SerializeColumns = true,
SerializeGrouping = true,
SerializeSorting = true,
SerializeTableSummaries = true,
SerializeCaptionSummary = true,
SerializeGroupSummaries = true,
SerializeStackedHeaders = true
};
}
Then I have another method to serialize the grid settings as follows:
private void RetrieveDefaultGridSettings()
{
using (MemoryStream ms = new MemoryStream())
{
gridReport.Serialize(ms, GetGridSerializationOptions());
_defaultGridSettings = Convert.ToBase64String(ms.ToArray());
}
}
I've followed the SyncFusion documentation (https://help.syncfusion.com/uwp/datagrid/serialization-and-deserialization) which describes how to serialize template columns. I have everything working perfectly in debug mode, but when I switch to release mode I get an exception on this line:
gridReport.Serialize(ms, GetGridSerializationOptions());
The exception is:
System.Runtime.Serialization.InvalidDataContractException: 'KnownTypeAttribute attribute on type 'Syncfusion.UI.Xaml.Grid.SerializableGridColumn' specifies a method named 'KnownTypes' to provide known types. Static method 'KnownTypes()' was not found on this type. Ensure that the method exists and is marked as static.'
I've had a look at the SerializableGridColumn class and can see a public static method called KnownTypes so I don't really understand why this exception is happening. I'm even more confused about why it's only happening in release mode.
In attempt to fix the problem I have tried referencing the entire SDK, removing the SDK and referencing the specific assemblies (Syncfusion.SfGrid.UWP, Syncfusion.Data.UWP, Syncfusion.SfInput.UWP, Syncfusion.SfShared.UWP, Syncfusion.SfGridConverter.UWP, Syncfusion.XlsIO.UWP and Syncfusion.Pdf.UWP) but neither yields a different result and the exception still occurs, but only in release mode.
Switching off the setting "Compile with .NET Native tool chain" does resolve the problem, but is not a practical solution as this blocks me from publishing the app to the Windows store.
Thanks very much for any assistance anyone can provide.
After exhausting all possible problems with my own code, I logged with an issue with SyncFusion. They're investigating and will hopefully provide a fix soon.

Create a PDF file using PDFTron and then rename or delete it

I am trying to create PDF file using PDFTron in application which runs in the UWP environment. I am able to create a file successfully. Depending on user input that newly created file might need to be renamed or completely deleted from the system. Although when I try to access the file that was just created the system throws the following exception:
Exception thrown: 'System.IO.IOException' in System.IO.FileSystem.dll The process cannot access the file (filename) because it is being used by another process.
The following part show what is used for the file to be created:
await sdfDoc.SaveAsync(filePath, SDFDocSaveOptions.e_linearized, "%PDF-1.5");
sdfDoc.Dispose();
And this is my delete implementation:
var filedelete = Task.Run(() => File.Delete(filePath));
The creation of the file is running on a seperate Task and the deletion takes place upon a button press.
I understand the nature of the exception, although I was wondering if the resources of the file are returned to the system from PDFTron after the creation of the file?
Any help or direction would be much appreciated.
Thank you.
PDFNet uses reference counting internally to know when to release the filesystem handles and memory.
For example, the following would trigger the issue where the file is still locked.
PDFDoc doc = new PDFDoc(input_filename);
doc.InitSecurityHandler();
SDFDoc sdfdoc = doc.GetSDFDoc();
await sdfdoc.SaveAsync(output_file_path, SDFDocSaveOptions.e_linearized, "%PDF-1.5");
sdfdoc.Dispose();
await Task.Run(() => File.Delete(output_file_path)); // fails, as PDFDoc still has reference.
But this would work as expected.
using(PDFDoc doc = new PDFDoc(input_filename))
{
doc.InitSecurityHandler();
SDFDoc sdfdoc = doc.GetSDFDoc();
await sdfdoc.SaveAsync(output_file_path, SDFDocSaveOptions.e_linearized, "%PDF-1.5");
sdfdoc.Dispose();
}
await Task.Run(() => File.Delete(output_file_path)); // works
Note the using statement for the PDFDoc instance, and the manual dispose of the SDFDoc instance, though you could use a using statement on that also.

Executing python file from Java code giving errors

I am executing python scripts from Java using the jython library(jython-standalone-2.7-b3). My only intention is to be able to trigger and execute python script files from my java code. I was able to do this properly writing standalone main classes and things went well. Now I put the same code inside my application(within my app server), and now for the same script i get errors at each and every stage. It says a few module cannot be found etc. But adding more to my confusion the same code and script executes just fine when i try it again from the main class. Is there anything that the running environment has to inject to make this run..
The code snippet used
public void executeScript(String inputFile, String outputFile) throws FileNotFoundException {
final PythonInterpreter inter = new PythonInterpreter(null, new PySystemState());
Writer writer = null;
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile)));
inter.setOut(writer);
inter.execfile(inputFile);
}
The exception that i get is
File "/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py", line 392, in normpath
AttributeError: 'NoneType' object has no attribute 'startswith'
at org.python.core.Py.AttributeError(Py.java:177)
at org.python.core.PyObject.noAttributeError(PyObject.java:946)
at org.python.core.PyObject.__getattr__(PyObject.java:941)
at posixpath$py.normpath$27(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py:412)
at posixpath$py.call_function(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/posixpath.py)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyBaseCode.call(PyBaseCode.java:137)
at org.python.core.PyFunction.__call__(PyFunction.java:347)
at sysconfig$py.f$0(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/sysconfig.py:712)
at sysconfig$py.call_function(/data/WorkArea/anoj/APPNEW/com.anoj.commons.core/lib/jython-standalone-2.7-b3.jar/Lib/sysconfig.py)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.imp.createFromCode(imp.java:393)
at org.python.core.util.importer.importer_load_module(importer.java:109)
at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161)
at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)
at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)
at org.python.core.imp.loadFromLoader(imp.java:520)
at org.python.core.imp.loadFromLoader(imp.java:520)
Please help..

Error when uploading file to SP - could not find file: c:\windows\system32\inetsrv\

I'm uploading a file to a SharePoint Document library using the following code:
string fileToUpload = oFile.PostedFile.FileName;
using (SPSite oSite = new SPSite(spsite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList library = oWeb.Lists[documentLibraryName];
using (FileStream fs = new FileStream(fileToUpload, FileMode.Open))
{
//more logic here
This works fine in my dev environment, but when I move it to QA, I get the following error when try to upload a file:
System.IO.FileNotFoundException:
Could not find file 'c:\windows\system32\inetsrv\file_to_upload'.
I have googled around, and it seems like I may need to use PostedFile.InputStream instead of PostedFile.Name.
But if set fileToUpload equal to oFile.PostedFile.InputStream, then I am not able to use this bit of code anymore:
using (FileStream fs = new FileStream(fileToUpload, FileMode.Open))
I would like to still use this code as I need to access fs.name later on in my code.
Any idea how I could get this problem resolved?
Give it a try, this might be helpful
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/96f81cea-12b2-46f0-83ec-64c7fd9532cd/using-aspnet-fileupload-control-in-sharepoint-2010-announcement-list-newformaspx?forum=sharepointdevelopmentprevious

Winrt StreamWriter & StorageFile does not completely Overwrite File

Quick search here yielded nothing. So, I have started using some rather roundabout ways to use StreamWriter in my WinRT Application. Reading works well, writing works differently. What' I'm seeing is that when I select my file to write, if I choose a new file then no problem. The file is created as I expect. If I choose to overwrite a file, then the file is overwritten to a point, but the point where the stream stops writing, if the original file was large, then the old contents exist past where my new stream writes.
The code is as such:
public async void WriteFile(StorageFile selectedFileToSave)
{
// At this point, selectedFileToSave is from the Save File picker so can be a enw or existing file
StreamWriter writeStream;
Encoding enc = new UTF8Encoding();
Stream dotNetStream;
dotNetStream = await selectedFileToSave.OpenStreamForWriteAsync();
StreamWriter writeStream = new StreamWriter(dotNetStream, enc);
// Do writing here
// Close
writeStream.Write(Environment.NewLine);
await writeStream.FlushAsync();
await dotNetStream.FlushAsync();
}
Can anyone offer clues on what I could be missing? There are lots of functions missing in WinRT, so not really following ways to get around this
Alternatively you can set length of the stream to 0 with SetLength method before using StreamWriter:
var stream = await file.OpenStreamForWriteAsync();
stream.SetLength(0);
using (var writer = new StreamWriter(stream))
{
writer.Write(text);
}
Why not just use the helper methods in FileIO class? You could call:
FileIO.WriteTextAsync(selectedFileToSave, newTextContents);
If you really need a StreamWriter, first truncate the file by calling
FileIO.WriteBytesAsync(selectedFileToSave, new byte[0]);
And then continue with your existing code.