C# equivalent of Java org.json.JSONObject - c#

I'm trying to convert a java project to C#. In the following piece I don't know how to convert the Json part.
Cursor resultSet = helper.openDataBase().rawQuery("Select * from word where wname=?", new String[] {String.valueOf(editable)});
TextView TextView_FA = findViewById(R.id.textView_FA);
if( resultSet.moveToFirst())
{
String str_json = resultSet.getString(2);
try {
JSONObject obj = new JSONObject(str_json);
String trans = obj.getJSONArray("ss").optJSONObject(0) .getString("s");
TextView_FA.setText(trans);
} catch (JSONException e) {
TextView_FA.setText(e.getLocalizedMessage());
}
}
else {
TextView_FA.setText("no translation found");
}
This is what I've tried:
EditText EditText_en = FindViewById<EditText>(Resource.Id.EditText_en);
Java.IO.File fil = new Java.IO.File(db_src);
SQLiteDatabase db = SQLiteDatabase.OpenDatabase(fil,null);
Android.Database.ICursor resultSet = db.RawQuery("Select * from word where wname =? ",new[]{ EditText_en.Text});
TextView TextView_FA = FindViewById<TextView>(Resource.Id.TextView_fa);
if (resultSet.MoveToFirst())
{
String str_json = resultSet.GetString(2);
try
{
// JSONObject obj = new JSONObject(str_json);
// String trans = obj.getJSONArray("ss").optJSONObject(0).getString("s");
TextView_FA.Text = trans;
}
catch (Exception e)
{
TextView_FA.Text = e.Message;
}
}
else
{
TextView_FA.Text = "no translation found" ;
}
The two line I've commented is the question.
I tried to use System.Text.Json or System.Json as some of the internet docs has said but VS2019
intellisense doesn't recognize them as a valid library.

To use the NewtonSoft.JSon i probably the most common way to Deserialize json and a bit easier (forgiving) than the System.Text.Json. It is also easier to work with JSon if you have a known type. I don't know how your JSon sttring look like but I have made my own example string
//[
// {
// color: "red",
// value: "#f00"
// },
// {
// color: "green",
// value: "#0f0"
// },
// {
// color: "blue",
// value: "#00f"
// }
//]
string myJson = "[\r\n\t{\r\n\t\t\"color\": \"red\",\r\n\t\t\"value\": \"#f00\"\r\n\t},\r\n\t{\r\n\t\t\"color\": \"green\",\r\n\t\t\"value\": \"#0f0\"\r\n\t},\r\n\t{\r\n\t\t\"color\": \"blue\",\r\n\t\t\"value\": \"#00f\"\r\n\t}\r\n\t\r\n]";
If you have a class or can define it, it will be easier to work with the JSon, but I have created an example without use of the class to
public class custColor
{
public string color { get; set; }
public string value { get; set; }
}
Examples with both NewtonSoft and System.Text.Json
//NewtonSoft JSON
var arrayOfColors = JsonConvert.DeserializeObject<custColor[]>(myJson);
var valueFromArray = arrayOfColors[0].value; //Will give #f00
var dynamicColorArray = JsonConvert.DeserializeObject<dynamic>(myJson);
var valueFromDynArray = dynamicColorArray[0].value; //Will also give #f00
//System.Text.Json
var stjArrayOfColors = System.Text.Json.JsonSerializer.Deserialize<custColor[]>(myJson);
var stjValueFromArray = stjArrayOfColors[0].value; //Will give #f00

Related

How to Get index of a Character in an Unknown Line of a Multiline string in c#

