小编Saf*_*afa的帖子

使用DataAnnotation在Xamarin中进行验证

我想在Xamarin中添加验证.为此,我使用这篇文章作为参考点:使用Data Annotation进行验证.以下是我的行为.

public class EntryValidationBehavior : Behavior<Entry>
    {
        private Entry _associatedObject;

        protected override void OnAttachedTo(Entry bindable)
        {
            base.OnAttachedTo(bindable);
            // Perform setup       

            _associatedObject = bindable;

            _associatedObject.TextChanged += _associatedObject_TextChanged;
        }

        void _associatedObject_TextChanged(object sender, TextChangedEventArgs e)
        {
            var source = _associatedObject.BindingContext as ValidationBase;
            if (source != null && !string.IsNullOrEmpty(PropertyName))
            {
                var errors = source.GetErrors(PropertyName).Cast<string>();
                if (errors != null && errors.Any())
                {
                    var borderEffect = _associatedObject.Effects.FirstOrDefault(eff => eff is BorderEffect);
                    if (borderEffect == null)
                    {
                        _associatedObject.Effects.Add(new BorderEffect());
                    }

                    if (Device.OS != TargetPlatform.Windows) …
Run Code Online (Sandbox Code Playgroud)

c# behavior data-annotations xamarin xamarin.forms

19
推荐指数
2
解决办法
2445
查看次数

在数据库迁移失败时恢复以前的应用程序状态(ClickOnce)

我想恢复使用ClickOnce发布的以前版本的C#应用​​程序,如果数据库迁移失败,因为数据库不是最新的,并且它不支持最新版本的应用程序.

细节

我正在开发一个应用程序,将在没有互联网的偏远地区本地使用.一个人会偶尔以某种方式通过互联网更新他/她的应用程序,然后将在本地网络上部署该应用程序.从那里每个人都可以获得更新版本的应用程序.我现在想要的是使用此应用程序使用数据库迁移,如果应用程序失败它应该还原到以前的版本.我已经使用FluentMigrator进行数据库迁移,并使用ClickOnce来部署应用程序.我也经历过这里的几乎所有链接,看看我该怎么做.我现在知道使用ClickOnce是不可能的.任何人都可以通过其他方式告诉我或者可能是某种黑客攻击吗?我正在使用ClickOnce,因为它具有自动更新功能,所以现在不想丢失该功能.任何帮助将不胜感激.

c# clickonce

12
推荐指数
1
解决办法
228
查看次数

任务扩展以迎合App广泛的服务呼叫

我正在使用xamarin并尝试使用一种方法来使用所有服务.为此我写了一个TaskExtension.因此,从应用程序的每个页面我都可以调用该扩展方法.这是为了禁用按钮,显示加载屏幕,响应处理以及从一点开始处理异常处理.我在下面附上我的代码.需要您对此解决方案的专家意见

这是我的扩展类

public static class TaskExtensions
{
    public static async Task<ResultViewModel<U>> ExecuteAsyncOperation<U>(this Task<HttpResponseMessage> operation, object sender = null)
    {
        ResultViewModel<U> resultModel = new ResultViewModel<U>();
        Button button = BeforeAsyncCall(sender);
        try
        {
            await BackgroundOperation(operation, resultModel);
        }
        catch (Exception ex)
        {
            resultModel.Status = HttpStatusCode.InternalServerError;
            resultModel.Errors = new List<string>() { "Some error occurred. Please try again." };
        }
        finally
        {
            AfterAsyncCall(button);

        }
        return resultModel;
    }
    static async Task BackgroundOperation<U>(Task<HttpResponseMessage> operation, ResultViewModel<U> resultModel)
    {
        HttpResponseMessage RawResult = await operation;
        var Response = await RawResult.Content.ReadAsStringAsync();
        resultModel.Status …
Run Code Online (Sandbox Code Playgroud)

c# generics async-await xamarin xamarin.forms

9
推荐指数
1
解决办法
143
查看次数

连接到连接到服务器的生物识别设备

我一直在使用生物识别设备已有一段时间了.我一直能够连接生物识别设备并从中获取数据.但这次我一直在给一台连接到服务器的旧设备(Pegasus PB-7).我只获得远程桌面连接和访问生物识别设备.我面临的问题是远程桌面上已经安装了软件,当我提供IP和端口时,它会在几秒钟内连接到它.但是,当我使用zkemSdk时,我一直用它来连接到其他设备,它没有连接,以下方法返回-7给我.

int idwErrorCode = -1;
this.objCZKEM.GetLastError(ref idwErrorCode);
Run Code Online (Sandbox Code Playgroud)

SDK手册中未定义此代码.我能够ping设备,telnet也可以工作.请给出一些可能出现问题的建议.

c# networking biometrics fingerprint

6
推荐指数
1
解决办法
1992
查看次数

标记接口以避免使用通用参数的通用控制器和构造函数

我已覆盖 Microsoft Identity 提供的默认 IdentityUser 和 UserStore。

    public class ApplicationUser<TIdentityKey, TClientKey> : IdentityUser<TIdentityKey>, IApplicationUser<TIdentityKey, TClientKey>
    where TIdentityKey : IEquatable<TIdentityKey>
    where TClientKey : IEquatable<TClientKey>
    {
        public TClientKey TenantId { get; set; }
    }

    public class ApplicationUserStore<TUser, TRole, TIdentityKey, TClientKey> : UserStore<TUser, TRole, IdentityServerDbContext<TIdentityKey, TClientKey>, TIdentityKey>
    where TUser : ApplicationUser<TIdentityKey, TClientKey>
    where TRole : ApplicationRole<TIdentityKey>
    where TIdentityKey : IEquatable<TIdentityKey>
    where TClientKey : IEquatable<TClientKey>
    {
        private readonly IdentityServerDbContext<TIdentityKey, TClientKey> _context;
        private readonly ITenantService<TIdentityKey, TClientKey> _tenantService;
        public ApplicationUserStore(IdentityServerDbContext<TIdentityKey, TClientKey> context, ITenantService<TIdentityKey, TClientKey> tenantService) : …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection marker-interfaces asp.net-identity asp.net-core

6
推荐指数
1
解决办法
393
查看次数

根据某些条件与另一个表连接后,在 IQueryable&lt;T&gt; 中设置属性值

我正在为 WPF 实施授权。我对屏幕有绑定权限。例如,有一个叫地板的屏幕。它有四个与之关联的权限。

  1. 查看楼层
  2. 添加楼层
  3. 编辑楼层
  4. 删除楼层

除了每个权限,我们还有四个级别的权限。

  1. 全部
  2. 自己
  3. 角色
  4. 用户

因此,如果用户具有权限级别为 {ALL} 的 {View Floor} 权限。他们可以查看任何用户创建的所有楼层。

如果用户具有 {Self} 权限级别。他们只能查看自己创建的楼层。

如果用户的权限级别为 {Role}。他们可以查看针对指定角色分配的所有楼层。

权限级别的角色分配如下:

Roles: Supervisor, Technician
Run Code Online (Sandbox Code Playgroud)

如果 BranchManager 具有上述权限级别。然后他可以查看自己创建的楼层以及任何具有主管或技术人员角色的用户创建的楼层。

权限级别 {User} 与 {Role} 相同。

这是我用于获取楼层的 IQueryable:

IQueryable<FloorModel> FloorsQueryable = (from f in Floors
                                          join b in Branches on f.BranchId equals b.Id
                                          where (string.IsNullOrEmpty(filters.Name) || f.Name.ToLower().Contains(filters.Name.ToLower()))
                                          && (string.IsNullOrEmpty(filters.BranchName) || b.Name.ToLower().Contains(filters.BranchName.ToLower()))
                                          && (f.IsDeleted == null || f.IsDeleted == false)
                                          && f.BranchId == CurrentBranchId
                                          && f.ApplicationId == CurrentApplicationId
                                          select new FloorModel
                                          { …
Run Code Online (Sandbox Code Playgroud)

linq entity-framework iqueryable automapper entity-framework-6

5
推荐指数
0
解决办法
161
查看次数

强制 JObject 以“dd-mm-yyyy”格式序列化日期

public Guid AddJobs(JObject parametrs)
{
        dynamic jsonParameters = parametrs;
        JobViewModel job = jsonParameters.Job.ToObject<JobViewModel>();
}
Run Code Online (Sandbox Code Playgroud)

以上是我的代码。我正在尝试使用上述方法反序列化此模型。问题是它一直给我一个例外,即日期格式不正确,因为它不期望“dd-mm-yyyy”。请帮我解决这个问题。

.net c# json.net deserialization

4
推荐指数
1
解决办法
2618
查看次数