4

他们的网站中,Xamarin 显示为他们的客户之一,但我无法安装软件包Breeze.Sharp,该软件包也带有Xamarin标记。

它确实安装到了 PCL 项目中,但是为了让它工作,我需要将它安装到所有平台项目中。当我尝试这样做时,我收到以下错误:

iOS/安卓:

无法安装包“Microsoft.AspNet.WebApi.Client 5.2.3”。您正在尝试将此包安装到以“Xamarin.iOS,Version=v1.0”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请联系包作者。

超轻量级:

Breeze.Sharp 0.6.0.9 包与 uap10.0 (UAP,Version=v10.0) / win10-x86-aot 不兼容。Package Breeze.Sharp 0.6.0.9 支持:net (.NETFramework,Version=v0.0) 一个或多个包不兼容 UAP,Version=v10.0 (win10-x86-aot)。

4

2 回答 2

1

我是这样解决的。
1. 创建新的可移植类库
2. 添加 BreezeSharp 作为新可移植类库(Nuget)
的参考 3. 添加新类库作为您的特定平台项目(Android、iOS)的参考。就我而言,只有安卓。
4. 在便携式图书馆。创建一个静态类 ex:Configs。
5.Android项目-> MainActivity.OnCreate

Configs.ModelAssembly = typeof(Customer).Assembly;
  1. 在可移植类库中实现 Breeze 的 DataService。前任:

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. 如果需要,请创建 CustomerService

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

于 2017-06-29T19:07:08.277 回答
1

在我从 Breeze# 的发明者 IdeaBlade 收到的一封电子邮件中,他说虽然 Breeze# 并没有消亡,但与 BreezeJS 相比,它所淹没的社区关注度要少得多,因此他们更愿意将资源投入到 JS 库中。

现在,我将使用@AnthonySneedTrackableEntities。虽然不如 Breeze# 全面,但可以很好地完成部分工作。

于 2017-07-09T01:59:27.880 回答