Help get this topic noticed by sharing it on Twitter, Facebook, or email.

automatically refresh

Hi!

A want to call refresh method automatically in runtime. Is it possible?
I don't use excel, only VS and I work in C#. I have a button and I want to check cxml file. If update happened, I want to call refresh. I know, I can refresh in table with right click, but I would like it automatically.
Do somebody know the answer?

1. Where is refresh method, and how can I override it?
2. How can I check the cxml file?

Thanks
Feri
3 people have
this question
+1
Reply
  • Jett (Official Rep) August 04, 2010 17:51
    Hi Feri,

    If you're asking for the WPF client - there isn't any programmatic support within the cxml to run this kind of polling. If you're using the silverlight control then you have a good bit more freedom to implement custom logic like this.

    1. To simulate refresh, call PivotViewer.LoadCollection() on the same file.
    2. To check for updates, use a WebRequest - most likely you'll just want the last-modified header, and the http HEAD verb.

    of course there are many different ways to check for file update - you might have some good luck on the silverlight.net forums too. Two early links I found:

    http://weblogs.asp.net/dwahlin/archiv...
    http://www.drdobbs.com/tools/20760277...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi Jett,
    "1. To simulate refresh, call PivotViewer.LoadCollection() on the same file. "
    But it doesn't force file to re-generate. Actually I generate .cxml from db (using jit sample). I know that some changes are made in db, and want to re-generate file. But calling LoadCollection() on the same file doesn't meet my needs, because collection remains the same and HttpHandler is never called again, untill I actually refresh the page. How can I force generated file to re-create?
    • Jett (Official Rep) August 11, 2010 21:24
      So if I'm reading right - there are two possible places for page caching, in the JIT server or in the silverlight control. I'm mostly sure the silverlight control issues new requests, but I haven't work with the JIT server a lot. Regardless I'll try to make some time to walk through using the two together to see why you might not see updates.
    • As mentioned below, the simplest way I've seen to force a refresh is to add a new string to the collection path or to the filter state (these are the two arguments to LoadCollection) - as long as it's still a valid url, the additional arguments will be otherwise ignored, but bypass caching.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • thanks all!
    Yes, I did. I need refresh when db was modified. So I call LoadCollection("same file", saved ViewState).
    Not force, but it's work....
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi Ference

    U mean that if I did
    pivotViewer.LoadCollection('http://xyz.com/abc.cxml", string.empty);

    where xyz.com is my site and abc.cxml gets data from my handler.

    And then if I call:
    pivotViewer.LoadCollection('http://xyz.com/abc.cxml", pivotViewer.ViewerState);

    it will work?

    Coz in my case its not working and in fact my httphandler is not getting even getting called when I try to reload the collection again.

    Please help.

    Thanks
    Akshaya
    • Hi!

      So you have a cxml. You can call pivot:
      LoadCollection("abc.cxml", ''");
      string viewState = PivotViewer.ViewState;

      and you have (for example) a refresh button:
      button source:
      LoadCollection("abc.cxml", viewState);
      //you must be see viewState in this block!
      //if you need reload collection with clear filter: LoadCollection("abc.cxml", "");

      I hope I helped.

      Best regards:
      Feri
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • I have tried this, initially I call:

    pivotViewer.LoadCollection('http://xyz.com/abc.cxml", "");

    my handler is called, handler returns the cxml and its rendered in pivot viewer.

    and then on button click, i call the same thing again i.e.

    pivotViewer.LoadCollection('http://xyz.com/abc.cxml", "");

    this time my handler is not called at all, and so the Pivot viewer is not refreshed...but when i refresh the page, the handler is called and the correct cxml is loaded.

    Now why on earth, is the pivot viewer not able to call the handler the second time? I think if we solve this problem our complete problem will be solved!

    What do you think?

    Thanks
    Akshaya
    • Hi!

      for example:
      //it's work

      namespace pivot
      {
      public partial class MainPage : UserControl
      {
      string collectionUrl = "..."; //your url
      public MainPage()
      {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(MainPage_Loaded);
      }

      void MainPage_Loaded(object sender, RoutedEventArgs e)
      {
      LoadCollection(collectionUrl);
      }

      private void Refresh_Click(object sender, RoutedEventArgs e)
      {
      LoadCollection(collectionUrl);
      }

      private void PivotViewer_Loaded(object sender, RoutedEventArgs e)
      {
      App app = (App)App.Current;
      string cxmlName = app.InitParamsCxml; /* need make in App.xaml.cs => public string InitParamsCxml { get; set; }*/
      if (!string.IsNullOrWhiteSpace(cxmlName))
      {
      LoadCollection(cxmlName);
      }
      }

      [ScriptableMember]
      public void LoadCollection(string cxmlName)
      {
      PivotViewer.LoadCollection(collectionUrl, string.Empty);
      }
      }
      }

      I hope, I helped.

      Best regards
      Feri
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi

    I'll try this. Meanwhile, can you please explain to me the following:

    1. Where are we assigning a value to app.InitParamsCxml? According to the code, the value of this variable will always be null. And since app.InitParamsCxml will always be null, the code inside PivotViewer_Loaded will never get executed. So why do we need it?

    2. In LoadCollection, the parameter we pass is cxmlName but in the code within the method this variable is never used, so is this parameter required or can we remove it?

    3. Last question, why are we using this ScriptableMember tag with LoadCollection? What is the significance?

    Thanks again for all your help. Please do answer these questions and instruct me with the changes, if any that I may have to do in my code.

    Thanks
    Akshaya
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi

    Ur code didnt work for me. But I did found a solution to this problem. As I told you before the problem was coming because the httphandler was not getting called, when i tried to load the collection for the second time.

    So what I did was to pass on unique context info with the url. For eq. consider my handler was available at http://xyz.com/abc.cxml, so I loaded the collection as

    pivotViewer.LoadCollection('http://xyz.com/abc.cxml?guid=" + Guid.NewGuid(), string.empty);

    and I called the same thing for second time as well. Now since everytime I used to load the collection, a new Guid was generated, so the browser looked upon this url as a new request, so my httphandler was called everytime I loaded the collection and hence I was able to get the updated collection.

    Thanks a lot for ur help.

    Akshaya
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi,

    Could you please post a working sample, cause it doesn't work for me.

    Thanks,
    Juliana
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi!

    I solved it with child window. You can add to child win for solution. And you can call child from MainPage:
    Child win = new Child();
    win.Show();

    and the Child.xaml.cs source:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Pivot;
    using System.Windows.Browser;
    using System.ComponentModel;
    using System.Globalization;

    namespace SilverlightApplication1
    {
    public partial class Child : ChildWindow, INotifyPropertyChanged
    {
    string _PivotSource = "http://localhost:49381/ClientBin/test...;
    public string PivotSource
    {
    get { return _PivotSource; }
    set
    {
    _PivotSource = value;

    if (_PivotSource != null)
    {
    PivotViewer.LoadCollection(PivotSource, "");
    }

    OnPropertyChanged("PivotSource");
    }
    }

    public string temp; //for ViewState

    public Child()
    {
    InitializeComponent();
    }

    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
    this.DialogResult = true;
    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
    PivotViewer = null;
    Close();
    }

    private void PivotViewer_ItemDoubleClicked(object sender, ItemEventArgs e)
    {
    PivotItem piv_item = PivotViewer.GetItem(e.ItemId);

    if (!string.IsNullOrWhiteSpace(piv_item.Href))
    {
    PivotViewer.CurrentItemId = e.ItemId;
    //selected_lb.Content = piv_item.Name; //get name
    OpenLink(piv_item.Href);
    }
    else
    {
    MessageBox.Show("No Web Page...");
    }
    }

    private void PivotViewer_Loaded(object sender, RoutedEventArgs e)
    {
    }

    private void OpenLink(string linkUri)
    {
    HtmlPage.Window.Navigate(new Uri(linkUri, UriKind.RelativeOrAbsolute), "PivotViewerSampleTargetFrame");
    }

    private void Refresh_button_Click(object sender, RoutedEventArgs e)
    {
    temp = PivotViewer.ViewerState.ToString();
    PivotViewer.LoadCollection(PivotSource, temp);
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    void OnPropertyChanged(string propertyName)
    {
    if (PropertyChanged != null)
    {
    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }
    }

    #endregion
    }
    }

    best regards
    Feri
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • I forgot:
    You need to make test.cxml in ClientBin folder (or change url of cxml)
    and you need to set in web project port in properties.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • @ Juliana

    My example works with a httphandler, is this the case with u as well? If yes, then only I think my code will be relevant to your problem. Else you can try the solution provided by Ferenc, I am not sure if it works. But u can try it. Let me know if you require a test app using httphandlers.

    @Ferenc: I'll try ur solution and let u know if its work for me as well i.e. in the case of httphandlers.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • My example works without httphandlers. This example use static cxml. I have dynamic example too.
    If I get a mail address, I send my solution.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited