xmlXPathFreeContext api is crashing a few times - libxml2

I have a piece of code that executes fine sometimes and few times it is crashing. crash occurs at XML api xmlXPathFreeContext.
Not an expert in XML, so no idea how to debug this.
xmlXPathObjectPtr SIQXmlParser::getnodeset (xmlDocPtr doc, xmlChar *xpath)
{
xmlXPathContextPtr context;
xmlXPathObjectPtr result;
context = xmlXPathNewContext(doc);
if (context == NULL) {
printf("Error in xmlXPathNewContext\n");
return NULL;
}
result = xmlXPathEvalExpression(xpath, context);
xmlXPathFreeContext(context);
if (result == NULL) {
printf("Error in xmlXPathEvalExpression\n");
return NULL;
}
if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
xmlXPathFreeObject(result);
printf("No result\n");
return NULL;
}
return result;
}

Related

Bluetooth Disconnection Takes Too Long

I can connect to my bluetooth device and when I want to disconnect it takes about 30 seconds to disconnect and for a few seconds it disconnects and automatically reconnects to the device in the background I don't want this to happen, how can I disconnect it literally?
I dispose service and device and pull to null but that doesn't work
This is Disconnect method :
public bool DisConnect()
{
try
{
IsScannerActiwe = false;
ButtonPressed = false;
IsConnected = false;
if (currentSelectedGattCharacteristic != null && currentSelectedService != null)
{
currentSelectedGattCharacteristic.Service?.Dispose();
currentSelectedService?.Dispose();
currentSelectedGattCharacteristic = null;
currentSelectedService = null;
if (bluetoothLeDevice != null)
{
bluetoothLeDevice.Dispose();
bluetoothLeDevice = null;
return true;
}
}
}
catch (System.Exception ex)
{
Trace.WriteLine("Exception Handled -> DisConnect: " + ex);
}
return false;
}
I dispose the device and the service and pull it to null and the function returns true but it does not break the connection and it is null for a few seconds and the service continues to run in the background automatically
I also tried another function for disconnection
public async Task<bool> ClearBluetoothLEDevice()
{
if (IsConnected)
{
IsScannerActiwe = false;
ButtonPressed = false;
IsConnected = false;
// Need to clear the CCCD from the remote device so we stop receiving notifications
var result = await currentSelectedGattCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
if (result != GattCommunicationStatus.Success)
{
return false;
}
else
{
if (currentSelectedGattCharacteristic != null)
{
currentSelectedGattCharacteristic.ValueChanged -= CurrentSelectedGattCharacteristic_ValueChanged;
IsConnected = false;
currentSelectedService.Dispose();
currentSelectedGattCharacteristic.Service.Dispose();
currentSelectedService?.Dispose(); //added code
currentSelectedService = null; //added code
bluetoothLeDevice?.Dispose();
bluetoothLeDevice = null;
currentSelectedGattCharacteristic = null;
return true;
}
}
}
return false;
}
I literally cannot disconnect from the device

edit api method error edit api code dose not working?

Error in putempdetail edit api not working
[HttpPut]
[Route("PutEmpDetail")]
public async Task<ActionResult<EmpDetail>> PutEmpDetail(int id,EmpDetail empDetail)
{
var obj = _empcontext.EmpDetails.Where(x => x.Id == empDetail.Id).FirstOrDefault();
if (obj != null)
{
obj.empcode = empDetail.empcode;
obj.empname = empDetail.empname;
obj.salary = empDetail.salary;
await _empcontext.SaveChangesAsync();
return CreatedAtAction("GetempDetail", empDetail);
}
}
error in putempdetail edit api not working
you must do a return for all action paths
if (obj != null)
{
obj.empcode = empDetail.empcode;
obj.empname = empDetail.empname;
obj.salary = empDetail.salary;
await _empcontext.SaveChangesAsync();
return CreatedAtAction("GetempDetail", empDetail);
}else{
return BadRequest();
}
You need to handle the case where the obj is null.
You can catch exception or return a badRequest.

cannot connect to itunes store xamarin forms

