小编Lin*_*ela的帖子

使用SignalR和Azure的实时通知系统

我试图在我们的ASP.NET MVC网站上制作类似facebook的通知系统

在一个场景中,通知系统的工作方式如下

  1. User1通过单击MVC站点中的跟随按钮来关注User2
  2. MVC站点发送NotificationItemNotificationManagervia API请求.

POST api/notifications/send

  1. NotificationManager 然后处理此notificationItem,然后将其保存到Azure表存储
   class NotificationManager { 
               void SaveNotification(NotificationItem item) { 
                 // save it to azure table storage
                } 
   }
Run Code Online (Sandbox Code Playgroud)
  1. 保存项目后,客户端(User2)然后通过NotificationHub(SignalR集线器)订阅notificationEvent

  2. NotificationHub然后通知User2以及处理过的通知数据.

 class NotificationHub: Hub {
       async Task NotifyUser(string recipientId) {

         // query data from storage and then process it
         var notificationData= await _repo.GetProcessedNotificationDataAsync(recipientId);

         Clients.Group(recipientId).notifyUser(notificationData);

      }
}
Run Code Online (Sandbox Code Playgroud)

我试图在这个图像上说明CURRENT过程和架构 在此输入图像描述

现在,困扰我的是第5步中的这行代码

 var notificationData= await _repo.GetProcessedNotificationDataAsync(recipientId);
Run Code Online (Sandbox Code Playgroud)

它背后的作用是查询notificationItem存储,将其处理为用户可读通知(例如"User1现在跟随你"),然后更新notificationItem后面的(IsSent,DateSent)状态.

不用说,它以某种方式执行"重"操作.而且它会实时每次有交付或广播给每个用户一个新的NotificationItem时间被触发.

显然,我在这里谈论性能和可伸缩性问题.所以我研究了一些可以解决这个问题的技术或方法.并且似乎使用Azure Service Bus背板方法是一个可行的选择

使用Azure …

asp.net azure signalr azureservicebus azure-servicebus-queues

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

Javascript字符串到Guid

在javascript中,转换此字符串的最简单方法是什么

798205486e954fa880a0b366e6725f71
Run Code Online (Sandbox Code Playgroud)

像这样的GUID格式

79820548-6e95-4fa8-80a0-b366e6725f71
Run Code Online (Sandbox Code Playgroud)

这是我这样做的凌乱方式:)我正在寻找最干净的方式

var employeeId = shift.employee.id.substring(0, 8) + "-" + shift.employee.id.substring(8, 12)
                    + "-" + shift.employee.id.substring(12, 16) + "-" + shift.employee.id.substring(16, 20) + "-" + shift.employee.id.substring(20, 32);
Run Code Online (Sandbox Code Playgroud)

javascript string jquery guid

7
推荐指数
3
解决办法
1万
查看次数

ASP.NET WebAPI:动态对象和OData服务

