|
Interopping through Excel.
In general, open files cannot be written to. This interop is a cheat, but with a big bottleneck and won't scale.
You might need an actual developer who can design a database, and those are expensive
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'll venture this: msdocs[^] ... since noone has yet made a similar citation.
|
|
|
|
|
RedDk wrote: since noone has yet made a similar citation
Who is "noone"?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Any malenky malchick az dim a citizen such as yourself might encounter at the mestos bar. I suppose.
modified 21-May-22 14:03pm.
|
|
|
|
|
Hello everybody, I pretty new to programming, what I want to do is a C# program that will send a message to a Microsoft teams group via a webhook connector of this group.
I was able to achieve it with a Desktop code(with form),but I need it to be a console program, I have pretty much copy/paste the code from my Desktop project to my console project, but there something that don't work. Here is my code from my desktop project:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test_team_2
{
public partial class Form1 : Form
{
string[] cmdLineMe = Environment.GetCommandLineArgs();
string webhookPdfTermine = "uri to my team groups;
HttpClient client = new HttpClient();
Message body = new Message();
string finalMessage = "";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < cmdLineMe.Length; i++)
{
finalMessage = cmdLineMe[i];
}
sendMsg();
}
public class Message
{
public string text { get; set; }
}
private async Task SendMsgAsync()
{
MessageBox.Show(finalMessage);
client.BaseAddress = new Uri(webhookPdfTermine);
body.text = finalMessage;
string serializeJson = JsonSerializer.Serialize(body);
StringContent content = new StringContent(serializeJson, Encoding.UTF8, "application/json");
_ = await client.PostAsync(client.BaseAddress, content);
}
void sendMsg()
{
_ = SendMsgAsync();
}
}
}
And here is my code for my console project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
namespace TeamBots
{
class Program
{
string[] cmdLineMe = Environment.GetCommandLineArgs();
string webhookPdfTermine = "uri to my team groups";
HttpClient client = new HttpClient();
Message body = new Message();
string finalMessage = "";
static void Main(string[] args)
{
Program myprog = new Program();
for (int i = 0; i < myprog.cmdLineMe.Length; i++)
{
myprog.finalMessage = myprog.cmdLineMe[i];
}
myprog.sendMsg();
}
private async Task SendMsgAsync()
{
Console.WriteLine(finalMessage);
client.BaseAddress = new Uri(webhookPdfTermine);
body.text = finalMessage;
string serializeJson = JsonSerializer.Serialize(body);
StringContent content = new StringContent(serializeJson, Encoding.UTF8, "application/json");
_ = await client.PostAsync(client.BaseAddress, content);
}
void sendMsg()
{
_ = SendMsgAsync();
}
public class Message
{
public string text { get; set; }
}
}
}
Like I said before, I pretty new to programming, the code was taken from website there and there...
If anyone can help it will be very appreciated.
Thank you
modified 18-May-22 15:09pm.
|
|
|
|
|
The first suspicious thing I see is you call an async method SendMsgAsync() without waiting for it. This means your Main method can execute the code following myprog.sendMsg() before the message is put on the network.
No problem you might think: There is no code there.... correct. And what happens to a console application when there is no more code to run. Well... it terminates the process (a bit simplified - you CAN get it to hang around, but you don't do that here, nor should you).
So my guess (without debugging which is how you REALLY find out these things) is that the program simply terminates before it can send any message.
You should make your Main async as well and await the async calls - then it will not terminate before completion (and you will also see any errors). You might also when googling find advise to call .Result or .Wait. Those are excellent advise for people who like to debug why there software occasionally hangs after they make a completely unrelated change. Sure you can use them if you know how it really works under the hood - but that is not a good topic for a beginner.
|
|
|
|
|
Thank you so much for your answer..
lmoelleb wrote: The first suspicious thing I see is you call an async method SendMsgAsync() without waiting for it. This means your Main method can execute the code following myprog.sendMsg() before the message is put on the network.
You was right, I was able to make it run by putting a Thread.Sleep(5000) after myprog.sendMsg(),is not optimal but it work
for now.
lmoelleb wrote: You should make your Main async as well and await the async calls - then it will not terminate before completion (and you will also see any errors). You might also when googling find advise to call .Result or .Wait. Those are excellent advise for people who like to debug why there software occasionally hangs after they make a completely unrelated change. Sure you can use them if you know how it really works under the hood - but that is not a good topic for a beginner.
I gonna check this.
Thank you so much for your help!
|
|
|
|
|
We have a system that uses Wonderware AOS objects with quite a bit of AOS scripting which interacts with a Sql Server database.
The scripting exists to access data from PLC's, add additional information from a Sql Server database, then write the combined data to a Sql Server table.
I'm wondering if anyone has converted this to a .net app (prefer C#), that would interrogates the PLC's with OPC, and performs the same functionality as above (as regards Sql Server).
The desired result is to stop using AOS objects and exit from Mobileframe.
Thanks.
|
|
|
|
|
I doubt it.
First, that's commercial software, innit? Means the source is not available for "porting".
Next problem, C# isn't used to interact with hardware directly. PLC-land is hardware interaction, and the GC of .NET means any .NET app execution can be put on hold by the system.
There's some OPC libraries available. Knock yourself out.
Bruce Armstrong 2022 wrote: The desired result is to stop using AOS objects Expensive?
If there was a free alternative, then this Wonderware would stop investing in it.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have a data table with around 13000 rows. I want to add all of them to the database. Which method has the best performance, using C# and EF Core or using SQL Server stored procedures?
|
|
|
|
|
You're neglecting the specifics; e.g. SQL Server / EF Bulk Insert.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
|
Hi, i am using HZH_Controls.Controls.UCTextBoxEx to embed a UCTextBoxEx into a DataGridView control's TextBox field. The program is like below:
private HZH_Controls.Controls.UCTextBoxEx uctextBox1=null;
uctextBox1 = new HZH_Controls.Controls.UCTextBoxEx();
this.uctextBox1.Leave += new EventHandler(uctextBox1_Leave);
this.uctextBox1.TextChanged += new EventHandler(uctextBox1_TextChanged);
this.uctextBox1.Visible = false;
this.uctextBox1.KeyBoardType = HZH_Controls.Controls.KeyBoardType.UCKeyBorderNum;
private void uctextBox1_Leave(object sender, EventArgs e)
{
this.uctextBox1.Visible = false;
}
private void uctextBox1_TextChanged(object sender, EventArgs e)
{
this.dataGridViewAxisDefine.CurrentCell.Value = ((HZH_Controls.Controls.UCTextBoxEx)sender).Text;
this.uctextBox1.Visible = false;
}
private void DataGridViewAxisDefine_CurrentCellChanged(object sender, EventArgs e)
{
if ( this.dataGridViewAxisDefine.CurrentCell.ColumnIndex == 2)
{
Rectangle rectangle = dataGridViewAxisDefine.GetCellDisplayRectangle(dataGridViewAxisDefine.CurrentCell.ColumnIndex, dataGridViewAxisDefine.CurrentCell.RowIndex, false);
string value = dataGridViewAxisDefine.CurrentCell.Value.ToString();
this.uctextBox1.Text = value;
this.uctextBox1.Left = rectangle.Left;
this.uctextBox1.Top = rectangle.Top;
this.uctextBox1.Width = rectangle.Width;
this.uctextBox1.Height = rectangle.Height;
this.uctextBox1.Visible = true;
}
else
{
this.uctextBox1.Visible = false;
}
}
i just want people to click the TextBox field that is on the DataGridView to display a soft number pad and edit the numbers on it.
Now the error apears onto the line "
this.dataGridViewAxisDefine.CurrentCell.Value = ((HZH_Controls.Controls.UCTextBoxEx)sender).Text; ", saying "'
HZH_Controls.Controls.TextBoxEx ' object cannot cast to '
HZH_Controls.Controls.UCTextBoxEx ' "
The TextBoxEx is also a control of
HZH_Controls.Controls
, but i never use it.
The error message is translated from Chinese and may not precisely decribe the original meaning since i am using a Chinese version VS 2017.
So, my question is what's the problem cause this error and how to solve this problem? Many thanks in advance!
|
|
|
|
|
There is some code that you are not showing, but at a guess the sender variable is an instance of HZH_Controls.Controls.TextBoxEx which is not compatible with HZH_Controls.Controls.UCTextBoxEx . You need to check the documentation, or ask for help from, the people who write the HZH_Controls library.
|
|
|
|
|
When i change the "HZH_Controls.Controls.UCTextBoxEx" to "HZH_Controls.Controls.TextBoxEx", the program still works fine. The soft number pad can still pass numbers onto the Textbox field.
Yes, i need to check the documentation of HZH_Controls library.
Anyway thank you very much for your kind help!!!
|
|
|
|
|
Looking at the source code[^], the UCTextBoxEx is a user control which wraps a TextBoxEx instance.
When the TextBoxEx instance raises its TextChanged event, the parent UCTextBoxEx instance raises its own TextChanged event. But it passes the original sender through unchanged, which means the sender is the wrapped TextBoxEx instance, not the UCTextBoxEx instance.
This feels like a bug in the library, but there might be a reason for it. You could try reporting an issue[^], but bear in mind the author is Chinese and claims to have poor English.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much for your kind help!!! yes, it still works fine after changing "UCTextBoxEx" to "TextBoxEx". And i also need to check the source code that you provided and may reporting an issue on it.
|
|
|
|
|
Hello,
I am new using a token, but i have to use it in a little WCF.
I found this code here.
As i can see, this generate a token, but i have a few questions:
1. What is Payload and it is each variable?
2. After generate de Token, how to i use in my WCF?
3. Do i have to put the CODE in the WCF?
CODE
static void Main(string[] args)
{
Console.WriteLine("");
string key = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b372742
9090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";
var securityKey = new Microsoft
.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials
(securityKey, SecurityAlgorithms.HmacSha256Signature);
var header = new JwtHeader(credentials);
var payload = new JwtPayload
{
{ "some ", "hello "},
{ "scope", "http://dummy.com/"},
};
var secToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(secToken);
Console.WriteLine(tokenString);
Console.WriteLine("Consume Token");
var token = handler.ReadJwtToken(tokenString);
Console.WriteLine(token.Payload.First().Value);
Console.ReadLine();
}
|
|
|
|
|
I am getting this error when I try to compile the below code:
string key = "mykey";
byte[] buf = Decrypt(key, payload);
unsafe
{
fixed(byte* ptr = buf)
{
IntPtr memoryAddress = (IntPtr)ptr;
VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);
ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));
func();
}
Errors:
pi.cs(60,124): error CS1525: Invalid expression term 'uint'
pi.cs(60,138): error CS1002: ; expected
pi.cs(60,138): error CS1525: Invalid expression term ')'
ooooo
modified 15-May-22 7:55am.
|
|
|
|
|
Check your C# version - the syntax Foo(out type varName) was only added at C#7.0
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for your answer. It was a version issue.
ooooo
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Complex class from Numerics does not have any Parse method
How to write parse method
public static bool TryParse(string s,out Complex z)
{
}
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|