Tag: c#

通过JSON / PHP(base64_encode)从基于图像的C#中解释base 64

所以我能够成功读取图像文件,并将其传递回我的C#应用​​程序,但我无法正确解码。 我通过PHP返回JSON数据(json_encode函数未显示): $imgbinary = fread(fopen($filename, “r”), filesize($filename)); if ( strlen($imgbinary) > 0 ){ return array(“success”=>true, “map”=>base64_encode($imgbinary)); } 然后在C#中我使用Newtonsoft.Json解码字符串(我可以成功读取成功和地图属性),但我无法使用base64解码将图像正确写入文件(或显示)。 我是这样做的: File.WriteAllText(System.Windows.Forms.Application.StartupPath + “\\MyDir\\” + FileName, Base64Decode(FileData)); public string Base64Decode(string data) { byte[] binary = Convert.FromBase64String(data); return Encoding.Default.GetString(binary); } 我在这里想念一些疯狂的东西吗? 真正奇怪的是我解码数据后,文件大小比原始文件大。 (我知道一旦你编码,数据增加了大约33%,奇怪的是,在我解码后,它仍然更大)。 任何帮助/指针将不胜感激!

通过特定的Source读取Windows事件日志

如何通过特定的源,日期时间和类别读取Windows事件日志?

如何在YouTube用户上传video时拨打电话?

我正在尝试创建一个简单的聊天机器人,它会在某个频道上传video时发送消息,理想情况下是video的名称和video的超链接。 YouTube的API非常奇怪,我对如何处理这个问题一无所知。 这是我到目前为止: using System; using System.Linq; using Google.Apis.Services; using Google.Apis.YouTube.v3; YouTubeService service = new YouTubeService(new BaseClientService.Initializer() { ApiKey = apiKey, ApplicationName = “GoodApp” }); var getChannel = service.Channels.List(“snippet”); getChannel.Id = channelId; var response = getChannel.Execute(); var channel = response[0]; //now what?

使用跨域创建cookie

我正在研究cookies。 我可以很容易地创建cookie。 要创建cookie我正在使用此代码: HttpCookie aCookie = new HttpCookie(“Cookie name”); aCookie.Value = “Value”; Response.Cookies.Add(aCookie); 这段代码对我来说很好,它给了我localhost作为主机。 但是当我尝试在这里添加域名时问题就出现了: HttpCookie aCookie = new HttpCookie(“Cookie name”); aCookie.Value = “Value”; aCookie.Domain = “192.168.0.11”; Response.Cookies.Add(aCookie); 现在没有生成cookie。 有什么建议?

WCF通用字典和了解WCF

好的,我在解决特定问题时遇到了很多困难。 通过服务传输对象。 从概念上讲,它是有道理的……我想? 根据我的阅读,除非已明确定义,否则无法序列化Generic。 所以我想提供我的榜样; 我根本无法上class。 意思是; 我确信还有其他人也遇到了一些困难。 当你提供帮助时,如果你能提供代码; 这将起作用并解释它。 这样我就可以完全理解这个问题。 这对我很有帮助,了解Windows Communication Foundation。 目标是一个客户端应用程序,它只有五个字段; 在其中“发布”到服务器。 名字 姓 电子邮件地址 电话号码 网站地址 这不是太复杂。 这就是我所做的,在我学习WCF的过程中,我尽可能地将其包含在基于SOA的应用程序中。 这样它就可以提供代码的可重用性。 型号/数据合同: #region Using Reference… using System.Runtime.Serialization; using System.Collections.Generic; using System.Threading.Tasks; using System.Text; using System.Linq; using System; #endregion namespace _2Do.Model.Customer { [DataContract(IsReference = true)] public class Person { #region Declared Variable. string […]

应该使用哪个:数组vs链表?

我打算在不使用Queue类的情况下实现有界队列。 在阅读了Arrays和LinkedList优缺点之后,我更倾向于使用Array来实现队列function。 该系列将是固定尺寸。 我只想添加和删除队列中的项目。 就像是 public class BoundedQueue { private T[] queue; int queueSize; public BoundedQueue(int size) { this.queueSize = size; queue = new T[size + 1]; } } 代替 public class BoundedQueue { private LinkedList queue; int queueSize; public BoundedQueue(int size) { this.queueSize = size; queue = new LinkedList(); } } 由于效率和集合是固定大小的事实,我选择了Array。 想就此得到其他意见。 谢谢。

StackExchange.Redis:获取频道订阅的数量(即PUBSUB NUMSUB)

有没有办法通过StackExchange.Redis库获取特定Redis频道的频道订阅数量? 当直接与Redis交互时,它可以使用PUBSUB NUMSUB命令( http://redis.io/commands/pubsub )但我没有看到C#客户端库中的等效调用。

查找使用c#开始的新流程

我正在使用以下代码来查找已启动的任何新进程。 该函数在线程中运行。 我需要登录启动的进程名称。 我使用两个arraylist。 在一个arraylist上,我在启动线程和另一个arraylist之前存储所有进程名称,我在线程中填充当前进程并比较两个arraylist以找到新进程。 现在的问题是,由于写入日志文件的字符串是针对每个循环的,我在日志文件中看到重复的进程名称。 我希望它只记录一次。 我怎么解决这个问题? class ProcessMonitor { public static ArrayList ExistingProcess = new ArrayList(); public static void Monitor() { existingProcesses = GetExistingProcess(); while (true) { ArrayList currentProcesses = new ArrayList(); currentProcesses = GetCurrentProcess(); ArrayList NewApps = new ArrayList(GetCurrentProcess()); foreach (var p in ExistingProcess) { NewApps.Remove(p); } string str = “”; foreach […]

如何强制浮点数和int有小数点或尾随零

我试图通过RS232与机器接口,机器要求所有输入都有一个小数分隔符,否则它采用小数位。 EG如果我发送25它会将其解释为0.025 ,但25.000或25.将被正确接收为25.000 我尝试过Math.Round但是对于整数值,它不包括尾随零。 所以,如果我有 float a = 90; float b = cos(24); comPort.WriteLine(“G01 A” + a + ” B” + b); 我需要添加什么才能强制增加3位小数? 我不关心它是如何舍入的,也不关心它是否被截断。

无法让我的相机正确限制其旋转

在我的游戏中,我想要夹住玩家的相机,这样就无法进行前翻或后翻。 我想将x轴夹在-75和50之间,但它不起作用。 每当我在我的代码中添加一个钳位时,相机就不希望将它的旋转距离输入的距离为0,0,0.GetAxisRaw表示鼠标正在移动。 我已尝试将if语句用作手动钳位,但如果我切换极性,它会不断地保持在0,0,0或恒定地保持在-75,0,0。 我已经尝试更换相机,以防它与其设置相关但没有任何变化。 我不想发布这个,因为它不应该这么难,但我已经花了好几天时间而且我没有选择; 任何和所有的想法都非常感激。 我使用Visual Studio作为我的编辑器。 using UnityEngine; public class PlayerMove : MonoBehaviour { Rigidbody rb; public Camera cam; public Transform camTrans; Vector3 movement; Vector3 rotation; public float sensitivityX; public float sensitivityY; public float playerSpeed; public float jumpForce; float forward; float sideways; void Start() { rb = GetComponent(); } void FixedUpdate () […]