小编Han*_*lse的帖子

服务器端NodeJS中requestAnimationFrame()的实现

关于广泛使用的requestAnimationFrame()函数,我有一些问题.最近我在多人游戏中遇到了一些在客户端而不是服务器端使用它的实现.

  1. 这样做有什么好处吗?
  2. 你能引用我在NodeJS中的任何"最佳实践"服务器端实现吗?

更新

我在动画和游戏循环之间有点混淆 - 我正在寻找的是NodeJS中的实现=>例如setInterval.

示例 - 客户端实现

(function () {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
        window.cancelAnimationFrame =
            window[vendors[x] + 'CancelAnimationFrame'] ||
            window[vendors[x] + 'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame)
        window.requestAnimationFrame = function (callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = …
Run Code Online (Sandbox Code Playgroud)

javascript client node.js server

10
推荐指数
1
解决办法
5569
查看次数

使用Verizon的Azure CDN - 重写URL以始终加载index.html


上下文


在过去的几天里,我一直在努力解决以下问题,由于CDN的本质和每个新规则的手动审查,我每次最多需要4小时才能部署新规则.

如下面的主题所述,我目前将我的Angular应用程序部署到一个存储帐户,该帐户有一个名为的blob容器cdn

在此输入图像描述

在此blob容器目录中,我的角度项目中的整个文件夹已通过我的CI设置进行复制.dist

在此输入图像描述

CDN配置文件也已设置,指向origin-path被叫/cdn

在此输入图像描述


问题


不幸的是,目前存在一个持续存在的问题,即您无法直接访问默认文件.

  1. 我想要的是将我的Angular应用程序中的所有传入流量重定向到该index.html文件.这是为了满足Angular路由.

    输入具有预期输出的URL

  2. 此外,我想让任何静态文件(例如图像)的请求通过没有任何特定的URL重写.

我已经看过关于这个问题的各种帖子,但没有一个答案似乎涵盖我的情况或没有提供预期的结果.

目前我正在使用Verizon 的Azure CDN规则引擎功能.

关于模式,我使用了下文中提到的所有模式,包括评论中提到的模式.

我还花了至少两天的时间来查找各种其他文章和stackoverflow文章,但它们都没有适合我的情况.

此外,我还创建了自己的正则表达式模式,但是虽然它们在我的测试环境中工作,但一旦将它们部署到CDN,它们就会工作.

我通常最终得到以下结果之一:

  • 顶级域名https://myFancyWebsite.azureedge.net不会重写网址index.html,我会收到一个http错误404
  • 顶级域名将重定向到index.html但是一旦我添加了网址路径就会停止工作https://myFancyWebsite.azureedge.net/login/callback- 一旦404我开始使用,就会再次出现http错误/login/callback
  • 顶级域名会将URL重写为类似于https://myFancyWebsite.azureedge.net/cdn/cdn/cdn/cdn/cdn/cdn/cdn/cdn/cdn/cdn ....http错误的内容431

微软的官方文档在我的案例中也没有帮助.

我很确定我不是第一个将Angular应用程序部署到存储帐户的人,并且有人遇到了与我相同的问题.

我感谢所有指出正确方向的信息,因为目前我肯定会考虑放弃整个存储帐户部署.


更新1


使用此处的文章中也提到的以下source模式,我能够处理至少顶级域重写到文件.((?:[^\?]*/)?)($|\?.*)index.html

不幸的是,我还需要一个额外的模式来重定向https://myFancyWebsite.azureedge.net/login/callback …

url-rewriting azure azure-cdn azure-storage-account angular

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

参考哪个地方没有参考?

以下代码段:

int ia[3][4] = { 0,1,2,3,4,5,6,7,8,9,10,11 };
int(&row)[4] = ia[1];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我无法理解为什么这个特定的代码是有效的.根据我目前的理解,我没有理性的解释.有人可以帮我解决这个问题吗?我的问题&row似乎在任何地方都没有引用.我唯一的解释是,这必须是有效的,因为它是初始化.

我的书中有以下解释:

.... 我们将row定义为对四个整数数组引用

哪个阵列?我们要初始化的那个?

c++

5
推荐指数
2
解决办法
345
查看次数

朋友功能 - 声明顺序

我有两个叫做Screen和的 课程Window_mgr.

Screen允许Window_mgr通过friend函数声明修改其私有/受保护成员.

结果Window_mgr在代码的最后定义了一个非成员函数Window_mgr::clear,该函数应该使用它.

不幸的是,我得到了一些荒谬的错误,我无法解释.

我错过了什么?

在此输入图像描述

Screen.h

#pragma once

#ifndef SCREEN_H
#define SCREEN_H

#include <string>
#include <vector>

class Window_mgr {
public:
    // location ID for each screen on the window
    using ScreenIndex = std::vector<Screen>::size_type;
    // reset the Screen at the given position to all blanks
    void clear(ScreenIndex);
private:
    std::vector<Screen> screens{ Screen(24, 80, ' ') };
};

class Screen {

public:

    // Friends
    friend void Window_mgr::clear(ScreenIndex);
    //friend class Window_mgr;

    // …
Run Code Online (Sandbox Code Playgroud)

c++ header-files friend-function

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

C# - Lambda/LINQ - 从Dictionary <string,string> []到List <string []>的转换

长话短说,我想要实现的是将a转换Dictionary<string, string>[]为a List<string[]>.我不介意丢失字典的关键信息.

我提出的解决方案是有效的,但我很确定有一种更好的方法可以用LINQ和Lambda表达式来实现相同的结果.

我特别讨厌的一部分,我需要使用额外的变量计数,但据我所知,这是不可能的遍历一个Dictionary<string, string>具有for循环

提前致谢.

 Dictionary<string, string>[] arrayOfStringDictionaries = new Dictionary<string, string>[2]
        {
            new Dictionary<string, string>(),
            new Dictionary<string, string>()
        };

        arrayOfStringDictionaries[0].Add("1", "Test1");
        arrayOfStringDictionaries[0].Add("2", "Test2");
        arrayOfStringDictionaries[0].Add("3", "Test3");

        arrayOfStringDictionaries[1].Add("1", "Test4");
        arrayOfStringDictionaries[1].Add("2", "Test5");
        arrayOfStringDictionaries[1].Add("3", "Test6");

        List<string[]> listofStringArrays = new List<string[]>();

        foreach (Dictionary<string, string> singledic in arrayOfStringDictionaries)
        {
            int count = 0;
            string[] stringArray = new string[singledic.Keys.Count];
            foreach (var key in singledic.Keys)
            {
                stringArray[count] = singledic[key];
                count++;
            }

            listofStringArrays.Add(stringArray);
        }
Run Code Online (Sandbox Code Playgroud)

c# linq lambda dictionary list

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

ASP.NET Core Web API - 使用 InstancePerRequest() 时 Autofac 和 EF Core 的问题

我正在尝试使用AutofacEF CoreAutoMapper设置我的ASP.NET Core Web API项目。

目前,我可以通过以下两种设置使我的项目工作:

  • 将所有内容注册为单例 => SingleInstance() (EF 上下文的并发问题,因为它不是线程安全的)
  • 注册所有内容,以便每次Resolve()调用时都会获得一个新实例=> InstancePerDependency() (额外开销)

不幸的是,我无法使其与InstancePerRequest()范围一起使用。

出于某种原因,我收到以下错误消息:

在此处输入图片说明

这听起来有点像我会InstancePerRequest()singelton服务的某个地方注入这些依赖项......

一旦我将所有内容更改为SingleInstance()InstancePerDependency()一切正常。与InstancePerRequest().

启动文件

    /// <summary>
    /// Is called by the ASP.NET Core application for all environments.
    /// </summary>
    /// <param name="builder">Builder container.</param>
    private static void ConfigureContainer(ContainerBuilder builder, ApplicationName applicationName)
    {
        // For all environments and for only user service specific registrations
        if …
Run Code Online (Sandbox Code Playgroud)

.net entity-framework dependency-injection autofac asp.net-web-api

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

Angular - 跨不同模块提供防护

基本上我现在有以下 Angular 模块:

  1. landing
  2. admin
  3. core
  4. shared

我想要的是注册一个在模块AuthenticationGuard内调用的新守卫shared,并在不同的模块中提供它。

目前,只有当我在landing-module( 这是我引导的) 中注册守卫时,它才起作用,而如果我在 或 中注册它,它也admin.module不起作用shared.module

如果我这样做,我会收到一条错误消息,内容如下:

在此输入图像描述

注册guard是通过providers相应模块的数组完成的。

我的目标是能够在所有模块中使用它。

core从模块内注入服务没有问题- 所以我认为两者admin之间一定存在差异?guardsservices

目前一些相关文件看起来像这样(为了简洁起见缩短了):

登陆模块.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { HomeComponent } from './home/home.component';
import { LandingRoutingModule } from './landing.routing.module';

import { SharedModule } from '../shared/shared.module';
import { CoreModule } from '../core/core.module';
import { SecurityModule } from …
Run Code Online (Sandbox Code Playgroud)

angular-module angular angular-router-guards angular-router

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