I need to dynamically generate the help for some WEB-API.
The problem is that are dynamic both in the input parameters that in the structure of output.
See the Example:
[HttpGet]
[Route("API/Individuals")]
[ActionName("Individuals")]
public HttpResponseMessage Select()
{
var Params = this.Request.RequestUri.ParseQueryString();
string UserNameCVT = Code.RemappingUser.Remap(UserName.Name);
DataSet ds = Models.Individuals.Individuals.SelectDS(UserNameCVT, Params);
List<Dictionary<string, object>> lDict = DecodeIndividualsFromDS(ds);
response = Request.CreateResponse(HttpStatusCode.OK, lDict);
return response;
}
By doing this, the API is to decouple that from FE DB below, leaving them free to modify the data structures according to their needs.
Is it possible to generate a complete Help once the structures are defined (without changing the code of the API)?
Yes, you can. The key line of code in the XML documentation provider is this (from this getting started page):
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
As you see, the documentation is read from a file path. If you can dynamically create that file on the start of your application, and then pass in the file path, you are set. (You have to find a way to handle those end points dynamically, but that is not in the scope of this question)
Also, if you need to do more, you can create a custom implementation by taking the XmlDocumentationProvider from Github and write your own.
Related
I'm at a loss with the KTA SDK. My intention is to pass a scanned document in PDF format with a few headers to KTA's jobs queue. As I'm still going through the documentation, my best guess right now is to use the Document class as a DTO then I need to call a method to pass that Document as a parameter:
...
[HttpPost]
public HttpResponseMessage Upload()
{
var httpRequest = System.Web.HttpContext.Current.Request;
var DocType = httpRequest.Headers["X-DocType"];
var Pages = httpRequest.Headers["X-DocPages"];
var Title = httpRequest.Headers["X-DocTitle"];
Agility.Sdk.Model.Capture.Document doc = new Agility.Sdk.Model.Capture.Document();
// doc.DocumentType = DocType; // Type DocumentTypeSummary
doc.NumberOfPages = Convert.ToInt32(Pages);
doc.FileName = Title;
...
I'm just wondering if I'm on the right track in doing this?
My other question is where can we store data from a custom header? In this example, I need to store custom header called Comments and AccountNumber.
Lastly, what service needs to be called to send this document to KTA jobs queue? Would CaptureDocumentService be the right one?
I'd greatly appreciate any help on this.
Start with the details laid out in the Sample App example. It shows what to add to your app.config, but what it doesn’t call out explicitly enough is that you should change the SdkServicesLocation value for your environment. You will simply call the functions in the services within the TotalAgility.Sdk namespaces and it will handle the webservice calls.
The CaptureDocumentService might be part of what you need, and there is a set of samples dedicated to the functions on that service. It refers to the Sample Processes folder, which by default is here:
C:\Program Files\Kofax\TotalAgility\Sample Processes\Capture SDK Sample Package
However what you will definitely need are the functions on the JobService. There are different functions with different options, but CreateJobWithDocuments is probably what you want to start with. You can see that this is creating document(s) and a job together in one step.
There is similarity with the parameters on CaptureDocumentService.CreateDocument3, so you might cross-reference with that to best understand the parameters. The difference is that CreateDocument3 just creates a document in the abstract: you want to actually use it as an input to create a job, so use the combined function.
Finally, to pass fields in, you will be setting RuntimeField objects as part of the RuntimeDocument objects going into your CreateJobWithDocuments call.
I'm trying to build a program in which I consume an API through a client that a company has made available for its software.
Here's a link to it.
Though it does make it easier for one to establish a connection and make a call through its embedded methods, I'm having a difficult time manipulating the data once I receive it.
[Note: I know it's sort of meaningless to provide y'all with the background of the client and how I'm making the call, but I would think it'd be hard for one to get a glimpse of what's going on if I'm not even providing how the connection is happening behind the client or how the database looks.]
Previously, I tried manipulating the data directly after making the call like this (link below), but I realized this is too difficult for me since I'm still a noob at C#, and it's been hard to mess with the results (object) as a dynamic[] value.
Link
Therefore, I believe it'd be best if I pursue the route of getting the data as an object, serialize it, turn it to (json), and map it to properties. I believe once I do this it should be easier to manipulate the data because I'd have an easier time turning the data into single values, lists, etc. However, I'm having a difficult time connecting the dots at this point of the code.
This is what I have so far..
I'm only interested in the EntryID, NameFirst, and NameLast of the results, but further along the way I do see myself utilizing the info from the other fields of this table and others. If someone could help me make the connection from the results to these properties, I would very much appreciate it. This would be a huge step in the application I'm trying to build using this API data.
Thanks in advance!
Class of Properties Link
JsonData Processor Link
JSON Results from Call Link
using System;
using [Custom]Api;
using Newtonsoft.Json;
namespace testing2
{
public class Program
{
public static void Main(string[] args)
{
[CustomApi]Client connection = new [CustomApi]Client("BaseURL",
"Username", "Password");
var value =
connection.Select("Entry",Criteria.Equals("NameLast","Rincon Recio"));
string results = JsonConvert.SerializeObject(value);
///not sure if making results as string is the right call to begin
this
//[Syntax where I tell results to match properties of Class 1]
//[Create list of EntryID, NameFirst, NameLast]
//[Display list in listbox]
Console.WriteLine(results);
Console.ReadLine();
}
}
}
No, JsonConvert.SerializeObject(value) shouldn't make a difference.
Try Deserialising values to array of Class1.
Like so
var realResult = JsonConvert.DeserializeObject<Class1[]>(values);
Source
I am currently trying to save a list in Xamarin forms. I use this code snippet:
var list = new List<myClass> ();
Application.Current.Properties["myList"] = list;
await Application.Current.SavePropertiesAsync();
When I then close the app and use this code...
if (Application.Current.Properties.ContainsKey("myList"))
{
}
...I cannot reach this if statement.
I read something about people having issues saving a list with this solution but they solved it by converting it to a string. I am a bit unsure on how to do this. If I do this...
Application.Current.Properties["myList"] = list.ToString();
...the app crashes.
I saw that there is a plugin called "Settings" that I might need to use instead in case there isn't a solution to this problem but I would prefer to work with my current code if possible.
The Properties dictionary can only serialize primitive types for
storage. Attempting to store other types (such as List can
fail silently).
It means that you can't save List because it's not a primitive type of object. You can serialize it to JSON string for example then it will work. Code example:
var jsonValueToSave = JsonConvert.SerializeObject(myList);
Application.Current.Properties["myList"] = jsonValueToSave;
await Application.Current.SavePropertiesAsync();
Don't forget to deserialize JSON to List<string> when loading the value back.
Note that yourList.ToString() will not work in this case. More info here.
P.S.: Get familiar with the official documentation & check this post on another related thread.
I'm using v2.0 of the API via the C# dll. But this problem also happens when I pass a Query String to the v2.0 API via https://rally1.rallydev.com/slm/doc/webservice/
I'm querying at the Artifact level because I need both Defects and Stories. I tried to see what kind of query string the Rally front end is using, and it passes custom fields and built-in fields to the artifact query. I am doing the same thing, but am not finding any luck getting it to work.
I need to be able to filter out the released items from my query. Furthermore, I also need to sort by the custom c_ReleaseType field as well as the built-in DragAndDropRank field. I'm guessing this is a problem because those built-in fields are not actually on the Artifact object, but why would the custom fields work? They're not on the Artifact object either. It might just be a problem I'm not able to guess at hidden in the API. If I can query these objects based on custom fields, I would expect the ability would exist to query them by built-in fields as well, even if those fields don't exist on the Ancestor object.
For the sake of the example, I am leaving out a bunch of the setup code... and only leaving in the code that causes the issues.
var request = new Request("Artifact");
request.Order = "DragAndDropRank";
//"Could not read: could not read all instances of class com.f4tech.slm.domain.Artifact"
When I comment the Order by DragAndDropRank line, it works.
var request = new Request("Artifact");
request.Query = (new Query("c_SomeCustomField", Query.Operator.Equals, "somevalue").
And(new Query("Release", Query.Operator.Equals, "null")));
//"Could not read: could not read all instances of class com.f4tech.slm.domain.Artifact"
When I take the Release part out of the query, it works.
var request = new Request("Artifact");
request.Query = (((new Query("TypeDefOid", Query.Operator.Equals, "someID").
And(new Query("c_SomeCustomField", Query.Operator.Equals, "somevalue"))).
And(new Query("DirectChildrenCount", Query.Operator.Equals, "0"))));
//"Could not read: could not read all instances of class com.f4tech.slm.domain.Artifact"
When I take the DirectChildrenCount part out of the query, it works.
Here's an example of the problem demonstrated by an API call.
https://rally1.rallydev.com/slm/webservice/v2.0/artifact?query=(c_KanbanState%20%3D%20%22Backlog%22)&order=DragAndDropRank&start=1&pagesize=20
When I remove the Order by DragAndDropRank querystring, it works.
I think most of your trouble is due to the fact that in order to use the Artifact endpoint you need to specify a types parameter so it knows which artifact sub classes to include.
Simply adding that to your example WSAPI query above causes it to return successfully:
https://rally1.rallydev.com/slm/webservice/v2.0/artifact?query=(c_KanbanState = "Backlog")&order=DragAndDropRank&start=1&pagesize=20&types=hierarchicalrequirement,defect
However I'm not tally sure if the C# API allows you to encode additional custom parameters onto the request...
Your question already contains the answer.
UserStory (HierarchicalRequirement in WS API) and Defect inherit some of their fields from Artifact, e.g. FormattedID, Name, Description, LastUpdateDate, etc. You may use those fields in the context of Artifact type.
The fields that you are trying to access on Artifact object do not exist on it. They exist on a child level, e.g. DragAndDropRank, Release, Iteration. It is not possible to use those fields in the context of Artifact type.
Parent objects don't have access to attributes specific to child object.
Artifact is an abstract type.
If you need to filter by Release, you need to make two separate requests - one for stories, the other for defects.
I am trying to figure out way to get source of same file from two different commits, but I just can't find any documentation about this.
I know there is Repository.Dif.Compare which is useful but I can only get Patch from it and that doesn't help much since I would like to implement my own side by side comparison.
Can someone provide an example? Is this even possible in libgit2sharp?
I am trying to figure out way to get source of same file from two different commits [...] Is this even possible in libgit2sharp?
Each Commit or Tree type exposes a string indexer that allows one to directly access a TreeEntry through its path. A TreeEntry can either be a Blob (ie. a file), another Tree (ie. a directory), or a GitLink (ie. a submodule).
The code below, gives a quick example of how to access the content of the same file in two different commits.
[Fact]
public void CanRetrieveTwoVersionsOfTheSameBlob()
{
using (var repo = new Repository(BareTestRepoPath))
{
var c1 = repo.Lookup<Commit>("8496071");
var b1 = c1["README"].Target as Blob;
var c2 = repo.Lookup<Commit>("4a202b3");
var b2 = c2["README"].Target as Blob;
Assert.NotEqual(b1.ContentAsText(), b2.ContentAsText());
}
}
I would like to implement my own side by side comparison
Depending of the size of the blob you're dealing with, you may not be willing to retrieve the whole content in memory. In that case, blob.ContentStream may be handy.
Update
I was missing the cast to blob, to figure the rest out
FWIW, you can rely on revparse expressions to directly access the Blob. As the result, the following should also work ;-)
[Fact]
public void CanRetrieveTwoVersionsOfTheSameBlob_ReduxEdition()
{
using (var repo = new Repository(BareTestRepoPath))
{
var b1 = repo.Lookup<Blob>("8496071:README");
var b2 = repo.Lookup<Blob>("4a202b3:README");
Assert.NotEqual(b1.ContentAsText(), b2.ContentAsText());
}
}
This post should answer your question, it's from another question here on this site:
How to diff the same file between two different commits on the same branch?
I hope that helps.