Xamarin Forms Labs - Geolocator - xamarin.forms

How do you use the "GeoLocator" function in Xamarin Forms Labs. When i added the "GeoLocator" method in my class i kept getting the error that this.SetProperty does not exist. Anyone know how to use "GeoLocator"?

SetProperty is only available on the very latest pre release nuget package, and it's a method from our Base ViewModel...
You have to show your code to see what you are trying to do.
but it should be as simple as this:
var geolocator = DependencyService.Get<IGeolocator>();
var result = geolocator.GetPositionAsync(10000);
var strLatitude = result.Latitude.ToString("N4");
var strLongitude = result.Longitude.ToString("N4"),

In addition to Rui's answer, I would recommend using Plugins for Xamarin for this type of behavior. Specifically, the Geolocator Plugin for Xamarin and Windows.
Both of these geolocation codebases derived from Xamarin.Mobile, but as far as I can tell, the plugin is a bit more up-to-date, and supports Windows 10 (UWP) development as well.

If you post some of the code that you are using, it will be easier to help you out. But in the meantime, SetProperty does not exist because you are not inheriting from the Xamarin.Forms.Labs.Data.ObservableObject class. It contains the SetProperty method which is merely an implementation of INotifyPropertyChanged (changes the property if the value is different and raises the PropertyChanged event).
So you can either inherit from the XFormsLab's ObservableObject (or it's base view model class which inherits from ObservableObject, Xamarin.Forms.Labs.Mvvm.ViewModel) and then you will have access to SetProperty. Or you can not use SetProperty at all and use your own implementation of INotifyPropertyChanged

We took the code from this library and cleaned it up. You can clone the repo here:
https://github.com/MelbourneDeveloper/Adapt.Presentation.git
It is complete with samples for each platform. If you run the sample, you will see a tab for GeoLocator and it should run on all platforms. Android and UWP have been tested thoroughly.
The NuGet package Adapt.Presentation works to some extent but I've had difficulty getting it to work correctly on all platforms.

Related

ASP.net Core Entity Framework CurrentValues.SetValues() best current alternative

As those of you working with Entity Framework Core may know, the current version does not have an implementation for CurrentValues.SetValues() for Entities. It looks like support for this will come in the next release v1.1 as this issue states. Until then, does anybody have a solution that works for updating entity entries?
For context, the SetValues function in the past entity framework takes an entity and updates it properties to the values of an entity passed as a parameter i.e.:
var updatedEntity = currentEntity.CurrentValues.SetValues(newValues);
_dbContext.SaveChanges();
I've found some implementations using PropertyInfo to make a generic update function but haven't found anything that looks to be a nice clean solution. Might just have to take what I can get though :)
p.s. I realize this function only worked for simple entities that don't have complex object graphs that would require updating other related entities. My use case is simple. It's just annoying to have to manually map properties right now.
EDIT: Now that EF Core v1.1.0 has been released, CurrentValues.SetValues() will work.
See the following code snippet
var currentEntity = dbSetEntity.Find(id);
_dbContext.Entry(currentEntity).CurrentValues.SetValues(newValues);

How do I get the declared functions of a Kotlin class (KClass in M12)?

Basically that. I'm wondering how to get the functions/methods given a KClass... looks like I can only iterate over the properties and extension properties.
Update: You can now get functions of a class with extensions declared in package kotlin.reflect: functions, declaredFunctions, memberFunctions, staticFunctions, etc.
Kotlin reflection is a work in progress at the moment. We plan to ship API for introspecting functions in the next milestone, presumably at the end of this summer.
Meanwhile, the only workaround is to use Java reflection for this task.
Kotlin reflection is more full featured in later milestones include the 1.0 betas.
View the overview documentation for Kotlin Reflection and specifically that of KClass.
For example, given a class you can see member functions using:
val functions = Someclass::class.declaredMemberFunctions
or properties:
val properties = Someclass::class.declaredMemberProperties
And to get from a Java Class to a KClass:
val kclz = this.javaClass.kotlin
See also: Kotlin.reflect package API docs

Functionality change while upgrading to Castle Windsor 3.3.0 from 3.2.0

