What does an IsolatedStorage_Operation_ISFS error thrown from the IsolatedStorageFileStream constructor mean? - silverlight

I have a Silverlight 4 application (plug... http://audioorchard.com ...end plug) that is occasionally throwing an exception in the IsolatedStorageFileStream constructor.
System.IO.IsolatedStorage.IsolatedStorageException: [IsolatedStorage_Operation_ISFS] Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50524.0&File=mscorlib.dll&Key=IsolatedStorage_Operation_ISFS at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) at AudioOrchard.Client.Utility.DiskManager.CreateNewFile(String fileName, Boolean wasDiskSpaceRequested) at... (enter's not SL runtime code here)
The url in the stack trace doesn't provide any help and neither did a google search. Where can I learn more about IsolatedStorage_Operation_ISFS and what would cause it?

It means you are hitting a file length limit in Silverlight isolated storage. The base storage location for isolated storage can be in a path with a very long name - it looks something like:
C:\\Users\\kevind\\AppData\\LocalLow\\Microsoft\\Silverlight\\is\\1325qaxz.ekn\\xyro13wm.cn0\\1\\s\\qc4wuhalx4ciu4u5hbqqfohd3y3y4m1guyj5xuv5ml5y5qjbjmaaaeea\\f
(and can be even longer on XP, where the base is C:\Documents and Settings)
Given that, it doesn't take much to hit the 260 character file path limit. The base path plus the internal path (inside isolated storage) plus the file name has to be less than 260 characters.
I've seen two different failure modes in this case:
Trying to create a directory where the total path length (base path plus new path) is longer than 260 characters. This results in a PathToLongException raised by IsolatedStorageFile.CreateDirectory
Trying to create a file using IsolatedStorageFileStream, where the total path length (base path plus internal path plus file name) is greater than 260 characters. This results in an IsolatedStorageException (IsolatedStorage_Operation_ISFS) raised by the IsolatedStorageFileStream constructor.
As far as I can tell, there's no real solution to this problem aside from catching the exceptions and carrying on. It's an unfortunately limitation of Silverlight.
There's a good article about the issue here:
http://msdn.microsoft.com/en-us/magazine/dd458794.aspx

Actually there is no constructor for IsolatedStorageFileStream with same parameters list:
System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String
path, FileMode mode, FileAccess
access, FileShare share, Int32
bufferSize, IsolatedStorageFile isf)
Int32 bufferSize parameter is really excess here. Please check documentation for IsolatedStorageFileStream constructors.
I think there is some third party component which try to use non supported IsolatedStorageFileStream constructor.

I actually had this issue and to fix it I cleared my Silverlight cache. If you to to Program Files --> Microsoft Silverlight and click on the Application Storage tab, you can delete any or all of the sites listed there. I removed the site in question and was able to get right in next time.

Related

Access Shared Preferences externally / Store a value into a new file and access it externally

I have the two following methods and I am using them to store a special value locally and be able to access it on application restart:
(Store value locally:)
private void SaveSet(string key, string value)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor prefEditor = prefs.Edit();
prefEditor.PutString(key, value);
// editor.Commit(); // applies changes synchronously on older APIs
prefEditor.Apply(); // applies changes asynchronously on newer APIs
}
(Read it again:)
private string RetrieveSet(string key)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
return prefs.GetString(key, null);
}
This works perfectly. Now is it possible to access and edit this Shared Preferences externally? Unfortunately, I cannot find any file when searching in folder
Phone\Android\data\com.<company_name>.<application_name>\files
nor anywhere else. I want / try to edit this value from my computer, after connecting the phone to it. Is this possible?
Alternatively: Can anyone maybe show me how to create a new file in the given path above, write/read it programmatically and how it stays there, even if application is closed / started again? So I can then edit this file with my computer anyhow?
I tried it with the following code, but unfortunately it doesn't work / no file is created or at least i cannot see it in the given path above:
//"This code snippet is one example of writing an integer to a UTF-8 text file to the internal storage directory of an application:"
public void SaveValueIntoNewFile(int value)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "newFile.txt");
using (var writer = System.IO.File.CreateText(backingFile))
{
writer.WriteLine(value.ToString());
}
}
Would be very happy about every answer, thanks in advance and best regards
What you're looking for is where Android stores the Shared Preference file for applications that make use of it's default PreferenceManager.
I'd refer to this SO post which answers your question pretty well
SharedPreferences are stored in an xml file in the app data folder,
i.e.
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml
or the default preferences at:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
SharedPreferences added during runtime are not stored in the Eclipse
project.
Note: Accessing /data/data/ requires superuser
privileges
A simple method is to use Android Device Monotor,you can open it by clicking Tools--> android-->Android Device Monotor...
For example:
The path in my device is as follows:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
And we notice three buttons in the upper right corner of the picture.
The first one is used toPull a file from the device,the second one is used to Push a file onto the device,and the last one is used to delete the preferences.xml file.
So we can pull the preferences.xml file from current device to our computer and edit it as we want, and then push the updated preferences.xml to the folder again.Then we will get the value of preferences.xml file .

