Swithing between Online/Offline mode - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Swithing between Online/Offline mode

Last post 10-08-2008 11:19 PM by BlindBoyGrunt. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 10-02-2008 07:08 AM

    Swithing between Online/Offline mode

    Hi

    Is there a possibility to switch between online/offline mode by code?

     BR
    Niclas

  • 10-02-2008 11:05 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Swithing between Online/Offline mode

    Hello.

    We will the get offline or online form by using the below code,

    Application.IsDestinationReachable("URL of the destination")

    If this value returns false then we need to set form is in offline mode otherwise online form.

  • 10-02-2008 11:10 PM In reply to

    Re: Swithing between Online/Offline mode

    Ok, but how do you set it to offline/online by code?

    BR,

    Niclas

  • 10-03-2008 03:36 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Swithing between Online/Offline mode

    Hello,

    In onLoad depends the ‘IsDestinationReachable' value, we have set this value in form (xml) node depends on this field value we can do different operations for offline and online mode forms.

  • 10-03-2008 05:13 AM In reply to

    Re: Swithing between Online/Offline mode

    Hi,Add a boolean field isOnline to the data source. Set the default value to true.In onload write the following code lines.thisXDocument.DOM.selectSingleNode(“xpath of the isOnline field”).text = Application.IsDestinationReachable("URL of the destination");If isOnline value is true then that form is in online mode. If it is false the form is in offline mode.  

     

    Swathip
    www.ggktech.com
  • 10-03-2008 05:33 AM In reply to

    Re: Swithing between Online/Offline mode

    Ok I undertstand that I can get the online/offline status by doing it this way.

    Let me more describe my problem.

    I have a web service as a data connection. The web service gets huge product catalog in a XML-file that will work as secondary data connection source. The product catalog is published once a month. In the Xml there is a field with the last publishing date for the product catalog.I don't want to query this connection each time I'm online as it would slow down the application, I just want to query it if a new product catalog has been published.

    My solution to this were to add another web service as sec data connection that only pulled out the publishing date from the XML. I then wants to compare this date to the one that is in the other data connection that has been cached. The problem is that InfoPath always start in online mode and then it seems like I can't get to the cached data. I would like to start in online mode, get the date, then switch to offline mode and get cached date. I then would like to compare them and if a new product catalog has been published I would like to query the data connection that gets the product catalog.

    // Niclas

  • 10-05-2008 11:06 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Swithing between Online/Offline mode

    Hello,

    Whenever you are first loading the secondary connection you have to set date to one field. Next time opens this form you have checked the condition to again connect to secondary connection or not? Based on data difference is more than 30 days then you having connected Product Catalog again otherwise get the cached one.

  • 10-05-2008 11:15 PM In reply to

    Re: Swithing between Online/Offline mode

    Hi that's exactly my idea but I can't get to the cached data. If the form isn't in offline mode it seems like I can't get to it. When I try to move to a node in a data source that has been cached I can't find any values if the form is in "online" mode. If I force it to offline mode then I can get to it. It seems kind of strange that I need to force it to offline mode to be able to access a cached data source.

     BR,

    Niclas

  • 10-08-2008 11:19 PM In reply to

    Re: Swithing between Online/Offline mode

    This is how I tried to solve this in the loading event for the form:

    DateTime pubDate = DateTime.Now;

    DateTime formDate = DateTime.Now;

    XPathNavigator priceBookDate = null;

    //First we want to connect to the datasource GetPriceBookDate that only returns the latest publishing

    //date for the PriceBook.

    try

    {

       WebServiceConnection wsc = (WebServiceConnection)this.DataSources["GetPriceBookDate"].QueryConnection;

       wsc.Execute();

       XPathNavigator GetPriceBookDate = this.DataSources["GetPriceBookDate"].CreateNavigator();

       priceBookDate = GetPriceBookDate.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetPriceBookDateResponse/tns:GetPriceBookDateResult", this.NamespaceManager);

       //Get the date for the latest published pricebook

       if (!String.IsNullOrEmpty(priceBookDate.Value))

       {

       pubDate = Convert.ToDateTime(priceBookDate.Value);

       }

    }

    catch

    {

    }

     

    //Here we want to work against the cached data for the datasource GetPriceBook that contains the whole PriceBook

    //This doesn't work if we are in online mode.

    XPathNavigator GetPriceBook = this.DataSources["GetPriceBook"].CreateNavigator();

    //Get the cached date.

    XPathNavigator formPriceBookDate = GetPriceBook.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetPriceBookResponse/tns:GetPriceBookResult/tns:PublishingDate", this.NamespaceManager);

    if (priceBookDate != null)

    {

       //Get the date for the latest publised pricebook that was cached in the form

       if (!String.IsNullOrEmpty(formPriceBookDate.Value))
          formDate = Convert.ToDateTime(formPriceBookDate.Value);

    //Give the user an option to download a new pricebook if there is a newer version
    //published or if the user hasn't a PriceBook cached

    if ((formDate < pubDate) || String.IsNullOrEmpty(formPriceBookDate.Value))

    {

       DialogResult result = MessageBox.Show("There is a new Price Book available. Do you want to download the new Price Book? ", null, MessageBoxButtons.YesNo, MessageBoxIcon.Question,       MessageBoxDefaultButton.Button2);

    if (result == DialogResult.Yes)

    {

       WebServiceConnection wscPB = (WebServiceConnection)this.DataSources["GetPriceBook"].QueryConnection;

       wscPB.Timeout = 1000;

       wscPB.Execute();

    }

    }

    }

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.