how to make custom extraction rule property data driven? - c#

I have created custom extraction rule and the property i need the properties to be data driven i.e. I want to attach a data source (CSV file). how do I go about it ?
Followings are the screen shots and code snippets that describes the problem
Code snippet for custom extraction rule class
public class CustomeExtractionClass : ExtractionRule
{
public string Name
{
get;
set;
}
public override void Extract(object sender, ExtractionEventArgs e)
{
// Code to extract text/values from Response Based On NAME(i.e. Property) value
received from UI
}
}
UI for Name property
Note : Textbox next to Name property
How do I make it Data driven ? just like the one we get while inserting FormPost parameters... here is the example
Note the dropdown button bottom right which pulls up the attached data sources... I want the Name property values to be attached to the same data source.... how do i go about it ???

Finally after spending many hours I was able to get the values from the CSV file into my custom extraction rule. I could not bind the CSV file column to the Extraction rule property, however i got the work around. here is what i was missing
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
here are the steps to achieve it
Step 1 : Add data Source to WebTest (Skip if already added)
Step 2 : Generate Code from WebTest (Skip if already done)
Step 3 : Bind datasource (i.e. CSV file) columns by adding following lines of code just above the declaration of your webtest class.
[DataSource("DataSource1", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\customextractionrule\\mycsvfile.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, Microsoft.VisualStudio.TestTools.WebTesting.DataBindingSelectColumns.SelectOnlyBoundColumns, "mycsvfile#csv")]
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
public class WebTest2Coded : WebTest
{
Note : in above code "MyProcessInstanceID" is the name of context parameter which will be created by visual studio and value of CSV file column will be assigned to this context parameter. you can give any name you wish.
Step 4 : Access the value of the Context parameter in your custom extraction rule
public override void Extract(object sender, ExtractionEventArgs e)
{
string ProcessIDinCSvFile = e.WebTest.Context["MyProcessInstanceID"].ToString());

To set the context parameter to the text within the field just enter the full name of the data source field enclosed in doubled curly braces into the field. The correct form of text is shown circled in red in an image in the question, namely {{DataSource1.mycsvfile#csv.ProcessInstanceID}}.
Data source fields can also be accessed directly from the context by code such as
string theText = e.WebTest.Context["DataSource1.mycsvfile#csv.ProcessInstanceID"].ToString();
If the Name field of the extraction rule is set to the name of a content parameter (ie not to its value) then the current value can be read out and a new value inserted with code like
string theText = e.WebTest.Context[Name].ToString();
e.WebTest.Context[Name] = "The new string";

Related

Getting values from gridView cell C#

I want to get the data from a cell from a selected row, in a gridView, and bring it into another form, inside a textEdit that then edit the row of the selected cell, the problem is that when using
var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.toString())
the messageBox writes Test01.parnersMissing, where Test01 is the name of the project and I really don't know why PartnersMissing is there. What is wrong in this code?
The datagrid has data from an sql database and it is made with DevExpress.
Please don't mind the names for the variables if you know italian, I was in a hurry :D
The current row can be obtained using the GridView's
GetFocusedRow method. This method returns an object whose actual
type is determined according to the data source.
If you are binding it with a List<PartnersMissing> objects then you are getting correct value from the GetFocusedRow method. If you want to access the property of the current row object then you can simply do it.
for example: PartnersMissing has property ABC then you can access as below:
var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.ABC)
ToString() method returns the type of the object not any property value. you just printing type of the object rather than accessing property of object.
As Dimitry Says, You can also access particular column value or row' PartnersMissing object property using the GetFocusedRowCellValue(String) Method.
As far as I can see from your code, the result is expected because the cacca.toString() expression return the type name for those types, which do not override the standard object.ToString method.
To show something helpful, you should either to override this method
class PartnersMissing {
public string Name { get; set; }
public override string ToString(){
return Name;
}
}
or to obtain the specific values from your object's fields:
MessageBox.Show(cacca.Name);
You can also to obtain the object's fields value directly from the gridView:
string name = gridView.GetFocusedRowCellValue("Name");

Add a column with derived data to a DataGridView

I have a datagridview bound to a list of "CarColor" objects. I am attempting to add an extra column to the dataGridView that takes the Name property of each CarColor and displays the localized version.
Currently I have an extension method that creates the column and populates it with the correct values but every time the dataGridView changes visibility or data, all the cells in the Localized Name column become empty. Before now I've managed a workaround by running the extension method on the dataGridView's VisibileChanged and DataSourceChanged events. This is cumbersome, especially if I am trying to affect a DataGridView in another control (such as a dialog).
I have read that using a DataGrid is an option, via setting the "Expression" value of a new column. However, I don't know if it's possible to convert a list to a DataGrid, or convert a DataGridView into a DataGrid.
How can I ensure that the values of the Localized Name table aren't erased?
If you have a List<CarColor> you don't need DataTable to add a new computed column. You can simply add a new property to the CarColor that returns the desired computed value or in your case the localized value of its Name property.
public partial class CarColor
{
publlic string LocalizedName
{
get
{
return GetLocalizedName(this.Name);
}
}
private string GetLocalizedName(string name)
{
// put the logic for localizing the name here
}
}
Note:
I wrote it partial, so you can let the original CarColor class untouched, just add this partial in the same namespace, or if you prefer, simply add body code of the class to the original CarColor.
If CarClass in not your class and you van not change it's code, yo can create a ViewModel class for CarColor and use the same idea to represent that property.

Mutator method not changing TextBox text to parameter contents

I have a series of mutator methods in another class, each of which is linked to a textBox.
(ClassA). Now, I am using an object of ClassA (myClassAObject.setFirstName(param here), to set the text, so the contents of that parameter will display in that textbox.
The content of that mutator method is as follows:
public void setFirstName (string newFirstName)
{
txtBoxFirstName.Text = newFirstName;
}
I know that the mutator works correctly, because otherwise I'd not see the first name of the patient, I'd see "null", or in the case of a println, a blank space.
The question is below this line
The mutator method, for some reason is not causing the textBox to display the text it is given in a parameter, when I access it from the other class. The textBox remains blank. How can I get it to work correctly? I have used MessageBoxes to check if there is a value for the textBox to display, and yes, the contents of the variable appear onscreen.
Here is how the parameter is passed from the second class, to the class in which the textBox resides:
myClassAObject.setFirstName(firstName);
The code above is example code, but it illustrates what I am doing.
Below is the actual code.
Firstly, from the class where the textBox resides.
Secondly, where the new parameter is being passed from.
public void setPatientFirstName(string newPatientFirstName)
{
txtBoxPatientFirstName.Text = newPatientFirstName;
}
Second part of code:
patientRecordClassOverseer.setPatientFirstName(patReaderFirstName);
I am using a "Reader" (OleDB) to read the data from the database. It is working, as I have MessageBoxes setup for debugging purposes.

Custom Data Attributes in C#

Is there a way that we define a custom attribute over a property so that when ever that property is used 1 is added to its amount and stored in database and when ever, I retrieve it from database 1 is subtracted from it?
For example
say this is the emdx class
public class book
{
[Required]
string author{get;set;}
[customAttribute]
int amount{get;set;}
}
so what I want is when ever amount is getting stored in database 1 is added into it and when ever I retrieve it 1 get subtracted. I know we can get and set it here but I want to do it using custom attribute because I want to do it on a lot of places and I don't want to write custom code every where.

Updating a property using the Content Service api in Umbraco 6.x

I've created a custom user control for the back-end of my Umbraco site that allows administrators to quickly update certain fields on nodes without having to navigate through the content tree.
So far my code is working as expected: I can update simple true/false properties without a problem. However now I'm trying to update a property that's of a custom data type and I'm running into difficulties.
The data type itself is just a simple drop down that lists a series of availability statuses ie. Available, Unavailable, Sold and Reserved. The datatype is storing the text values.
Here's the code I have that allows me to update my true/false properties:
public void ChangeInteractiveStatus(string nodeId, bool chkValue)
{
var cs = ApplicationContext.Current.Services.ContentService;
var apartment = cs.GetById(Convert.ToInt32(nodeId));
apartment.SetValue("displayOnInteractive", chkValue);
cs.SaveAndPublish(apartment);
}
This works absolutely fine as the data type of this property is a regular true/false data type.
Here's the code I'm using to change the value of my custom dropdownlist data type:
public void ChangeAvailabilityStatus(string nodeId, string status)
{
var cs = ApplicationContext.Current.Services.ContentService;
var apartment = cs.GetById(Convert.ToInt32(nodeId));
apartment.SetValue("status", status);
cs.SaveAndPublish(apartment);
}
As you can see there's very little difference and yet this code isn't working.
In order to check what was happening when I was updating the properties with the above code, I checked the umbraco.config file only to find that the property in question was displaying as follows:
<status><![CDATA[]]></status>
However when I change the value in the content tree (without using my admin control) the value gets saved properly as:
<status><![CDATA[Sold]]></status>
So for whatever reason, when I try to update the value it's being rejected and I can't work out why.
FYI I tried entering the value as:
"<![CDATA[" + status + "]]>"
Yet that made no difference.
Does anyone know how I can fix this? How can I get the property to update correctly?
Thanks
Okay I've figured out what the problem was. It seems the values were being stored as name-value pairs, so the actual value getting stored in the database was an integer. Once I updated the code to insert the integer id it all worked as expected! Hooray.

Categories

Resources