在 their website , Xamarin 显示为他们的客户之一,但我无法安装包 Breeze.Sharp ,它也被标记为 Xamarin。
它确实安装到 PCL 项目中,但要使其正常工作,我需要将其安装到所有平台项目中。当我尝试这样做时,我收到以下错误:
iOS/安卓:
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).
最佳答案
我是这样解决的。
1. 创建新的可移植类库
2. 添加 BreezeSharp 作为新的可移植类库 (Nuget) 的引用
3. 添加新类库作为您特定平台项目(Android、iOS)的引用。就我而言,只有Android。
4. 在可移植图书馆中。创建一个静态类,例如:Configs。
5. Android 项目 -> MainActivity.OnCreate
Configs.ModelAssembly = typeof(Customer).Assembly;
例如:
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;
}
}
public class CustomerDataService : BaseDataService<Customer>
{
public CustomerDataService(IConstants constants) : base("Customers")
{
}
}
关于xamarin.android - Xamarin.Forms(UWP、Droid 和 iOS)的 Breeze#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44815750/