我有一个dynamic有财产的实体

 public partial class Meeting  //partial class of POCO EF object
 {
       public dynamic UiPermissions { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

在我的web api中,我有一个实现OData查询的服务方法

    [Queryable(MaxExpansionDepth = 5)]
    [HttpGet("users/{id}/meetings")]
    public IEnumerable<Meeting> GetUserMeetings(int id)
    {
        var meetings = _meetingRepository.GetUserMeetings(id);

        // populate dynamic UiPermission
        meetings.SetMeetingPermission(_permissionRepository, id);

        return meetings;
    }
Run Code Online (Sandbox Code Playgroud)

我使用ExpandoObject作为IDictionary填充动态属性

 public static class PermissionExtensions
{
    public static void SetMeetingPermission(this IEnumerable<Meeting> meetings, IPermissionRepository permissionRepository, int userId)
    {
        // get properties to be created from database table 
        var permissions = permissionRepository.GetAll();

        // create a dynamic …
Run Code Online (Sandbox Code Playgroud)

c# json dynamic odata asp.net-web-api

5
推荐指数
1
解决办法
5292
查看次数

使用ClientId和ClientSecret进行Web API授权

我在我的web api授权中使用OWIN/Katana中间件.

流动.

我发布acess_tokenrefresh_token请求的客户端.

access_token有短暂的寿命,而refresh_token早已到期.

像往常一样,如果access_token到期,它将使用refresh_token请求另一个access_token.

现在,我的问题.由于我的refresh_token有很长的生命周期,看起来它失败了短命的access_token的目的.让我们说如果refresh_token被泄露,黑客仍然可以得到access_token,对吧?

我查看了谷歌和微软的OAuth实现,看起来他们还有这个额外的参数,你需要提供除了refresh_token.这就是client_idclient_secret.看起来它们是在API的开发者页面上登录时生成的.

现在,我如何在我的项目中实现它?我想要覆盖令牌创建并使令牌哈希基于ClientIdClientSecret.

我正在使用最新的web api的基本OWIN/Katana身份验证,我不打算使用像Thinktecture这样的其他授权服务器.我只想使用ASP.NET Web API 2默认提供的基本功能

Startup.OAuth.cs

public partial class Startup
{
   static Startup()
   {
      PublicClientId = "self";
      UserManagerFactory = () => new UserManager<IdentityUser>(new AppUserStore());
      var tokenExpiry = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ApiTokenExpiry"]);

      OAuthOptions = new OAuthAuthorizationServerOptions
      {
          TokenEndpointPath = new PathString("/Token"),
          Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
          AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
          AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(tokenExpiry),
          AllowInsecureHttp = true,
          RefreshTokenProvider …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-web-api owin katana asp.net-mvc-5

5
推荐指数
1
解决办法
8396
查看次数

Angular ui-select错误:404(无法加载模板)

有问题的人使用angular-ui-select

得到这个错误

GET http://localhost/select2/select.tpl.html 404 (Not Found) angular.js:8539
Error: [$compile:tpload] Failed to load template: select2/select.tpl.html
Run Code Online (Sandbox Code Playgroud)

从文档中 - 我只需要引用select.js和select.css

angularjs ui-select2 angularjs-select2

5
推荐指数
1
解决办法
3458
查看次数

Specflow:步骤的基类

我有一个奇怪的例子,执行顺序混乱

我为所有步骤定义创建了一个基类

public abstract class BaseSteps
{

    static BaseSteps()
    {
        Console.WriteLine("static Constructor");
    }

    protected BaseSteps()
    {
        Console.WriteLine("public Constructor");
    }


    [BeforeTestRun]
    public static void BeforeTestRun()
    {
        Console.WriteLine("static void BeforeTestRun");
    }

    [AfterTestRun]
    public static void AfterTestRun()
    {
        Console.WriteLine("static void AfterTestRun");
    }

    [Before]
    public static void Before()
    {
        Console.WriteLine("Base Before Scenario");
    }


}



 [Binding]
    public class SpecFlowFeature1Steps: BaseSteps
    {
    public SpecFlowFeature1Steps()
    {

    }
    [BeforeScenario()]
    public void Setup()
    {

    }
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,我的调试模式下的执行顺序看起来像这样

  1. 基类静态构造函数
  2. [测试运行之前]
  3. 基类构造函数
  4. 子类构造函数
  5. 子类[BeforeScenario]
  6. 基类 [BeforeScenario] ....

我原以为它会像...

  1. 基类[BeforeScenario]
  2. 基础构造函数
  3. 子类构造函数
  4. 子类[BeforeScenario] …

c# testing bdd specifications specflow

5
推荐指数
1
解决办法
2952
查看次数

重构:通用扩展方法

我有一个扩展方法,检查对象的类型,然后填充其成员属性

public static void LoadMeeting<T>(this T entity, IMeetingRepository meetingRepository) 
where T: MyEntity
            {
                var agenda = entity as Agenda;

                if (agenda != null)
                {
                    agenda.Meeting = meetingRepository.GetMeetingById(agenda.MeetingId);
                }

                var participant = entity as Participant;

                if (participant != null)
                {
                    participant.Meeting = meetingRepository.GetMeetingById(participant.MeetingId);
                }

            }
Run Code Online (Sandbox Code Playgroud)

我可以进一步重构这样的东西,使其更通用吗?

 public static void LoadMeeting<T>(this T entity, IMeetingRepository meetingRepository) where T : MyEntity
        {
            var obj = entity as Agenda || entity as Participant;

            if (obj != null)
            {
                obj.Meeting = meetingRepository.GetMeetingById(obj.MeetingId);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

PS:我不想把对象的属性 …

c# generics extension-methods

2
推荐指数
1
解决办法
123
查看次数

Angular2 - 使用Bitbucket(或其他GIT仓库)连续部署Azure

目标是在提交repo中的更改后立即在Windows Azure中进行两次自动部署.

这是我做的步骤

  1. 下载Angular2快速入门(确保它在本地运行)
  2. 推送回购中的文件(Bitbucket)
  3. 在Azure中配置连续部署(在Azure门户中使用Bitbucket集成)

在Azure中配置持续部署后,Azure会自动在repo中部署最新内容并失败(请参阅下面的azure部署日志) 在此输入图像描述

我在互联网上搜索了一段时间如何做到这一点.我不想使用Visual Studio,我只想使用VS Code.

是否有人可以一步一步地指导这样做?

TIA

更新 - 我实际上使用的是Angular-CLI样板,而不是angular-quickstart.这是package.json

{
  "name": "my-webapp",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "postinstall": "typings install",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.3",
    "@angular/compiler": "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.3",
    "@angular/forms": "0.1.1",
    "@angular/http": "2.0.0-rc.3",
    "@angular/platform-browser": "2.0.0-rc.3",
    "@angular/platform-browser-dynamic": "2.0.0-rc.3",
    "@angular/router": "3.0.0-alpha.7",
    "@angular2-material/button": "^2.0.0-alpha.5-2",
    "@angular2-material/core": "^2.0.0-alpha.5-2",
    "@angular2-material/toolbar": "^2.0.0-alpha.5-2",
    "@angular2-material/icon": "^2.0.0-alpha.5-2",
    "@angular2-material/sidenav": "^2.0.0-alpha.5-2",
    "@angular2-material/list": "^2.0.0-alpha.5-2",
    "@angular2-material/card": "^2.0.0-alpha.5-2", …
Run Code Online (Sandbox Code Playgroud)

bitbucket azure node.js npm angular

0
推荐指数
1
解决办法
788
查看次数

将字典转换为列表

如何将此字典转换为列表

var dict = new Dictionary<string, List<string>>();

dict.Add("1", new List<string>() { "a", "b" });
dict.Add("2", new List<string>() { "a", "c" });
Run Code Online (Sandbox Code Playgroud)

我期待这个输出

List<dynamic> = new List<dynamic>() 
{
    new { id = "1", value = "a" }
    new { id = "1", value = "a" }
    new { id = "2", value = "a" }
    new { id = "2", value = "a" }
}
Run Code Online (Sandbox Code Playgroud)

我试过这个但是无法获取嵌套集合的值:

dict.Select(c => new { id=c.Key, value= c.Value })
Run Code Online (Sandbox Code Playgroud)

c# linq dictionary list

-2
推荐指数
1
解决办法
91
查看次数