SWFUpload multiple files server-side handling - asp.net

I need the user to be able to upload multiple files to my server, thus I am using the SWFUpload utility. SWFUpload sends the files one by one, and I need to store them all in the same temporary directory. My ASP.NET handler recieves the files one by one and I can store the file appropriately.
My problem is: How do I know which files belong to the same upload? Rephrased, how do I connect the files in my handler?

I see 2 ways to do this (but they inherit the same idea).
The idea is based on the thing you should have something like sessionId parameter. This value should be unique for each set of files. You could use javascript uuid generators or something like so.
Further, this sessionId variable may be passed through query string(a little bit modified your handler url): ~/UploadHandler.ashx?sessionId={whatever} or as post parameter(guess, the better way).
The value may be retrieved on the server side by using: context.Request["SessionId"] for example.
On the client side you should be able to change post parameters or handler url dynamically. It could be done by using:
void addPostParam(name, value)
The addPostParam function adds a
name/value pair that will be sent in
the POST for all files uploaded.
The name/value pair will also appear
in the post_params setting.
or
void setUploadURL(url)
Dynamically modifies the upload_url
setting.
client methods. They should be called from the
fileDialogComplete(number of files selected, number of files queued, total number of files in the queued)
The fileDialogComplete event fires
after the File Selection Dialog window
has been closed and all the selected
files have been processed. The 'number
of files queued' argument indicates
the number of files that were queued
from the dialog selection (as opposed
to the number of files in the queue).
method.
Hope, this helps.

Related

Executing a method which is named via a config file

In short: I have a method name provided via a JSON configuration file. I'd like to call a method using this provided name. The method (with a matching name) will exist in the backend. What's the best way of going about this?
I am not quite sure what I should be searching for as an example.
To detail: I am working with a legacy application, hence the VB.NET. I am building a single PDF file from multiple PDF sources. Most of these are as is, I simply read the configuration and grab the relevant files and the job is done. However some require processing, I'd like the configuration file to pass in a method name to be called that will perform extra processing on the PDF, whatever that may be.
As there can be a lot of PDF files that can vary, I cannot simply use a property such as "PostProcessing: true".
Any ideas?
You could use reflection to reflect method names back and check them against the name passed from the property in the config file.
Like so
Type magicType = Type.GetType("MagicClass");
MethodInfo magicMethod = magicType.GetMethod("ItsMagic");
object magicValue = magicMethod.Invoke(magicClassObject, new object[]{100});
That would work.. but to be honest, I'd go with a case statement as you'll be hardcoding the method names anyway (because they are code), and it'll be strongly typed (less chance of typos and errors).

Use of struct in CAPL CANalyzer

