|
Thanks for the links. I've heard of Roslyn but I never looked into it before. I like the idea of being able to write a C# workflow in text, store it anywhere (file, database), and execute it when needed.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
Roslyn is awesome. I really like it.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Jint[^] is a JavaScript interpreter written in C#.
If you don't mind importing native DLLs, PythonNET[^] is quite cool.
Roslyn has been mentioned already, and the official repo is on Github[^] (Beware, the build process can be quite finicky at times, failing for no obvious reason)
NLua[^] allows .NET applications to leverage the Lua language (currently Lua 5.2).
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Jint looks interesting. I will have to follow it.
Brisingr Aerowing wrote: Beware, the build process can be quite finicky at times, failing for no obvious reason
Interestingly enough, I used to work with MS System Center Orchestrator and one thing I really liked about it was that you could write actual C# code to be used anywhere in a Runbook. I don't know why I didn't think of it before because it was using Compiler Services the whole time. It too would throw some cryptic errors when I forgot to put the end quote on a string literal or a parameter was empty.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
The errors from Roslyn are pretty much always to the point and actually tell you what went wrong.
I don't use Jint, so I can't say what it's like.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I've been looking at about a dozen flavors of scripting strategies for C# including those mentioned here (but, not Lua, Python, or IronPython). There's lots of open-source projects going on that offer scripting from light to heavy.
Defining what the facilities you need now, and in the future, seems to me the most criteria for choice of package. And, one can use T4, or .NET's compiler-services to generate code, or objects, on-the-fly, compile, run, instantiate the objects, etc.
One interesting script language for C# I have been exploring is Jing Lu's ReoScript; he used that in the ReoGrid project that he presented in an article here (just look it up); Jing made the choice to move ReoGrid from open- to closed-source some time ago, but his last open-source version is still up here. AFAIK ReoScript is still available as open-source: [^].
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
There seems to be a lot of competing scripting implementations for .Net. I do happen to be gravitating to Roslyn as you can write normal C#/VB code outside of a library and execute it inside the CLR. The idea of writing all your workflows in text and placing them in any storage medium, granting the workflows a level of independence from the program which executes them, affords system architects a level of flexibility that is hard to ignore.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
Is there any plugin or provision for End user can build a query and generate a Chart.
Example: My application have a list of master items, i can select master item and make a project. Consider i have 20 master items in which 5 projects are In Progress, 5 are Completed projects and 10 items Not started a Project yet. Based on this i want to draw a pie chart or a bar chart.
|
|
|
|
|
Where does the data come from and how is it managed? And when you say 'plugin', plugin for what? Please put some proper detail in your question.
|
|
|
|
|
Plugin for accepting the data returned by query and to generate a chart.
Data i have a plan to display tables or views which enduser can query
Thanks,
Gopichand N
|
|
|
|
|
|
Am sorry for asking the question here. Initially i don't find where to ask the question then i came here and posted. If possible can you move it to my questions.
Thanks,
Gopichand N
|
|
|
|
|
Sorry no, I do not have the power to move it. However, that is not the issue, it is the fact that we have no idea what your problem is.
|
|
|
|
|
I'm stil beginner in c#. and i have made a small program. here is Main Program :
class Program
{
public static void Main()
{
while (true)
{
Console.WriteLine("Welcome");
Console.WriteLine("1 to go to Data class");
Console.WriteLine("type q to exit");
string input = Console.ReadLine();
if (input == "1")
{
}
else if (input == "q")
{
break;
}
else
{
Console.WriteLine("invalid option");
}
}
}
}
And this One is the Data Class.
class Data
{
public Data()
{
while (true)
{
Console.WriteLine("Choose Option : ");
Console.WriteLine("Press 1 to add and Press 2 To Go to Main Program");
int entry = int.Parse(Console.ReadLine());
if (entry == 1)
{
Console.WriteLine("Enter any number ");
int input = int.Parse(Console.ReadLine());
int result = input += 3;
Console.WriteLine("result");
Console.WriteLine(result);
}
else if (entry == 2)
{
}
else
{
Console.WriteLine("Invalid OPtion");
}
break;
}
}
}
And I want to do is . When the user type 2 in data class. then the program should go to main program, but unfortunately I dont know how to do that. Anyone Help please
|
|
|
|
|
Basically, don't.
Look at your code for the Data constructor (I'll rip out some of it top make it clearer):
while (true)
{
...
if (entry == 1)
{
...
}
else if (entry == 2)
{
}
else
{
...
}
break;
} Which means that regardless of what path you take though the if, you will always exit your loop at the end of the first iteration. So why is the loop there at all?
But there are more fundamental things: why are you getting the values inside the class constructor at all? That "locks" the class to always only work from the Console, you can't create an instance from data he entered last time if you save it. That's bad design - there is no good reasond for the Data class to have any idea where the data comes from. In fact is much, much better from an OOPs standpoint if the class has no idea where data comes from!
But your Data class is not a "real" class - it's just code you will call from your main method by a silly mechanism.
Classes aren't there to act as "super containers" for blocks of procedural code - they are supposed to be there to contain the data and it's related methods so each instance can work on it's own data.
For example, a simple class:
public class User
{
private string name;
private string hairColour;
private DateTime dateOfBirth;
public User(string name, string hairColour, int year, int month, int day)
{
this.name = name;
this.hairColour = hairColour;
dateOfBirth = new DateTime(year, month, day);
}
public int GetAge()
{
DateTime start = dateOfBirth;
DateTime end = DateTime.Now.Date;
int days = end.Day - start.Day;
if (days < 0)
{
end = end.AddMonths(-1);
days += DateTime.DaysInMonth(end.Year, end.Month);
}
int months = end.Month - start.Month;
if (months < 0)
{
end = end.AddYears(-1);
months += 12;
}
int years = end.Year - start.Year;
return years;
}
public string GetDetails()
{
return string.Format("{0} ({1}) is now {2}", name, hairColour, GetAge());
}
}
You create users thus:
User mike = new User("Mike Smith", "Blonde", 1990, 11, 14);
User joe = new User("Joe Ninety", "Mousey", 1983, 2, 1); And the class then handles all the work itself:
User mike = new User("Mike Smith", "Blonde", 1990, 11, 14);
User joe = new User("Joe Ninety", "Mousey", 1983, 2, 1);
Console.WriteLine(mike.GetDetails());
Console.WriteLine(joe.GetDetails());
And it will print:
Mike Smith (Blonde) is now 25
Joe Ninety (Mousey) is now 33
The User class is independent of the input and output mechanism, it just handles users and their data.
Do you see the difference between that and what you are trying to do?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have a treat for you
public static class AgeCalculationExtension
{
public static int CalculateCurrentAge(this DateTime birthday)
{
return CalculateAgeAsOf(birthday, DateTime.Today);
}
public static int CalculateAgeAsOf(this DateTime birthday, DateTime appointedDate)
{
if (appointedDate < birthday)
throw new ArgumentOutOfRangeException(nameof(appointedDate));
int age = appointedDate.Year - birthday.Year;
if (birthday > appointedDate.AddYears(-age))
age--;
return age;
}
}
edit: Added input validation.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 27-Apr-16 7:48am.
|
|
|
|
|
Ooh goody. Here's an input for it:
DateTime dateTime = new DateTime(1968, 2, 29);
int age = dateTime.CalculateAgeAsOf(new DateTime(1964, 2, 29)); Apparently, that person is -4.
This space for rent
|
|
|
|
|
Totally correct answer.
You have the birthday in 1968, and are asking age as of 1964.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
While it's syntactically correct, it's also logically bogus. It's why public inputs should always be checked.
This space for rent
|
|
|
|
|
I agree - and added it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: if (birthday == null) ...
if (appointedDate == null) ...
A DateTime can never be null .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, Richard - it was a bit too late yesterday.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I have my custom error handler defined in Global.asax:
void Application_Error(Object sender, EventArgs e)
{
var exception = Server.GetLastError();
var httpException = exception as HttpException;
Response.Clear();
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Error";
routeData.Values["action"] = "General";
routeData.Values["exception"] = exception;
Response.StatusCode = 500;
if(httpException != null)
{
Response.StatusCode = httpException.GetHttpCode();
switch(Response.StatusCode)
{
case 403:
routeData.Values["action"] = "Http403";
break;
case 404:
routeData.Values["action"] = "Http404";
break;
}
}
IController errorController = new ErrorController();
var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
errorController.Execute(rc);
}
Im trying to test my error handler by raising an error like this in my service model:
if(albums != null)
{
albums = null;
ctx.SpotifyAlbums.AddRange(albums);
ctx.SaveChanges();
}
This raises an exception, but how can I "catch" this exception with my custom error handler?
|
|
|
|
|
Member 12045692 wrote: This raises an exception, but how can I "catch" this exception with my custom error handler? According to MSDN[^];
An error handler that is defined in the Global.asax file will only catch errors that occur during processing of requests by the ASP.NET runtime. For example, it will catch the error if a user requests an .aspx file that does not occur in your application. However, it does not catch the error if a user requests a nonexistent .htm file. For non-ASP.NET errors, you can create a custom handler in Internet Information Services (IIS). The custom handler will also not be called for server-level errors.
You may want to play around with the Complete Example for Error Handlers[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Create a menu
1.Register Student
2.View Student details");
3.Check student balance");
4.Pay fees");
5.Exit"
1. when you click on register student the program should prompt you for name,surname,date of birth,gender,student number,
2. when you click on view student details it should allow you to retrieve information in 1......search by student number or name
3. allow you to chk student balance....search student number or name.....
4. allow you to deducted from a constant double variable 200000
store all details in a file.
it should be able to store 400 students
this is what i tried out.......
........................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string info;
int code;
const double totalcost=20000;
double amount_owed;
string Firstname;
string Surname;
DateTime DOB;
char Gender;
double Total_Fees_paid;
string nTitle;
string nFirstname;
string nsurname;
DateTime nDOB;
string nOccupation;
string nDesgination;
int students;
Console.WriteLine("The Hogwarts Academy");
Console.WriteLine("---- ----------");
Console.WriteLine(" 1. Register Student");
Console.WriteLine(" 2. View Student details");
Console.WriteLine(" 3. Check student balance");
Console.WriteLine(" 4. Pay fees");
Console.WriteLine(" 5. Exit");
Console.WriteLine("---- ----------");
try
{
code = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("You enter the wrong character e.g abcd!@#");
Console.WriteLine("Please re-enter a number e.g 12345");
Console.Clear();
code = int.Parse(Console.ReadLine());
}
if (code > 5)
{
Console.WriteLine("The Hogwarts Academy");
Console.WriteLine("---- ----------");
Console.WriteLine(" 1. Register Student");
Console.WriteLine(" 2. View Student details");
Console.WriteLine(" 3. Check student balance");
Console.WriteLine(" 4. Pay fees");
Console.WriteLine(" 5. Exit");
Console.WriteLine("---- ----------");
Console.WriteLine("\n\nPlease re-enter a number which is on the code list");
code = int.Parse(Console.ReadLine());
}
else if (code == 1)
{
StreamWriter writer = new StreamWriter("Student.txt");
Console.WriteLine("Number of students");
students=int.Parse(Console.ReadLine());
for (int i = 0; i < students; i = i + 1)
{
Console.WriteLine("________________Student information______________");
Console.WriteLine("Enter student name ");
Firstname = Console.ReadLine();
Console.WriteLine("Enter the Surname ");
Surname = Console.ReadLine();
Console.WriteLine("Enter student date of birth");
DOB = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Enter student Gender either F/M ");
Gender = char.Parse(Console.ReadLine());
Console.WriteLine("Total fees paid N$");
Total_Fees_paid = double.Parse(Console.ReadLine());
amount_owed = totalcost - Total_Fees_paid;
Console.WriteLine("__________NEXT OF KIN__________");
Console.WriteLine("Enter next of kin/parent/gurdian's Title ");
nTitle = Console.ReadLine();
Console.WriteLine("Enter next of kin/parent/gurdian's Name ");
nFirstname = Console.ReadLine();
Console.WriteLine("Enter next of kin/parent/gurdian's Surname ");
nsurname = Console.ReadLine();
Console.WriteLine("Enter next of kin/parent/gurdian's date of birth");
nDOB = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Enter next of kin/parent/gurdian's Occupation");
nOccupation = Console.ReadLine();
Console.WriteLine("Enter next of kin/parent/gurdian's Desgnation");
nDesgination = Console.ReadLine();
//StreamWriter SW; //new StreamWriter("@info.txt");
//SW = File.AppendText(Firstname + Surname + DOB + Gender + Total_Fees_paid + amount_owed + "Next of kin" + nTitle + nFirstname + nsurname + nDOB + nOccupation + nDesgination + ".txt");
//SW.Close();
}
}
else if (code == 2)
{
}
}
}
}
|
|
|
|
|