|
As you said, the value can be an actual integer or an array, when it's an array it attempts to cast the array as an integer and it returns null value, which causes the error. What needs to happen here, you need to check first if it's an array and then search in the array
var roleFour = (from people in json.SelectTokens("DataFeed.People")
.SelectMany(i => i)
let ids = people["roleIds.int"]
where (int) people["active"] == 1 &&
(ids.Type == JTokenType.Array) ?
((int[]) ids.ToObject(typeof(int[]))).Any(k => k == 4) :
(int) ids == 4
select new {
Id = (int) people["id"],
ResAnFName = (string) people["firstName"],
ResAnLName = (string) people["lastName"]
});
|
|
|
|
|
I'm getting the following error:
NullReferenceException: Object reference not set to an instance of an object.
|
|
|
|
|
Can you change the Json source to force the "int" property to an array, so that your first value would be '["1"]'? That would simplify things considerably, especially since your cast is wrong for 2 of the supplied data elements (id 65 and 66 should be (int[])people["roleIds.int"].Contains(4) not (int)people["roleIds.int"] == 4).
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Sorry. I don't have any control over that. Yes, it makes more sense if it was always an array, but that's what I get from the web service feed.
|
|
|
|
|
You see the attached image file, this very same combobox control when you hover on the number 1 click on the arrow down 1 the same menubar menu, hover in the 2 and 3 show up as the number 1 button, if in the area No. 2 is clicked, the button will be displayed on the No. 1 as we manipulate click items in the combobox, if in the number 3 is clicked will open 1 form, particularly in the region of 2 to add or delete items will be added or removed as combobox manipulation, you know DevExpress controls are in the name of anything? [IMG]http://imagizer.imageshack.com/img923/6672/I3JgLe.jpg[/IMG]
|
|
|
|
|
I've looked at the image, and I can't figure out what you are asking here.
Are you using Windows Forms, and your goal is to add some special behavior to interaction with the standard ComboBox ?
If you are using DevXPress, they have good support forums, I hear.
Please clarify.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
What is your question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have this sample FTP code that works fine:
public class SFTP
{
private string _address = "";
private string _userName = "";
private string _password = "";
public SFTP(string address, string userName, string password)
{
_address = address;
_userName = userName;
_password = password;
}
public void DownloadFile(string localFile, string remoteFile)
{
var ftpConnection = GetConnection();
ftpConnection.DownloadFile(localFile, remoteFile);
}
public FTPFile[] GetFileList()
{
var ftpConnection = GetConnection();
FTPFile[] fileDetails = ftpConnection.GetFileInfos();
return fileDetails;
}
public void UploadFile(string localFile, string remoteFile)
{
var ftpConnection = GetConnection();
ftpConnection.UploadFile(localFile, remoteFile);
}
private FTPConnection GetConnection()
{
FTPConnection ftpConnection = new FTPConnection();
ftpConnection.ServerAddress = _address;
ftpConnection.UserName = _userName;
ftpConnection.Password = _password;
ftpConnection.ConnectMode = FTPConnectMode.ACTIVE;
ftpConnection.BytesTransferred += FtpConnection_BytesTransferred;
try
{
ftpConnection.Connect();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
return ftpConnection;
}
private void FtpConnection_BytesTransferred(object sender, BytesTransferredEventArgs e)
{
Console.WriteLine("{0}: {1}", e.RemoteFile, e.ByteCount);
}
}
Now I want to be able to upload or download multiple files at once and show progress for each. Basically this code needs to run seperetly for each file being uploaded or downloaded. What's the right way to implement this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 20-Sep-16 16:18pm.
|
|
|
|
|
Confused? Why don't you simply do
public void UploadFile(string[] localFiles, string[] remoteFiles)
{
var ftpConnection = GetConnection();
for(int i=0; i<localFiles.Count; i++)
{
ftpConnection.UploadFile(localFiles[i], remoteFiles[i]);
}
}
|
|
|
|
|
The files need to upload/download simultaneously, not one at a time
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Well, then replace for by Parallel.ForEach . First get your filenames into a Dictionary<string, string> , then do
Parallel.ForEach(dictionary, keyValuePair =>
{
ftpConnection.UploadFile(keyValuePair.Key, keyValuePair.Value);
});
|
|
|
|
|
Good idea.. Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You might also need to consider the server's limit on the number of simultaneous transfers. If you're lucky, your excess transfers will just queue, but I wouldn't count on it.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
When you're using a third-party library, it helps if you tell us which one.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It really doesn't matter. The code I posted works. However, FYI, since you asked, I'm using this.[^]
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I am trying to extract the IDs or Names from a string and insert them in the first cell of each row and put the rest of the string in the remaining cells of each row.
For instance if I have the following string
{ID:AA, Make:ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name:XD, Make:DHS, Year:2006}
The data in the array will look like the following after extracting the IDs or Names, inserting them into the first cell of each row, then putting the rest of the string in the remaining cell of each row. The vertical bars represent the cells of the array.
|ID:AA|Make:ABC, Year:1995|
|ID:BB|Make:BBC, Year:2000|
|ID:XD|Make:DHS, Year:2006|
I have tried the following but its giving me the IndexOutOfRange exception.
string testString = "{ID:AA, Make:ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name:XD, Make:DHS, Year:2006}";
string[] outerArray = Regex.Split(testString, "},{");
string[,] innerArray = new string[2, outerArray.Length];
string idPattern = "^(ID)(.*?),";
string namePattern = "^(Class)(.*?),";
for (int i = 0; i < outerArray.Length; i++)
{
outerArray[i] = outerArray[i].Replace("{", "").Replace("}", "");
for (int y = 0; y < innerArray.Length; y++)
{
for (int x = 0; x < innerArray.Length; x++)
{
var matched_ID = Regex.Match(outerArray[i], idPattern);
var matched_Name = Regex.Match(outerArray[i], namePattern);
if (matched_ID.Success)
{
innerArray[x, y] = (matched_ID.Value).Replace(",", "");
}
else if (matched_Name.Success)
{
innerArray[x, y] = (matched_Name.Value).Replace(",", "");
}
if (outerArray[i].Length > 0 && !outerArray[i].Contains("ID:") && !outerArray[i].Contains("Name:"))
{
innerArray[x, y] = outerArray[i];
}
outerArray[i] = outerArray[i].Replace(matched_ID.Value, "");
outerArray[i] = outerArray[i].Replace(matched_Name.Value, "");
}
}
}
modified 20-Sep-16 12:47pm.
|
|
|
|
|
Are you sure?
If I copy and paste your code I get
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: String cannot be of zero length.
On this line:
outerArray[i] = outerArray[i].Replace(matched_Class.Value, "");
Because matched_Class didn't succeed but you don't check for it - because Matched_ID did.
Use the debugger and you should see what I mean.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you so much for replying. I have made some modifications to my code and now it's giving me IndexOutOfRange Exception.
Please see my modified code below.
string testString = "{ID:AA, Make: ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name: PDA, Make: DHS, Year:2006}";
string[] outerArray = Regex.Split(testString, "},{");
string[,] innerArray = new string[2, outerArray.Length];
string idPattern = "^(ID)(.*?),";
string namePattern = "^(Class)(.*?),";
for (int i = 0; i < outerArray.Length; i++)
{
outerArray[i] = outerArray[i].Replace("{", "").Replace("}", "");
for (int y = 0; y < innerArray.Length; y++)
{
for (int x = 0; x < innerArray.Length; x++)
{
var matched_ID = Regex.Match(outerArray[i], idPattern);
var matched_Name = Regex.Match(outerArray[i], namePattern);
if (matched_ID.Success)
{
innerArray[x, y] = (matched_ID.Value).Replace(",", "");
}
else if (matched_Name.Success)
{
innerArray[x, y] = (matched_Name.Value).Replace(",", "");
}
if (outerArray[i].Length > 0 && !outerArray[i].Contains("ID:") && !outerArray[i].Contains("Name:"))
{
innerArray[x, y] = outerArray[i];
}
if(matched_ID.Success)
{
outerArray[i] = outerArray[i].Replace(matched_ID.Value, "");
}
else if (matched_Name.Success)
{
outerArray[i] = outerArray[i].Replace(matched_Name.Value, "");
}
}
}
}
|
|
|
|
|
MadDashCoder wrote: now it's giving me IndexOutOfRange Exception. This is a very, very simple error to fix and debug. You should be able to fix it faster than it takes to post this message.
Put a breakpoint and step through the code and you'll see exactly what is happening.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
As RyanDev says: the debugger makes it obvious.
You declare the array as
string[,] innerArray = new string[2, outerArray.Length];
So what value is in x when the error occurs?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
MadDashCoder wrote: y < innerArray.Length
x < innerArray.Length
For a multi-dimensional array, the Length property returns the total number of elements in the array.
The total number of elements in all the dimensions of the Array; zero if there are no elements in the array.
If you have a 2 × 5 array, the Length will be 10. Obviously, that's not a valid upper limit for either dimension in the array.
Try changing your loops to:
for (int y = 0; y < innerArray.GetLength(1); y++)
{
for (int x = 0; x < innerArray.GetLength(0); x++)
{
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Or you could try something different:
string testString = "{ID:AA, Make:ABC, Year:1995},{ID:BB, Make:BBC, Year:2000},{Name:XD, Make:DHS, Year:2006}";
string[] rows = testString.Split( new string[] { "},{", "{", "}" }, StringSplitOptions.RemoveEmptyEntries );
string[,] array = new string[ rows.Length, 2 ];
for ( int i = 0; i < rows.Length; i++ ) {
string[] cols = rows[ i ].Split( new char[] { ',' } );
array[ i, 0 ] = cols[ 0 ].Replace( "Name", "ID" );
array[ i, 1 ] = cols[ 1 ] + ", " + cols[ 2 ];
}
|
|
|
|
|
Does anyone know how to login to an SSO website with winforms?
We have an API through http behind an SSO. I would like to test this API through a real application, it works in the browser. Basically the API returns images, JSON, XML stuff through GET depending on the URL you give.
We did a test through linux command lines and this inferred a two step process, login using the credentials and then using the received tokenid for each request.
If I know which classes to look at, would already be helpful. (looking at System.Security.* now, but I can't make any sense of it.) Tutorials usually write their own SSO stuff ,whereas I am working with an existing one (we don't manage).
[UPDATE]
I receive the token now on the first request, now I have to use that somehow to get to the API. I tried:
wrGETURL.Headers.Add(HttpRequestHeader.Authorization, "Basic " + tokenid);
(and variations) but this doesn't work
[/UPDATE]
thanks.
modified 20-Sep-16 8:04am.
|
|
|
|
|
Hello all. I have a C# Winforms application. A form has a report viewer control. The Reports and Stored Procedures exist on the report server. Right now we can run the application and display the reports just fine. Everything is working.
But now we have a new requirement. The reports display several tablix controls and each tablix is connected to an embedded dataset, which in turn gets is data from a stored procedure. The new requirement is to point the dataset to another stored procedure.
The C# application already has the following capability. It reads the SQL from an existing SP. It adds a WHERE clause to the query and then saves the modified query as the same stored procedure name with _modified at the end of the name. For example, an original stored procedure is called SP1. The new stored procedure is SP1_modified. The modified SP has a where clause in it. So, I want to change the embedded dataset (SP1) to point to SP1_modified. The dataset names are the same as the stored procedure names.
After the report is rendered in the reportviewer control, I want to change the datasets back to point to SP1, for example. The _modified stored procedures will be deleted from the server.
We can already do most of this. The only thing I have not figured out is how to point the embedded dataset to a different stored procedure. Thanks for your help.
|
|
|
|
|
You can configure a dataset before "loading" it.
The SSRS object model's dataset has a Query property used to specify: a stored procedure; text command; whatever.
Just like in ADO.NET.
|
|
|
|
|