How to call API using C#? - c#

I am not a c# guy. Needless to say that I don't have experience on this topic.
I bought a software and I installed it on my computer. Now I thought of using some of it's functions on my software(that I make to plan in c#). So I messaged the person who sold me the software and he send me a two page pdf file explaining what to do.
It states:
This software features a COM interface.
And it goes saying it's API contains a function "stackAPI".
and the parameters used are apiname type string, apipass type string.
Return values type long. 0 for sucess and 1 for error.
That's all it states, I tired searching google, it could not help me at all. So how do I start?
when I write the following code on c# it gives me error.
string[] apiname;
string[] apipass;
stackAPI(apiname, apipass);
I know if I was using dll I would import it as
[DllImport("example.dll"]
But no dll is provided.
Do I need to add the path to the folder where the software is installed to call the API ?

To get started:
using example.dll;
Then in your main class:
example.CustomService api = new example.CustomService();
var response = api.Dostuff();
Console.WriteLine(response);

If anyone wants to know how I did it. After a week of searching I was able to find the solution today. I wanted to call the function stackAPI(apiname, apipass);.
stackAPI(apiname, apipass) was the member of stack.callapi
So I wrote:
dynamic lifestohack = Activator.CreateInstance(Type.GetTypeFromProgID("stack.callapi"));
than just you can call the function like this.
int rv;
string[] apiname;
string[] apipass;
rv=lifestoahck.stackAPI(apiname, apipass);
Hope it may help someone.

Related

iOS iCloud failing to write with, Couldn't get container configuration from the server error

I have one app that I wrote already reading from and writing to the iCloud. I am essentially using the same code in my new app to do the same thing, but for some reason it will not work, giving me the following error, "Couldn't get container configuration from the server". Let me clarify, with this new app it does puts an entry in iCloud under manage storage, but instead of being under the name of my app, it is under adhoc.
Here is the line in my info.Plist,
Here is the line from my Entitlements,plist
lastly, here is my identifier defined on the apple developer site,
I have verified and reverified that everything is pointing to the correct thing so I am baffled. Any help would be much appreciated.
EDIT I guess what it is doing is writing file to my phone, but when it goes to save data to it, it fails with this message, Here is my call to save the data.
CKRecordID recordID = new CKRecordID(strDate);
await Task.Delay(200);
// Save it to iCloud
await pvc.SaveToiCloud(newRecord);
Here is my code to save the record,
public async Task SaveToiCloud(CKRecord newRecord)
{
ThisApp.PrivateDatabase.SaveRecord(newRecord, (record, err) =>
{
Edit:
I was thinking that possibly the number of nodes I had was too many, so I took out the "dist" one you see below, but that did not help. I thought maybe that was why I was seeing module name of adhoc under icloud on my phone, but I guess I was wrong.
Old:
New:
Edit
I have been doing more digging and found that this line of code is actually the one throwing the error.
File.WriteAllText(Path.Combine(filePath.Path, name + date), "Test");
The name and date contain correct values and the path looks fine to me... I guess... Don't know actually how it should look. Here is how the file path is getting set right above this call,
NSUrl filePath = NSFileManager.DefaultManager.GetUrlForUbiquityContainer(null).Append("Documents", true);
If anyone could offer any advice, I would be most appreciative.
So, I finally figured out the issue and it works like a champ now. The issue was the case in my bundle id in my info.plist. In CloudKit the DB name was all lower case, but my bundle Id in my info.plist, had AdHoc as my last node instead of adhoc as was in the CloudKit. You might say, what does the bundle Id have to do with the iCloud name, and actually I am not really sure, but I noticed that it was taking the case of that last node from my Bundle Id, not the case specified in the iCloud definition as I have shown above. Hope this helps someone who is struggling with a similar issue Have a great day!

Call a SAP transaction/program with the SAP 3.0 .NET Connector

I am aware of the option to call RFC-functions with .NCo 3.0 but is it possible to call transactions/programs directly with the SAP Connector? (Like using the fields defined in SAP as parameters and fill them, or use a variation, something like this?).
This answer provides a workaround that I am aware of, and sure - I could call a VBScript from my C# code but that is not what I want to do.
I also checked all of the 64 Questions tagged with sap-connector but there was nowhere a direct answer if it is possible or not.
Also the SAP documentations I got from the SAP marketplace aren't mentioning transactions/programs at all. Does this mean it is not wanted/possible ?
If so, why is it possible to do it with macros/pre-recorded VBScripts but not with the .NET-Connector ? Or am I just doing something wrong ?
When I try to call a program/transaction with the standart-code:
SAPHandle.ECCDestinationConfig cfg = new SAPHandle.ECCDestinationConfig();
RfcDestinationManager.RegisterDestinationConfiguration(cfg);
RfcDestination dest = RfcDestinationManager.GetDestination("QP2");
dest.Ping(); //works fine -> Connection is OK
RfcRepository repo = dest.Repository;
IRfcFunction zzmkalzzm23fnc = repo.CreateFunction("ZMZKALZZM23");
it gives me the following (expectable) error:
metadata for function ZMZKALZZM23 not available: FU_NOT_FOUND:
function module ZMZKALZZM23 is not available
CreateFunction, as the name already suggests, creates a proxy to call a remote-enabled function module in the SAP system. You can't call a transaction or program this way. I am not aware of any way to call a report with SAP .Net Connector. The solution you linked uses SAP Gui, which provides the SAP system with a UI to display graphical elements. AFAIK, SAP NCo doesn't provide such an interface and you can't call reports from NCo.
However, there are products that allow you to execute transactions and catch their output. We are using the product Theobald Xtract to extract SAP ERP data for BI purposes, but they also have a more generic .Net library (Theobald ERPConnect) available that may be able to provide this functionality. It won't be as simple as calling a function and extracting the strongly typed data, but with some filtering you should be able to get the output you need. Those products are not cheap, but they do provide a nice set of functionality you otherwise would have to reinvent yourself.
Some example code how you could call the transaction you ended up calling through VBS-Scripts.
From the Theobald ERPConnect Knowledgbase:
private void button1_Click(object sender, System.EventArgs e)
{
// Reset the batch steps
transaction1.BatchSteps.Clear();
// fill new steps
transaction1.ExecutionMode = ERPConnect.Utils.TransactionDialogMode.ShowOnlyErrors;
transaction1.TCode = "MMBE";
transaction1.AddStepSetNewDynpro("RMMMBEST","1000");
transaction1.AddStepSetOKCode("ONLI");
transaction1.AddStepSetCursor("MS_WERKS-LOW");
transaction1.AddStepSetField("MS_MATNR-LOW",textBox1.Text);
transaction1.AddStepSetField("MS_WERKS-LOW",textBox2.Text);
// connect to SAP
r3Connection1.UseGui = true;
R3Connection r3Connection1= new R3Connection("SAPServer",00,"SAPUser","Password","EN","800");
r3Connection1.Open(false);
// Run
transaction1.Execut e();
}

QuickBooks Intuit IPP Issue Check

I am attempting to issue a check to a vendor through the Intuit.IPP API (Interop.QBFC12) using the following code:
IMsgSetRequest messageSet = session.CreateMsgSetRequest("US", 7, 0);
ICheckAdd cheque = messageSet.AppendCheckAddRq();
cheque.AccountRef.ListID.SetValue(vendor.ListID.GetValue());
cheque.AccountRef.FullName.SetValue("myAccountName");
cheque.TxnDate.SetValue(DateTime.Today);
IMsgSetResponse responseSet = session.DoRequests(messageSet);
IResponse response = responseSet.ResponseList.GetAt(0);
responseType = (ENResponseType)response.Type.GetValue();
if (responseType == ENResponseType.rtCheckAddRq)
returnMessage = response.StatusMessage;
The resulting response.StatusMessage = "Object 80000005-1374598713 specified in the request cannot be found. " The object ID specified is the ListID I pulled for the vendor.
I'm coding pretty much blind as I'm not finding the IPP documentation very helpful or up to date for version 12.
What am I missing?
This:
cheque.AccountRef.ListID.SetValue(vendor.ListID.GetValue());
cheque.AccountRef.FullName.SetValue("myAccountName");
Is what's causing you the problem.
The AccountRef node is for specifying an Account, not a Vendor. An Account is something from the QuickBooks Chart of Accounts (an "Account" object). A Vendor is something from the vendor list (a "Vendor" object) and they are not interchangable objects.
Since you're already setting an AccountRef/FullName:
cheque.AccountRef.FullName.SetValue("myAccountName");
You don't need to set a AccountRef/ListID.
You should always either set a ListID or a FullName - there's no reason to set both (it's just alternative ways to reference the same object - both are "foreign keys" of sorts to QuickBooks).
What you probably meant to do is set the AccountRef like you meant to, but also set the PayeeEntityRef. For example:
cheque.PayeeEntityRef.ListID.SetValue(vendor.ListID.GetValue());
Also, regarding this:
I'm coding pretty much blind as I'm not finding the IPP documentation
very helpful or up to date for version 12.
IPP is an entirely different API from what you're using. The IPP docs aren't going to be useful to you, because it's not anywhere close to the API you're using.
What you should be using for reference is the QuickBooks OSR:
https://member.developer.intuit.com/qbSDK-current/Common/newOSR/index.html
And also the QuickBooks SDK downloadable .EXE, which has a bunch of relevant PDF documentation.

C# code completion with NRefactory 5

I just found out about NRefactory 5 and I would guess, that it is the most suitable solution for my current problem. At the moment I'm developing a little C# scripting application for which I would like to provide code completion. Until recently I've done this using the "Roslyn" project from Microsoft. But as the latest update of this project requires .Net Framework 4.5 I can't use this any more as I would like the app to run under Win XP as well. So I have to switch to another technology here.
My problem is not the compilation stuff. This can be done, with some more effort, by .Net CodeDomProvider as well. The problem ist the code completion stuff. As far as I know, NRefactory 5 provides everything that is required to provide code completion (parser, type system etc.) but I just can't figure out how to use it. I took a look at SharpDevelop source code but they don't use NRefactory 5 for code completion there, they only use it as decompiler. As I couldn't find an example on how to use it for code completion in the net as well I thought that I might find some help here.
The situation is as follows. I have one single file containing the script code. Actually it is not even a file but a string which I get from the editor control (by the way: I'm using AvalonEdit for this. Great editor!) and some assemblies that needs to get referenced. So, no solution files, no project files etc. just one string of source code and the assemblies.
I've taken a look at the Demo that comes with NRefactory 5 and the article on code project and got up with something like this:
var unresolvedTypeSystem = syntaxTree.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
// Add parsed files to the type system
pc = pc.AddOrUpdateFiles(unresolvedTypeSystem);
// Add referenced assemblies:
pc = pc.AddAssemblyReferences(new CecilLoader().LoadAssemblyFile(
System.Reflection.Assembly.GetAssembly(typeof(Object)).Location));
My problem is that I have no clue on how to go on. I'm not even sure if it is the right approach to accomplish my goal. How to use the CSharpCompletionEngine? What else is required? etc. You see there are many things that are very unclear at the moment and I hope you can bring some light into this.
Thank you all very much in advance!
I've just compiled and example project that does C# code completion with AvalonEdit and NRefactory.
It can be found on Github here.
Take a look at method ICSharpCode.NRefactory.CSharp.CodeCompletion.CreateEngine. You need to create an instance of CSharpCompletionEngine and pass in the correct document and the resolvers. I managed to get it working for CTRL+Space compltition scenario. However I am having troubles with references to types that are in other namespaces. It looks like CSharpTypeResolveContext does not take into account the using namespace statements - If I resolve the references with CSharpAstResolver, they are resolved OK, but I am unable to correctly use this resolver in code completition scenario...
UPDATE #1:
I've just managed to get the working by obtaining resolver from unresolved fail.
Here is the snippet:
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
var resolver3 = unresolvedFile.GetResolver(cmp, loc); // get the resolver from unresolvedFile
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
Update #2:
Here is the complete method. It references classes from unit test projects, sou you would need to reference/copy them into your project:
public static IEnumerable<ICompletionData> DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time
{
var doc = new ReadOnlyDocument(editorText);
var location = doc.GetLocation(offset);
string parsedText = editorText; // TODO: Why there are different values in test cases?
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value};
pctx = pctx.AddAssemblyReferences(refs);
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var resolver3 = unresolvedFile.GetResolver(cmp, location);
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
var data = engine.GetCompletionData(offset, controlSpace: false);
return data;
}
}
Hope it helps,
Matra
NRefactory 5 is being used in SharpDevelop 5. The source code for SharpDevelop 5 is currently available in the newNR branch on github. I would take a look at the CSharpCompletionBinding class which has code to display a completion list window using information from NRefactory's CSharpCompletionEngine.

How to upload images using an API Key that gives you permission to upload? [Python source code included]

The documentation of the API shows source code on how to accomplish this in Python:
#!/usr/bin/python
import pycurl
c = pycurl.Curl()
values = [
("key", "YOUR_API_KEY"),
("image", (c.FORM_FILE, "file.png"))]
# OR: ("image", "http://example.com/example.jpg"))]
c.setopt(c.URL, "http://imgur.com/api/upload.xml")
c.setopt(c.HTTPPOST, values)
c.perform()
c.close()
I'd like a bit of guidance on how to do this in C#. For instance, I'm lost on what these "values" would be in C#, how would I even declare them?
I'm not familiar with cURL at all, so that might be holding me back from translating a bit.
Help me Obi-wan. You're my only hope. /click
You just need to perform an HTTP POST, e.g. this code with a "parameters" string of key=YOUR_API_KEY&image=http://example.com/example.jpg or the like.

Categories

Resources