I'm working on a Kinvey project right now, and I'm having some Problems with reading the Username or special Attributes from a User instance. I first tried it the same way getting _User.ID by calling _User.UserName, but this didnt return anything(But ID did curiously). I also searched on Google, but there weren't any articles about it. Hope you can help, would be greatly appreciated!
For special attributes, use the .Attributes array on the User class.
Like this code:
Console.WriteLine ("custom attribute is: " + kinveyClient.User ().Attributes["myAttribute"]);
For username, try .UserName() but it seems you must do an explicit retrieval of the User object before this field is populated
User retrieved;
try {
retrieved = await kinveyClient.User().RetrieveAsync();
} catch (Exception e) {
Console.WriteLine("{0} caught exception: ", e);
retrieved = null;
}
Console.WriteLine ("logged in as: " + retrieved.Username );
Console.WriteLine ("custom attribute is: " + retrieved.Attributes["myAttribute"]);
Documentation: http://devcenter.kinvey.com/xamarin/guides/users#UserClass
(answer applies to SDK version 1.6.11)
Related
We have a chat application which is using Smack, XMPP, ejabberd. I'm wondering if it's possible to achieve something like below:
A chat is open between 2 users.
User1 is typing some message.
User2 is able to see the message typed by User1 as he types it.
I have done a bit of research but couldn't find anything related.
Please let me know how to achieve this use case.
Thanks in advance!
That is not possible. You can send the text as user types but each piece will go as independent message. If you want that one you might want to have your own way to do so. XMPP have no way to do so!
With Smack it is easy, whenever the user changes the text you send a typing stanza to the other person using the ChatStateExtension:
private void sendTypingStatus(final String toJid) {
//you must have a valid xmpp connection of course
if (null == mConnection)
return;
try {
Message message = new Message(JidCreate.from(toJid));
message.addExtension(new ChatStateExtension(ChatState.composing));
message.setType(Message.Type.chat);
mConnection.sendStanza(message);
} catch (InterruptedException | SmackException.NotConnectedException | XmppStringprepException ex) {
Log.w(TAG, "sendTypingStatus error", ex);
}
}
The other person should be prepared to receive the stanza and use it correctly. The best option is to use ChatStatesStanzaListener for that:
public class ChatStatesStanzaListener implements StanzaListener {
private static final String TAG = ChatStatesStanzaListener.class.getSimpleName();
#Override
public void processStanza(Stanza packet) {
Message message = (Message) packet;
if (message.hasExtension(ChatStateExtension.NAMESPACE)) {
ChatStateExtension chatStateExtension = (ChatStateExtension) message.getExtension(ChatStateExtension.NAMESPACE);
ChatState chatState = chatStateExtension.getChatState();
String fromJid = message.getFrom().asBareJid().toString();
if (message.getType().equals(Message.Type.chat)) {
Log.v(TAG, "got chat state " + fromJid + " " + message.getType() + " " + chatState);
//you got youe information here, call a callback or broadcast an event, whatever
} else if (message.getType().equals(Message.Type.groupchat)) {
//out of your question
}
}
}
}
Don't forget to add the stanza listener to your xmpp connection once it's established:
1. Set the stanza filter:
// set up a stanzalistener and filter chatstates messages only
StanzaFilter chatStatesStanzaFilter = stanza -> {
// filter for chatstates message only
return stanza.hasExtension(ChatStateExtension.NAMESPACE);
};
Use it once you initialize the xmpp connection:
mConnection.addAsyncStanzaListener(new ChatStatesStanzaListener(), chatStatesStanzaFilter);
I hope it helps :)
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.
I'm trying to pull the text from the Permission Details page from a typical Google App page using Jsoup. For example, the permission details from this url. https://play.google.com/store/apps/details?id=com.imangi.templerun
I'm not very well versed with JSoup, so I'm not sure of the elements I should be targeting to achieve the effect. I've tried the following:
Elements permission= doc.getElementsByAttributeValueContaining("class", "permission-bucket");
for(Element p :permission)
{
try{
p.select("span[class=bucket-title]").text();
}
catch (Exception e)
{
tv.setText("Error in reading & storing permissions: " + e.getMessage());
}
But it is throwing null. Any help?
I have a table with many, many fields. When trying to insert data with jt400 (flei00.write(newrec);) I get error CPF5035 Data mapping error on member FLEI00.. Even when trying to insert empty or nearly empty record, the error message is the same. Is there a way to get know, which field is causing the problem? I've been fighting with it a whole day and have no more idea what to check :-(. Any help (e.g. where to look for more info) will be appreciated.
On IBM i, the job log is THE place to find details about errors occurring in a given job. In the case of JT400 jobs, the JT400 app connects via sockets to a server job. Typically, there are a bunch of these jobs 'prestarted', waiting for a connection. This can be difficult to navigate if you're not accustomed to the 5250 interface.
Here's a JT400 program that gets the job log messages for you. If you run this in the same session that you are getting the error in you should see the details about what field is causing the issue.
import java.util.*;
import com.ibm.as400.access.*;
public class TestJobLog {
public static void main(String[] args) {
int i = 0;
try {
AS400 system = new AS400();
JobLog jobLog = new JobLog(system);
// what attributes?
jobLog.clearAttributesToRetrieve();
jobLog.addAttributeToRetrieve(JobLog.MESSAGE_WITH_REPLACEMENT_DATA);
jobLog.addAttributeToRetrieve(JobLog.MESSAGE_HELP_WITH_REPLACEMENT_DATA);
// load the messages
jobLog.load();
// Create a list and subset it
Enumeration list = jobLog.getMessages();
System.out.println("There are " + Integer.toString(jobLog.getLength()) + " messages.");
while (list.hasMoreElements()) {
i++;
QueuedMessage message = (QueuedMessage) list.nextElement();
String text = message.getID() +
" " + message.getType() +
" " + message.getText() + "\n" +
" " + message.getMessageHelpReplacement() + "\n";
System.out.println(Integer.toString(i) + " " + text);
}
jobLog.close();
System.exit(0);
} catch (Exception e) {
System.out.println(e);
}
}
}
I am working withing Google Spreadsheet creating a script file that has to deal with obtaining user information on my Google Apps Domain. I have admin rights and the Provisioning API is enabled. In my code, I am trying to catch the error when looking up a specific user on a Google Apps Domain (user not found) and instead display a message and continuing on with the rest of the program. The try-catch statement I have here works when there is no error on the user. However, when there is an error on retrieving the user, I get the error: "Unexpected exception upon serializing continuation". Here is my code:
function testOfDomainAccess() {
var i=0;
var anArray= ["johhn.smith", "susan.que]; //john smith misspelled
var user;
for (i=0; i < anArray.length; ++i)
{
Logger.log("\nThe current user being processed is " + anArray[i]);
try
{
user = UserManager.getUser (anArray [i]);
}
catch (error)
{
Browser.msgBox("Error: " + error.name + "\n Check your spreadsheet for misspellings of " + anArray[i] + " and We will continue to the next user.");
user = null;
}
if (user != null) {
//Perform tasks
}
else
Logger.log("User not found in domain. Moving on the next item in the array.");
}
If anyone can help with this problem I would greatly appreciate it. I am new to Google Apps Script and Provisioning API. Thanks!
It looks like the same bug reported at http://code.google.com/p/google-apps-script-issues/issues/detail?id=980.
The workaround is to replace the Browser.msgBox() call with Logger.log() and your script should run as expected.