|
I just had a look at the sample code, and they are using a try/catch exception block as well.
FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read, "C:\\test_r");
f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, "C:\\example\\out.txt");
try
{
f2.Demand();
}
catch (SecurityException s)
{
Console.WriteLine(s.Message);
}
Apart from adding another couple of usings to my code and being a bit shorter, I don't know that this is an improvement.
Is there a reason that the above is better practice than the code I wrote?
|
|
|
|
|
I also said CAS can be declaritive, as in specify an attribute not code; however if you read more about CAS, as you should, you will understand its use and get beyond your naive comments. There is more to coding than just counting the number of lines.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Checking for that sort of thing before you need it is generally not worthwhile -- things change. And maybe the user won't try writing or deleting anyway so you've wasted your time.
Simply let the user try, then deal with any Exceptions that occur at that point.
|
|
|
|
|
This is where the user tries.
The Application reads an XML File and does a bunch of processing of documents in the selected directory.
There are a number of log files that need to be created and the processing should not occur if the log files can not be written.
Due to how the application is installed and used (Admin installs, normal user then runs) the user may not always have the appropriate level of access.
Life would be so much easier without users.
|
|
|
|
|
Sure, so just before you start, begin writing the log file -- "Processing begun by <user> at <date time> ... Reading file <filename> ... "
RCoate wrote: Life would be so much easier without users.
Yes, yes it is. I write mostly Windows Services and batch processing.
|
|
|
|
|
Our watershed group has an IP camera that serves a video stream via a java applet. When we navigate to the camera's web page we see the video streem. The front end of thecode behind the camera's serving page is Is included below.
I am writing a C# Windows Application that has a webbrowser control that navigates to the page. I want to capture still images with a timer tick event. Right now, I have an hack that does a copy from screen on the webbrowser control:
Bitmap BMP_now = new Bitmap(webBrowser1.ClientSize.Width, webBrowser1.ClientSize.Height);
Graphics g = Graphics.FromImage(BMP_now);
g.CopyFromScreen(this.PointToScreen(webBrowser1.Location), new Point(0, 0), webBrowser1.ClientSize);
g.Dispose();
This cumbersome approach has the major drawback that the windows form must always be topmost. There's gotta be a better way.
Here's the source behing the IP Camera's page:
lt;html>
<head>
<TITLE>TRENDnet | CS-7835E0(TV-IP100)</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<link rel="stylesheet" href="style.css" type="text/css">
<script language="JavaScript">
<!--
function MM_preloadImages() {
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_openBrWindow(theURL,winName,features) {
window.open(theURL,winName,features);
}
function MM_swapImgRestore() {
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) {
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() {
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
<style type=text/css>
A:link {FONT-WEIGHT: bold; FONT-SIZE: 14px; COLOR: ff6600; FONT-FAMILY: arial,geneva,sans-serif}
A:visited {FONT-WEIGHT: bold; FONT-SIZE: 14px; COLOR: ff6600; FONT-FAMILY: arial,geneva,sans-serif}
.org-news {FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: ff6600; FONT-FAMILY: arial,geneva,sans-serif}
</style>
</head>
<script language="JavaScript">
function Init() {
if ((navigator.appName != "Netscape") &&
(navigator.userAgent.indexOf('Opera') == "-1"))
{
window.setInterval("ShowFrameRate()", 1000);
}
}
function ShowFrameRate() {
if (1)
{
var fFrameRate = cvcs.GetFrameRate();
window.status = "Frame:" + fFrameRate.toString() + " fps";
}
cvcs.GetRealTimeData() ;
CurrentTime.innerHTML = cvcs.GetTimeString();
GetTrigger();
}
function GetTrigger() {
if (cvcs.GetImageUpload() == 1) {
ImageUpload.innerHTML = "[ON]";
}
else {
ImageUpload.innerHTML = "[OFF]";
}
if (cvcs.GetImageEmail() == 1) {
EmailImage.innerHTML = "[ON]";
}
else {
EmailImage.innerHTML = "[OFF]";
}
}
</script>
|
|
|
|
|
OK, so I discovered the mshtml namespace.
There is a tutorial at http://www.developerfusion.com/code/4712/generate-an-image-of-a-web-page/[^]
The example uses an interface (IHTMLDocument2) and creates an instance of another interface (IHTMLElement) from the document's body. From here it is a render and draw operation. Trouble is, the procedure does not render the applet's stream to the page. Rather, it shows the (blank) html target page that the applet streams into.
However, the mshtml namespace appears to be rich in interfaces, none of which are well documented. It appears that IHTMLElement can be instantiated with other document properties (besides “body) such as “applet” which in turn has an items collection. I have had no luck on this glory path yet. Any ideas?
|
|
|
|
|
Hey guys, I ve got this question, I tried to look for it online but haven't been lucky!
I've got this:
string[] names = new string[] { "Alan Smith", "Anne Dodsworth", "Boyan Mastoni", "Richard Duncan"};
Now I want to fill it from database, so I used a generic list
public List<string> ClassroomList = new List<string>();
then fill it with data from database,
but when I want to assign it to my string I get an error and can't convert it ....
string[] names = new string[10];
foreach (var item in ClassroomList)
{
for (int i = 0; i < names.Length; i++)
{
names[i] = item;
}
}
please help me out.
thanx
|
|
|
|
|
What you are doing there is very odd, filling the array first with the first item, then with the second item, etc.. Eventually you'd have an array with 10 times the same string (the last one in ClassroomList), not a very useful way to spend CPU cycles.
What is your intent? What is the error?
|
|
|
|
|
public List<string> ClassroomList = new List<string>();
...
string[] names=ClassroomList.ToArray();
would probably do it (and it takes care of the array dimension as well, without imposing an artificial limit such as the 10 you had).
|
|
|
|
|
0) Don't use var
1) Don't use foreach in this case
2) Why copy a perfectly good List to an array?
3) If you need an array, why use the List?
|
|
|
|
|
there's more questions than answers here.
|
|
|
|
|
|
Hi
I have an application that uses a 3rd party API that saves a fingerprint image to file,I cannot retrieve the image in any way to a image object in the programming code so I need to save it to disk before i can load it into an Image object to convert the minutiae template between different vendor types. Now due to information law I need to protect that saved fingerprint image, even for the split second it is on the drive before i delete it
So I need to know is there a way I can either
Create a folder, storage space I can save to that only my Assembly can access.
or
Create a virtual drive that encrypts data that gets written into it.
or
Create a folder that requires a password to access it (which I can parse through my program).
Primarily i am using C# to code this application but any C++ console wrapped app that can be of use to me would also help.
Any advice or help will be appreciated.
Hitting my head against the wall on this one
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
Chona1171 wrote: I cannot retrieve the image in any way to a image object in the programming code so I need to save it to disk before i can load it into an Image object to convert the minutiae template between different vendor types.
How does the API return the image?
Chona1171 wrote: So I need to know is there a way I can eitherCreate a folder, storage space I can save to that only my Assembly can access.orCreate a virtual drive that encrypts data that gets written into it.orCreate a folder that requires a password to access it (which I can parse through my program).
SqlCe or SqlExpress, using a blob-field. Or use the encryption-routines that come with .NET.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: SqlCe or SqlExpress, using a blob-field. Or use the encryption-routines that come with .NET.
It's a 3rd party API, right? If it offered support for those things, surely the OP would have thought of them..
|
|
|
|
|
harold aptroot wrote: surely the OP would have thought of them..
Assumptions, my dear Watson
..I don't expect that the API will save directly to a blob, I'd expect one to get an array of bytes. And yes, those could be securely stored in a blob.
I are Troll
|
|
|
|
|
If you get an array then there is no problem, he could just make the image of that without going through disc, so it can't be that either
btw, I'm just assuming "OP is not an idiot" - I'm sure he will correct me if I'm wrong..
|
|
|
|
|
harold aptroot wrote: he could just make the image of that without going through disc
Yup. Hence the question how the 3d party library supplies the image. If it's in memory, then it can be encrypted, but that doesn't guarantee it not being written to disc.
A SecureString for bitmaps?
I are Troll
|
|
|
|
|
What if he disables the pagefile?
|
|
|
|
|
Guess that'd be safer. It would be a major handicap for a fingerprintingdevice if you couldn't use it on a system that uses virtual memory though. Nah, it's prolly just an array of bytes in memory that need be transformed to a bitmap, with the restriction of not using temporary files.
Must be a good time to get some sleep
I are Troll
|
|
|
|
|
Thats exactly it you do not get an array of bytes. the only image Method available on the entire API is Save
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
the only way it returns an image is a save command with only 1 overload allowing me to save the file to a path.
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
An encrypted volume (think TrueCrypt) would be overkill, but I can't think of any alternatives.
I are Troll
|
|
|
|
|
Something that may help you is the Namespace System.IO.IsolatedStorage, for example IsolatedStorageFile-Class. Sorry, no time to do some tests but read this[^] to get an idea.
|
|
|
|