I'm writing a piece of code to simulate some stuff of diagnostic.
I've created with CANalyzer, a panel with tons of information that need to be shown using a picklist (called combobox)
What I want to do is to create a giant array of that struct that need to be selected using the SPN combobox (the picklist) , and the other parameters of the struct/object need to populate the other elements of the panel.
Is this possible without doing a tons of SysSetVariableInt or SysSetVariableString for each element?
Before I was doing this stuff using another technique, I parse the file with all the information that are stored in a giant matrix, then I use the method "on sysvar update" on the variable associated to the SPN picklist, to get the index of that, so I search for that index in the matrix, then I use the SysSetVariableInt or others, to set the values to the elements in the panel.
To populate the picklist I've found a pretty nice method "sysSetVariableDescriptionForValue" that helps to add elements, but the problem with this method, is that if you want to change elements, you can just overwrite, and not change all...so, if in a next iteration you push less element in the picklist, you will see also the old ones.
With "sysSetVariableDescriptionForValue" you basically are writing via code, the value table of that sysvariable, and is not possible (according to Vector), be flushed, on runtime... :/
I would love to do this thing using another approach, maybe with the struct is possible...i really don't know.
Any help will be very appreciated!
Regards!
TLDR; build a tool to create a .sysvar file from a structured input (comma-separated for instance), run it, get the .sysvar file and link it to the CANalyzer configuration.
I once had to create the entire testing interface with some components of the software. We didn't have a structured release procedure, and the test environment was rebuilt every time from scratch based on the new internal software interfaces. I too had to add hundreds of variables.
My solution was to generate .sysvar files programatically outside CANalyzer. Links to the .sysvar files are symbolic in the CANalyzer configuration, meaning if a file by the right name is in the right location, that file is going to be loaded.
What I want to do is to create a giant array of that struct that need
to be selected using the SPN combobox (the picklist) , and the other
parameters of the struct/object need to populate the other elements
of the panel. Is this possible without doing a tons of
SysSetVariableInt or SysSetVariableString for each element?
Create an external script to generate the .sysvar file. In the end it is just an xml file, you may study the structure of a demo one you save. Then, import that file in the CANalyzer config. You may need to close/re-open the configuration in case the .sysvar file changes.
PROs: no need to write a complicated CAPL script and update it every time a variable changes.
CONs: you must have a source for all the information, even a simple excel sheet, with all the description and such, and you have to create a tool that accepts the input file (let's assume a .csv file) and turns it into a .xml file with .sysvar extension instead.

How can I obtain a Reliable Unique ID per Browser tab?

I have several ASP.NET pages that store an object in the session and use it for data binding etc. The object in the session is referenced in several pages of a 'wizard'.
I want users to be able to have several tabs open and work on several different objects stored in the session at the same time.
I am using a URL param to do this, where the param is incremented each time the page is hit, i.e:
http://server/MyPage.aspx?action=1
http://server/MyPage.aspx?action=2
And my session access is simply
return (MyObject) Session["MyObject" + Request.Params["action_id"]]
This is fine, but it doens't work for object data sources when they are data bound - the error is "Request is not available in this context"
How can I get an ID that I can retrieve on the server side reliably in callbacks and page loads? The ViewState doesn't seem to be available in
Ah, the trick is to use
System.Web.HttpContext.Current.Request

Webmatrix 2: Storing static values

Where would be the best place to store static values.
And how would I access it.
I want to be able to access static values from any page. But only have to define them in one place.
For example 'email' and 'phoneNumber'
I have tried things like Session and PageData, and defining the variables in my header (used by all pages) but this does not work.
The partial is initialised after the page, so it either doesnt work at all, or doesnt work on first time load.
E.g. First time Load:
Page Loaded <- Tries to Access variable. Not initialised.
Header Partial Loaded <- Variable initalised.
Result. Page does not show variable.
I have considered storing it in the config file. But I have no idea how to access this from Webmatrix 2.
I could just create a txt/ini file or something but surely parsing a file isn't the best way to do it. - I have since tried this and it doesnt seem valid like in mvc3 (config),and txt files are not practical to read for each request.
By "static", if you mean values that don't change across the lifetime of the application, you would normally use HelperPage.App property for storage. It is based on the dynamic type so you can create arbitrary properties:
App.Email = "someone#somewhere.com";
Or you can use the more traditional name/value collection approach with AppState:
AppState["email"] = "someone#somewhere.com";
However, if your "static" variables are user-specific, you should use Session as that is scoped to the user. Or use a database if you want to store them permanently.
You can set session values in _PageStart.cshtml (may need creating), or in the Session_Start event of the global.asax file and then access them in any partial / view you desire.

How to maintain the cache in the servlet?

I want to maintain db cache(some keywords) in the servlet. When I am typing for 'a' I have 1000 keywords in Db which starts with 'a' and presently I am using js file to store all the keywords in cache. I want to maintain the DB cache in servlet also and decrease the browser cache and next hitting keyword matches in the servlet Db, I want to retrieve the top 10 keywords for the this hitting.
Can you tell me how can I create the servlet cache? Can you provide any pseudo code for that?
Thanks,
Murali
I can imagine you have a Servlet that accesses the Database in order to retrieve the top 10 keyboards based on the input delivered. That means whenever an A is pressed in the input field, you must use an XMLHttpRequest to call the servlet with that input.
The servlet should return you a list of keywords which you should parse and translate properly to your user again. (you could do this in multiple ways. An easy way is to just let the servlet respond with HTML for you,which you can set with Javascript in an element (innerHTML)).
As for caching, the servlet could use some cache and identify the requested input. You can build an own cache by generating a key from the input and the result of that input should be put into a Map.
You could also use an existing caching framework, like EHCache.

Resources