|
Yeah ... some of my data classes I binary serialize, then encrypt, then compress, then embed as resources. Make them work a little.
"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
|
|
|
|
|
Smart, no-one would expect you to encrypt before compressing.
|
|
|
|
|
Hey there,
Hope everyone is well.
I have a method in my Form1()
public void checkCommand(string command)
{
this.label1.Text = command;
}
I've written an external .dll class library with other methods, which I'm also using inside my main Form1(). But I do need to call a method/methods that are in my Form1() from this external .dll class library. However, I can't access it.
public class Commands
{
private string myCommand;
public void readCommand()
{
checkCommand(myCommand);
}
private void
}
Please note, I'll be using this external class library in multiple applications. So assigning Form1 inside my external dll is out of question, unfortunatelly.
Does anyone know the best solution to this, please?
I'll be very grateful for all your ideas. Thank you!
modified 29-Dec-22 17:20pm.
|
|
|
|
|
Question is not very clear.
C# has classes and methods (static or not.) You cannot access a method without the class.
Beyond that the class must also have a namespace.
So you must resolve the namespace. You must have a instance. You must call the method with that instance. Examples of all of that.
using SomeNamespace:
...
YourClass c = new YourClass();
c.checkCommand(myCommand);
To get to that class (as defined by the namespace) you must have the dll referenced in the binary build. Even to compile it it will need to be available. And of course delivered into an appropriate space (same file system directory) as the primary executable.
|
|
|
|
|
Thank you jschell. I appreciate your involvement.
Apologies, if perhaps I haven't made myself clear.
As per my post above, I've mentioned that I am using external dll. Therefore, I use namespace to it, exactly as per your suggestion. So in my Form1 I can access all methods from my external class library.
To be clear, this is an external dll class for my sockets client.
OnReceive(IAsyncResult ar) I need to display value on label.text in my Form1, or other forms where I will be using my external sockets class dll assembly.
Another method within that class need to call method from Form1 checkCommand(string command). Hope this will help explaining it better
Thank you again
|
|
|
|
|
There's a bunch of different ways of doing this, but NONE of them involve your class library calling a method in the form class.
Looking at your example code, I wouldn't even consider putting that code in the Form class, but instead in it's own class where you create an instead of it and pass that instance to your class library. Of course, that class will have to implement an interface your class library exposes and expects by an implementer.
|
|
|
|
|
You need to add an "interface" (e.g. IFormCommand) to your external dll that your form can implement; then you call into the dll with the interface ("sender" as IFormCommand); the dll can then use to interface to call the form's method(s); as defined in the interface.
You're basically trying to avoid a circular "using" reference (from dll to form) by using an interface (class).
"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
|
|
|
|
|
Impossible: for a dll in some unknown app to invoke a method in a WinForm app ... the dll must get passed a valid reference to the Form instance in the WinForm App.
You need to describe in detail what you are trying to achieve.
Theoretically, it is possible to use reflection to enumerate all running processes and locate the WinForm app process of interest ... believe me, you don't want to go there [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Turn the problem on it's head, and ask yourself "does it happen in other code?"
And the answer is "yes": it happens all the time. When something happens in a class, it wants to tell the outside world about it.
When the user clicks a button, when data arrives at a serial port, when a timer expires - they all need to tell your code that it happened. They do this by means of Events which your code subscribes to and processes via a handler method.
The user clicks a button? The Button raises the Click event, your code handles it and checks the data he entered.
Data arrives? The SerialPort class raises the DataRecieved event, your code handles it and processes the characters.
The timer interval expires? The Timer class raises the Tick event, your code handles it and updates the on screen clock.
So why not use the same mechanism in your code? Your external class creates an Event, your form adds a Handler; your external class wants your form to do something, it raises the event, the handler method does the work.
Have a look here: Transferring information between two forms, Part 2: Child to Parent[^] - it's form / control based, but it's exactly the same process for "normal" classes.
"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!
|
|
|
|
|
I have a good prototype to draw some fancy mathematical models in Windows Form application.
now I want to wrap this drawing logic into a chart control.
how difficult is it for this conversion?
try to get some ideas from you gurus here. plan to do this conversion in this year end break.
diligent hands rule....
|
|
|
|
|
Not too difficult: create a UserControl and start adding your logic code to that. If you code already draws on a form, it should work pretty much unchanged on a UC (remember that a Form is derived from Control and so shares a lot of properties and methods).
"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 confirmation! I will convert it by myself.
diligent hands rule....
|
|
|
|
|
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!
|
|
|
|
|
I had this code working in VB.net, and I tried switching it to C# as follows. did anyone ever do this before?
(how do I "type" objMyform? What would be the equivalent of "dim")
objMyForm = Server.CreateObject("CutePDF.Document"); 'Create form object
int nReturn;
objMyForm.initialize("FS21-001-39268470-03111634") ; 'Initialize object by serial number of the license
int familyID = session("FamilyID");
FM Family = new Family();
FM.GetByID(familyID);
Camper CP = new Camper();
int CamperID;
GetCamper(CamperID );
'Open an encrypted PDF form file from an URL with password 'cutepdf'
if objMyForm.openFile("/../Forms/Parentalconsent.pdf") == false then
errorMessage = objMyForm.GetLastError();
end if
'Set some value into fields
nReturn = objMyForm.setField("chkAgudah", CP.att_camp ==1? "on":"off");
nReturn = objMyForm.setField("chkBnos", CP.att_camp ==2? "on":"off");
nReturn = objMyForm.setField("chkCCM", CP.att_camp =31? "on":"off");
nReturn = objMyForm.setField("chknu", CP.att_camp ==4? "on:"off");
|
|
|
|
|
Quote: (how do I "type" objMyform? What would be the equivalent of "dim")
objMyForm = Server.CreateObject("CutePDF.Document"); 'Create form object
int nReturn;
The Dim statement in VB is simple:
Dim variableName As variableType = ... In C#, it's even simpler:
variableType variableName = ...
If you don't know both languages, then use an online converter: Code Converter C# to VB and VB to C# – Telerik[^] is the one I use.
"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!
|
|
|
|
|
Cute PDF SDJ support request: [^].
The form indicates questions re evaluation version may be accepted.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Hello everyone
i am using Thread and inside it there is for loop
it starts fast for first 30 times then it becomes slow and after 500 times it become much slower any idea why this happen?
modified 26-Dec-22 6:17am.
|
|
|
|
|
Without your code (and probably your data)?
We have no idea why this happens - there are just too many different things you could be doing! There is nowhere near enough information here for us to begin to help you - we have no idea what you are trying to do, or where you are starting from.
Start here: Asking questions is a skill[^] and think about what you need to know, and what you need to tell us in order to get help.
"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!
|
|
|
|
|
you are right sorry for that
and i finally got what was the problem i am using inside loop linq and when i use function inside where it took too much time
|
|
|
|
|
It's OK, at least you tried to ask a "proper question" - it's not the worst question we've ever had, just look two threads down ...
"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!
|
|
|
|
|
of course, we have no idea how you are using Linq, but:
"inside loop linq:" keep possibility of multiple enumerations in mind: [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Probably creating a memory leak.
"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
|
|
|
|
|
I have an IEnumerable<employee> that I need to update some fields based on the user's security permissions. If a user is in the Admin or HR roles, the CanEdit and CanDelete properties should be set to true. If the user is not Admin or HR, but is their own record, CanEdit should be true. I have come up with two options, and wanted to know which would be considered the better method (or a different way) for speed, readability, and maintainability.
Method 1 first checks if the user is Admin or HR, then loops through the entire collection and updates the values. If the user is not Admin/HR, then it checks each record to see if it is the users and updates. Currently, a user can only have one record, so I quit once I update the matching employee record.
if(_userManager.User.IsInRole("Admin") || _userManager.User.IsInRole("HR"))
{
foreach(var employeeRecord in employeeList)
{
employeeRecord.CanEdit = employeeRecord.CanDelete = true;
}
return employeeList;
}
foreach(var employeeRecord in employeeList)
{
if(employeeRecord.WorkEmail.Equals(_userManager.User.Identity.Name, StringComparison.OrdinalIgnoreCase))
{
employeeRecord.CanEdit = true;
return employeeList;
}
}
return employeeList; Method 2 stores a boolean if the user is an Admin/HR, and just sets that as the permission, then checks if the current employeeRecord belongs to the user and sets the permission.
bool hasEditDeletePermission = _userManager.User.IsInRole("Admin") || _userManager.User.IsInRole("HR");
foreach(var employeeRecord in employeeList)
{
employeeRecord.CanEdit = employeeRecord.CanDelete = hasEditDeletePermission;
if(_userManager.User.Identity.Name.Equals(employeeRecord.WorkEmail, StringComparison.OrdinalIgnoreCase))
{
employeeRecord.CanEdit = true;
}
}
return employeeList; Method 2 seems shorter and easier to understand, but Method 1 can be faster when the user isn't Admin or HR, which would happen more often. There's also the issue that Method 1 leaves the CanEdit/CanDelete values to whatever they were originally supplied as (currently defaults to false), where as Method 2 will always override any preexisting values which might cause unexpected behavior if other rules are added elsewhere.
Any recommendations on which you would rather use, or even suggestions on better ways to code this would be appreciated.
|
|
|
|
|
If the user was limited to certain records in the first place, that particular process should have been "data driven" with a proper query. Instead, you've got "generic" process that attempts to apply some logic to "every record" from who knows where.
The "data driver" could be data records, references or simply keys. Another design decision.
What you're dealing with is affectionately known as "tramp data".
"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
|
|
|
|
|
Could you explain a bit more what you mean by 'data driven with a proper query'? Almost every tutorial/example I've found only seems to be basic "Can Access/Can Not Access", but my needs are more granular. I'm currently using CQRS to have my Controller send an EmployeeQuery request. I've added a pipeline to the request handler which has my security logic and updates the results from the query as I need to apply information not just to the records themselves, but also potentially individual properties of the record. I didn't want to mix my security logic in with my query as I thought that could get hard to expand in the future. Here's an example of the current rules/permissions:
- Admin : Full Create, Read, Update, (Soft/Hard) Delete.
- HR : Full Create, Read, Update, Soft Delete.
- Manager : Full Read (of specific columns), Update of their own record (excluding some columns).
- User : Full Read (of specific columns different than Manager), Update of their own record (excluding some columns).
I'm using EFCore and LINQ for the query and I had first thought about trying to have the security logic in the pipeline 'build' the IQueryable that will get executed by the query handler, but I haven't found a good resource on how to do that, so I am updating the results of the handled query before sending it back to the Controller.
|
|
|
|
|