I'm trying to get covid-19 results (only information about Iran) from an Api and show it on a textbox.
and the full result (all countries) that i get from the Api is a json format.
so to get only Iran section i made a Function that loops through lines of the string one by one and check if in that line there is a "{" and if yes get index of that and continue checking if in another line there is a "}" and get index of that too then check if between these, there is "Iran" then add this text (from "{" to "}") in a string:
private string getBetween(string strSourceText, string strStartingPosition, string strEndingPosition)
{
int Starting_CurlyBracket_Index = 0;
int Ending_CurlyBracket_Index = 0;
string FinalText = null;
bool isTurnTo_firstIf = true;
foreach (var line in strSourceText.Split('\r', '\n'))
{
if (isTurnTo_firstIf == true)
{
if (line.Contains(strStartingPosition))
{
Starting_CurlyBracket_Index = line.IndexOf(strStartingPosition); //i think problem is here
isTurnTo_firstIf = false;
}
}
else if (isTurnTo_firstIf == false)
{
if (line.Contains(strEndingPosition))
{
Ending_CurlyBracket_Index = line.IndexOf(strEndingPosition); //i think problem is here
if (strSourceText.Substring(Starting_CurlyBracket_Index, Ending_CurlyBracket_Index - Starting_CurlyBracket_Index).Contains("Iran")) //error here
{
FinalText = strSourceText.Substring(Starting_CurlyBracket_Index, Ending_CurlyBracket_Index - Starting_CurlyBracket_Index);
break;
}
else
{
isTurnTo_firstIf = true;
}
}
}
}
return FinalText;
}
and i call the function like this:
string OnlyIranSection = getBetween(Sorted_Covid19_Result, "{", "}"); //Sorted_Covid19_Result is the full result in json format that converted to string
textBox1.Text = OnlyIranSection;
but i get this Error:
and i know.. its because it gets indexes in the current line but what i need is getting that index in the strSourceText so i can show only this section of the whole result:
USING JSON
As per the comments I read it was really needed to use JSON utility to achieve your needs easier.
You can start with this basic example:
static void Main(string[] args)
{
string jsonString = #"{
""results"": [
{""continent"":""Asia"",""country"":""Indonesia""},
{""continent"":""Asia"",""country"":""Iran""},
{""continent"":""Asia"",""country"":""Philippines""}
]
}";
var result = JsonConvert.DeserializeObject<JsonResult>(jsonString);
var iranInfo = result.InfoList.Where(i => i.Country.ToString() == "Iran").FirstOrDefault();
}
public class JsonResult
{
[JsonProperty("results")]
public List<Info> InfoList { get; set; }
}
public class Info
{
public object Continent { get; set; }
public object Country { get; set; }
}
UPDATE: USING INDEX
As long as the structure of the JSON is consistent always then this kind of sample solution can give you hint.
Console.WriteLine("Original JSON:");
Console.WriteLine(jsonString);
Console.WriteLine();
Console.WriteLine("Step1: Make the json as single line,");
jsonString = jsonString.Replace(" ", "").Replace(Environment.NewLine, " ");
Console.WriteLine(jsonString);
Console.WriteLine();
Console.WriteLine("Step2: Get index of country Iran. And use that index to get the below output using substring.");
var iranIndex = jsonString.ToLower().IndexOf(#"""country"":""iran""");
var iranInitialInfo = jsonString.Substring(iranIndex);
Console.WriteLine(iranInitialInfo);
Console.WriteLine();
Console.WriteLine("Step3: Get inedx of continent. And use that index to get below output using substring.");
var continentIndex = iranInitialInfo.IndexOf(#"""continent"":");
iranInitialInfo = iranInitialInfo.Substring(0, continentIndex-3);
Console.WriteLine(iranInitialInfo);
Console.WriteLine();
Console.WriteLine("Step4: Get the first part of the info by using. And combine it with the initialInfo to bring the output below.");
var beginningIranInfo = jsonString.Substring(0, iranIndex);
var lastOpenCurlyBraceIndex = beginningIranInfo.LastIndexOf("{");
beginningIranInfo = beginningIranInfo.Substring(lastOpenCurlyBraceIndex);
var iranInfo = beginningIranInfo + iranInitialInfo;
Console.WriteLine(iranInfo);
OUTPUT USING INDEX:

Translate from C# to PROGRESS OPENEDGE ABL

I received an C# DLL to access an API and another C# to invoke the DLL.
I'm trying to make an ABL program to INVOKE the DLL.
Ive tried the USING, also run it as an EXTERNAL but no luck.
Never used C#, but it looks like a very simple program can't find how to instatiate the DLL from ABL.
Thanks in advance,
Hugo
Here is the C# code, will appreciate any help
Code:
using System;
using System.Windows.Forms;
namespace CayanConnectSample
{
public partial class MainFrm : Form
{
public MainFrm()
{
InitializeComponent();
}
private string merchantName = "Test Dynamic Payments";
private string merchantSiteId = "2Q5JSJH3";
private string merchantKey = "GQPXT-GTJTP-66A1Y-RWT5G-CNULU";
private string terminalIPAddress = "192.168.1.32"; //ip address in CDI Technologies
private int requestTimeout = 60;
private void btnCreateTransaction_Click(object sender, EventArgs e)
{
decimal amount = Convert.ToDecimal(0.09);
string clerkId = "MIKE";
//only transactionType used are sale & refund
CayanConnect.CreateTransaction.Request request = new CayanConnect.CreateTransaction.Request()
{
MerchantName = merchantName,
MerchantSiteId = merchantSiteId,
MerchantKey = merchantKey,
TransactionType = CayanConnect.CreateTransaction.TransactionTypeEnum.SALE,
ClerkId = clerkId,
Dba = merchantName,
Amount = amount,
//[Amount] is always positive. TransactionType has the sign. Sale or Refund
OrderNumber = "1234"
};
CayanConnect.CreateTransaction createTrx = new CayanConnect.CreateTransaction();
CayanConnect.CreateTransaction.Response ctr = createTrx.Process(request, CayanConnect.ThemeEnum.None);
if (ctr.Success)
{
CayanConnect.InitiateTransaction it = new CayanConnect.InitiateTransaction(terminalIPAddress, ctr.TransportKey, null, CayanConnect.ThemeEnum.None, "Waiting for customer...");
CayanConnect.InitiateTransaction.Response response = it.Process(requestTimeout, true);
string emvDetail = response.EMVDetail;
bool approved = false;
if (response.Success)
{
//THERE IS NO TIMEOUT OR ERROR CALLING THE SERVICE
if (response.Status.ToUpper() == "APPROVED")
{
//AN AMOUNT HAS BEEN APPROVED
if (Convert.ToDecimal(Math.Abs(amount)) == response.AmountApproved)
{
//FULL AMOUNT APPROVED
approved = true;
txtResponse.Text = "Good to go!!";
}
else
{
//PARTIALLY APPROVED, HAS TO VOID THIS
string v = this.VoidApprovedTransaction(response.Token);
string em = v.IsEmpty() ? "Transaction was voided succesfully." : v;
txtResponse.Text = $"Invalid approved amount.{Environment.NewLine}Amount: {amount.ToString("C")}{Environment.NewLine}Approved Amount: {response.AmountApproved.ToString("c")}{em}";
}
}
else
{
//AMOUNT WAS DECLINED
txtResponse.Text = response.DeclinedMessage(amount);
}
}
else
{
//THERE WAS A PROBLEM CALLING THE SERVICE
txtResponse.Text = response.ErrorMessage;
}
}
else
{
//THERE WAS A PROBLEM CALLING THE SERVICE
txtResponse.Text = ctr.ErrorMessage;
}
}
private string GetStatus()
{
string rt = string.Empty;
CayanConnect.GetStatus status = new CayanConnect.GetStatus(this.terminalIPAddress, null, CayanConnect.ThemeEnum.None, "Verifying terminal status...");
CayanConnect.GetStatus.Response statusResponse = status.Process(this.requestTimeout);
rt = statusResponse.ToXml();
return rt;
}
private string VoidApprovedTransaction(string token)
{
string rt = string.Empty;
CayanConnect.Void _void = new CayanConnect.Void();
CayanConnect.Void.Request request = new CayanConnect.Void.Request()
{
MerchantName = this.merchantName,
MerchantKey = this.merchantKey,
MerchantSiteId = this.merchantSiteId,
Token = token,
Timeout = this.requestTimeout
};
CayanConnect.Void.Response response = _void.Process(request, CayanConnect.ThemeEnum.None);
if (!response.Success)
{
rt = $"Error voiding transaction.{Environment.NewLine}{Environment.NewLine}{response.ErrorMessage}";
}
return rt;
}
private void btnIsOnLine_Click(object sender, EventArgs e)
{
txtResponse.Text = GetStatus();
}
}
}
============================================================================
You don't need to 'invoke' the DLL. I have found that the DLL's doc is very important to read - you'll need to know things like who's in charge (ABL or the DLL) of memory allocation and deallocation, structure sizes etc. Also, the AVM is not re-entrant (so cannot be registered as a callback for any DLL).
For an example of calling DLL/SO functions from within an ABL class, take a look in the repo at https://github.com/PeterJudge-PSC/abl_odbc_api .
You'll need to create function prototypes (see an example at https://github.com/PeterJudge-PSC/abl_odbc_api/blob/master/src/OpenEdge/Data/ODBC/ODBCConnectionProto.i ) and you can then call those functions from within a method . Take a look at https://github.com/PeterJudge-PSC/abl_odbc_api/blob/master/src/OpenEdge/Data/ODBC/SqlCommonFunctions.cls for examples.

c# using advanced datagridview (ADGV) filter without BindingSource

I am using the advanced DataGridView (ADGV) found here to add filtering capabilities to my application.
The code for filtering or sorting is mentioned as:
private void advancedDataGridView1_SortStringChanged(object sender, EventArgs e)
{
this.stockHistoryBindingSource.Sort = advancedDataGridView1.SortString;
}
private void advancedDataGridView1_FilterStringChanged(object sender, EventArgs e)
{
this.stockHistoryBindingSource.Filter = advancedDataGridView1.FilterString;
}
But I can't use this because in my project I am reading an XML file and binding it to my ADGV with this code:
void QueryFoos()
{
IEnumerable<FooViewData> query =
from foo in XmlFiles.FOO.Root.Descendants("foo")
select new FooViewData
{
ID = Convert.ToInt32(foo.Attribute("id").Value),
Num = Convert.ToInt32(foo.Attribute("num").Value),
...
};
advancedDataGridView1.DataSource = query.OrderBy(n => n.ID).ThenBy(r => r.Num).ToList();
}
I tried a code like this but I am not surprised that it is throwing exception in my face:
BindingSource x = (BindingSource)this.advancedDataGridView1.DataSource;
x.Filter = advancedDataGridView1.FilterString;
this.advancedDataGridView1.DataSource = x;
Is there some work around to use the filtering and sorting of the ADGV ?
As it turns out I had this same problem today and was looking for solutions. Basically the problem is that ADGV was written to be used with a DataTable and not a list of objects.
This solution works for me however your mileage may vary.
What I ended up doing was using dynamic linq to perform the filter on the list of objects myself. The hack part was me converting the filter string that ADGV produces and converting it to a string that dynamic linq expects.
We start with some data. I have a class named DataPointGridViewModel that looks like this:
public class DataPointGridViewModel
{
public int DataPointId { get; set; }
public string Description { get; set; }
public bool InAlarm { get; set; }
public DateTime LastUpdate { get; set; }
public double ScalingMultiplier { get; set; }
public decimal Price { get; set; }
}
The data could be anything. This is the data that you will be filtering on in the grid. Obviously you will have your own data class. You need to replace this DataPointGridViewModel clas with your own model/data object.
Now, here is the code example code you need to add. I have also got a sample project on github here: I have a working version of this code on github: here
Here is the code you need to add:
List<DataPointGridViewModel> m_dataGridBindingList = null;
List<DataPointGridViewModel> m_filteredList = null;
private void dataGridView2_FilterStringChanged(object sender, Zuby.ADGV.AdvancedDataGridView.FilterEventArgs e)
{
try
{
if ( string.IsNullOrEmpty(dataGridView2.FilterString) == true )
{
m_filteredList = m_dataGridBindingList;
dataGridView2.DataSource = m_dataGridBindingList;
}
else
{
var listfilter = FilterStringconverter(dataGridView2.FilterString);
m_filteredList = m_filteredList.Where(listfilter).ToList();
dataGridView2.DataSource = m_filteredList;
}
}
catch (Exception ex)
{
Log.Error(ex, MethodBase.GetCurrentMethod().Name);
}
}
And this is the function to convert the ADGV filter string to the Dynamic Linq filter string:
private string FilterStringconverter(string filter)
{
string newColFilter = "";
// get rid of all the parenthesis
filter = filter.Replace("(", "").Replace(")", "");
// now split the string on the 'and' (each grid column)
var colFilterList = filter.Split(new string[] { "AND" }, StringSplitOptions.None);
string andOperator = "";
foreach (var colFilter in colFilterList)
{
newColFilter += andOperator;
// split string on the 'in'
var temp1 = colFilter.Trim().Split(new string[] { "IN" }, StringSplitOptions.None);
// get string between square brackets
var colName = temp1[0].Split('[', ']')[1].Trim();
// prepare beginning of linq statement
newColFilter += string.Format("({0} != null && (", colName);
string orOperator = "";
var filterValsList = temp1[1].Split(',');
foreach (var filterVal in filterValsList)
{
// remove any single quotes before testing if filter is a num or not
var cleanFilterVal = filterVal.Replace("'", "").Trim();
double tempNum = 0;
if (Double.TryParse(cleanFilterVal, out tempNum))
newColFilter += string.Format("{0} {1} = {2}", orOperator, colName, cleanFilterVal.Trim());
else
newColFilter += string.Format("{0} {1}.Contains('{2}')", orOperator, colName, cleanFilterVal.Trim());
orOperator = " OR ";
}
newColFilter += "))";
andOperator = " AND ";
}
// replace all single quotes with double quotes
return newColFilter.Replace("'", "\"");
}
...and finally the sort function looks like this:
private void dataGridView2_SortStringChanged(object sender, Zuby.ADGV.AdvancedDataGridView.SortEventArgs e)
{
try
{
if (string.IsNullOrEmpty(dataGridView2.SortString) == true)
return;
var sortStr = dataGridView2.SortString.Replace("[", "").Replace("]", "");
if (string.IsNullOrEmpty(dataGridView2.FilterString) == true)
{
// the grid is not filtered!
m_dataGridBindingList = m_dataGridBindingList.OrderBy(sortStr).ToList();
dataGridView2.DataSource = m_dataGridBindingList;
}
else
{
// the grid is filtered!
m_filteredList = m_filteredList.OrderBy(sortStr).ToList();
dataGridView2.DataSource = m_filteredList;
}
}
catch (Exception ex)
{
Log.Error(ex, MethodBase.GetCurrentMethod().Name);
}
}
Finally, you will need the Dynamic Linq library from here
You can use Nuget to bring it into your project:
Install-Package System.Linq.Dynamic
DataTable OrignalADGVdt = null;
private void advancedDataGridView1_FilterStringChanged(object sender, Zuby.ADGV.AdvancedDataGridView.FilterEventArgs e)
{
Zuby.ADGV.AdvancedDataGridView fdgv = advancedDataGridView1;
DataTable dt = null;
if (OrignalADGVdt == null)
{
OrignalADGVdt = (DataTable)fdgv.DataSource;
}
if (fdgv.FilterString.Length > 0)
{
dt = (DataTable)fdgv.DataSource;
}
else//Clear Filter
{
dt = OrignalADGVdt;
}
fdgv.DataSource = dt.Select(fdgv.FilterString).CopyToDataTable();
}
Here follow my code sample for filter advanced datagrid
string myFilter = "(Convert([myCol],System.String) IN ('myfilter'))"
dg.LoadFilterAndSort(myFilter, "");
and to clear filter
dg.CleanFilter();

Amazon MWS receiving MalformedInput on GetMyFeesEstimate

I'm trying to access Amazon MWS API from my .Net application, using Products API Section Client Library - C# (https://developer.amazonservices.com/doc/products/products/v20111001/cSharp.html/138-8219342-3408216)
Everything works fine, except for GetMyFeesEstimate calls.
I use this method from example:
public GetMyFeesEstimateResponse InvokeGetMyFeesEstimate()
{
// Create a request.
GetMyFeesEstimateRequest request = new GetMyFeesEstimateRequest();
string sellerId = "example";
request.SellerId = sellerId;
string mwsAuthToken = "example";
request.MWSAuthToken = mwsAuthToken;
FeesEstimateRequestList feesEstimateRequestList = new FeesEstimateRequestList();
request.FeesEstimateRequestList = feesEstimateRequestList;
return this.client.GetMyFeesEstimate(request);
}
And I add item to FeesEstimateRequestList like this:
feesEstimateRequestList.FeesEstimateRequest.Add(new FeesEstimateRequest
{
MarketplaceId = marketplaceId,
IdType = "ASIN",
IdValue = "B0078LENZC",
PriceToEstimateFees = new PriceToEstimateFees { ListingPrice = new MoneyType { Amount = 30.49M, CurrencyCode = "GBP" }, Shipping = new MoneyType { Amount = 3.5M, CurrencyCode = "GBP" }, Points = new Points { PointsNumber = 0 } },
Identifier = "request_" + Guid.NewGuid().ToString(),
IsAmazonFulfilled = false
});
But constantly get MalformedInput error with no message describing what is wrong:
<ErrorResponse
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Error>
<Type>Sender</Type>
<Code>MalformedInput</Code>
</Error>
<RequestId>f79b9147-90d7-4ea2-b51c-d6c37c6a1bd0</RequestId>
</ErrorResponse>
Have someone any ideas how to make it work?
I have found solution:
Due to my OS regional settings, decimal separator in price had being set to comma, instead of dot when converting parameters to string.
I have to modify method putValue of MwsAQCall class like this:
private void putValue(object value)
{
if (value==null)
{
return;
}
if (value is IMwsObject)
{
parameterPrefix.Append('.');
(value as IMwsObject).WriteFragmentTo(this);
return;
}
string name = parameterPrefix.ToString();
if (value is DateTime)
{
parameters.Add(name, MwsUtil.GetFormattedTimestamp((DateTime)value));
return;
}
string valueStr = value.ToString();
if (value is decimal)
{
valueStr = valueStr.Replace(",", ".");
}
if (valueStr==null || valueStr.Length==0)
{
return;
}
if (value is bool)
{
valueStr = valueStr.ToLower();
}
parameters.Add(name, valueStr);
}

Sony Camera API with C#

I have asked a previous question on SO with regards to the Sony Camera API and I did get some help but I am still having a problem. I found the following library https://github.com/kazyx/kz-remote-api that someone made to use with the Sony Camera API but I had to make changes to it to work with a WPF app as it was optimized for windows store apps.
I am now resorting to do everything myself but I am unsure if I need to attach a Camera API file to my solution and if I do where can I find the exact file because the one the API file that I downloaded only has files for Android and iOS in which won't help me.
I finally got my thing working and I tried to put it in such a manner so that it is easily understandable. If anyone would like my Sony Library that I wrote that please let me know as I also tried the Kazyx library and that didn't work for me.
My code is below.
private string cameraURL;
private bool recModeActive;
public void ControlCamera(string cameraResp)
{
cameraURL = string.Format("{0}/{1}", GetCameraURL(cameraResp), GetActionType(cameraResp));
}
private string CameraRequest(string cameraUrl, string cameraRequest)
{
Uri urlURI = new Uri(cameraURL);
HttpWebRequest cameraReq = (HttpWebRequest)WebRequest.Create(cameraURL);
cameraReq.Method = "POST";
cameraReq.AllowWriteStreamBuffering = false;
cameraReq.ContentType = "application/json; charset=utf-8";
cameraReq.Accept = "Accept-application/json";
cameraReq.ContentLength = cameraRequest.Length;
using (var cameraWrite = new StreamWriter(cameraReq.GetRequestStream()))
{
cameraWrite.Write(cameraRequest);
}
var cameraResp = (HttpWebResponse)cameraReq.GetResponse();
Stream cameraStream = cameraResp.GetResponseStream();
StreamReader cameraRead = new StreamReader(cameraStream);
string readCamera = cameraRead.ReadToEnd();
return readCamera;
}
public string GetCameraURL(string cameraResp)
{
string[] cameraXML = cameraResp.Split('\n');
string cameraURL = "";
foreach (string cameraString in cameraXML)
{
string getCameraURL = "";
if (cameraString.Contains("<av:X_ScalarWebAPI_ActionList_URL>"))
{
getCameraURL = cameraString.Substring(cameraString.IndexOf('>') + 1);
cameraURL = getCameraURL.Substring(0, getCameraURL.IndexOf('<'));
}
}
return cameraURL;
}
public string GetActionType(string cameraResp)
{
string[] cameraXML = cameraResp.Split('\n');
string actionType = "";
foreach (string cameraString in cameraXML)
{
string getType = "";
if (cameraString.Contains("<av:X_ScalarWebAPI_ServiceType>"))
{
getType = cameraString.Substring(cameraString.IndexOf('>') + 1);
actionType = getType.Substring(0, getType.IndexOf('<'));
if (actionType == "camera")
{
break;
}
}
}
return actionType;
}
public string StartRecMode()
{
string startRecMode = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "startRecMode",
#params = new List<string> { },
id = 1,
version = "1.0"
});
recModeActive = true;
return CameraRequest(cameraURL, startRecMode);
}
public string TriggerCamera()
{
string _triggerCamera = JsonConvert.SerializeObject(new Camera.StillCapture
{
method = "actTakePicture",
#params = new List<string> { },
id = 1,
version = "1.0"
});
return CameraRequest(cameraURL, _triggerCamera);
}
public string EchoRequest()
{
string _echoRequest = JsonConvert.SerializeObject(new Camera.TestCameraComm
{
method = "getEvent",
#params = new List<bool> { true },
id = 1,
version = "1.0"
});
return CameraRequest(cameraURL, _echoRequest);
}
public string StopRecMode()
{
string stopRecMode = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "stopRecMode",
#params = new List<string> { },
id = 1,
version = "1.0"
});
recModeActive = false;
return CameraRequest(cameraURL, stopRecMode);
}
public string SetImageQuality()
{
string qualityReq = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "setStillSize",
#params = new List<string> { "4:3", "20M"},
id = 1,
version = "1.0"
});
recModeActive = false;
return CameraRequest(cameraURL, qualityReq);
}`

Categories

Resources