|
I am splitting this out and returning it as separate rows The delim is \r\n:
{[Report Criteria, Filter Criteria
:.Archived
: :.All
:.Request ID
: :.xxx
:.Group & Sort Criteria
:.Employee Name Ascending
:.Agency Org Ascending
Report Executed on : xxxxxxxxxxxxxxxxxx UTC]}
Here is the code: I am going to replace rx with rx1, but rx1 does not have "rx1.MoveNext" look below
var rx = ((IEnumerable)e.Current).GetEnumerator();
IEnumerable enumerable;
var rx1 = (IEnumerable)rebuildReportCriteria(((IEnumerable)e.Current).GetEnumerator());
for (int j = 0; rx1.MoveNext(); j++)
{
object v = ((KeyValuePair<string, object>)rx.Current).Value;
string s = "", l = "";...................................
private static object rebuildReportCriteria(IEnumerator enumerator)
{
var list = new List<KeyValuePair<string, string>>();
string v = "";
for (int j = 0; enumerator.MoveNext(); j++)
{
v = ((KeyValuePair<string, object>)enumerator.Current).Key;
if (v == "Report Criteria")
{
string[] stringSeparators = new string[] { "\r\n" };
string[] lines = ((KeyValuePair<string, object>)enumerator.Current).Value.ToString().Split(stringSeparators, StringSplitOptions.None);
foreach (string s in lines)
{
list.Add(new KeyValuePair<string, string>(((KeyValuePair<string, object>)enumerator.Current).Key, ((KeyValuePair<string, object>)enumerator.Current).Value.ToString()));
}
}
}
if (v == "Report Criteria")
{
return list.GetEnumerator();
}
else
{
return enumerator;
}
}
modified 10-Mar-16 11:24am.
|
|
|
|
|
|
Hi,
In my application I am in the process of writing I am building a string containing the result of a test and a comma to be saved out as a CSV file however a test can be re-triggered by accident, not an issue. The problem I have is that the re-triggering can lead to a result being added to the string. I have added a Boolean variable to see if its being re-triggered and if it is only add to the string once see below:
lblPumpMotorSpin_.BackColor = Color.Green;
if (ResultsRecordedOncePumpMotor == false)
{
Results += "Pump Motor OK,";
}
ResultsRecordedOncePumpMotor = true;
This then reset to false in the reset routine for the next attempt.
My thinking was this before it entered Reset() which was after the save routing it would be set to true so it would not enter the if(), but it does!
Any thoughts anyone??
Glenn
modified 11-Mar-16 8:22am.
|
|
|
|
|
What are they declared as?
Are Results and ResultsRecordedOncePumpMotor both static, or both class instance? Or a mix of the two?
If the test can be restarted while a test is in progress, then that implies multiple threads, so you probably want to cancel any running test before you start a new one - which would get rid of the need for the bool.
And a couple of style points:
1) You can use "!" instead of "== false"
if (!ResultsRecordedOncePumpMotor)
2) You shouldn't really add to strings, particularly to build large results sets. Since strings are immutable, each time you add two strings, you create a new longer one and copy both over. Use a StringBuilder instead and Append the data - it's a lot more efficient.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ah Ha! Threads dang it! Thanks for that.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Umm Griff, do you know of a good string builder reference as I can create the string save the string like I could with a string, how can I search the string to find the last item added to it and if its the same don't append it?
Further reading has revealed the .Remove method, however I am not sure this would work as you have to know the exact location in the string, however if you placed a test loop after each function that talked to the string something like
int i=0;
foreach(string subString in sbResults(',')
i++
if( i >4)
{
MessageBox.Show("extra!");
sbResults.Remove(i,5);
} if the message was 5 long. Am I on to anything here??
modified 10-Mar-16 11:11am.
|
|
|
|
|
StringBuilders don't have Contains, StartsWith, or EndsWith methods - so basically you can't search one.
What are you actually building up? Is this a single line of CSV data, or a file full, or what?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sorry looks like you replied as I was updating my earlier response, I cannot type today for some reason. Its a single line of a CSV, some times the data can get duplicated via a switch...
|
|
|
|
|
I'd be tempted to say "sod that" and cheat!
Is the order important?
If not, then create a List<String> of elements to make up your CSV data, and use the Linq Method .Distinct to remove duplicates. Then String.Join to bolt 'em together with commas.
string csv = string.Join("," myList.Distinct());
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The order is not really important, I am starting the record process from scratch. Thanks I will give it a look.
|
|
|
|
|
If threads are causing your duplicate, you're in even bigger trouble, since you are also accessing a Control property, something only the GUI thread is allowed to do.
IMO your code needs a big overhaul: use a model that holds your data, a view that takes care of the UI, and a separate object (or at least an explicit method) to create the output file(s) you need.
By not mixing it all up you'll avoid both illegal cross-thread Control accesses and the risk of duplicates in your CSV.
|
|
|
|
|
Thanks, I will give a look!
|
|
|
|
|
I would more likely keep a Dictionary or something to hold the items to be written, you can add an item more than once and it'll just overwrite the existing value, then format and write it once everything is ready.
A small class could easily be written to encapsulate Add, Write, Clear functions.
|
|
|
|
|
I'll look into that! Thanks
|
|
|
|
|
Hi.
Lemme try to be clear here.
I've a code, with two files: Form1.cs and Classes.cs
Classes.cs contains all my methods, variables, etc (and the FilesystemWatcher implementation).
Form1.cs (The main form) contains some button calls, and a call to FilesystemWatcher (when the button is pressed).
What i'm trying to accomplish and can't see to figure out is: Show a ProgressBar from this FilesystemWatcher.
Consider the following scenario: I Just clicked a button and FilesystemWatcher has started. It will monitor the folder and do operations over created files. How i'm gonna show the progress for that ?
On my readfiles() method (inside the Classes.cs) i've tought about passing a variable trough parameter that indicates how much of the file has been read - for so i would have to implement FilesystemWatcher in the Form1.cs. But the FilesystemWatcher calls all my methods.
His method on Classes.cs looks like:
SetupFileWatcher()
all other methods to convert files, etc...
Even if i move FilesystemWatcher to Form1 main code, he doesn't return any progress value - he just run methods as soon files are added.
Lemme try to show a piece of code (This happens at Classes.cs)
Implementing filesystem watcher on this method...
protected FileSystemWatcher SetupFileWatcher(string path)
FileSystemWatcher Call
public void ProgramProcessing(string filePath)
{
SetupFileWatcher(SelectedFolder);
InputFolderSelect();
ReadFiles();
FileDefinition();
ColorExtraction();
ColorValueExtraction();
DataGrouping();
NumberProcessing();
ColorPoolManipulation();
WriteInkzoneXML();
WriteColorPoolXML();
}
Now, this happens inside Form1.cs:
private void btnGo_Click_1(object sender, EventArgs e)
prg.ProgramProcessing(textBox1.Text);
How could i possibly achieve that ? Is it possible ? Al i would like is to show the progress for the operation (or at least the methods for reading files and write XML).
Thanks in advance for any help\guidance.
|
|
|
|
|
|
Message Removed
modified 8-Mar-16 4:20am.
|
|
|
|
|
Hi All,
I am trying to write console application using C# which can export IBM DB2 table data from master database and import same to IBM DB2 table in target database , provided both tables are not coming under same DB2 instance.
can someone please provide direction how to achieve this ?
I tried using DB2BulkCopy Class but not succeeded.
pls help
Thanks
|
|
|
|
|
|
Or you can hit it with a hammer - make a connection to DB1, query the data and store it somewhere.
Connect to DB2 and write each record into the target table from the temp store.
Definitely not elegant and may be unworkable with serious volume.
Explore setting up a linked server and creating a stored proc that can do the job without taking the data into your c# client.
There should also be the equivalent of SQL Servers DTS ETL tools!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for reply,
One more POC i am planning to write using SSIS package. Only one thing i need to check support of IBM DB2 with SSIS package.
|
|
|
|
|
i need to code windows form project to alert Earth quakes. This is i use web site. its update live earth quakes in world. No i need to get that details(Earth quake value) and active a alarm or message. so i need to read that values of this site. How can i do.. can anybody help me.. thank you..
|
|
|
|
|
Probably the easiest way for you to do this would be for your windows application to loop around and check to see if there are any new events. You would have to do this on a background thread.
This space for rent
|
|
|
|
|
Just to add to what Pete says, you also need to look at site scraping to extract teh data you are interested in.
A simple google should help with that: site scraping c# - Google Search[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|