How to get network connection status in apple watch standalone application? - watchkit

Using NWPathMonitor, I get network information in watch simulator (with usesInterfaceType) and it showing right status, but in real device it's not working. It alway showing no network. I developed independent watch application. Please check below code that I write for this:
let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
if path.status == .satisfied {
print("We're connected!")
if path.usesInterfaceType(.wifi) {
print("It's WiFi!")
} else if path.usesInterfaceType(.cellular) {
print("3G/4G FTW!!!")
} else if path.usesInterfaceType(.wiredEthernet) {
print("wiredEthernet")
}else if path.usesInterfaceType(.loopback) {
print("loopback")
}else if path.usesInterfaceType(.other) {
print("other")
}
}
else {
print("No connection.")
}
}
let queue = DispatchQueue(label: "InternetConnectionMonitor")
monitor.start(queue: queue)

Related

How to overcome caching issue when downloading data from internet using CHttpFile

This is how I currently download a ZIP file from the internet in my MFC project:
strTargetZIP = theApp.GetWorkingPath() + _T("AutoUpdate\\MWBDataUpdate.zip");
strDownloadURL = _T("https://www.publictalksoftware.co.uk/mwbdata/MWBDataUpdate.zip");
// ask user to go on line
const BOOL bOnline = InternetGoOnline(strDownloadURL.GetBuffer(), hWnd, 0);
strDownloadURL.ReleaseBuffer();
if (!bOnline)
return false;
try
{
// our session should already be open
// try to open up Internet session to my URL
// Use flag INTERNET_FLAG_RELOAD
pWebFile = dynamic_cast<CHttpFile*>(iSession.OpenURL(strDownloadURL, 1,
INTERNET_FLAG_SECURE | INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD));
if (pWebFile != nullptr)
{
if (pWebFile->QueryInfoStatusCode(dwStatusCode))
{
// 20x codes mean success
if ((dwStatusCode / 100) == 2)
{
if (fileLocal.Open(strTargetZIP,
CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))
{
iRead = pWebFile->Read(&szBuffer[0], 4096);
while (iRead > 0)
{
iBytesRead += iRead;
fileLocal.Write(&szBuffer[0], iRead);
iRead = pWebFile->Read(&szBuffer[0], 4096);
}
fileLocal.Close();
bOK = true;
}
}
else
{
// There was a problem!
strError.Format(IDS_TPL_INVALID_URL, dwStatusCode);
AfxMessageBox(strError, MB_OK | MB_ICONERROR);
}
}
}
else
{
// Note, there is no error log. Use new error message?
AfxMessageBox(IDS_STR_UPDATE_CHECK_ERR, MB_OK | MB_ICONERROR);
}
}
catch(CException *e_)
{
const gsl::not_null<CException*> e{ e_ };
e->ReportError();
e->Delete();
}
As you can see, I have tried to cater for caching issues. However, it seems that on occasion, for some users, the software does not download the latest ZIP and uses a cached version.
What further steps can I as a developer (or they as a user) take to ensure that my software does actually download the latest ZIP file on my website server?

How to detect the single tap in DispatchTouchEvent method in forms android

Am using DispatchTouchEvent and need to detect a single tap, for that considered the down point and up point, when both are same, detected the single tap.
But this works fine in some android devices, but in some device, there in a pixel difference in down and up point. How to overcome this?
public override bool DispatchTouchEvent(MotionEvent e)
{
if (e.Action == MotionEventActions.Down)
{
touchDownPoint = new Xamarin.Forms.Point(e.GetX(), e.GetY());
}
else if (e.Action == MotionEventActions.Up)
{
var position = new Xamarin.Forms.Point(e.GetX(), e.GetY());
if (touchDownPoint == position) // this condition not gets satisfied in some devices
{
// single tap detected.
}
}
else if (e.Action == MotionEventActions.Move)
{
}
return base.DispatchTouchEvent(e);
}

Firebase firestore document changes

I just want to ask how can I properly use the document changes in my app? Btw there are 3 types of that which is ADDED, MODIFIED and lastly REMOVED. TYPE.ADDED works perfectly fine, but in modified and removed it doesn't work well in modified it. I am using a recyclerview for that and here's my code. Am I wrong utilizing it? Also, I am using a instance oldindex and newindex to know the index which is affected by the action performed.
for (DocumentChange doc : documentSnapshots.getDocumentChanges()) {
if(doc.getType() == DocumentChange.Type.ADDED) {
PostsClass post = doc.getDocument().toObject(PostsClass.class).withId(doc.getDocument().getId());
postList.add(post);
Log.d(TAG, post.toString());
postsAdapter.notifyDataSetChanged();
}
else if (doc.getType() == DocumentChange.Type.MODIFIED) {
adoptList.clear();
AdoptClass adopt = doc.getDocument().toObject(AdoptClass.class).withId(doc.getDocument().getId());
adoptList.add(adopt);
adoptListAdapter.notifyItemChanged(oldIndex);
}
else if (doc.getType() == DocumentChange.Type.REMOVED) {
adoptList.remove(oldIndex);
adoptListAdapter.notifyItemRemoved(oldIndex);
}
}
below code worked for me in 3 conditions ADDED,MODIFIED,REMOVED (Android Firestore)
for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
if (documentChange.getType() == DocumentChange.Type.ADDED) {
String doc_id = documentChange.getDocument().getId();
PostModel postModel = documentChange.getDocument().toObject(PostModel.class).withDocId(doc_id);
postModelList.add(postModel);
} else if (documentChange.getType() == DocumentChange.Type.MODIFIED) {
// modifying
String docID = documentChange.getDocument().getId();
PostModel changedModel = documentChange.getDocument().toObject(PostModel.class).withDocId(docID);
if (documentChange.getOldIndex() == documentChange.getNewIndex()) {
// Item changed but remained in same position
postModelList.set(documentChange.getOldIndex(),changedModel);
postListAdapter.notifyItemChanged(documentChange.getOldIndex());
}else {
// Item changed and changed position
postModelList.remove(documentChange.getOldIndex());
postModelList.add(documentChange.getNewIndex(),changedModel);
postListAdapter.notifyItemMoved(documentChange.getOldIndex(),documentChange.getNewIndex());
}
postListAdapter.notifyDataSetChanged();
} else if (documentChange.getType() == DocumentChange.Type.REMOVED) {
// remove
postModelList.remove(documentChange.getOldIndex());
postListAdapter.notifyItemRemoved(documentChange.getOldIndex());
}
}

