小编Ale*_*lex的帖子

没有名为setuptools的模块

我想安装twilio的安装文件.当我通过给定的命令安装它时,它给我一个错误"没有名为setuptools的模块".

你能告诉我怎么办?

我正在使用python 2.7.

Microsoft Windows [版本6.1.7601]版权所有(c)2009 Microsoft Corporation.版权所有.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Python27>python D:\test\twilio-twilio-python-26f6707\setup.py install
Traceback (most recent call last):
  File "D:\test\twilio-twilio-python-26f6707\setup.py", line 2, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools
Run Code Online (Sandbox Code Playgroud)

python setup.py python-2.7

83
推荐指数
4
解决办法
22万
查看次数

MS Bot Builder:如何将会话数据设置为主动消息?

我首先通过OAuthCallback方法中的短信通道向用户发送主动消息

 var connector = new ConnectorClient();
 Message message = new Message();
 message.From = new ChannelAccount { Id = Constants.botId, Address = "+12312311", ChannelId = "sms", IsBot = true };
 message.To = new ChannelAccount { Id = newUserId, Address = "+18768763", ChannelId = "sms", IsBot = false };
 message.Text = $"How are you doing? ";
 message.Language = "en";
 connector.Messages.SendMessage(message);

 IBotData myDataBag = new JObjectBotData(message);

 myDataBag.UserData.SetValue("Username", "Bob");
 myDataBag.PerUserInConversationData.SetValue("Newuser", "yes");
Run Code Online (Sandbox Code Playgroud)

然后在我的主Dialog.cs中尝试访问它

