Ranorex validate-How to check if RepoItemInfo object is equal to string data in C# code? - c#

I just want to check if my RepoItemInfo object (which is username Joe McAdam btw) is equal to string data.
I just tracked this element in Chrome, stored it in my repository and it is a span with #innertext="JoeMcAdam"
Then I made code module for mapping these objects in C# code:
public RepoItemInfo LeftNameRepoItem {get {return _pageHome.Home.ImeLijevoInfo; }}
And I have prepared data Name in my context file for this LeftName to check if they are equal:
void ITestModule.Run()
{
var dto = new LoginDto () {
Name = "Joe McAdam",
WaitTimeLimit = 20000,
};
LoginDtoContext.template = dto;
}
I just need a proper code example for checking if they are eqal. What should I do? Do I have to make some adapter for this RepoItemInfo to convert it in string, text or something else?
I hope I provided enough details about my problem.
Thanks in advance!

Related

Why is this function not printing out the specified objects values? C#

Im creating a program that will be used like a library, where you can for exampel look up a spesific book.. Let me run you through the code..
The problem im trying to solve is that the lookup function does NOT print out the books in my library list that contain that letters in question
This class is used for creating the books in the library
class Bok
{
public string titel;
public string author;
public bool loaned;
public Bok(string titel, string author, bool loaned)
{
this.titel = titel;
this.author = author;
this.loaned = loaned;
}
}
And with this I have created a new list, called library along with an example books
List<Bok> library = new List<Bok>() { };
Bok book = new Bok("alex bok", "alexander", false);
Now I'm letting the user input a string, which will be used to search for a specific book located in that list, im making all the cases of the string answer to lower and then checking if any object in the list library has an object of which the values "author" or "title" contains the string that the user entered, and then prints it
void Print(Bok bok)
{
Console.WriteLine("hej");
Console.WriteLine($"{bok.titel}\n" +
$"{bok.author}\n" +
$"Lånad : {bok.loaned}");
}
void Lookup()
{
Console.WriteLine("Sök efter titel, eller författare");
string svar = (Console.ReadLine()).ToLower();
foreach(Bok bok in library)
{
if (bok.author.Contains(svar) || bok.titel.Contains(svar))
{
Print(bok);
}
else
{
Console.WriteLine("Boken finns inte i biblioteket.");
}
}
}
Since we are not seeing the whole code, I'm not sure if you already did this at some point of your code, but i would try to:
Add the Bok book = new Bok("alex bok", "alexander", false); to the list List<Bok> library = new List<Bok>(); (get rid of the {} after creating the new list, you don't need them) with library.Add(book). Otherwise you iterate through an empty array in your Lookup() function.
Did you call your Lookup() function at some point in the code? Otherwise its just defined, but not executed.
I think what you are trying to do is add a collection of books then match the lower cased value.
Also consider using comparison or regex for more complex searches.
This however will work.
https://dotnetfiddle.net/nBswHI

How do I assign parameter values to a string using c#

I'm working on an implementation of workfront api and my application. This is suppose to be simple. Perhaps my code will explain better.
JToken tasks = client.Search(ObjCode.TASK, new { fields = "ID, extRefID, assignedTo:name" });
taskid = c.Value<string>("ID");
workItem = c.Value<string>("extRefID");
taskAssgTo = c.Value<string>("assignedTo:name");
Now, taskid and workItem return values correctly. I'm having trouble understanding why taskAssgTo will always return null. When debuggin, I can clearly see that assignedTo:name has correct values, but for some reason I will not assign it to taskAssgTo. (taskAssgTo is a string variable).
This is how it looks when retrieving the data using REST:
{
"ID": "4c78285f00000908ea8cfd66e084939f",
"extRefId": "4561",
"assignedTo": {
"ID": "4c78285f00000908ea8cfd66e084215a",
"name": "Admin User"
}
}
Please I would appreciate an explanation and a possible solution to this. Thanks in advance!
I don't see any documentation that says that you can access child values in the manner you are trying to access them.
I would try using dot notation instead, such as
taskAssgTo = c.Value<string>("assignedTo.name");
or following the link below to see how to navigate a JObject hierarchy
Searching for a specific JToken by name in a JObject hierarchy

Parse & Unity 3D : Update an existing row

Using the example code from the Unity Developer Guide | Parse
# https://www.parse.com/docs/unity_guide#objects-updating
// Create the object.
var gameScore = new ParseObject("GameScore")
{
{ "score", 1337 },
{ "playerName", "Sean Plott" },
{ "cheatMode", false },
{ "skills", new List<string> { "pwnage", "flying" } },
};
gameScore.SaveAsync().ContinueWith(t =>
{
// Now let's update it with some new data. In this case, only cheatMode
// and score will get sent to the cloud. playerName hasn't changed.
gameScore["cheatMode"] = true;
It just adds a new row and leaves the original row unchanged.
I guess i'm thinking Parse would do something "SQL like" such as UPDATE where primaryKey = 123.
Searching for an answer i found this code #
https://parse.com/questions/updating-a-field-without-retrieving-the-object-first, but there was no example in C#. All attempts to port this to C# result in multiple syntax errors.
UnityScript:
// Create a pointer to an object of class Point with id dlkj83d
var Point = Parse.Object.extend("Point");
var point = new Point();
point.id = "dlkj83d";
// Set a new value on quantity
point.set("quantity", 6);
// Save
point.save(null, {
success: function(point) {
// Saved successfully.
},
error: function(point, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
}
});
Does Parse have some way to update a row that already exists using C#? And where is it in the docs? And how can their own example be so useless?
One of the posts related to my question stated "retrieve the object, then write it back with the changes" and i had not the faintest idea how to execute the stated objective (especially after the epic fail of Parse Documentation's example code)
Here is what i have been able to figure out and make work:
var query = new ParseQuery<ParseObject>("Tokens")
.WhereEqualTo ("objectId", "XC18riofu9");
query.FindAsync().ContinueWith(t =>
{
var tokens = t.Result;
IEnumerator<ParseObject> enumerator = tokens.GetEnumerator();
enumerator.MoveNext();
var token = enumerator.Current;
token["power"] = 20;
return token.SaveAsync();
}).Unwrap().ContinueWith(t =>
{
// Everything is done!
//Debug.Log("Token has been updated!");
});
the first part retrieves the object with the stated objectId, the second part sets the fields in the object. The third part reports all is well with the operation.
it's a monkey see, monkey do understanding at this point being that i do not understand the finer points in the code.
the code can be tested by creating a class named "Tokens". in that class create a tokenName field and a power field. make a few rows with Fire, water, mud as the tokenNames. Replace the objectId in the .WhereEqualTo clause with a valid objectId or any other search parameters you like. Execute the code and observe the changes in the Parse Data Browser.
For extra credit create the class required to implement the example code from the Chaining Tasks Together section of Parse's Documentation.
https://www.parse.com/docs/unity_guide#tasks-chaining

jquery create list<dictionary<string,string>> object

I have a object defined in my C# code behind as
public List<Dictionary<string, string>> attributesList
{
get;
set;
}
now I need to fill this object from Jquery
That is, in my Jquery file I m getting certain values that I need to fill in this object.
I am stuck on how to create a JSON object from the following code
selectedAttributes.each(function (key, value) {
var attributeName = value.attributes.title.value;
var attributeValue = $('#' + attributeName + ' option:selected').text();
});
that can be supplied to the attributesList
I need to put (attributeName, attributeValue) pair in the attributelist object
I know I am not clear enough in asking this question, but if any information is required please comment and I'll reply almost instantly.
A Dictionary would be just an object in JS. You're able to address the items within the dictionary by it's name.
dic['name'] = 'value'; // valid
dic.name = 'value'; // also valid
var attrName = 'name';
dic[attrName] ='value'; // also valid
That should be enough info to let you accomplish your task.

MongoDB: update only specific fields

I am trying to update a row in a (typed) MongoDB collection with the C# driver. When handling data of that particular collection of type MongoCollection<User>, I tend to avoid retrieving sensitive data from the collection (salt, password hash, etc.)
Now I am trying to update a User instance. However, I never actually retrieved sensitive data in the first place, so I guess this data would be default(byte[]) in the retrieved model instance (as far as I can tell) before I apply modifications and submit the new data to the collection.
Maybe I am overseeing something trivial in the MongoDB C# driver how I can use MongoCollection<T>.Save(T item) without updating specific properties such as User.PasswordHash or User.PasswordSalt? Should I retrieve the full record first, update "safe" properties there, and write it back? Or is there a fancy option to exclude certain fields from the update?
Thanks in advance
Save(someValue) is for the case where you want the resulting record to be or become the full object (someValue) you passed in.
You can use
var query = Query.EQ("_id","123");
var sortBy = SortBy.Null;
var update = Update.Inc("LoginCount",1).Set("LastLogin",DateTime.UtcNow); // some update, you can chain a series of update commands here
MongoCollection<User>.FindAndModify(query,sortby,update);
method.
Using FindAndModify you can specify exactly which fields in an existing record to change and leave the rest alone.
You can see an example here.
The only thing you need from the existing record would be its _id, the 2 secret fields need not be loaded or ever mapped back into your POCO object.
It´s possible to add more criterias in the Where-statement. Like this:
var db = ReferenceTreeDb.Database;
var packageCol = db.GetCollection<Package>("dotnetpackage");
var filter = Builders<Package>.Filter.Where(_ => _.packageName == packageItem.PackageName.ToLower() && _.isLatestVersion);
var update = Builders<Package>.Update.Set(_ => _.isLatestVersion, false);
var options = new FindOneAndUpdateOptions<Package>();
packageCol.FindOneAndUpdate(filter, update, options);
Had the same problem and since I wanted to have 1 generic method for all types and didn't want to create my own implementation using Reflection, I end up with the following generic solution (simplified to show all in one method):
Task<bool> Update(string Id, T item)
{
var serializerSettings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
var bson = new BsonDocument() { { "$set", BsonDocument.Parse(JsonConvert.SerializeObject(item, serializerSettings)) } };
await database.GetCollection<T>(collectionName).UpdateOneAsync(Builders<T>.Filter.Eq("Id", Id), bson);
}
Notes:
Make sure all fields that must not update are set to default value.
If you need to set field to default value, you need to either use DefaultValueHandling.Include, or write custom method for that update
When performance matters, write custom update methods using Builders<T>.Update
P.S.: It's obviously should have been implemented by MongoDB .Net Driver, however I couldn't find it anywhere in the docs, maybe I just looked the wrong way.
Well there are many ways to updated value in mongodb.
Below is one of the simplest way I choose to update a field value in mongodb collection.
public string UpdateData()
{
string data = string.Empty;
string param= "{$set: { name:'Developerrr New' } }";
string filter= "{ 'name' : 'Developerrr '}";
try
{
//******get connections values from web.config file*****
var connectionString = ConfigurationManager.AppSettings["connectionString"];
var databseName = ConfigurationManager.AppSettings["database"];
var tableName = ConfigurationManager.AppSettings["table"];
//******Connect to mongodb**********
var client = new MongoClient(connectionString);
var dataBases = client.GetDatabase(databseName);
var dataCollection = dataBases.GetCollection<BsonDocument>(tableName);
//****** convert filter and updating value to BsonDocument*******
BsonDocument filterDoc = BsonDocument.Parse(filter);
BsonDocument document = BsonDocument.Parse(param);
//********Update value using UpdateOne method*****
dataCollection.UpdateOne(filterDoc, document);
data = "Success";
}
catch (Exception err)
{
data = "Failed - " + err;
}
return data;
}
Hoping this will help you :)

Categories