Adding a game service in XNA 4.0 through vb.net - xna-4.0

I have seen a number of examples explaining how to add a game service in C#. They usually look like the following:
this.Services.AddService(typeof(SpriteBatch), spriteBatch);
For the time being, I will be working on the vb.net side, and don't know enough C# to translate this. the typeOf method seems to want a type and an object, and return a boolean value. This doesn't seem like what I want. Does anyone know enough of both C# and vb.net to translate or fill me in on what I'm missing?

Related

Trying to design a Gui based Boolean logic to Boolean Equation program

my job is in automation and I deal a lot with Boolean logic for when a piece of equipment has permission to do something or not do something. this requires that I design expressions in simple one line equations. I'm trying to figure out how I can design a little helper app to make it easier to code.
For example, let's say I'm trying to design a permissive to allow a vehicle to start moving, just jumping into a car won't make it start going, there steps that need to happen before the car will go any where. such as turning on the motor. i'f you look at the image below you can kind of get an idea of a simpler equation.
https://i.ibb.co/fnQ3x9x/IMG-2389.jpg
The eq for the picture is:
Start Permission = MotorTurnedOn AND ((AutoMode OR (ManualMode AND (OilTempNorm OR OilCoolingActive))) OR EmerOvr)
A lot of time I'm editing code that someone wrote a long time ago so it's not always easy to understand and some are very long as seen in the picture below
https://i.ibb.co/tXtrKwk/IMG-2388.jpg
the picture are generated by a third party software that is used to create the GUI's for the equipment.
I'm trying to figure how how could I design something where I could take block and drop them into something resembling the picture and it could export an equation for the equivalent boolean expression.
I'm only familiar with Python, Matlab, C++ and a little bit of java, if there's some template out there that could help me get started I'd be willing to learn a new language otherwise, i'd wanna stick closer to what I know.
Any help or ideas would be appreciated.

UIPath. Vb.net? if condition

Im new to uipath and coding in general. I know most of the basics from what was taught but they didnt go through how to form "condition" statements in the "if" activity. or basically any form of conditions. Where can i go about to learning them? is it a specific language?
kinda like: not Months.Contains(ExpenseMonth)
i wouldnt be able to come up with that because i dont know what is acceptable/readable to uipath studio
also regarding those calculations. where can i find more information on those? to learn more about
kinda like: (int32.Parse(row("Value").ToString) * 100 / monthlyTotal).ToString
they didnt really give me details on how to form that
so essentially, if i wasnt spoon fed with those statements, i would be stuck
It depends on which activity you are using. Usually it's VB.net. Find more about that programming language here.
And yes you will need to get the basics of that language on your own. UiPath isn't really helping you find the correct condition. It is more a tool that can use VB.net.
And soon you can switch to C# completely. But that is not yet ready and still experimental. Also, I would recommend you to stay with VB.net as it is way easier to learn as a first language. Currently, you can only use C# and Invoke Code activity.
To your first example from above:
not Months.Contains(ExpenseMonth)
That depends on your variable type. That looks like a DateTime or a String type and so you are able to use predefined functions that come with it. You can show them but simply clicking CTRL + SPACE after the dot.
And your second one:
(int32.Parse(row("Value").ToString) * 100 / monthlyTotal).ToString
I would always recommend you to use CInt instead of int32.parse. Look here. And it is often not needed to convert the row value into a String. As it is usually already in that type by default.
But again. You will need to learn the basics of VB.net before you are able to write a good business logic in UiPath that makes sense and is best practice.

Does C# 6 make it possible to imply type inference (not explicitly use the var keyword)?

This is an odd question, I know.
Earlier this week, I was browsing hacker news and glossed past an article about the power of C# 6. I meant to 'pocket' the link at the time but I didn't and now I can't find the article again.
Long story short, there was an example of code which looked roughly like this...
using static Variables;
public class Blah
{
public Blah()
{
s = "something"
Console.WriteLine(s);
}
}
... as if to say, somehow it was possible using some magical combination of C# 6 features to remove the 'var' element of that equation and have valid code.
I'm struggling to see how that's possible without some extra Roslyn magic and even then, I'd struggle.
If you know where the article is please let me know. If not, is this even remotely possible? I'm fairly confident it would be an odd thing to do,..I'm just intrigued.
Thanks in advance.

Automating Excel 2010 using F#