Using webdriver, I am able to run successfully for the first user & for next user it is failing at if condition. If condition is not working properly

If condition is not working properly. I have some set of user id to login to my application, using webdriver, I am able to run successfully for the first user & for next user it is failing at if condition. Please find the code below and it has to check the more if conditions to run successfully.
for (int i = 1; i < sh.getRows(); i++)
{
while(iter.hasNext())
{
System.out.println("Main Window ID :"+iter.next());
}
driver.findElement(By.id("lgnLogin_UserName")).clear();
driver.findElement(By.id("lgnLogin_UserName")).sendKeys(sh.getCell(0,
i).getContents());
driver.findElement(By.id("lgnLogin_Password")).clear();
driver.findElement(By.id("lgnLogin_Password")).sendKeys(sh.getCell(1,
i).getContents());
driver.findElement(By.id("lgnLogin_LoginButton")).click();
Thread.sleep(5000L);
if(driver.findElements(By.linkText("Logout")) != null)
{
driver.findElement(By.id("ctl00_Header_Lbtn_Logout")).click();
msg ="Valid User Login";
System.out.println(msg);
}
else
if(driver.getTitle().contains("700Dealers Inc."))
{
driver.findElement(By.xpath("//table[#id='lgnLogin']/tbody
/tr/td/table/tbody/tr[4]/td")).getText();
System.out.println(msg);
}
else
if(driver.getTitle().contains("Security Question And Answers"))
{
driver.findElement(By.xpath("//table[#id='Table_01']/tbody
/tr[5]/td/table/tbody/tr/td/table/tbody/tr/td/span/span[1]")).getText();
System.out.println(msg);
}
else
if(driver.getTitle().contains("700 credit Change Password"))
{
driver.findElement(By.xpath("//div[#id='panelscreen']/table
/tbody/tr/th/span")).getText();
System.out.println(msg);
}
Please help me out in this issue. Help will be appreciated.
Thread.sleep(5000L); is probably the root of your problems.
So, you may want to replace that :
Thread.sleep(5000L);
if(driver.findElements(By.linkText("Logout")) != null)
with an explicit wait :
try {
WebElement logout = (new WebDriverWait(driver, 5))
.until(new ExpectedCondition<WebElement>(){
#Override
public WebElement apply(WebDriver d) {
return d.findElement(By.linkText("Logout"));
}});
//Logout found, do stuff
} catch(TimeoutException e) {
//No logout element, do stuff
}

Message Stucks (Microsoft.Samples.BizTalk.Adapter.Common )

We use Microsoft.Samples.BizTalk.Adapter.Common library for our custom SMTP Receive Adapter. Everything seems fine except one situation. The message stucks if it larger than approximatly 5 MB and it includes more than two attachments. Our adapter is run on isoletadHost. In query window we see that the message stay in active status. During our investigation we found that it stucks in a batch.Wait() method. Any other messages handling well. We are running Biztalk 2006 Standart.
Could anyone provide us with any suggestion?
SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(transportProxy, terminator, 1);
Int32 count = 0;
foreach (IBaseMessage msg in messages)
{
try
{
batch.SubmitMessage(msg, null);
count++;
}
catch (Exception ex)
{
try
{
msg.SetErrorInfo(ex);
batch.MoveToSuspendQ(msg);
ThreadContext.Properties["EventID"] = 1007;
logger.Error("Submit Error", ex);
}
catch (Exception ex2)
{
ThreadContext.Properties["EventID"] = 1008;
logger.Error("Suspend Error", ex2);
}
}
}
if (count != 0)
{
batch.Done();
if (batch.Wait())
{
ThreadContext.Properties["EventID"] = 1009;
logger.Debug("Messages publised");
}
else
{
ThreadContext.Properties["EventID"] = 1010;
logger.Warn(String.Format("Publish error. Sucssefully publised {1}, error in {0} messages", batch.FailedMessages.Count, count - batch.FailedMessages.Count));
}
}
else
{
ThreadContext.Properties["EventID"] = 1011;
logger.Warn("No message found");
}
This fix: http://support.microsoft.com/kb/928078 helped to solve the problem. Thanks all.

Resources