Spring Batch FlatFileItemWriter does not write data to a file

I am new to Spring Batch application. I am trying to use FlatFileItemWriter to write the data into a file. Challenge is application is creating the file on a given path, but, now writing the actual content into it.
Following are details related to code:
List<String> dataFileList : This list contains the data that I want to write to a file
FlatFileItemWriter<String> writer = new FlatFileItemWriter<>();
writer.setResource(new FileSystemResource("C:\\Desktop\\test"));
writer.open(new ExecutionContext());
writer.setLineAggregator(new PassThroughLineAggregator<>());
writer.setAppendAllowed(true);
writer.write(dataFileList);
writer.close();
This is just generating the file at proper place but contents are not getting written into the file.
Am I missing something? Help is highly appreciated.
Thanks!
This is not a proper way to use Spring Batch Writer and writer data. You need to declare bean of Writer first.
Define Job Bean
Define Step Bean
Use your Writer bean in Step
Have a look at following examples:
https://github.com/pkainulainen/spring-batch-examples/blob/master/spring-boot/src/main/java/net/petrikainulainen/springbatch/csv/in/CsvFileToDatabaseJobConfig.java
https://spring.io/guides/gs/batch-processing/
You probably need to force a sync to disk. From the docs at https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/file/FlatFileItemWriter.html,
setForceSync
public void setForceSync(boolean forceSync)
Flag to indicate that changes should be force-synced to disk on flush. Defaults to false, which means that even with a local disk changes could be lost if the OS crashes in between a write and a cache flush. Setting to true may result in slower performance for usage patterns involving many frequent writes.
Parameters:
forceSync - the flag value to set

How can Apache Camel be used to monitor file changes?

I would like to monitor all of the files in a given directory for changes, ie an updated timestamp. This use case seems natural for Camel using the file component, but I can't seem to find a way to configure this behavior.
A uri like:
file:/some/directory
will consume the files in the provided directory but will delete them.
A uri like:
file:/some/directory?noop=true
consumes each file once when it is added or when the route is started.
It's surprising that there isn't an option along the lines of
consumeOnChange=true
Is there a straightforward way to monitor file changes and not delete the file after consuming?
You can do this by setting up the idempotentKey to tell Camel how a file is considered changed. For example if the file size changes, or its timestamp changes etc.
See more details at the Camel file documentation at: https://camel.apache.org/components/latest/file-component.html
See the section Avoiding reading the same file more than once (idempotent consumer). And read about idempotent and idempotentKey.
So something alike
from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:size}")
Or
from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:modified}")
You can read here about the various ${file:xxx} tokens you can use: http://camel.apache.org/file-language.html
Setting noop to true will result in Camel setting idempotent=true as well, despite the fact that idempotent is false by default.
Simplest solution to monitor files would be:
.from("file:path?noop=true&idempotent=false&delay=60s")
This will monitor changes to all files in the given directory every one minute.
This can be found in the Camel documentation at: http://camel.apache.org/file2.html.
I don't think Camel supports that specific feature but with the existent options you can come up with a similar solution of monitoring a directory.
What you need to do is set a small delay value to check the directory and maintain a repository of the already read files. Depending on how you configure the repository (by size, by filename, by a mix of them...) this solution would be able to provide you information about news files and modified files. As a caveat it would be consuming the files in the directory very often.
Maybe you could use other solutions different from Camel like Apache Commons VFS2 (I wrote a explanation about how to use it for this scenario: WatchService locks some files?
I faced the same problem i.e. wanted to copy updated files also (along with new files). Below is my configuration,
public static void main(String[] a) throws Exception {
CamelContext cc = new DefaultCamelContext();
cc.addRoutes(createRouteBuilder());
cc.start();
Thread.sleep(10 * 60 * 1000);
cc.stop();
}
protected static RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("file://D:/Production"
+ "?idempotent=true"
+ "&idempotentKey=${file:name}-${file:size}"
+ "&include=.*.log"
+ "&noop=true"
+ "&readLock=changed")
.to("file://D:/LogRepository");
}
};
}
My testing steps:
Run the program and it copies few .log files from D:/Production to D:/LogRepository and then continues to poll D:/Production directory
I opened a already copied log say A.log from D:/Production (since noop=true nothing is moved) and edited it with some editor tool. This doubled the file size and save it.
At this point I think Camel is supposed to copy that particular file again since its size is modified and in my route definition I used "idempotent=true&idempotentKey=${file:name}-${file:size}&readLock=changed". But camel ignores the file.
When I use TRACE for logging it says "Skipping as file is already in progress...", but I did not find any lock file in D:/Production directory when I editted and saved the file.
I also checked that camel still ignores the file if I replace A.log (with same name but bigger size) in D:/Production directory from outside.
But I found, everything is working as expected if I remove noop=true option.
Am I missing something?
If you want monitor file changes in camel, use file-watch component.
Example -> RECURSIVE WATCH ALL EVENTS (FILE CREATION, FILE DELETION, FILE MODIFICATION):
from("file-watch://some-directory")
.log("File event: ${header.CamelFileEventType} occurred on file ${header.CamelFileName} at ${header.CamelFileLastModified}");
You can see the complete documentation here:
Camel file-watch component