I have been searching for a FAQ to tell me how to open a Excel Workbook/Worksheet and also how to Save the File once I have finished.
I notice that in most FAQ and all the books I have purchased on F# one is show how to create a new Workbook/Worksheet but is never shown how to either open or Save it.
Being a newbie to F# I would very much appreciate it if anyone could kindly provide me with either an answer or perhaps a few pointers?
Update
As for why F# and not C# or VB?
I am pleased to say that inspite of being a newbie (with the exception of Forth, VBA & Excel 2003, 2007 & 2010 and Visual Basic) I can do this in both VB, VBA & C# and since I've been retired on medical grounds, with plenty of time unfortunately on my hands, I like to continually set myself challenges to keep my little grey cells active and being a sucker for trying new languages....well!
F# is now an intergral part of Visual Studio 2010 so I thought - why not. Consider this - if we are not willing to use or at least try a new languages - I would always be wonder if I might have prefer it to VBA, VB, C# ..... and if you look at it from another point of view, if no one is going to use it - why create it in the first place? I suppose you can say if cave men hadn't experimented and made fire by rubbing two sticks together - where would we be now and would matches have been invented?
Although an complete answer would be good, I prefer a few pointers, to keep my challenge going.
And lastly but not least - thank you for taking the trouble to respond!
I don't think their is a specific F# library for Office, so you will just use the exact same .NET library that you use in VB.NET/C#. F# is a .NET language, so anything that can be done in C# can be done in F# (but you probably already knew that :) ). The API call will be exactly the same, it just that they will be done using the F# syntax instead of the VB/C# one. So for example something that look like this
public void SaveMyWorkbook() {
string filePath = #"C:\failworkbooks\catfail.xlsx";
workbook.Save(filepath);
}
Will be expressed in F# as
let filePath = "C:\\failworkbooks\\catfail.xlsx";
let saveWorkbook() = workbook.Save(filePath) |> ignore //if the Save method return something
Now, what you will soon realize is that the API isn't exactly designed to be easily used from a functional language. It can be done, but this task in particuliar is much more tailored to C#/VB.NET.
If you really want to enjoy F#, I suggest you use in area where its strength really show. My personal experience is that functional language are awesome when a lot of math is involved. It is also marvellous if you want to easily introduce parallelism in your application (since F# code is usually side effect free). So anything that require data crunching on a lot of data is perfect for it. But for task that consist mainly of putting together a bunch of API call to an external library, F# is kind of meh. You could say that F# is kind of like a graphic card programming language, while C# a general purpose CPU programming language. A lot of thing run better with C#, but the stuff that run better on F# run really better on it.
But if you really want to go that route, my suggestion is to try to use the Office API as you already know it, but with a F# syntax. If at some point you really have no idea how to do a specific task, ask a question about it on stackoverflow with your code and exactly want you want to do. Those question get answered ridiculously fast compared to broad all-encompassing question, so you won't wait long. (Programmer seem to love precise question with a specific answer ^^)
I hope that it helped a little.
I found this http://iouri-khramtsov.blogspot.co.uk/2011/12/automating-excel-with-f.html helpful advice. Briefly, you'd use something like this:
#r "Microsoft.Office.Interop.Excel" // Assuming it's a script
let excel = ApplicationClass(Visible = true)
let openFileName = #"C:\MyDir\MyFilenameToOpen.xls"
excel.Workbooks.Open(openFileName)
// Do stuff
let savedFileName = #"C:\MyDir\MyFilename.xls"
workbook.SaveAs(savedFileName)
Using F# with Excel seems like a natural fit.
Getting to a result in Excel requires the use of several immutable values, each driven by formulas. Excel has a brilliant user interface, a lovely model of the world - I love rows, columns and cells - but to automate or customise things requires macros. Why learn this when you can use F#? Formulas and immutable values are fundamental to its design.
Ideally you'd write formulas yourself as a User Defined Function (UDFs) also in F# - see http://excel-dna.net/ . Then, perhaps, you'd want to do something interesting with objects/types - Look for "github com mndrake ExcelObjectHandler" (I don't have enough reputation to post a 3rd link).
Jack

Simple (Dumb) LINQ Provider

How easy would it be to write a dumb LINQ provider that can just use my class definitions (which don't have any object references as properties) and give me the translated SQL. It can assume the name of the properties and the columns to be same as well as the names of the classes and the underlying tables. Can you please give me some pointers.?
It took me about 4 months of fulltime work (8 hours a day) to build a stable, working provider that implements the entire spec of linq. I would say I had a very simple, buggy and unstable version after about three weeks, so if you're just looking for something rough I would say you're probably looking at anything from a week up to two months depending on how good you are and what types of requiements you have.
I must point you to the Wayward blog for this, Matt has written a really good walkthrough on how to implement a linq provider, and even if you're probably not going to be able to copy and paste, it will help you to get to grips with how to think when working. You can find Matt´s walkthrough here: http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx . I recommend you go about it the same way Matt does, and extend the expression tree visitor Matt includes in the second part of his tutorial.
Also, when I began working with this, I had so much help from the expression tree visualizer, it really made parsing a whole lot easier once you could see how linq parsed to queries.
Building a provider is really a lot of fun, even if a bit frustrating at times. I wish you all the best of luck!
Give a look to the LINQExtender project, is a toolkit for creating custom LINQ providers.
Another option for giving you a leg up seems to be re-linq which is a framework for creating custom LINQ providers.
Here's the Source code and a nice overview (pdf) of what's involved in writing one.
I’ve written a tutorial series on my blog base on my experience developing a LINQ-to-SQL provider from scratch, starting with the expression tree composition stage (calling the LINQ methods), continuing with the expression visitor, breaking down of the query into components, parsing the where clause, generating the text and parameter and, eventually, compiling the whole thing into IL using the .NET expression namespace.
I’ve seen many incomplete posts that promised to explain how to write a provider, falling very short of the mark, barely scratching the surface and not actually delivering anything remotely executable.
The blog series I’ve written based on my experience has a sample project available for download with the simple provider that covers only the functionality required by the tutorial example. However, it also includes the production version supporting a number of operations (where, join, first, count, top, etc.), subqueries, nested statements, and etc. Additionally, it produces a cleaner SQL than a lot of what I’ve seen from Entities and LINQ-to-SQL. There’s no unnecessary/redundant nesting, wrapping everything in brackets and etc.
For anyone with a good level of abstract thinking, developing such a provider isn’t such a difficult task many set it out to be. I’ve developed one that’s used in production environment in about 3 months of part time work (meaning some evenings and weekends). From the get go it was aimed with performance and tidy SQL in mind – a goal it achieved.
It was a little hard to find the time to publish this material, but I thought – if it may help someone out there, there’s no reason for this experience to go to waste:
How to write a LINQ to SQL provider in C# Part 1 - Introduction
How to write a LINQ to SQL provider in C# Part 2 - Expression Visitor
How to write a LINQ to SQL provider in C# Part 3 - Where Clause Visitor
How to write a LINQ to SQL provider in C# Part 4 - Compiling Expression Trees
I have created a project 'LinqToAnything' which is designed to make it very very easy to implement a (simple) Linq provider.

Resources