Objective:
When a table is updated with a new row (ParseFile + ParseUser + ParseUser), send one of the ParseUsers a push notification
When a new user is created, add a new row to a table (ParseFile + user)
Can either of these be easily achieved without jumping through some major hoops? I'm completely unfamiliar with Cloud Code, though I tried to read through some of the documentation. Cloud Code looks like it has the potential to perform this task, but I haven't seen any examples of doing something like I would like to do.
Does anyone have concrete examples of using Parse Cloud Code in conjunction with the .NET SDK and table updates?
Parse has a nice Documentation: Parse CloudCode
This is an example Code, which sends a push every time a user is created
//instead of Parse.User you can use any custom parse class too, but write them inside quotes
Parse.Cloud.afterSave(Parse.User, function(request) {
if(!request.object.existed()){//existed() returns false if the object was just created
var query = new Parse.Query(Parse.Installation);
query.equalTo("User", request.object);
Parse.Push.send({
where: query,
data: {
badge: "Increment",
alert: "Welcome " + request.object.get("username"),
sound: "beep.caf"
}
}, {
success: function(){
//succeed
},
error: function(err){
console.error("Got an error " + error.code + " : " + error.message);
}
});
}
});
There are also other hooks available:
beforeSave
afterSave
beforeDelete
afterDelete
Inside these hooks you can send push notifications, create new objects, manipulate objects, do nearly whatever you want.
In Parse CloudCode you can take advantage of the Parse JavaScript API.
Related
I have a Kendo DataSource that takes its data from a remote server (Json) and it bind the data to a kendo template in the client-side.
On the client, right now I just display the Data. However, I want to add/remove data in the dataSource as well. How can I send the dataSource after modification back to server and store it in there ?
Here is a good example of what I am trying to do. While this example reads its data from a local variable, would you please let me know:
How can I store the dataSource on the server-side after user make modification on the client ?
http://jsfiddle.net/derickbailey/D4g8S/
For example the add method just update the datasource on the client side. However, I want to send it to the Server and store it some how there. As a results, if someone else open the same web page in another client, he/she can see the changes as well.
$("#add").click(function(e){
e.preventDefault();
var $todo = $("input[name='description']");
currentId += 1;
dataSource.add({
id: currentId,
done: false,
description: $todo.val()
});
$todo.val("");
$todo.focus();
});
I am using C# .Net MVC on the server side.
As I understand you are asking how you can made server changes based on changes on client side? If is that true you can do three things:
catch data which you modify (added, deleted, updated),
Serialize to JSON,
send to the controller's action.
Here is simple example how you can read data from your datasource:
var dataSource = new kendo.data.DataSource({
data: [
{ id: 1, name: "Jane Doe", age: 30 },
{ id: 2, name: "John Doe", age: 33 }
]
});
dataSource.fetch(function(){
// reading data from dataSource
var raw = dataSource.data();
// entire dataSource
alert("This is entire dataSource: " + JSON.stringify(raw));
// this is what will be removed
alert("This is removed: " + JSON.stringify(raw[0]));
dataSource.remove(raw[0]);
// this is what is rest
alert("This is rest: " + JSON.stringify(raw));
});
After you assign these data to some object you can serialize into JSON with: JSON.stringify(data) method.
Than you can post these data to controller's action and do some work. How to post JSON to MVC controller is common question, please read here.
For deleting and updating is similar. Basically you have to catch data which you want, serialize and post to action.
You can use the add method on the data source and specify there where to post the new data. There is an example in the KendoUI documentation. From there you can also configure the edit/remove methods.
To get JSON array from dataSource object use toJSON method
dataSource.data().toJSON()
then you can post it back to the server
Demo
So I've been banging my head against a wall trying to figure this one out. A StackOverflow is crashing my server whenever I try to retrieve data from SQL Server using several different methods but I am unable to pinpoint the exact cause of the issue.
I've been able to put together a structure with Express that retrieves data from my database when the server stands up, but when I attach a route to the same method, I get "the" StackOverflow (I'm unsure if there is a single cause for the crash or if I'm dealing with two separate issues that both manifest as Stack Overflows)
I'll focus this question on one of the stack overflows in the hope that it is responsible for all of the crashes.
At any rate, this is the server config that was able to marshal data back to node from the .NET class library(which in turn makes the ADO.NET calls into my MSSQL db):
var express = require('express');
var http = require('http');
var edge = require('edge');
var app = express();
app.set('port',process.env.PORT || 3000);
app.use(app.router);
var repository = {
list: edge.func({assemblyFile:'bin\\Data.dll',typeName:'Data.GetListTask',methodName:'Invoke'})
});
app.get('/tickets', repository.list);
http.createServer(app).listen(app.get('port'),function(request,response){
console.log('Express server listening on port ' + app.get('port'));
console.log('[Before][repository.list]');
repository.list({}, function(error, result) {
console.log('[Result][repository.list]');
if(result){
result.forEach(function(item){
console.log('[List contains]{' + item.Id + '|' + item.Description + '}');
});
}
else{
console.log('No items found');
}
});
});
Whenever the server starts, the repository's list is retrieved and spooled to the console; however, if I use my /tickets route, the server crashes with a Stack Overflow.
The "good" response:
The crash when I try to activate my route (the real route is named 'tickets')
I'm not very experienced with node or express, so I'm not entirely sure I've specified that '/tickets' route properly.
This was a stupid problem with my Express route.
app.get('/tickets', function (request, response) {
ticketRepository.getTickets({}, function (error, result){
response.json(result);
});
});
returns the results from my database as expected.
protip: If you're trying to respond with "stuff", it helps to actually put "stuff" on the response.
In ASP.NET (web forms), I am retrieving a set of key/value pairs from an SQL database to be used in a DropDownList. This list is quite large (can be over 2000 entries) and used multiple times over many of the pages on the website and I've been looking into ways to cache this set of data on the local client to reduce bandwidth. The list doesn't change often so having a cached copy a week or more should be fine.
I wanted to know if it was at all possible and/or practical to have this list stored using HTML5 local storage and have a DropDownList fill from the client storage. If no data if found locally, then going on to query the database for the list.
If you have over 2000 entries in a select box it dosnt sound all that usable anyway.
Have a look at something like Select2. Particularly the "Loading Remote Data" example.
http://ivaynberg.github.io/select2/
I have been involved in writing a couple of apps where data is pushed back and forth regularly and we built an API object in Javascript to handle data being pulled from the server on request.
The API module requested data and took an action depending on its success status. You could build a simple API module to use if you feel that you may need to expand the type of data returning later, or just build a single AJAX call to pull the data for the drop down list.
An example of the API interface would be as such:
/**
* Parameter 1, string - Command Name for the server to interpret
* Parameter 2, object - Data that should be passed to the server (if necessary)
* Parameter 3, string - the HTTP method to use: 'GET', 'POST', 'PUT' etc.
* Parameter 4, function - the callback to fire once the response is received.
**/
api('CommandName', { key: 'value' }, 'METHOD', function(response) {
if(response.success) {
//Store data in localStorage here
}
});
As you stated above, you are using the data multiple times throughout the pages on your website. Therefore in the JavaScript you would write a check on load which determines if the data has been stored within the localStorage, and if not makes a call to the API to populate it. This would ensure that the client always has that data available. This can be done like so:
//On Load
if(!localStorage.dropdown) {
api('CommandName', { key: 'value' }, 'METHOD', function(response) {
if(response.success) {
localStorage.dropdown = response.data;
}
});
}
I have a jQuery Countdown Timer that I am using, and I need to be able to access my Database and perform some calculations and then return the result:
$('#expireMessage').countdown({until: shortly,
expiryText: '<div class="over">It\'s all over</div>'});
$('#expireMessageStart').click(function() {
shortly = new Date();
shortly.setSeconds(shortly.getSeconds() + 5.5);
$('#expireMessage').countdown('change', {until: shortly});
});
Now, the above code just displays a countdown timer, and counts down. And when it hits
00:00:00
it displays a message "It's all over".
But what I need it to do is display a different message depending on the result of the DB calculations.
The DB work I can do, but I'm not sure how to go about retrieving that info from the database when using jQuery. I'd really appreciate your help.
Thank you
You need to set up something on the server side to talk to the database for you, then return the result in JSON format. What that something is depends on what your server-side code is written in. Are you using PHP? Java? ASP.NET?
I work primarily in ASP.NET, so one way I might tackle this is adding a WebMethod to my page that executes a database query, builds the message, serializes it to JSON, and returns it to the client.
In your JavaScript, you'll want to execute either an XMLHttpRequest (if you're using regular JavaScript) or a jQuery AJAX request.
Here's a very simple example of what a jQuery AJAX call might look like:
$.ajax({
url: 'http://mysite.com/getmymessage',
success: function( data ) {
// Here's where you'd update your countdown display, but I'm just writing to the console
console.log( 'The server says: ' + data.myDbResult );
}
});
I'm trying to put together a small app that will allow me to create events in Facebook. I've already got my Facebook app set up and have successfully tested a post to my feed through the application using the code below.
wc.UploadString("https://graph.facebook.com/me/feed", "access_token=" + AccessToken + "&message=" + Message);
When I try to take things to the next step, I've just hit a brick wall.
The code that I've written is here:
JavaScriptSerializer ser = new JavaScriptSerializer();
wc.UploadString("https://graph.facebook.com/me/events?" + "access_token=" + AccessToken, ser.Serialize(rawevent));
rawevent is a small object I wrote that puts together the elements of an event so I can pass it around my application.
I'm using a similar method using ser.Deserialize to parse the user data coming back from Facebook, so I believe this should work the other way too.
Setting the above code aside for a moment, I also have tried simply putting plain text in there in various formats and with differing levels of parameters, and nothing seems to work.
Is there something wrong with the way I'm approaching this? I've read over everything I could get my hands on, and very few of the samples out there that I could find deal with creating events, and when they do, they're not in C#.
I would appreciate any help on this. If you even just have a clean copy of JSON code that I can look at and see where mine should be tweaked I would appreciate it.
I have included a copy of what the ser.Serialize(rawevent) call produces below:
{"name":"Dev party!","start_time":"1308360696.86778","end_time":"1310952696.86778","location":"my house!"}
EDIT:
thanks to bronsoja below, I used the code below to successfully post an event to Facebook!
System.Collections.Specialized.NameValueCollection nvctest = new System.Collections.Specialized.NameValueCollection();
nvctest.Add("name", "test");
nvctest.Add("start_time", "1272718027");
nvctest.Add("end_time", "1272718027");
nvctest.Add("location", "myhouse");
wc.UploadValues("https://graph.facebook.com/me/events?" + "access_token=" + AccessToken, nvctest);
All the posting examples in the graph api examples in FB docs show using curl -F, which indicates values be POSTed as normal form data. Just key value pair like you did in your first example.
The error is likely due to sending JSON. If you are using WebClient you may be able to simply create a NameValueCollection with your data and use WebClient.UploadValues to send the request.
I've recently found that Facebook returns (#100) Invalid parameter when we are trying to post data when there is already a record on file with the same name. So for example, if you are creating a FriendList via the API, and the name is "foo", submitting another identical request for the same name will immediately return that error.
In testing events you probably deleted the "Dev party!" event after each test, or maybe changing the time since you don't want two events to collide. But I'm wondering if you duplicated your wc.UploadValues(...) statement just as a test if you would see that error again. You're either deleting your 'test' event or maybe changing names and didn't notice that two events with the same name might return the error.
What's really bad here is that the error comes back as a OAuthException, which seems very wrong. This isn't a matter of authentication or authorization, it's purely a data issue.
Facebook Engineers, if I'm right about how this works, it's a bug to return this error under these conditions, and this forum has many examples of related confusion. Please return more appropriate errors.