|
Hello there, I need to do the same thing, I'm trying to import the C or VB DLL into C#, but it's the first time that I try to do a similar thing.. Any suggestions for where to start?
My task is really simple, I just have to Detect another NFC tag and then to Write and Read one message.
Did you finish successfully your task? Or it's better to use another NFC tag reader with available C# DLL?
Greetings Davide.
|
|
|
|
|
Hello forum,
actually i'm trying to build my first C# GUI and first C# program ever.
I used Glade to design the GUI. But after compiling and debug-run i'm getting:
/usr/bin/mono --debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555,setpgid=y /home/sascha/RiderProjects/PublicanCreators/PublicanCreators/bin/Debug/PublicanCreators.exe
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-primary-button-warps-slider' of type `gboolean' from rc file value "((GString*) 0x20b82e0)" of type `gboolean'
(PublicanCreators:7404): libglade-WARNING **: Expected <glade-interface>. Got <interface>.
(PublicanCreators:7404): libglade-WARNING **: did not finish in PARSER_FINISH state
(PublicanCreators:7404): libglade-CRITICAL **: glade_xml_get_widget: assertion 'self != NULL' failed
(PublicanCreators:7404): libglade-CRITICAL **: glade_xml_get_widget: assertion 'self != NULL' failed
(PublicanCreators:7404): libglade-CRITICAL **: glade_xml_get_widget: assertion 'self != NULL' failed
(PublicanCreators:7404): libglade-CRITICAL **: glade_xml_get_widget: assertion 'self != NULL' failed
(PublicanCreators:7404): libglade-CRITICAL **: glade_xml_signal_autoconnect_full: assertion 'self != NULL' failed
The gui.glade can be found there: PublicanCreators/gui.glade at master · saigkill/PublicanCreators · GitHub[^]
Can anyone help me to get the GUI running, please?
Greetings
Sascha
|
|
|
|
|
I found it out, why it doesn't work. The Glade file was produced with Glade 3.x. My implementation was for using with the old libglade library. But since some time this library was replaced by Gtk.Builder. This one can now handle the Glade 3.x output.
If anyone has such problem again, so you can start there with your journey: GtkSharp - Part 3 - Basic Example with VS and Glade - The Grbd Blog[^]
|
|
|
|
|
I'm trying to calculate the area of different shapes using Strategy pattern and below are my code thus far.
public class Shape
{ public string Name{get;set;}
}
public class Circle:Shape
{ public double Radius{get;set;}
public Circle (string name, double radius)
{Name = name; Radius = radius;}
}
public class Square:Shape
{ public double Side {get; set;}
public Square(string name, double side)
{ Name = name; Side = side;}
}
public interface ICalculateAreaStrategy
{ double Calculate(Shape shape);
}
public class CalculateCircleAreaStrategy: ICalculateAreaStrategy
{ double Calculate(Shape shape)
{
return Math.Pow(shape.Radius,2)*3.14;
}
}
public class CalculateSquareAreaStrategy: ICalculateAreaStrategy
{ double Calculate(Shape shape)
{
return shape.Side * shape.Side
}
}
public class CalculateAreaService
{ readonly ICalculateAreaStrategy calculateAreaStrategy;
public CalculateAreaService(ICalculateAreaStrategy strategy)
{
calculateAreaStrategy = strategy;
}
double CalculateArea(Shape shape)
{
return calculateAreaStrategy.Calculate(shape);
}
}
The reason I'm stuck is I cannot get access to the Circle or Square class from the Shape object passed to the Calculate() method in the CalculateCircleAreaStrategy and CalculateSquareAreaStrategy classes.
modified 17-Jan-17 4:37am.
|
|
|
|
|
The reason you can't access it is because you are passing in a Shape which does not have the relevant parameters because they are defined in the subclasses. If you know that you are passing in a certain type, then you just need to cast them before you try to access them. For instance, in the Circle strategy, your Calculate method could be converted to this:
double Calculate(Shape shape)
{
Circle circle = shape as Circle;
if (circle == null)
{
throw new InvalidOperationException("You didn't pass in a circle");
}
return Math.Pow(circle.Radius, 2)* 3.14;
}
This space for rent
|
|
|
|
|
Thanks, that's exactly what I needed.
|
|
|
|
|
This isn't what the strategy pattern is for anyway.
You could just define these methods on their respective classes, it doesn't make sense to calculate the area of a circle as if it was a square, and vice versa. So changing the strategy doesn't even apply to this situation. Even if you do apply it, a strategy is supposed is not supposed to work only conditionally, they're supposed to be usable interchangeably - that's their whole point.
|
|
|
|
|
Thanks for replying. I'll look into this topic more.
|
|
|
|
|
 To answer your specific question you need to up caste to the type you need
public class Shape
{
public string Name { get; set; }
}
public class Circle : Shape
{
public double Radius { get; set; }
public Circle(string name, double radius)
{ Name = name; Radius = radius; }
}
public class Square : Shape
{
public double Side { get; set; }
public Square(string name, double side)
{ Name = name; Side = side; }
}
public interface ICalculateAreaStrategy
{
double Calculate(Shape shape);
}
public class CalculateCircleAreaStrategy : ICalculateAreaStrategy
{
public double Calculate(Shape shape)
{
Circle c = shape as Circle;
if (c == null)
{
return 0;
}
return 3.14 * c.Radius * c.Radius;
}
}
public class CalculateSquareAreaStrategy : ICalculateAreaStrategy
{
public double Calculate(Shape shape)
{
Square s = shape as Square;
if (s == null)
{
return 0;
}
return s.Side * s.Side;
}
}
public class CalculateAreaService
{
readonly ICalculateAreaStrategy calculateAreaStrategy;
public CalculateAreaService(ICalculateAreaStrategy strategy)
{
calculateAreaStrategy = strategy;
}
public double CalculateArea(Shape shape)
{
return calculateAreaStrategy.Calculate(shape);
}
}
Usage
CalculateAreaService cas = new CalculateAreaService(new CalculateSquareAreaStrategy());
Console.WriteLine(cas.CalculateArea(new Square("Square", 3)));
cas = new CalculateAreaService(new CalculateCircleAreaStrategy());
Console.WriteLine(cas.CalculateArea(new Circle("Circle", 3)));
Console.ReadLine();
However the strategy pattern isn't that great for things that require different parameters such as you have with Square, Circle etc. I appreciate you're doing this to learn the strategy pattern and this might not be your ultimate use for it, but if you wanted to do something like you're doing then you could do it more simply like this
public interface ICalculateArea
{
double Calculate();
}
public class CalculateCircleArea : ICalculateArea
{
private Circle circle;
public CalculateCircleArea(Circle circle)
{
this.circle = circle;
}
public double Calculate()
{
return 3.14 * circle.Radius * circle.Radius;
}
}
public class CalculateSquareArea : ICalculateArea
{
private Square square;
public CalculateSquareArea(Square square)
{
this.square = square;
}
public double Calculate()
{
return square.Side * square.Side;
}
}
Usage
List<ICalculateArea> calcs = new List<ICalculateArea>();
calcs.Add(new CalculateSquareArea(new Square("Square", 3)));
calcs.Add(new CalculateCircleArea(new Circle("Circle", 3)));
foreach (var calc in calcs)
{
Console.WriteLine(calc.Calculate());
}
Or even simpler still have Square, Circle etc implement ICalculateArea and return their own area.
|
|
|
|
|
Thank you for your time, I would not have known that the Strategy pattern isn't suited for my situation if you hadn't shared your thoughts.
Can you please explain why "the strategy pattern isn't that great for things that require different parameters". I've checked the definition of the Strategy pattern and there wasn't anything that says it shouldn't be used on situations that are similar to mine.
The following are part of the definition of the Strategy pattern I've found online.
* "Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it." (Gang of Four)
* "Specifies a set of classes, each representing a potential behaviour. Switching between those classes changes the application behaviour. (The Strategy)
From my perspective all of my classes which inherit from the ICalculateAreaStrategy interface have the same exact method and it takes the same exact number and type of parameter no matter which class it's used in.
modified 17-Jan-17 13:40pm.
|
|
|
|
|
Liagapi wrote: vary independently from clients That's the point: in your case, a Circle requires the algorithm for a circle, not for a rectangle, etc.: the algorithm absolutely depends on the client.
Think of something different, say a chess game. How to find out the next move? You could use "brute force" calculating a few moves ahead, or you could implement some "artificial intelligence strategy". There could be external constraints, e.g. how much time you may use for calculating the next move, and hence apply different algorithms with different trade-offs.
Select the algorithm applicable for the current scenario - and with the next scenario use an algorithm for that scenario.
|
|
|
|
|
My first impulse would have been to use polymorphism:
Polymorphism (C# Programming Guide)
(The example looks very familiar).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have a SQL table with a Started column that is of type DateTimeOffset.
In a Linq To Entities query I'm trying to query against a DateTime value:
.
.
.
where t.Started.Value.DateTime >= startDT
.
.
.
I get "The specified type member 'DateTime' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."
I've never used a DateTimeOffset. What's the right way to query this field using Linq To Entities?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
There are many things you can't do with L2E - sadly, this is one of them. What you need to do is materialize the data into something like a list first, and then apply the filtering to the list.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: What you need to do is materialize the data into something like a list first
I thought of that, but what this means is first querying the ENTIRE table into a list, then applying the date check. This obviously won't work.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Turns out that it works with Linq To SQL, but not Linq To Entities.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I know - that's why I said this is one of the things you can't do with L2E.
This space for rent
|
|
|
|
|
ya, no big deal. I'm just getting started to converting isn't an issue.
Thanks for the heads up.. Save me hours of Googling & fiddling.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
How about:
where t.Started >= startDT
The implicit cast from DateTime to DateTimeOffset will let the C# compile, and the L2E query should just work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I would have to know what the offset is that I'm looking for, then add that to the DateTime I'm using as my paramater
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
So you want the rows where the local value of the DateTimeOffset is after a particular DateTime value?
Seems a bit strange to me, but you should be able to do something like this:
int startYear = startDT.Year;
int startMonth = startDT.Month;
int startDay = startDT.Day;
int startHour = startDT.Hour;
int startMinute = startDT.Minute;
int startSecond = startDT.Second;
...
where t.Started >= EntityFunctions.CreateDateTimeOffset(
startYear, startMonth, startDay, startHour, startMinute, startSecond,
SqlFunctions.DatePart("tz", t.Started))
...
EntityFunctions is defined in System.Data.Entity.Core.Objects in the EntityFramework assembly;
SqlFunctions is defined in System.Data.Entity.SqlServer in the EntityFramework.SqlServer assembly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good evening everyone I'm looking on google but I do not find a solution that allows me to display the checkbox check in datagridview in a line specify. The display should not be vertical as the result in this image.
|
|
|
|
|
|
How can I implement NLP in c# program? Is there any logic for extracting single/multiple words from one or more sentences?
For more understandability, I included a paragraph(Doctor's Note) here.
The patient x is suffering from fever. He has no headache, cough or neck pain. But he has back pain.
Moreover patient x suffers Sleeplessness.
<big>My requirement is</big>,
I need to iterate symptoms such as <big>fever, back pain and sleeplessness</big>. And
do not take symptoms <big>headache, cough and back pain</big> .
|
|
|
|
|