Error parsing undefined value. Path '', line 0, position 0.when serializing anonymous type in windows phone 8 development - windows-phone-8

Here is my code..
var signUpData = new
{
first = "abcd",
last ="efgh",
email ="sometext",
password = "sometext",
phone = contactSession.ContactNumber,
dialing_code = "some",
country = "some"
};
JsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(signUpData);
var tcs = new TaskCompletionSource<Tuple<string, bool>>();
tcs.SetResult(new Tuple<string, bool>(request.ResponseBody,false));//request.ResponseBody is jsonbody that comes from server.
var result = await tcs.Task;
if (result.Item2 == false)
{
var errors = JsonConvert.DeserializeAnonymousType(result.Item1, new { error = "" });
return false;
}
Then i am getting above error sometimes not all the time.
What is the scenario?
Can anyone tell?`

Related

NativeScript JobScheduler JobService.class is undefined

I have weird error while i'm trying to create component in the JobScheduler
At the first line when setting a component value i get this error:
ERROR TypeError: Cannot read property 'MyJobService' of undefined
Both of the files are in the same folder, and its all worked yesterday.
I cleaned up the platforms folder just to be sure, because i dragged some pics to the drawble folders in the app_Resources and i had to build the project again and maybe something has changed. but it did not helped.
What can cause this problem ? am i missing something ?
JobScheduler.js :
function scheduleJob(context) {
var component = new android.content.ComponentName(context, com.tns.notifications.MyJobService.class);
const builder = new android.app.job.JobInfo.Builder(1, component);
builder.setPeriodic(15 * 60 * 1000);
builder.setOverrideDeadline(0);
const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
console.log("Job Scheduled: " + jobScheduler.schedule(builder.build()));
}
module.exports.scheduleJob = scheduleJob;
MyJobService.js :
android.app.job.JobService.extend("com.tns.notifications.MyJobService", {
onStartJob: function(params) {
console.log("Job execution ...");
var utils = require("utils/utils");
var context = utils.ad.getApplicationContext();
var builder = new android.app.Notification.Builder(context);
console.log("setting notification head and body")
builder.setContentTitle("notification triggered ")
.setAutoCancel(true)
.setColor(android.R.color.holo_purple)//getResources().getColor(R.color.colorAccent))
.setContentText("body)
.setVibrate([100, 200, 100])
.setSmallIcon(android.R.drawable.btn_star_big_on);
var mainIntent = new android.content.Intent(context, com.tns.NativeScriptActivity.class);
var mNotificationManager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
const channelId = "my_channel_01";
const name = "Channel name";
const description = "Channel description";
const importance = android.app.NotificationManager.IMPORTANCE_LOW;
if (android.os.Build.VERSION.SDK_INT >= 26) {
console.log("api level is good",android.os.Build.VERSION.SDK_INT)
}
const mChannel = new android.app.NotificationChannel(channelId, name,importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mNotificationManager.createNotificationChannel(mChannel);
builder.setChannelId(channelId);
mNotificationManager.notify(1, builder.build());
return false;
},
onStopJob: function() {
console.log("Stopping job ...");
}
});

I am trying to connect my R script and Node JS

But this error has been coming up lately:
C:\Users\vidyush.bakshi\Desktop\node-karteek\node_modules\r-script\index.js:48 if (child.stderr) throw child.stderr;
The source code is as follows:
R.prototype.callSync = function(_opts) {
var opts = _opts || {};
this.options.env.input = JSON.stringify([this.d, this.path, opts]);
var child = child_process.spawnSync("Rscript", this.args, this.options);
if (child.stderr) throw child.stderr;
return(JSON.parse(child.stdout));
};
Can anyone help me with this please..

JSON with variables in Javascript

I am trying to send Rest web service request with JSON. But it throws Bad request(http 400) error. The application does not require any login. I tried different formats, but nothing helped. The main problem is JSON variables are dynamic i.e values entered by user.
var jsonObject = [];
var first_name = document.getElementById("firstName").value;
var last_name = document.getElementById("lastName").value;
var u_password = document.getElementById("password").value;
var u_password_hint = document.getElementById("passwordHint").value;
var email = document.getElementById("email").value;
var u_phone = document.getElementById("phone").value;
var u_organization = document.getElementById("organization").value;
var user = new User(first_name,last_name,email,u_password,u_password_hint,u_organization);
jsonObject.push(user);
var client = new XMLHttpRequest();
client.open("POST","https://instance.service-now.com/api/now/v1/table/user_registration_request");
client.setRequestHeader('Accept','application/json');
client.setRequestHeader('Content-Type','application/json');
client.send(body);
window.location = 'activate account.do';
function User(first_name, last_name, email, u_password_hint, u_password, u_organization) {
this.first_name = first_name;
this.last_name = last_name;
this.email = email;
this.u_password = u_password;
this.u_password_hint = u_password_hint;
this.u_organization = u_organization;
}
I would recommend to test your API with the ServiceNow's REST API explorer.
Not tested your code but your user function should return an "user" object.
function User(first_name, last_name, email, u_password_hint, u_password,
u_organization) {
return {
'first_name': first_name,
'last_name': last_name,
'email': email,
'u_password': u_password,
'u_password_hint': u_password_hint,
'u_organization': u_organization,
};
}
that you can pass as JSON to
client.send(JSON.stringify(user));
there is no need to use "new" var user=new User(
After lot of trouble, I found the solution. Original JSON format works with small modifications.
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST","https://instance.service-now.com/api/now/table/ecc_queue");
var data='{"agent":"AttachmentCreator","topic":"AttachmentCreator","name":"'+fileName+'","source":"u_itinerary_attchements:"'+sysid+'","payload":"'+encodedFile+'"}';
xhr.setRequestHeader("authorization", "Basic anBhdmFuOmpwYXZhbg==");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
};
Note: be careful with single quotes and double quotes. I messed up with these and took lot of time to fix it.

validate xml against xsd reading from mysql in mirth connect

Validation of the xml file against xsd from file location is working fine, but when we validate the xml against xsd from mysql location, it is not working.
this is channel
var SQLText = "";
var ResultSet = "";
var dbConn =GetCtDexConn();
function validateHL7Msg(incomingXml)
{
var validMessage = true;
var HL7xml = new XML(SerializerFactory.getSerializer('HL7V2').toXML(incomingXml));
logger.info('HL7xml '+HL7xml);
try
{
//SQLText = "select DEXPropXML from dbo.DEXUserProperties where Property = 'ClaimTrakValidationXml'";
SQLText = "select * from TestXML";
ResultSet = dbConn.executeCachedQuery(SQLText);
while (ResultSet.next()){
var clobdata = ResultSet.getClob(1);
var cloblength = clobdata.length();
var StringXML = clobdata.getSubString(1, cloblength);
var Validations = new XML(StringXML);
logger.info('Validations: '+Validations);
}
}
finally
{
dbConn.close();
}
var schemaFactory = Packages.javax.xml.validation.SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
var schema = schemaFactory.newSchema(Validations);
for each(mshxml in HL7xml)
{
var reader = new Packages.java.io.StringReader(mshxml);
var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(reader);
// create a new validator for the schema
var validator = schema.newValidator();
try {
// validates the message
validator.validate(xmlFile);
// valid message
logger.info('valid');
} catch (err) {
// invalid message
logger.error(err.toString());
logger.info("error")
}
return validMessage;
}
}
/************Main Flow*****************/
var incomingXml = msg;
if(validateHL7Msg(incomingXml))
{
logger.info("message processed");
}
else
{
logger.info("message discarded");
}

Implementing Login Using JSON in Titanium

I hope someone will help me.
I have an API which is implemented with JSON web-services. I want to implement Login. A user is created and I need to have login the user. That is when I enter username and password it must log the user in .
I have read the tutsplus tutorial, but I am unable to authenticate the user. Can anyone help me out.
Here is the code I am using:
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title:'Login',
backgroundColor:'#fff'
});
var username = Ti.UI.createTextField({
top:'10%',
borderRadius:3,
hintText:'username',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
width:'80%',
height:'auto',
left:'10%',
right:'10%',
touchEnabled: true,
});
win1.add(username);
var pass = Ti.UI.createTextField({
top:'30%',
borderRadius:3,
hintText:'password',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
width:'80%',
height:'auto',
left:'10%',
right:'10%',
touchEnabled: true,
passwordMask: true
});
win1.add(pass);
var loginBtn = Titanium.UI.createButton({
title:'Login',
top:'50%',
width:'60%',
height:'15%',
borderRadius:1,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win1.add(loginBtn);
var url = 'http://qudova.com/api.php?function=AuthenticateUser&u=ns.nadeem.m#gmail.com&p=qudovatest';
var json;
var loginReq = Titanium.Network.createHTTPClient();
loginBtn.addEventListener('click',function(e)
{
if (username.value != '' && pass.value != '')
{
// Here I will get the Token (asdfasdf....)
loginReq.open("GET",url);
authstr = 'Basic ' +Titanium.Utils.base64encode(username.value +':' +pass.value);
loginReq.setRequestHeader('Authorization', authstr);
loginReq.send();
}
else
{
alert("Username/Password are required");
}
});
loginReq.onload = function()
{
var jsonObject = JSON.parse(this.responseText);
// Here I have made a check if the Token is returned successfully it will alert the user that he authenticated
if (jsonObject.Token == "asdfadsfasdfadsf")
{
alert("Authenticated");
}
else
{
alert("response.message");
}
};
win1.open();
Thanks in Advance. Is my concept clear ?
You get a JSON array as response. So you should access jsonObject[0].Token.
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title:'Login',
backgroundColor:'#fff'
});
var username = Ti.UI.createTextField({
top:'10%',
borderRadius:3,
hintText:'username',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
width:'80%',
height:'auto',
left:'10%',
right:'10%',
touchEnabled: true,
});
win1.add(username);
var pass = Ti.UI.createTextField({
top:'30%',
borderRadius:3,
hintText:'password',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
width:'80%',
height:'auto',
left:'10%',
right:'10%',
touchEnabled: true,
passwordMask: true
});
win1.add(pass);
var loginBtn = Titanium.UI.createButton({
title:'Login',
top:'50%',
width:'60%',
height:'15%',
borderRadius:1,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win1.add(loginBtn);
var url = 'http://qudova.com/api.php?function=AuthenticateUser&u=ns.nadeem.m#gmail.com&p=qudovatest';
var json;
var loginReq = Titanium.Network.createHTTPClient();
loginBtn.addEventListener('click',function(e)
{
if (username.value != '' && pass.value != '')
{
// Here I will get the Token (asdfasdf....)
loginReq.open("GET",url);
authstr = 'Basic ' +Titanium.Utils.base64encode(username.value +':' +pass.value);
loginReq.setRequestHeader('Authorization', authstr);
loginReq.send();
}
else
{
alert("Username/Password are required");
}
});
loginReq.onload = function()
{
var jsonObject = JSON.parse(this.responseText);
// Here I have made a check if the Token is returned successfully it will alert the user that he authenticated
if (jsonObject[0].Token === "asdfadsfasdfadsf")
{
alert("Authenticated");
}
else
{
alert("response.message");
}
};
win1.open();
Alternatively you can change your backend implementation, that the result will be an object instead of an array.
Nevertheless you should change your backend because at the moment it's possible to authenticate via plain GET parameters.