I'd like to use a language server client to communicate with a language server protocol. I've been trying to connect to sumneko-lua with this language server client.
I have been trying to request completion from the language server, but it would only respond with
[0] Workspace loading: 0 / 0
This is the code:
var lsp = Path.Combine(Directory.GetCurrentDirectory(), "lsp", "bin", "lua-language-server.exe");
var server = new Process
{
StartInfo =
{
FileName = lsp,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
}
};
var languageClient = LanguageClient.Create(options =>
{
var dir = Path.Combine(Directory.GetCurrentDirectory(), "sample");
server.Start();
options
.WithRootPath(dir)
.WithInput(server.StandardOutput.BaseStream)
.WithOutput(server.StandardInput.BaseStream)
.WithWorkspaceFolder(DocumentUri.FromFileSystemPath(dir), "sample");
});
await languageClient.Initialize(CancellationToken.None).ConfigureAwait(false);
var completion = await languageClient.RequestCompletion(new CompletionParams
{
TextDocument = Path.Combine(Directory.GetCurrentDirectory(), "sample", "a.lua"),
Position = (0, 5)
});
foreach (var completionItem in completion.Items)
Console.WriteLine(completionItem.ToString());
Related
As the title described, I'm having a problem with this proto message:
(Proto file)
message StreamingRecognizeRequest{
oneof streaming_request{
StreamingRecognitionConfig streaming_config = 1;
bytes audio_content = 2;
}
}
Here is how I called it:
(C# main function)
await voice.RequestStream.WriteAsync(new StreamingRecognizeRequest
{
StreamingConfig =
{
SingleUtterance = true,
InterimResults = true,
Config =
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
MaxAlternatives = 1,
SampleRateHertz = 8000,
Enhanced = true,
SpeechContexts =
{
}
}
}
});
But the debugger keep marking my Stream Recognize Reuqest as null reference exception, the same pattern works fine in NodeJS but I only have this error in C#. Note that the first message send to the gRPC server doesn't require "Audio Content". So what is the root cause of this error and how to solve it? Or this is gRPC bug on c#?
Thank you!
It's pretty funny how I fixed it. Just not putting them inside each other but seperately create new object:
RecognitionConfig regcfg = new RecognitionConfig
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
MaxAlternatives = 1,
SampleRateHertz = 8000,
Enhanced = true,
};
StreamingRecognitionConfig stc = new StreamingRecognitionConfig
{
Config = regcfg,
SingleUtterance = true,
InterimResults = true,
};
//Create new gRPC stream listener
var voice = vaisclient.StreamingRecognize(meta);
await voice.RequestStream.WriteAsync(new StreamingRecognizeRequest
{
StreamingConfig = stc
}) ;
I'm using MQTTnet library to connect to my MQTT server that needs a server certificate. The client one is not needed.
I already installed the certificate inside my PC as i found in other post and created the .pfx file to create the certificate but the program doesn't give me any error..it simply doesn't connect to the topic.
This is my example code
//Create a new MQTT client
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();
var caCert = new X509Certificate(#"C:\caserverroot.pfx", "mypsw");
var url = "mymqtt.com";
var username = "user";
var psw = "user";
var port = 8885;
var options = new MqttClientOptionsBuilder()
.WithClientId(Guid.NewGuid().ToString())
.WithTcpServer(url, port)
.WithCredentials(username, psw)
.WithTls(new MqttClientOptionsBuilderTlsParameters()
{
AllowUntrustedCertificates = true,
UseTls = true,
Certificates = new List<byte[]> { new X509Certificate2(caCert).Export(X509ContentType.Cert) },
CertificateValidationCallback = delegate { return true; },
IgnoreCertificateChainErrors = false,
IgnoreCertificateRevocationErrors = false
})
.WithCleanSession()
.WithProtocolVersion(MQTTnet.Serializer.MqttProtocolVersion.V311)
.Build();
// Connecting
var result = await mqttClient.ConnectAsync(options);
// Subscribe to a topic
mqttClient.Connected += async (s, e) =>
{
Console.WriteLine("### CONNECTED WITH SERVER ###");
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("/mytopic").Build());
Console.WriteLine("### SUBSCRIBED ###");
};
With all the orther events that i found here: https://github.com/chkr1011/MQTTnet/wiki/Client
Any of you had experience about this library? How to debug it and find the error?
Thanks
So, I don't know why i was wrong but using the ManagedMqttClient saved my situation.
This is the code that works like a charm
//Create a new MQTT client
var mqttClient = new MqttFactory().CreateManagedMqttClient();
var caCert = new X509Certificate(#"C:\cert.pfx", "psw");
var url = "myurl.com";
var username = "user";
var psw = "user";
var port = 8885;
var options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(30))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithClientId(Guid.NewGuid().ToString())
.WithTcpServer(url, port)
.WithCredentials(username, psw)
.WithTls(new MqttClientOptionsBuilderTlsParameters()
{
AllowUntrustedCertificates = false,
UseTls = true,
Certificates = new List<byte[]> { new X509Certificate2(caCert).Export(X509ContentType.Cert) },
CertificateValidationCallback = delegate { return true; },
IgnoreCertificateChainErrors = false,
IgnoreCertificateRevocationErrors = false
})
.WithCleanSession()
.WithProtocolVersion(MQTTnet.Serializer.MqttProtocolVersion.V311)
.Build())
.Build();
// Connecting
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("$share:mygroup:/mytopic").Build());
await mqttClient.StartAsync(options);
I want to parse a page on Microsoft Virtual Academy with PhantomJs. For instance this one. I am able to load it (see result) but in the downloaded source code I don't see the description of the course or its duration.
To download a page I've used next approach: https://gist.github.com/DotNetNerd/5635371.
public string Grab(string url)
{
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = Config.PhantomJSPath,
Arguments = string.Format("\"{0}\\{1}\" {2}", Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "index.js", url)
};
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
and IndexJs
var page = require('webpage').create(),
system = require('system');
page.onLoadFinished = function() {
console.log(page.content);
phantom.exit();
};
page.open(system.args[1]);
Should I configure phantomjs to wait until binding will take effect or PhantomJs simply doesn't support it?
Finally, I decided to wait for 5s after the page was loaded. It doesn't guarantee that everything will load by this time but worked for me.
Index.js was updated to:
var page = require('webpage').create(),
system = require('system');
page.onLoadFinished = function() {
setTimeout(function () {
console.log(page.content);
phantom.exit();
}, 5000);
};
page.open(system.args[1]);
The problem comes in the looping. It seems to perform the comparison between the wmi qfe list and the KB list. The issue I run into is taking and searching the contents of the .msu file name list for the KB and then installing it. I have made a similar program in python and was mimicking a similar construct in the C# code. Any guidance on how to make this function properly would be greatly appreciated. The code is as follows:
static void Server08r2Patches()
{
var IE9 = from a in IAVA.Worksheet<IE9>("IE9") select a;
var Server08r2 = from a in IAVA.Worksheet<Server08r2>("Server08r2") select a;
var KBlist = Server08r2.Select(s=>new {KB = s.KB}).ToList();
var ExeList = Server08r2.Select(s=>new {Executable = s.Executable}).ToList();
string path = (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+#"\x64\");
foreach (var item in KBlist)
{
if (OsPatches.Contains(item.KB))
{
Console.WriteLine(item.KB+" is already installed.");
}
else
{
Console.WriteLine(item.KB+" will now be installed.");
foreach (var inst in ExeList)
{
do
{
var kb_inst = new ProcessStartInfo()
{
CreateNoWindow = true,
UseShellExecute = true,
FileName =path+inst.Executable,
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = (#" /quiet /norestart"),
};
try
{
Process update = new Process();
update.StartInfo = kb_inst;
update.Start();
update.WaitForExit();
Console.WriteLine(inst.Executable+" was successfully installed");
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message+" "+inst.Executable);
}
}
while (inst.Executable.Contains(item.KB) == true);
}
}
}
}
We have about 200 web sites (on 3 separate servers, so 600 total) that we're going to have to update to run on .net 4 framework. They're currently set to run on .net 2. Does anyone know if there's a way to do this with a c# console program? Thanks!
Edit: I found a tool called IIS Metabase Explorer. Using that along with some code I had found a while ago for setting up a site in IIS 6, I came up with the following code. Hopefully it will be of help to others.
I would call it like
UpdateSiteToDotNet4("mytestsite", "mywebserver", #"D:\inetpub\wwwroot\", "DotNet4");
private void UpdateSiteToDotNet4(string siteName, string server, string serverPath, string newAppPoolId)
{
var service = new DirectoryEntry("IIS://" + server + "/W3SVC");
DirectoryEntries sites = service.Children;
bool found = false;
foreach (DirectoryEntry siteEntry in sites)
{
var siteId = siteEntry.Name;
DirectoryEntries siteSettings = siteEntry.Children; //Root
foreach (DirectoryEntry siteSetting in
from DirectoryEntry siteSetting in siteSettings
where siteSetting.SchemaClassName == "IIsWebVirtualDir"
let siteRoot = siteSetting.Properties["Path"][0].ToString()
where siteRoot.ToLower().Trim() == (serverPath + siteName).ToLower().Trim()
select siteSetting)
{
siteSetting.Properties["AppPoolId"].Value = newAppPoolId;
siteSetting.CommitChanges();
//Update to version v4.0.30319
var aspnet = string.Format(#"{0}\Microsoft.NET\Framework\v{1}\aspnet_regiis.exe", Environment.GetEnvironmentVariable("windir"), "4.0.30319");
var startInfo = new ProcessStartInfo(aspnet)
{
Arguments = string.Format("-sn \"{0}\"", "W3SVC/" + siteId + "/Root"),
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
CreateNoWindow = true
};
var process = new Process { StartInfo = startInfo };
process.Start();
process.WaitForExit();
process.Dispose();
found = true;
break;
}
if (found) break;
}
}