|
Hello,
I'm having a problem where an exception is thrown while trying to download files, using the Tamir.SharpSSH library, if the files don't exist. It's expected behavior, however, after the exception is thrown I'm unable to close the connection because I lose scope. I'm sure there is a simple solution. I would appreciate any help. The code is currently...
try
{
Sftp sftp = new Sftp(sftpServer, sftpUserName);
sftp.Password = sftpPassword;
sftp.OnTransferProgress += new FileTransferEvent(sftp_OnTransferProgress);
sftp.OnTransferStart += new FileTransferEvent(sftp_OnTransferStart);
sftp.Connect(22);
if (sftp.Connected)
{
DateTime now = DateTime.Now;
string year = now.Year.ToString();
string month = now.Month.ToString();
if (month.Length < 2) { month = "0" + month; }
Log("Attempting to download all files from todalton directory for the current month");
sftp.Get("balance//todalton//daltonAutoload" + year + month + "*", @"C:\higherone\");
Log("Transfer Complete");
}
}
catch (Tamir.SharpSsh.jsch.SftpException)
{
Log("No files of the given criteria exist on the server.\r\n\t\tDownload aborted."
+ "\r\n\t :NOTE: If this is the first run of the month, this is the expected behavior.");
}
catch (Exception ex)
{
Log(ex.Message + " :NOTE: sftp connection failed during download");
}
finally
{
sftp.Close();
}
I can't reach the Close method from within finally or either catch. Originally the close was where it is commented. Obviously the exception causes that line to be missed though.
Thanks
|
|
|
|
|
I can't see how your code even compiles. You declare sftp inside your try block, which is means that it shouldn't be available in your finally block. This leads me to think that you have declared a member called sftp as well.
|
|
|
|
|
The obvious solution is to give sftp a wider scope, maybe like so:
Sftp sftp;
try {
sftp=new Sftp(...);
...
} catch (...) {
...
} finally {
if (sftp!=null) sftp.Close();
}
The better approach, if the class implements IDisposable() and relying on the assumption that a call to Dispose() also closes the connection, would be based on the using statement:
try {
using(Sftp sftp=new Sftp(...)) {
...
}
} catch(...) {
...
}
Now in whatever way you leave the using block (short of killing the process!) sftp.Dispose() will be called automatically, even when an exception gets thrown.
|
|
|
|
|
Don't think you have added compiled code, declare sftp outside, you get correct output
|
|
|
|
|
Thank you all. That was the problem. I created it outside of my try and it's good. DOH, right?
|
|
|
|
|
|
[7 years later]
The shame
|
|
|
|
|
Hello,
does anyone know where I can find the function which maps the pixel coordinates from the source to the destination?
I draw a (stretched) bitmap using
InterpolationMode.NearestNeighbor
and
PixelOffsetMode.Half
onto a canvas and now want to know which pixel was mapped to a certain position - so that if I click with the mouse on that stretched pixel, I get the original coordinates.
Thank you in advance!
Alex
modified 27-Jun-12 9:12am.
|
|
|
|
|
(this gibberish sentence has been necessary to get the message accepted by CP as it "appears to have already been posted")
No I've never seen that function being available. However there are two simple solutions for what you seem to want:
1.
the interpolation is quite simple, it basically is a linear re-scaling, something like:
xNew = x * scaleNew / scaleOld
and then the options determine the petty details.
For one you need a floating point operation, and the result needs turned into an int again; that is where NearestNeighbor comes in (it basically means regular rounding: less than 0.5 becomes 0; 0.5 or more becomes 1). And PixelOffsetMode.Half means 0.5 is added anyways, so I would give this a try:
xNew = floor (*(x+0.5) * floatScaleNew / floatScaleOld)+0.5)
Caveat: one has to be careful with negative values, so when you run some tests, include both positive and negative values (unless negatives are irrelevant to your app).
2.
As a big alternative you could simply use the function they use without having direct access to it; this is how it works:
make a synthetic image, width=your original width, height=1; fill it with a wedge, i.e. the values 0, 1, 2, 3... etc. if it is a gray image; or perhalps (0,0,0), (1,1,1), (2,2,2), (3,3,3) if you prefer a regular RGB image (you may need a modulo-256 then).
now let the system apply your scaling to it (in x direction), yielding a larger image with the same width as your actual scaled image. When you click the actual scaled image, use the mouse position and look into the scaled synthetic image; it will return a pixel value which equals the original x coordinate (or at least the lowest 8-bits of it if your synthetic is RGB).
You can use the same trick in the other direction of course (i.e. there is no need to have a 2-D synthetic image).
modified 27-Jun-12 15:58pm.
|
|
|
|
|
Thank you for your answer.
At the moment, I use a formula similar to your first aproach where I get an error of up to +/- 1 pixel - it may be enough for the moment...
Your second aproach is clever. Perhaps I will try it later (using an invisible bitmap filled with the index as rgba value ...).
Alex
|
|
|
|
|
I am trying to add local group to adam group and it throws an exception Quote: "Only domain Principal objects can be inserted into groups in this store."
This is the code, groups are GroupPrincipal instances from System.DirectoryServices.AccountManagement
adamGroup.Members.Add(machineGroup);
adamGroup.Save();
It works when trying to add domain group in adam group and adam group to adam group
Only local groups have this problem
|
|
|
|
|
Don't post in Quick Answers[^] _and_ here. Pick one and stick to it.
Ciao,
luker
|
|
|
|
|
I have a problem, i have text stored in xml file formatting like this:
<sentence>
<token tag='man'>
John
</token>
<token>
is
</token>
<token>
a doctor
</token>
</sentence>
<sentence>
<token tag='man'>
He
</token>
<token>
has
</token>
<token>
a wife
</token>
</sentence>
....
I want to show this text for User(on a TextBox, a Panel,...) ,and tokens which have tag='man'(in this case:John,He ) have different color from the rest ,plus, they can be Clicked (to show extra information,etc) .It appears that in ToolBox there is not such a tool could do this .So I don't know how to solve it, does anybody have any suggestions ??Thanks for reading this!
|
|
|
|
|
Either use a RichTextBox and have some complicated code to catch it when the user clicks an embedded hyperlink, or add a label for each word to a panel and hook up their click-events.
Bastard Programmer from Hell
|
|
|
|
|
Thanks for advice, Eddy, I'm not a programmer yet, just a student getting stuck with this problem
|
|
|
|
|
Aight, then we'll take the easy route. Can you create a panel dynamically and add it to a form? Would be something like this;
public Form1: Form
{
Panel myPanel;
public Form1()
{
InitializeComponent();
myPanel = new Panel();
myPanel.Dock = DockStyle.Fill;
Controls.Add(myPanel);
}
}
After that you'd add a Label control to the panel for each token in your file, in a similar way. If you set their Dock property to align to the left, they'd line up nicely within the panel. Once you got that, it'd be easy to hook up a method that gets executed when someone clicks on a label
Bastard Programmer from Hell
|
|
|
|
|
Hi,
I have a crystal report.
I have list of items which gets printed in the detail section of the report.
I have one field which should come at the end of detail section, regardless of number of items.
currently that field is coming after first item.
I want something like below
===============================
DETAIL SECTION:
ITEM1
ITEM2
ITEM3
(Here I want my field, which should come only once)
===================================
Thanks in advance
|
|
|
|
|
Hi,
Why the App.Config is usually copied in the application folder in Program Files? any technical reason?
Is it advisable to move it to the AppData folder?
|
|
|
|
|
jrahma wrote: Why the App.Config is usually copied in the application folder in Program Files? any technical reason?
Is it advisable to move it to the AppData folder?
A logical reason; it's a configuration at application level. The documentation on the <a href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx">SpecialFolder</a>[<a href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx" target="_blank" title="New Window">^</a>] enum contains explanation on what the different folders are used for.
Bastard Programmer from Hell
|
|
|
|
|
I never use App.Config; I always roll my own in AppData.
|
|
|
|
|
you should not move application configuration file to AppData.
Reason : App.config file is configuration for the application as its name suggest but at the time of deployment. You should not touch this file once the application is installed.
The reason why this file is copied to the installation folder is same as that of all the exes and dlls that you deploy. which are not editable or undergo any changes unless a new version is installed.
Installation folder : is a base image of your application
App Data Folder : is deployment/user specific and can be altered at any time.
Generally, administrator has a rights to change the installation folder. A normal user can not change any files within it. Problem arises when you give control to user over this installation directory. Think if this config file is tempered by the user. Config files are automatically loaded by the application and hence result in application crash where as, appData folder can be loaded and validated by the code.
I am not sure why you want to do this but, I am guessing you want some of the settings to be altered at the run time. If that is the case then there is option for doing this in the visual studio. There are two types of the settings Application & User, user use setting for this case
Hope this helps
Happy Coding
|
|
|
|
|
G'day people,
I was wondering if I could get a point in the right direction on how to squash a bug. The app I am writing is basically a control panel type thing, and it brings up notification boxes if something needs to be actioned.
On certain computers, if the user clicks "Snooze All" in the notification box, the application crashes with a StackOverflowException. All the "Snooze All" button is doing is manipulating DataTables and closing the notification box. I was originally wondering if it was a DLL issue, but I can't see why it would happen whilst running - not opening or closing any forms at all!
The error information is listed below.
Problem Event Name: CLR20r3
Problem Signature 01: afns gui 3.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4fe2c742
Problem Signature 04: System.Windows.Forms
Problem Signature 05: 4.0.0.0
Problem Signature 06: 4da3cf4e
Problem Signature 07: 3e23
Problem Signature 08: 0
Problem Signature 09: System.StackOverflowException
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 3081
Additional Information 1: c51c
Additional Information 2: c51c01e8afa2e7706a621e0a166b392d
Additional Information 3: a841
Additional Information 4: a841e87d6b8fde0994c2a1134b39ab43
|
|
|
|
|
Without knowing more about exactly what is happening, you and I are in the same boat - it could be anything.
I would start by looking at the computers: is there anything specific to the computers it crashes on, that is not applicable to those it doesn't?
Does it happen every time? If not, when does it happen? Occasionally? Often? Very rarely? To a particular user? OS? Network segment?
Basically, you need more info. If you can get it to happen reliably, then insert logging code to try to track the path it is taking, and look for oddities in the log.
I know all this is basic stuff, and I'm probably teaching my Granny to suck eggs, but with the information so far, all I can suggest is generalities.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Basically in one room the office is shared by 8 computers. On 7/8 computers the application crashes when the snooze button is hit. This doesn't write anything back to the SQL Server, only to local DataTables.
Only one of them works correctly, all are up to date with Windows Updates.
It appears to be computer related, as when I use my local user account (I haven't tried my domain administrator account) it carries the same error. I use the same login on my Developer PC (I know, not a good test) and it works fine.
I have a rough idea of where it fails, but I have no experience with StackOverflowExceptions, so where do I go from there?
|
|
|
|
|
If you can't use visual studio I would wrap the method call in your button click with a try { }catch (StackOverflowException e){\\log the error message and stacktrace } (if any try catch blocks are inside the method calls log there also)
If you can use visual studios to debug and replicate the exception then go to the menu "debug>exceptions" and in the window that comes up expand "Common Language Runtime Exceptions" and then expand "System" and find StackOverflowException and then check the check box under "thrown". This will take you right to the line throwing the exception when using the debugger. Before you stop the debugger you can look at your locals window to see current values of any variables.
Hope that helps...
|
|
|
|