InternetGetCookieEx: not working

I am trying to read an HttpOnly cookie through a WPF, VB.NET application.
The site in question, upon visit, serves 2 cookies: one HttpOnly, one regular.
I visit the site whose cookie I want to read via Internet Explorer. Then Developer tools --> Cache --> View cookie information. ONLY the regular cookie is shown there, not the HttpOnly one (Chrome displays both of them correctly. If I delete it and refresh, the site returns a 500 error so the cookie definitely exists).
I run my code, based on what is explained here: c# Get httponly cookie, which is as follows:
Private Const INTERNET_COOKIE_HTTPONLY As Integer = &H2000
<SuppressUnmanagedCodeSecurity, SecurityCritical, DllImport("wininet.dll", EntryPoint:="InternetGetCookieExW", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Friend Shared Function InternetGetCookieEx(<[In]> Url As String, <[In]> cookieName As String, <Out> cookieData As StringBuilder, <[In], Out> ByRef pchCookieData As UInteger, flags As UInteger, reserved As IntPtr) As Boolean
End Function
<SecurityCritical()>
Public Shared Function GetCookie(url As String) As String
Dim size As Integer = 0
Dim sb As New StringBuilder
If InternetGetCookieEx(url, vbNullString, Nothing, size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero) Then '<-- this always returns false
If size <= 0 Then
Return Nothing
End If
sb = New StringBuilder(size + 1)
If Not InternetGetCookieEx(url, vbNullString, sb, size, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero) Then
Return Nothing
End If
End If
Dim lastErrorCode = Marshal.GetLastWin32Error '<-- 259
Return sb.ToString()
End Function
GetCookie("https://www.xyz.com")
I have tried numerous variations of the above, the result is the same: lastErrorCode ALWAYS equals to 259, which in turn translates to ERROR_NO_MORE_ITEMS, meaning that no cookies have been found.
1) The site in question is in the trusted sites zone, so it doesn't work under protected mode.
2) The site is under SSL (I do not know if this has to do with anything).
3) I have desperately searched my hard disk for these cookies' location, to no avail.
4) Both are session cookies (ie no declared expiration date)
5) Windows 8 x64, IE10, VS2012
This is a tiny bit of a project milestone which has given me countless hours of pain, so any help will be greatly appreciated.
I am very willing to change my methodology completely as soon as it will give me this cookie's value, unless it's overkill (ie winpcap / fiddlercore etc.)
You're correct to note that your code would only ever work in the Trusted Zone, due to Q10 here: http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx since cookies aren't shared between IE (which runs in Protected Mode or AppContainer) and your application (which runs at Medium IL).
You should pass a valid URL into the function (e.g. you need at least a trailing slash after the hostname); even if an invalid URL works today, it might not in the future.
Also keep in mind that you'll only ever see IE's persistent cookies with this code; Session cookies are isolated per-process, so your application won't see Session cookies from an IE tab.
To all whom it may concern:
Eric was absolutely right: Session cookies are in-process, so they are virtually invisible from the outside world.
One possible solution that works is the following:
Load the site in a webbrowser control.
The code I posted works as expected.

IsolatedStorageFileStream exception is throw when file is opened?

when I attempt to open a file in a WP7 app:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = new IsolatedStorageFileStream("Names.xml", System.IO.FileMode.Open, isf);
I recieve the following error:
Operation not permitted on IsolatedStorageFileStream.
I'm not sure why it isn't opening because I used the exact code somewhere else in my app and it works fine.
Any leads as to why this is happening?
EDIT
I used the following code to add the file to isolated storage in the App.xaml.cs Application_Launching Event:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream feedXmlFile = new IsolatedStorageFileStream("Names.xml",System.IO.FileMode.Create, isf);
One of the problems with using the IsolatedStorageFileStream constructor is that the exception generated has limited info. The alternative OpenFile method has a richer set of exceptions.
As a general rule of thumb if an API allows you to do the same thing with a constructor or with a method go with the method. In this case try this code instead:-
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream nameXmlFile = isf.OpenFile("Names.xml", System.IO.FileMode.Open);
If this fails you will have at least narrowed down the potential cause.
This may seem obvious but in your creation code you have actually written to and closed the file you created?
IsolatedStorage Exception is a known issue whil fires Application_Launching. more details
When you run into an exception during file access, check for two things:
isolated storage is not thread safe, so use a 'lock' when accessing the file system
Isolated storage best practices
Fully read the stream into memory before closing the stream. So don't pass the filestream back to for example an image control.
Reading a bitmap stream from isolated storage

Resources