4

In their website, Xamarin appears as one of their clients, but I'm unable to install the package Breeze.Sharp, which is also tagged with Xamarin.

It does install into the PCL project, but for it to work I need to install it into all of the platform projects. When I try to do so, I get the following errors:

iOS/Android:

Could not install package 'Microsoft.AspNet.WebApi.Client 5.2.3'. You are trying to install this package into a project that targets 'Xamarin.iOS,Version=v1.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

UWP:

Package Breeze.Sharp 0.6.0.9 is not compatible with uap10.0 (UAP,Version=v10.0) / win10-x86-aot. Package Breeze.Sharp 0.6.0.9 supports: net (.NETFramework,Version=v0.0) One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
  • I tried your approach with the same result. So, I created a Portable assembly with the reference of BreezeSharp. The problem I facing now is executing Configuration.Instance.ProbeAssemblies in that shared library, because I have no access to Type.Assembly property. UPDATE: I resolved my problem passing the Assembly got in Android project to my shared library. Maybe is not an elegant approach but resolve my problem. If anybody have a better approach I'll appreciate it. – Leonardo Neninger Jun 29 '17 at 16:08
  • How about the UWP? Did you get it working with Breeze# too? – Shimmy Weitzhandler Jun 30 '17 at 11:21
  • I'm working only with Android. As I'm using Portable Class Library I assume that there are not differences (or just a little) between the platforms – Leonardo Neninger Jul 01 '17 at 02:54
  • @LeonardoNeninger, as you saw in my post, the error I'm getting with UWP is different. I'm using XF to target the 3 platforms: Droid, iOS, and UWP. I can only use Breeze# if it supports them all. – Shimmy Weitzhandler Jul 01 '17 at 23:44
  • Did you already tried create a separated portable class library as I suggested? – Leonardo Neninger Jul 03 '17 at 10:41
  • Does it work in UWP? I can only use it if it works in all of the 3 platforms. – Shimmy Weitzhandler Jul 06 '17 at 05:28

2 Answers2

1

I resolve in this way.
1. Create New Portable Class Library
2. Add BreezeSharp as reference of the new Portable Class Library(Nuget)
3. Add the New Class Library as reference of your specific platform projects(Android, iOS). In my case only Android.
4. In Portable Library. Create a static class ex: Configs.
5. Android project -> MainActivity.OnCreate

Configs.ModelAssembly = typeof(Customer).Assembly;
  1. Implement Breeze's DataService in the Portable Class Library. ex:

public abstract class BaseDataService<T> where T : BaseEntity
    {
        public static string Metadata { get; protected set; }
        public string EntityName { get; protected set; }
        public string EntityResourceName { get; protected set; }
        public EntityManager EntityManager { get; set; }
        public string DefaultTargetMethod { get; protected set; }
        static BaseDataService()
        {
            Constants = ConstantsFactory.Get;
            try
            {
                var metadata = GetMetadata();
                metadata.Wait();
                Metadata = metadata.Result;

            }
            catch (Exception ex)
            {
                var b = 0;
            }
        }


        public BaseDataService(string resourceName, string targetMethod = null)
        {
            var modelType = typeof(Customer);
            Configuration.Instance.ProbeAssemblies(ConstantsFactory.BusinessAssembly);
            try
            {
                this.EntityName = typeof(T).FullName;
                this.EntityResourceName = resourceName;

                this.DefaultTargetMethod = (string.IsNullOrWhiteSpace(targetMethod) ? "GetAll" : targetMethod);

                var dataService = new DataService($"{ConstantsFactory.Get.BreezeHostUrl}{this.EntityResourceName}", new CustomHttpClient());
                dataService.HasServerMetadata = false;
                var metadataStore = new MetadataStore();
                var namingConvention = NamingConvention.CamelCaseProperties; /*metadataStore.NamingConvention;*/ /*NamingConvention.Default;*/// new NamingConvention()
                namingConvention = namingConvention.WithClientServerNamespaceMapping(
                    new Dictionary<string, string> { { "Business.DomainModels", "DomainModel.Models" } }
                    );

                metadataStore.NamingConvention = namingConvention;

                metadataStore.ImportMetadata(Metadata, true);

                this.EntityManager = new EntityManager(dataService, metadataStore);
                this.EntityManager.MetadataStore.AllowedMetadataMismatchTypes = MetadataMismatchTypes.AllAllowable;
                // Attach an anonymous handler to the MetadataMismatch event
                this.EntityManager.MetadataStore.MetadataMismatch += (s, e) =>
                {
                    // Log the mismatch
                    var message = string.Format("{0} : Type = {1}, Property = {2}, Allow = {3}",
                                                e.MetadataMismatchType, e.StructuralTypeName, e.PropertyName, e.Allow);

                    // Disallow missing navigation properties on the TodoItem entity type
                    if (e.MetadataMismatchType == MetadataMismatchTypes.MissingCLRNavigationProperty &&
                        e.StructuralTypeName.StartsWith("TodoItem"))
                    {
                        e.Allow = false;
                    }
                };
            }
            catch (Exception ex)
            {
                var b = 0;
            }
        }

        public async Task<List<T>> GetAll(string targetMethod = null)
        {
            var internalTargetMethod = (string.IsNullOrWhiteSpace(targetMethod) ? this.DefaultTargetMethod : targetMethod);
            var query = new EntityQuery<T>(internalTargetMethod);
            var qr = await this.EntityManager.ExecuteQuery(query);
            var result = qr.ToList();
            return result;
        }

        public void Delete(T entity)
        {
            entity.EntityAspect.Delete();
        }


        private static async Task<string> GetMetadata()
        {
            var client = new HttpClient();
            var metadata = await client.GetStringAsync(ConstantsFactory.Get.MetadataUrl).ConfigureAwait(false);
            var ret = JsonConvert.DeserializeObject<MetadataModel>(metadata);
            return ret.metadata;
        }


    }
  1. Create CustomerService if you need as

public class CustomerDataService : BaseDataService<Customer>
    {
        public CustomerDataService(IConstants constants) : base("Customers")
        {
            
        }
    }
1

In an email I got from IdeaBlade, the inventor of Breeze#, he said that while the Breeze# is not dead, it has drown much less community attention compared to BreezeJS, thus they prefer to invest their resources in the JS library.

For now, I'm just gonna use TrackableEntities by @AnthonySneed. Although not as comprehensive as Breeze#, does part of the job nicely.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632