Selenium windows Handle Return - selenium-webdriver

I am using Selenium to get windows handles. Now something which am curious is on the return type of Handles. Is there a possibility that Handles might return duplicate values and hence they have made it to return Set instead of List. My Initial Assumptions are windows handle might return duplicate values. I feel that it returns Set and not Map because of having two parameters key and values. So they would have made it return a simple Set.

getWindowHandles() is returning Set<String> only in Java. In C# WindowHandles returns ReadOnlyCollection<string> which is wrapper to List<string>.
Window handles can't be duplicated as they are unique identifier for the open windows.

Related

Why use ImageSource.FromStream instead of FromFile in Xamarin Media plugin?

I am using James Montemagno's Xamarin Media Plugin (https://github.com/jamesmontemagno/MediaPlugin) and his usage example shows an image being updated in this way from the captured photo:
targetImage.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
This seems to work just as well:
targetImage.Source = ImageSource.FromFile(file.Path);
However I feel that James' example must be showing a better way but I can't figure why -- maybe some subtle thing on one platform or another. Can anyone tell me why the Xamarin ImageSource should be set one way versus another?
The reason for choosing either FromFile() or FromStream() depends on the use case at hand. Also, the methods used depend on the data type as documented here.
WhereasFromFile() requires a string to a path, FromStream() requires a Func<System.IO.Stream>.
In the specific case you mention, and the sample hereof, it is sensible to return a Stream since a photo is being taken which is not yet stored.
First, TakePhotoAsync() is called which returns a MediaFile. This class then returns a Stream when calling GetStream(). Afterwards, the Source of the Image is set to the result.
In essence, the approach you decide on depends on the use case and data type at hand.

Compare thread IDs using windows api

I'm working with windows api threads and I would like to compare thread IDs.
First I create a thread with CreateThread() and store the handle( HANDLE ) and ID ( LPDWORD ) that I get from the function.
Then I get the handle and id from the created thread using GetCurrentThread() and GetThreadId().
I always get different values for both handles and both IDs.
Is there a way to compare threads in a similar fashion as pthread?
I'm doing this to as a debug option to confirm correct execution. I have always gotten correct results from other libraries( pthread.h, threads.h) but not from windows api. It is not a critical problem but I would like to learn the procedure in winapi
Instead of using GetCurrentThread() and GetThreadId(), you can use GetCurrentThreadId() [http://msdn.microsoft.com/en-us/library/windows/desktop/ms683183%28v=vs.85%29.aspx].
As said before, don't use pseudo-HANDLE (returned by GetCurrentThread()) on another thread.
From what I know, there could several different HANDLE to one thread but ID should be an unique identifier.
GetCurrentThread() does not return a real handle. From MSDN:
Retrieves a pseudo handle for the calling thread.
...
A pseudo handle is a special constant that is interpreted as the current thread handle.
You cannot compare this value to the result of CreateThread(). If you are using this value in GetThreadId() from a different thread, you will also not get the ID you want.
You can use DuplicateHandle() on the pseudo handle to retrieve the real handle.

WCF DataService 5 Any on single Entity (Client-Side)

I have a question according to the WCF Data Services 5.0.1 Any/All-Features. I want to use it in a Silverlight 5 Application and I want to query against an Entity called "Employee" (with a unique EmpNo=personalNr) and check if it already exists (therefore, I check if there is an Employee with the same personalNrfor validation purposes)..
In older versions it was not possible to do this on the Client. I had to call a custom Service Operation on the Server which returned a boolean value.
Is there a way to do this on the Client likes this (and get a boolean value as a result):
bool result = this.Context.Employees.Any(e => e.PersonalNr.Equals(personalNr, StringComparison.OrdinalIgnoreCase));
Thanks in advance!
Steve
The any/all feature is only usable inside the filter expression and it is used to query based on related entities or collection properties. If you want to check just for existence of an employee without any relationship, you can do that without any/all. The idea is to simply filter all employees on the given condition and see if you get at least 1 result back.
Now since you're doing this in Silverlight, the operation must be asynchronous, so a simple statement like above will not work. You could do something like:
var query = (DataServiceQuery<Employee>)this.Context.Employees.Where(e => e.PersonalNr.ToLower() == personalNr.ToLower()).Take(1);
query.BeginExecute((ar) =>
{
var results = query.EndExecute(ar);
// The usage of Any here is simply because it's the easiest way to do this
// and it is not used over OData/WCF DS, this is simply checking if the results returned
// from the service contain at least one result.
bool employeeExists = results.Any();
}, null);
Few notes about the code above:
The WCF Data Services doesn't support the Equals method with comparison options and the OData protocol doesn't support case insensitive string comparison either. So to workaround that, simply convert all values to lower case before comparing.
The Take(1) is used to only ask for the first value which matches the condition. Since we're only gonna use the existence of the result anyway, we don't need to ask the service for all the results (small optimization).

What does AlwaysUsesMultipleValuesMarker do in NSTreeController?

According to Apple's documentation,
setAlwaysUsesMultipleValuesMarker:
Sets whether the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.
- (void)setAlwaysUsesMultipleValuesMarker:(BOOL)flag
Discussion:
Setting flag to YES can increase performance if your application doesn’t allow editing multiple values. The default is NO.
However, I have trouble understanding what this all means even after reading the documentation. Can anybody offer a simpler explanation with examples?
Found the answer to this question deep inside apple docs on Cocoa Binding Guide.
NSMultipleValuesMarker
The NSMultipleValuesMarker indicates that more than one object is selected in the controller and the values for the requested key aren’t the same.
By default controllers return the NSMultipleValuesMarker only when the values for the requested key differ. For example, if the value for selection.name returns an array containing three strings—”Tony”, “Tony”, “Tony”—the string “Tony” is returned instead of the NSMultipleValuesMarker.
A collection controller can be configured—either programmatically using the method setAlwaysUsesMultipleValuesMarker: or by checking the Always uses multiple values marker checkbox in Interface Builder—such that it always returns NSMultipleValuesMarker when multiple items are selected, even if the values are equal.

ironjs: returning objects to JS

Using Ironjs. I have a c# function registered as a JS function (via SetGlobal)
It gets called , but I want to return a value to from that function. The value is an IEnumerable of CLR objects. Using Jint this just works: I return the object and can foreach it etc, how do I do the same thing in IronJS (Why not use Jint, well it has bugs, for example it wont compile underscore.js)
EDIT: Since I am not a fluent F# person I cannot answer this question myself by reading the code. So instead I fixed Jint. However it would still be nice to know the answer
We are still working on our .NET interop. As such, the foreach in IronJS is not set up to enumerate IEnumerables, but instead works on CommonObject type objects.

Resources