I'm trying to query a view using TouchDB in C#. I used the binding between TouchDB and MonoTouch available here : https://github.com/mono/monotouch-bindings/tree/master/Couchbase
When the emit delegate method is called, I get a "System.Runtime.InteropServices.MarshalDirectiveException" saying "The type MonoTouch.Foundation.NSObject which is passed to unmanaged code must have a StructLayout attribute."
I found this bug report here : https://bugzilla.xamarin.com/show_bug.cgi?id=4781 that is similar to my problem but there isn't any updates since July 27, 2012.
Here's my test code :
CouchTouchDBServer server = new CouchTouchDBServer ();
CouchDatabase database = server.GetDatabase ("grocery-sync");
database.TracksChanges = true;
// Create a test view
design = database.DesignDocumentWithName ("grocery");
design.DefineView ("testView", (doc,emit) => {
emit (doc, doc); // Crashes here
}, "1.0");
// Query the view
CouchQuery query = design.CereateQuery("testView");
RestOperation op = query.Start();
string response = op.ResponseBody.AsString;
Console.WriteLine(response);
Has anyone successfully queried a view on TouchDB with MonoTouch? Thanks for your help
It seems to be a bug of Xamarin
Related
My mvc application is updating the status on a custom entity in CRM dynamics 2015. we have a plugin which gets triggered when we update a specific status. We are facing a concurrency issue here, when two different is trying to update the same status at a same time on the entity, the status gets updated twice and system fires the plugin twice.
I tried using in my MVC code but it gives an error. Seems like i cannot use it on custom entity
Portal.abcclaim obj= new Portal.abcclaim ();
obj.Attributes["abcclaimreceiveddate"] = Convert.ToDateTime(DateTime.Now);
obj.Attributes["abcdateclaimsubmitted"] = Convert.ToDateTime(DateTime.Now);
obj.Attributes["abcmodifiedbycontact"] = new EntityReference(Portal.Contact.EntityLogicalName, loggedInId);
obj.Attributes["abcstatus"] = new EntityReference(Portal.abc_status.EntityLogicalName, status);
obj.Attributes["SuppressDuplicateDetection"] = false;
obj.Id = objid;
serviceProxy.Update(obj);
is there any other way to handle this?
You should use dedicated request if you want to set request parameters. In yours case it will be UpdateRequest (https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.updaterequest?view=dynamics-general-ce-9).
var updateRequest = new UpdateRequest()
{
Target = obj,
};
updateRequest["SuppressDuplicateDetection"] = false;
var response = (UpdateResponse)osvc.Execute(updateRequest);
But it doesn't look like duplicate detection will solve concurrency problems. You should check check how to use ConcurrencyBehavior parameter. You can read more about concurrency in Dynamics 365 in this MS docs article: https://learn.microsoft.com/en-us/powerapps/developer/common-data-service/optimistic-concurrency
Hope that helps.
We were using cefsharp version 57.0 in our application and it was working all fine. But now due to some limitations we need to update cefsharp version to 75.1.143 and suddenly our working code broke. One change was to change LegacyJavascriptBindingEnabled to true and secondly this line is breaking:
browser.RegisterJsObject("objectForCallingServerSideMethods", this);
giving error System.ArgumentException: Registering of .Net framework built in types is not supported, create your own Object and proxy the calls if you need to access a window/Form/Control. Parameter name: value.
It was all working fine. I don't know how to deal with this. Sample code is here which was working before update.
Cef.Initialize(new CefSettings() { IgnoreCertificateErrors = true, PersistSessionCookies = true, CachePath = LocalFolderPath + "/cache" });
CefSharpSettings.ShutdownOnExit = true;
CefSharpSettings.LegacyJavascriptBindingEnabled = true; // added now for version 75.1.143
browser = new ChromiumWebBrowser("url goes here");
browser.DownloadHandler = new DownloadHandler();
browser.Width = 0;
browser.Height = 0;
browser.MenuHandler = new CustomContextHandler();
this.Controls.Add(browser);
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.RegisterJsObject("objectForCallingServerSideMethods", this); // this line is throwing exception now. screenshot is attached.
I have sort out its solution. I was passing winform object as 'this' and in version 75.1.143 they have changed the implementation now we cannot use Window/Form/Control. I have created another class named as "BoundObject" and passed its object and it worked as expected.
public class BoundObject
{
// some implementation
// all methods from JS will be catched in this class. Before this (in version 57) we were receiving these methods from JS on windows form.
}
browser.RegisterJsObject("objectForCallingServerSideMethods", new BoundObject());
So I'm building an app with twilio voice, and I've got all the phonecall stuff working. But I'm having a little trouble understanding which parameters my callback should have.
I've registered the URL as described in the docs:
options.From = formatPhoneNumber(callout.callback_number);
options.To = formatPhoneNumber(offer.employee_phone_number);
options.Url = TwilioCallBotController.TwilioCalloutScriptURL;
options.StatusCallback = TwilioCallBotController.StatusCallbackURL;
options.StatusCallbackEvents = new []{"initiated", "ringing", "answered", "completed" };
options.StatusCallbackMethod = "POST";
I've also made a callback method here, but I'm not having much luck finding out how the parameters are supposed to work with their API. I'm kindof at a loss as to what could be the reason behind this one not working:
[HttpPost]
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
twiml.Say("This is a test");
string CallSid = Request.Form["CallSid"];
string CallStatus = Request.Form["CallStatus"];
Debug.WriteLine("Status Callback Delivered");
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == CallSid).ToList()[0];
shoffer.status = CallStatus.ToString();// + DateTime.Now.ToString();
return TwiML(twiml);
}
Edit:
So it turns out that the API is very sensitive about the method signature (the call was previously throwing a method not found exception in a number of microsoft DLLs, including System.Web and System.Web.Mvc.
So I've actually gotten the software to call the method by using an empty method signature (no parameters).
However I'm still having trouble getting the parameters from the HTTPPOST
Edit: So upon further investigation I've managed to inspect the Request. The values I'm after exist in Request.Form["foo"], but they don't seem to be getting put into the two strings I have declared. I've removed the ["HttpPost"] attribute to try to troubleshoot the issue, but I'm really at a loss as to why I can see the values in the debugger, but they're not translating into memory.
public ActionResult TwilioStatusCallback()
{
var twiml = new Twilio.TwiML.TwilioResponse();
string sid = Request.Form["CallSid"];
string status = Request.Form["CallStatus"];
Shift_Offer shoffer = db.Shift_Offers.Where(s => s.twillio_sid == sid).ToList()[0];
shoffer.status = status;// + DateTime.Now.ToString();
return TwiML(twiml);
}
Last issue was that the database wasn't being saved.
Just added a db.SaveChanges() and we're good.
I am trying to programatically insert a discussion post into a Sharepoint discussion board list using the client object model in C#. I am using the following code:
var discussionList = sharepointContext.Web.Lists.GetByTitle("Discussion");
var discussionItem = Utility.CreateNewDiscussion(sharepointContext, discussionList, "Test");
discussionItem["Body" ] = "Hello world!"
discussionItem["Author" ] = 22;
discussionItem["Editor" ] = 22;
sharepointContext.Load(discussionItem);
discussionItem.Update();
sharepointContext.ExecuteQuery();
However, whenever I run it, I get this exception
Microsoft.SharePoint.Client.ServerException was unhandled
Message=Field or property "Body" does not exist.
Source=Microsoft.SharePoint.Client.Runtime
ServerErrorCode=-1"
Does anyone know what I'm doing wrong?
The reason the code in the question didn't work is because you called Update() after calling SPContext.Load(). If you call Update() first, you'll be fine.
This is proof of concept project - The goal is to create an application that receive some system wide events and based on some business rules invokes a specific workflow.
The workflows are created separately and the xaml source is stored in a database.
Following is the code that used to invoke the workflow:
public void RaiseEvent(IEvent e, IEventData eventData)
{
var typeName = e.GetType().FullName;
// Query Db for all workflows for the event
var repo = new WorkflowRepository();
var workflows = repo.GetActiveWorkflowsByEvent(typeName);
foreach (var wf in workflows)
{
var condition =
ConditionEvaluator.PrepareCondition(wf.Condition.Expression, eventData);
var okToStart = ConditionEvaluator.Evaluate(condition);
if (okToStart)
{
// Next line is throwing an exeption
object o = XamlServices.Parse(wf.WorkflowDefinition.Expression);
DynamicActivity da = o as DynamicActivity;
WorkflowInvoker.Invoke(da,
new Dictionary<string, object>
{{ "EventData", eventData }});
}
}
We have created very simple workflow that runs without problems on its own. But when xaml is being loaded using XamlService.Parse it throw following exception:
System.Xaml.XamlObjectWriterException was unhandled
Message='No matching constructor found on type 'System.Activities.Activity'.
You can use the Arguments or FactoryMethod directives to construct this type.'
Line number '1' and line position '30'.
Any idea what is wrong?
Thank you.
Not sure what is causing your problem, I have used XamlServices.Load() in the past without any problems, but the easiest way of loading a workflow XAML at runtime is by using the ActivityXamlServices.Load(). See here for an example.
Ok I have solved this by using ActivityXamlServices
So Instead of this line:
object o = XamlServices.Parse(wf.WorkflowDefinition.Expression);
I am using following snippet:
var mStream = new memoryStream(
ASCIIEncoding.Default.GetBytes(wf.WorkflowDefinition.Expression));
object o = ActivityXamlServices.Load(mStream);