enter image description hereHi Thanks in advance i have facing a problem in my xamarin forms ios. Problem is that when i want to purchase product it thrown an exception that cannot to connect to itune store my same code in working fine on xamarin forms android.My code for restore purchases is working fine.
Here is my code for make purchases
private async Task<bool> MakePurchase(string ProductId, string Payload)
{
if (!CrossInAppBilling.IsSupported)
{
return false;
}
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync();
if (!connected)//Couldn't connect to billing, could be offline,
alert user
{
DependencyService.Get<IToast>().Show("Something went
wrong or you may not connected with the internet!");
return false;
}
//try to purchase item
var purchase = await billing.PurchaseAsync(ProductId,
ItemType.InAppPurchase, Payload);
if (purchase == null)
{
return false;
}
else
{
//Purchased, save this information
var responseId = purchase.Id;
var responseToken = purchase.PurchaseToken;
var state = purchase.State;
return true;
}
}
catch (InAppBillingPurchaseException ex)
{
if (ex.PurchaseError == PurchaseError.DeveloperError)
{
DependencyService.Get<IToast>().Show("DeveloperError");
ex.Message.ToString();
}
else if (ex.PurchaseError == PurchaseError.AlreadyOwned)
{
DependencyService.Get<IToast>().Show("AlreadyOwned");
return true;
}
else if(ex.PurchaseError == PurchaseError.BillingUnavailable)
{
DependencyService.Get<IToast>
().Show("BillingUnavailable");
return false;
}
else if(ex.PurchaseError == PurchaseError.InvalidProduct)
{
DependencyService.Get<IToast>().Show("InvalidProduct");
return false;
}
else if(ex.PurchaseError == PurchaseError.ItemUnavailable)
{
DependencyService.Get<IToast>().Show("ItemUnavailable");
return false;
}
else if(ex.PurchaseError == PurchaseError.GeneralError)
{
DependencyService.Get<IToast>().Show("General Error");
return false;
}
//Something bad has occurred, alert user
}
finally
{
//Disconnect, it is okay if we never connected
await billing.DisconnectAsync();
}
return false;
}

Delete Records from a database

I am trying to delete set of records under my ASP.NET Application - API Controller. Here is my code from API Controller:
public JsonResult Delete([FromBody]ICollection<ShoppingItemViewModel> vm)
{
if (ModelState.IsValid)
{
try
{
var items = Mapper.Map<IEnumerable<ShoppingItem>>(vm);
_repository.DeleteValues(items, User.Identity.Name);
return Json(null);
}
catch (Exception Ex)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(null);
}
}
else
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(null);
}
}
And here is my AngularJS Controller part taking care of this:
$scope.RemoveItems = function () {
$scope.isBusy = true;
$http.delete("/api/items", $scope.items)
.then(function (response) {
if (response.statusText == "OK" && response.status == 200) {
//passed
for (var i = $scope.items.length - 1; i > -1; i--) {
if ($scope.items[i].toRemove == true) {
$scope.items.splice(i, 1);
}
}
}
}, function (err) {
$scope.errorMessage = "Error occured: " + err;
}).finally(function () {
$scope.isBusy = false;
});
}
For unknown reason, this works like a charm in my POST method but not in the Delete Method. I believe that the problem might be caused by the fact, that DELETE method only accepts Integer ID?
If that is the case, what is the correct way how to delete multiple items with one call?

SCAN_SDT_UNKNOWN - Motorola OPOS Scanner

I am receiving an odd error with my scanner integration. I am making use of an OPOS scanner in my program. When the program closes I disable, release and close the device, but no other application can use it after my program runs. Also if I restart no application can use it. Not even my application which causes the issue. I did find that if I do not claim the device the issue doesn't happen. I am currently trying to get a fresh copy of the DLL in case the release method is somehow corrupted? Any other ideas?
public bool InitBarcode(bool overrideLGBarcode)
{
Util.LogMessage("Initializing barcode scanner!");
if (_barcodeScanner == null)
{
Util.LogMessage("Barcode scanner was null. instantiating a new one");
_barcodeScanner = new OPOSScanner();
_barcodeScanner.AutoDisable = true;
_barcodeScanner.DataEvent += BarcodeDataEventHandler;
Util.LogMessage("Added event handler");
}
else
{
Util.LogMessage("Barcode scanner was not null");
}
if (_barcodeScanner.Open("STI_USBSCANNER") != 0)
{
Util.LogMessage("Barcode scanner \"STI_USBSCANNER\" could not be opened!");
return false;
}
else
{
Util.LogMessage("STI_USBSCANNER was opened");
}
int result = _barcodeScanner.ClaimDevice(-1);
Util.LogMessage("Claiming barcode scanner returned result: " + result);
_barcodeScanner.DecodeData = true;
_barcodeScanner.DeviceEnabled = true;
_barcodeScanner.DataEventEnabled = true;
return true;
}
public void CloseBarcode()
{
Util.LogMessage("Disabling, Releasing and Closing the barcode scanner!");
_barcodeScanner.DataEvent -= BarcodeDataEventHandler;
Util.LogMessage("Removed event handler");
_barcodeScanner.AutoDisable = false;
_barcodeScanner.DecodeData = false;
_barcodeScanner.DataEventEnabled = false;
_barcodeScanner.DeviceEnabled = false;
if (_barcodeScanner.DeviceEnabled != false)
{
Util.LogMessage("Barcode scanner could not be disabled!");
}
else
{
Util.LogMessage("Barcode scanner was disabled!");
}
int result = _barcodeScanner.ReleaseDevice();
Util.LogMessage("ReleseDevice() yielded result of: " + result);
if (result != 0)
{
Util.LogMessage("Barcode scanner could not be released!");
}
else
{
Util.LogMessage("Barcode scanner was released!");
}
if (_barcodeScanner.Close() != 0)
{
Util.LogMessage("Barcode scanner could not be closed!");
}
else
{
Util.LogMessage("Barcode scanner was closed!");
}
_barcodeScanner = null;
}

Resources