public static readonly IDialog<string> dialog = Chain
    .PostToChain()            
    .Switch(new Case<Message, IDialog<string>>((msg) => …
Run Code Online (Sandbox Code Playgroud)

c# botframework

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

属性规范中的奇怪歧义(两个使用指令)

背景:属性规范中,有时存在两种写入应用属性的有效方法。例如,如果属性类具有名称HorseAttribute,则可以将属性应用为[HorseAttribute][Horse]。歧义可以用@例如来解决[@Horse]

以下是有效的程序:

using System;
using Alpha;
using Beta;

namespace N
{
  [Horse]
  class C
  {
  }
}

namespace Alpha
{
  // valid non-abstract attribute type with accessible constructor
  class HorseAttribute : Attribute
  {
  }
}

namespace Beta
{
  // any non-attribute type with that name
  enum Horse
  {
  }
}
Run Code Online (Sandbox Code Playgroud)

Alpha.HorseAttribute我编写just时,C#编译器可以选择[Horse]。毕竟,类型Beta.Horse完全不适合在属性规范中使用。

即使交换名称,C#编译器也会知道该怎么做:

using System;
using Alpha;
using Beta;

namespace N
{
  [Horse] …
Run Code Online (Sandbox Code Playgroud)

c# compiler-errors custom-attributes .net-attributes

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

MVC Razor View渲染测试

我正试图找出一种方法来检查剃刀视图在测试中呈现的HTML.

我一直在看人们提出类似问题的帖子,但每一次,我都做不到.我得到的问题是视图引擎尝试加载.cshtml文件.它从函数中返回一个空引用异常.

[Test]
public void GetRazorViewEngine() {
    var _HttpContextBaseMock = new Mock<HttpContextBase>();
    var _HttpRequestMock = new Mock<HttpRequestBase>();
    var _HttpResponseMock = new Mock<HttpResponseBase>();
    _HttpContextBaseMock.SetupGet(x => x.Request).Returns(_HttpRequestMock.Object);
    _HttpContextBaseMock.SetupGet(x => x.Response).Returns(_HttpResponseMock.Object);

    var routeData = new RouteData();
    routeData.Values.Add("controller", "Home");
    routeData.Values.Add("action", "About");

    var controller = new HomeController();
    controller.ControllerContext = new 
    ControllerContext(_HttpContextBaseMock.Object,
                      routeData,
                      controller);
    controller.Url = new UrlHelper(new RequestContext(_HttpContextBaseMock.Object, routeData),
                                   new RouteCollection());


    var razorEngine = ViewEngines.Engines
                                 .Where(x => x.GetType() == typeof(System.Web.Mvc.RazorViewEngine))
                                 .FirstOrDefault();

    var path = "/Users/dan/Projects/Playground/MvcPlayground/Views/Home/About.cshtml";
    var master = "/Users/dan/Projects/Playground/MvcPlayground/Views/Shared/_Layout.cshtml";

    ViewEngineResult viewEngineResult = razorEngine.FindView(controller.ControllerContext,
                                                             path,
                                                             master, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc unit-testing razor xamarin

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

MEF没有检测到插件依赖性

我有MEF和使用插件文件夹的问题.

我有一个主应用程序,通过MEF支持插件.主应用程序不引用包含.NET任务类型的程序集用于多线程,但是一个或多个插件可以.

插件位于Plugins文件夹中,我正在使用DirectoryCatalog.

我一直ReflectionTypeLoadException被MEF抛出

无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.

LoaderExceptions属性包含一个 FileNotFoundException

"无法加载文件或程序集'System.Threading.Tasks,Version = 1.5.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项.系统找不到指定的文件.":"System.Threading.Tasks ,Version = 1.5.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"

该插件System.Threading.Tasks通过Microsoft NuGet包引用引用.

这是我的助手方法:

public static void Compose(IEnumerable<string> searchFolders, params object[] parts)
{
    // setup composition container
    var catalog = new AggregateCatalog();

    // check if folders were specified
    if (searchFolders != null)
    {
        // add search folders
        foreach (var folder in searchFolders.Where(System.IO.Directory.Exists))
        {
            catalog.Catalogs.Add(new DirectoryCatalog(folder, "*.dll"));
        }
    }

    catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));

    // compose and create plug ins …
Run Code Online (Sandbox Code Playgroud)

.net c# plugins mef

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

根据正在录制的WAV音频,使用C#中的VLC创建http音频流

我正在使用NAudio库来记录系统麦克风输入 - 连续.

private void RecordStart() {
        try {
            _sourceStream = new WaveIn {
                DeviceNumber = _recordingInstance.InputDeviceIndex,
                WaveFormat =
                    new WaveFormat(
                    44100,
                    WaveIn.GetCapabilities(_recordingInstance.InputDeviceIndex).Channels)
            };
            _sourceStream.DataAvailable += SourceStreamDataAvailable;
            _sourceStream.StartRecording();
        } catch (Exception exception) {
            Log.Error("Recording failes", exception);
        }
}
Run Code Online (Sandbox Code Playgroud)

有一个事件处理程序,只要有数据,它就会从记录流中获取数据.

我能够使用现有的音频文件创建一个音频(mp3)HTTP流媒体,并在我的系统中安装VLC播放器.

const int portNumber = 8089;
const string streamName = "fstream_1789846";
const string audio = "C:\\Recording\\Audio\\1789846.wav";
const string windowQuiet = "-I dummy --dummy-quiet";
const string tanscode = ":sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}";
var stream = String.Format(@":http{{mux=mp3,dst=:{0}/{1}}}", portNumber, streamName);
const string keep = ":sout-keep"; …
Run Code Online (Sandbox Code Playgroud)

c# vlc audio-streaming bass http-live-streaming

10
推荐指数
0
解决办法
1138
查看次数

来自Socket的UWP SendToAsync导致AddressFamilyNotSupported

我正在使用UWP 的Socket类通过UDP将数据发送到特定设备.

问题是,经过几次发送和返回后,我的SocketAsyncEventArgs发送被卡住了,在SocketError中我得到了AddressFamilyNotSupported.

类的初始化就是这样完成的

m_Socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
m_Socket.Bind(new IPEndPoint(IPAddress.Any, 51020));
m_SocketReceiveEventArgs = new SocketAsyncEventArgs();
m_SocketReceiveEventArgs.Completed += SocketArgsReceived;
m_SocketReceiveEventArgs.SetBuffer(m_ReceivingBuffer, 0,m_ReceivingBuffer.Length);
m_SocketSendEventArgs = new SocketAsyncEventArgs();
m_SocketSendEventArgs.Completed += SocketArgsSend;
Run Code Online (Sandbox Code Playgroud)

当我发送via时(循环的条件仅用于测试目的):

m_SocketSendEventArgs.SetBuffer(aunReqBuffer, 0,aunReqBuffer.Length);
m_Socket.SendToAsync(m_SocketSendEventArgs);

while (m_SocketSendEventArgs.BytesTransferred == 0)
{
    // AddressFamilyNotSupported happens here after a few packets have been send
}
Run Code Online (Sandbox Code Playgroud)

并通过访问套接字并调用ReceiveFromAsync()来在一个单独的线程中重复接收,这是有效的.

知道它突然停止工作的原因吗?如果您需要更多信息,我很乐意帮忙.

更新08.03.2017

我将发送方法包装在using语句中,现在它可以工作了.有人能向我解释这个吗?特别是我得到的奇怪的SocketError.在我的记忆中,我已经尝试过.Dispose()手动,所以我混淆了那里有什么不同.

using (var sendargs = new SocketAsyncEventArgs())
{
    sendargs.Completed += SocketArgsSend;
    sendargs.RemoteEndPoint = m_remoteIpEndPoint;
    sendargs.SetBuffer(aunReqBuffer, 0, aunReqBuffer.Length);
    m_Socket.SendToAsync(sendargs);
    while (sendargs.BytesTransferred == 0)
    {
        // …
Run Code Online (Sandbox Code Playgroud)

c# sockets asynchronous udp uwp

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

交换属性GetMethod实现运行时

我目前正在尝试通过用一些IL替换它来交换属性获取实现.我正在使用这个问题作为参考:如何替换指向从系统类继承的方法类中的方法的指针?

我唯一的区别是我的方法是通过MethodBuilder声明的:

MethodBuilder propertyGetBuilder = builder.DefineMethod
(
    dynamicFunctionName,
    MethodAttributes.Public,
    propertyInfo.PropertyType,
    Type.EmptyTypes
);

ILGenerator propertyGetIlGenerator = propertyGetBuilder.GetILGenerator();

propertyGetIlGenerator.Emit(OpCodes.Ldarg_0);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, propertyInfo.Name);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, relationKeyField.Name);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, relationAttribute.RelationColumn);
propertyGetIlGenerator.Emit(OpCodes.Call, loadRelationMethod);

propertyGetIlGenerator.Emit(OpCodes.Ret);
Run Code Online (Sandbox Code Playgroud)

这会为生成的类型添加一个新函数 BeforeGet{PropertyName}

生成新类型后,我实例化它以确保内存地址存在: dynamic fakeType = Activator.CreateInstance(type);

我从现有类中检索propertyInfo GetMethod,以及新创建的BeforeGet{PropertyName}fakeType类Type.

之后,在此函数中使用了两个MethodInfo:

RuntimeHelpers.PrepareMethod(methodA.MethodHandle);
RuntimeHelpers.PrepareMethod(methodB.MethodHandle);

unsafe
{
    if (IntPtr.Size == 4)
    {
        int* inj = (int*)methodA.MethodHandle.Value.ToPointer() + 2;
        int* tar = (int*)methodB.MethodHandle.Value.ToPointer() + 2;
#if DEBUG
        Console.WriteLine("\nVersion x86 Debug?\n");

        byte* injInst = (byte*)*inj;
        byte* tarInst = (byte*)*tar;

        int* injSrc = (int*)(injInst + 1);
        int* …
Run Code Online (Sandbox Code Playgroud)

c# pointers

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

即使日期是JSON中的UTC,为什么ServiceStack会发出本地时间?

长话短说 - 通过ServiceStack.Text的JSON解析器跳转的日期会丢失时区信息.奇怪的是,DateTimeSerializerTests.DateTime_Is_Serialized_As_Utc_and_Deserialized_as_local()似乎期待这种行为,并DateTimeSerializer.Prepare()显式调用ToLocalTime()解析为UTC的每个日期时间对象!

这是一个示例测试用例(MSTest,但很容易在任何东西中运行).本地通行证,但UTC和未指定不通过 - DateTime对象返回的类型始终为"本地".

[TestMethod]
public void TestParseSingleDateTime_UTC()
{
    // In canonical UTC format
    var date = "2014-06-03T14:26:20.0030000Z";
    var raw = new DateTime(2014, 6, 3, 14, 26, 20, 3, DateTimeKind.Utc);
    var value = DateTimeSerializer.ParseShortestXsdDateTime(date);
    Assert.AreEqual(DateTimeKind.Utc, value.Kind);
    Assert.AreEqual(raw, value);
}

[TestMethod]
public void TestParseSingleDateTime_Local()
{
    // In local time zone
    var date = "2014-06-02T11:15:49.1480000-05:00";
    var raw = new DateTime(2014, 6, 2, 11, 15, 49, 148, DateTimeKind.Local);
    var value = DateTimeSerializer.ParseShortestXsdDateTime(date);
    Assert.AreEqual(DateTimeKind.Local, value.Kind);
    Assert.AreEqual(raw, …
Run Code Online (Sandbox Code Playgroud)

c# servicestack servicestack-text

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

WNS推送仅发送到某些标签

大纲

我正在尝试为我的应用游戏实施WNS.我目前在创建具有以下功能的新用户时发送通知,该功能有效:

public async void SendNotificationToTag(string tag, string content)
{
    var wnsToast = "<toast><visual><binding template=\"ToastText01\">"
        + "<text id=\"1\">Breaking " +content + "An WNS News!"
        + "</text></binding></visual></toast>";

    WindowsPushMessage wnsMessage = new WindowsPushMessage();
    wnsMessage.XmlPayload = wnsToast;

    await Services.Push.HubClient.SendWindowsNativeNotificationAsync(wnsToast, tag);
    Services.Log.Info("WNS TEST - SendWindowsNativeNotificationAsync - done");
}
Run Code Online (Sandbox Code Playgroud)

我得到了每个用户名的通知,即个人通知.然后我更新用户监听的标签,查看集线器数据库,这似乎也有效:

  1. -Usernamecph - gameID1151 - gameID1152 - gameID1153 - gameID1154 - gameID1155 - gameID1156 - gameID1157 - gameID1158
  2. -gameID1157 - UsernameFyn - gameID1151 - gameID1153 - gameID1155 - gameID1156-

使用此检查从集线器中提取标签

foreach (Microsoft.ServiceBus.Notifications.RegistrationDescription t in a)
{ …
Run Code Online (Sandbox Code Playgroud)

c# azure push-notification azure-notificationhub wns

9
推荐指数
0
解决办法
361
查看次数