Can't update Parse Object - parse-platform

I've created an object previously that I'm now trying to update in an "edit" screen
The id of the object is correct (as it correctly queries earlier in the activity to update the text labels. This should save when a button is clicked.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Product");
Intent i = getIntent();
String queryString = i.getStringExtra("id");
query.getInBackground(queryString, new GetCallback<ParseObject>() {
public void done(ParseObject editProduct, ParseException e) {
if (e == null) {
editProduct.put("productName", ProductName.getText().toString());
editProduct.put("ISDN", ISDN_text.getText().toString());
editProduct.put("expiry", expiry_date.getText().toString());
editProduct.put("type", spinnercategory.getSelectedItem().toString());
editProduct.put("quantity", quantity.getText().toString());
editProduct.put("username", "Admin");
editProduct.put("shoppingList", true);
editProduct.put("mainList", false);
editProduct.saveInBackground();
}
}
});
This is lifted from the Parse Android developers guide, but doesn't appear to be working. Any suggestions

Figured it out. Sort of.
editProduct.put("expiry", expiry_date.getText().toString()); is the line that's breaking it. I'm trying to pass a string to what is defined as a date at the backend, which apparently cancels the whole save operation.
Commented this out in my solution for now until I can fix the issue with the date

Related

MS Dynamics CE CRM 365 - Pre Operation Plugin - Given key was not present in the dictionary

After few years doing some other stuff I'm back to CRM business. I'm already questioning my life choices. I don't understand what is wrong here. I'm trying to create a simple plugin that will run on Incident / Case creation. It will look if description field contains a valid url and if yes then it should update first url that has been found to another field. Here's the plugin execution method.
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (pluginExecutionContext.InputParameters.Contains("Target") && pluginExecutionContext.InputParameters["Target"] is Entity)
{
Entity targetEntity = (Entity)pluginExecutionContext.InputParameters["Target"];
if (targetEntity.LogicalName != Incident.EntityLogicalName)
{
return;
}
IOrganizationServiceFactory orgServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService orgService = orgServiceFactory.CreateOrganizationService(pluginExecutionContext.UserId);
try
{
string desc = (string)targetEntity.Attributes["description"];
string pattern = #"\b(?:https?://|www\.)[^ \f\n\r\t\v\]]+\b";
MatchCollection collection = Regex.Matches(desc, pattern);
if (collection.Count > 0)
{
throw new Exception(collection[0].Value);
}
}
catch (Exception ex)
{
tracingService.Trace("Error in CaseUrlPlugin {0}", ex.ToString());
throw ex;
}
}
}
The problem is that when I'm creating a new case (description field filled with text and url) and hit save I get "Given key was not present in the dictionary" exception as if description field is not there. When I hit ok to that error window and hit save again then description field is founded and my code throws an exception with that link.
So why is not the description field present in the first time? I don't like the idea doing this post operation because that would require another sql transaction right (to save incident again)?
Aah ffs. The problem was that when I was trying to save for the first time I used CTRL + S while my focus was still on description field because that's the last field I was filling. Now it seems that UI doesn't register that field to be filled if focus on that field and hitting CTRL + S. Hitting save icon works because that would get focus off the description field. And of course in my case hitting ok for that error window also unfocus the field thus second save works.............
Well, at least I figured it out right after posting question here. Been trying to solve this way too long.

How to Grab an image file from Parse

So i've tried looking over the documentation and cant make heads or tails of it... so i'm hoping someone here can help:
so i've created a ParseFile with an image stored in a byte[]. I've saved this parsefile and then assigned it into a parseObject. I have then saved the parseObject
profilePicFile = new ParseFile( "profilePic.png", bytes);
Task saveProfilePic = profilePicFile.SaveAsync();
yield return saveProfilePic;
user["Profile_Pic"] = profilePicFile;
Task updateUser = user.SaveAsync();
Then i've made a temporary button just to check that this works. I've assigned it a new script. Basically when I hit the button, I just want it to grab the user, and its profile_pic and tell me if there is something there.
ParseObject receivedUser = new ParseObject("ReceivedUser");
ParseQuery<ParseObject> query = ParseObject.GetQuery("User");
query.GetAsync("DwRfTQ66tA").ContinueWith(t =>
{
receivedUser = t.Result;
});
if (receivedUser.IsDataAvailable == true) {
print ("getting data");
byte[] data = receivedUser.Get<byte[]> ("Profile_Pic");
} else {
print ("no user");
}
}
Am I doing this right? Do i need to re-initialise anything? Do I need to add the other script component to this or use Getcomponent to get the user data? (I dont think so since the ParseUser object is supposed to be a static right?). Or does this script need to re-log in to grab data from Parse?
currently the error i'm getting is KeyNotFoundException.
I deff have a User Class on parse and a Profile_Pic column. I'm using the object ID as the reference. Is this correct?
Instead of
ParseObject.GetQuery("User")
you should be using:
ParseUser.Query