I am attempting to migrate from version 3.2.0 to 3.3.0. I am getting a compile error. I could not find an entry in the "Breaking Changes" section but here are my two errors in hope someone can guide me to a workable alternative.
public void RegisterTypeSingleton<T>(Type component, string name)
{
if (_container.Kernel.HasComponent(name))
_container.Kernel.RemoveComponent(name);
_container.Register(Component.For<T>().ImplementedBy(component).Named(name).LifeStyle.Singleton);
}
It seems Kernel.RemoveComponent() function has been depreciated. What has replaced this?
The second compiler error is at _container.Register(Component.For<T>().ImplementedBy(component).Named(name).LifeStyle.Singleton);
I am getting "The Type 'TService' must be a reference type in order to use it as a parameter.
I think you might be upgrading from an older version than 3.2.0. See below.
The removal of IKernel.RemoveComponent() is documented in the Breaking Changes document with v3.0.0. Here is the extract where Krzysztof explains why it was removed:
change - Removed the following methods:
GraphNode.RemoveDepender,
GraphNode.RemoveDependent,
IKernel.RemoveComponent,
IKernelEvents.ComponentUnregistered,
INamingSubSystem.this[Type service],
INamingSubSystem.GetHandler,
INamingSubSystem.GetService2Handler,
INamingSubSystem.GetKey2Handler,
INamingSubSystem.UnRegister(String key),
INamingSubSystem.UnRegister(Type service)
Also INamingSubSystem.Register now takes only IHandler as its argument
impact - low
fixability - none
description - The methods were implementation of "remove component from the container" feature
which was flawed and problematic, hecen was scraped.
fix - Working around is quite dependant on your specific usage. Try utilizing IHandlerSelectors.
For changed Register method, just update your calling code not to pass the name.
handler.ComponentModel.Name is now used as the key, as it was happening in all places so far
anyway, so this change should have no real impact.
RegisterComponent() won't overwrite an existing service registration, it'll just register another component for the same service, unless you specify the same name where it'll throw an exception informing you there is another component registered with that name. If your application doesn't replace components very often you could use the IsDefault() method on the registration to get Windsor to resolve the new component by default, just note the other component is still registered.
If your application replaces components often and you don't want the other registrations left there, you'd be best using a custom IHandlerSelector or ISubDependencyResolver so Windsor will ask you each time what component you want used for a specific service.
Also in v3.0.0 a change was made to ensure that value types cannot be passed to the registration methods. You'll need to add a generic constraint to your method that accepts a generic parameter so that it also only accepts reference types:
public void RegisterTypeSingleton<T>(Type component, string name)
where T : class
{
...
}

How to use Community SQLite plugin in MVVMCross

In my application I was using the old SQLite-plugin.
Since MVVMCross 3.0.14 this version is deprecated and the Community.Sqlite plugin is advised.
The Community plugin was added via Nuget.
When trying to use the plugin without a bootstrapper, at runtime I get the error:
Failed to resolve parameter for parameter connectionFactory of type ISQLiteConnectionFactory when creating...
When trying to use the plugin with a bootstrapper, also at runtime, I get the error:
plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite
How should this plugin be used?
-Edit-
This is my bootstrapper code:
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
public class SqlitePluginBootstrap : MvxPluginBootstrapAction<PluginLoader>
{
}
Okay, Nuget added a reference to the portable library. I added a reference to the Sqlite.Touch library and then altered my bootstrapper:
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}
This solved the "plugin not registered"-error for me.
Confirmed - I came across the same issue.
Nuget downloads the right things, but only adds the one reference, as Jacco points out.
It doesn't add the reference to Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch.dll, and it doesn't put the bootstrap in for you automatically.
I have one extra using statement in my bootstrap for MvxLoaderPluginBootstrapAction. Here's the complete code:
using Cirrious.CrossCore.Plugins;
using Cirrious.MvvmCross.Community.Plugins.Sqlite;
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch;
public class SqlitePluginBootstrap : MvxLoaderPluginBootstrapAction<PluginLoader, Plugin>
{
}

Metadata for Exceptions thrown by a class

Flash builder lets me insert metadata for events fired by a class, example:
[Event("myEvent", "flash.events.Event")]
public class MyClass() {
}
Is there any way to do the same for Exceptions?
Currently I have checked here, and can't see it documented. Perhaps it's not even worthwhile, what are your thoughts.
There are ways to create your own metadata; and add that into your app at compile time. Use the keep-as3-metadata compiler argument.
It will be up to you to write code to do something with it at runtime; or to build IDE extensions to make use of the code while writing the code.
To access such metadata at runtime, you'll need to perform some type of introspection. Here are some docs and another StackOverflow Question about this.
Many Flex Frameworks make use of custom metadata.

Resources