windows phone c# check for valid url and replace foreach item in list

I am getting a list of objects in Windows Phone, and show them in a listbox with databinding.
some image urls are not valid, so after every object is added in the list, i run the following code to check and replace, if not valid
private void CheckLinkUrl(Person p)
{
Uri filePath = new Uri(p.img_url);
string correct = p.img_url;
HttpWebRequest fileRequest = HttpWebRequest.CreateHttp(filePath);
fileRequest.Method = "HEAD";
fileRequest.BeginGetResponse(result =>
{
HttpWebRequest resultInfo = (HttpWebRequest)result.AsyncState;
HttpWebResponse response;
try
{
response = (HttpWebResponse)resultInfo.EndGetResponse(result);
}
catch (Exception e)
{
p.img_url = "http://somethingelse.com/image.jpg";
}
}, fileRequest);
}
the problem is that it is very slow, it takes sometimes 2 minutes+ to load every image (although the UI remains responsive, and everything else is displayed immediately in the listbox, apart from the images)
am I doing something wrong? can i get it to run faster?
EDIT:
I tried using the imagefailed event and replace the link, no improvement at the speed of loading the pics
What I have done to avoid this problem in my application is, I have loaded the items with a default Image, The image source is binded to a property in my result item of type ImageSource. By default it returns the default image. After processing or download completion the imagesource value changes to the new Image triggering the NotifyPropertyChanged event and hence it is automatically reflected on the UI. I hope it helps you.

SelectedItem must always be set to a valid value. Windows Phone Local Database

I am using the local database example taht Microsoft created.
I can add items to the list, and delete them. But I now want to select the items and get the text of the item and use that in the next page.
This is the select changed event:
private void allToDoItemsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/LiveTimes.xaml?selectedItem=" + allToDoItemsListBox.SelectedIndex, UriKind.Relative));
// string urlWIthData = string.Format("/LiveTimes.xaml?name={0}", " ");
// this.NavigationService.Navigate(new Uri(urlWIthData, UriKind.Relative));
}
Then this is the on page load on the other page.
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
int index = int.Parse(selectedIndex);
DataContext = App.ViewModel.HomeToDoItems[index];
}
Then when i use this, the error is on the DataContext line.
Whats the solution?
There is no problem in the above code that you have shown, The actual problem may be in the way how you defined your ViewModel and HomeToDoItems . It helps us to solve your problem, if you can show some of that code.
Also before setting your data to DataContext, try the following steps:
First, make sure you are getting the valid selectedIndex.
var tempData = App.ViewModel.HomeToDoItems[index];
DataContext = tempData;
And then insert a break point at tempData to check whether you are getting the expected data.
This answer may not solve your problem, but guide you in identifying the actual problem.

Clicking Open Word Document tries to reconnect to Controller action while downloading

I have a requirement to download a file from the server, but open inline if possible. I'm currently doing;
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", documentFileName));
result = new FileStreamResult(new FileStream(documentFilePath, FileMode.Open), "application/msword");
I've put application/msword in there right now, because that's what I'm having a problem with. When I click Open on the word document, it's as if the document makes multiple calls back to the action, but there is no session and no database so it crashes. When the user is running this, they see a long hang, the "Downloading" dialog finally appears in word and they have to cancel it. The document is there and is valid but this is not desirable.
Pdfs, pngs etc. download fine. Can anybody explain this behavior, and give me some hints as to how I fix it?
Update:
The action basically looks like;
[HttpPost]
public FileResult View(int id, int source)
{
var document = GetDocumentFromDatabase(id, source);
documentFilePath = Path.Combine( documentsDirectory, document.Name);
documentName = document.Name;
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", documentFileName));
result = new FileStreamResult(new FileStream(documentFilePath, FileMode.Open), "application/msword");
return result;
}
I've trimmed it down, as I can't share the specifics, but the full idea is there.
Answer:
I have a lookup of available content-types, in there I have defined whether the file is inline or attachment, and when I detect a word document, I set it to attachment. No more error. PDF opens in the browser still because I set it to inline.
I use:
public ActionResult GetAttachment(int id)
{
var attachment = _repository.GetAttachByID(id);
if (attachment != null)
{
Response.AppendHeader("Content-Disposition",string.Format("inline; filename={0}",attachment.FileName));
return File(attachment.File, attachment.MimeType, attachment.FileName);
}
else
{
return null;
}
}
Regards

Resources