locked
Read xml content RRS feed

  • Question

  • Hi guys, I'm using MEF to create a modular application.

    The main application downloads an external xap. This external xap includes an xml file. How to read the file from the plugin once downloaded from the main app?

    Thank you.


    Edit: the real problem is

    This plugin uses a WCF service to access data. It works fine if I configure the service access by code. But when I use the configuration file servicereference.clientconfig the service doesn't work.

    Tuesday, October 26, 2010 3:56 AM

Answers

  • I do, because it allows the service to be configurable on the fly rather than depending on modifying the XAP everytime it must be re-pointed.

    Tuesday, October 26, 2010 7:49 AM
  • Hi,

    this may be help.

    public class ThemeChangeCommand : ICommand
        {
            private bool isThemed;
            #region ICommand Members

            public bool CanExecute(object parameter)
            {
                if (parameter == null)
                    return isThemed;
                var themeResource = Application.GetResourceStream(new Uri("/ThaiSilverlight;component/Assets/" + parameter + "Theme.xaml", UriKind.Relative));
                return themeResource != null;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                if (isThemed)
                {
                    ((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.RemoveAt(((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.Count - 1);
                    isThemed = false;
                }
                if (parameter == null)
                    return;
                var themeResource = Application.GetResourceStream(new Uri("/ThaiSilverlight;component/Assets/" + parameter + "Theme.xaml", UriKind.Relative));
                ResourceDictionary rd = (ResourceDictionary)(XamlReader.Load(new StreamReader(themeResource.Stream).ReadToEnd()));
                ((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.Add(rd);
                isThemed = true;
                if (CanExecuteChanged != null)
                    CanExecuteChanged(this, new EventArgs());
            }

            #endregion
        }

    Tuesday, October 26, 2010 8:24 AM

All replies

  • Is the service on the same host as your XAP or external? In my opinion it's far easier to wire up the bindings instead of depending on the service.clientconfig - take a look here:

    http://csharperimage.jeremylikness.com/2009/07/abstracting-wcf-service-calls-in.html

    and here:

    http://csharperimage.jeremylikness.com/2009/12/simplifying-asynchronous-calls-in.html

     

    Tuesday, October 26, 2010 6:46 AM
  • @Jeremy

    Thank you for your reply. Yes, I've wired up configuration parameters within the code, such as your links. Do you think that wiring up the bindings is better then depending on the service.clientconfig? Thank you again.

    Tuesday, October 26, 2010 7:09 AM
  • I do, because it allows the service to be configurable on the fly rather than depending on modifying the XAP everytime it must be re-pointed.

    Tuesday, October 26, 2010 7:49 AM
  • Hi,

    this may be help.

    public class ThemeChangeCommand : ICommand
        {
            private bool isThemed;
            #region ICommand Members

            public bool CanExecute(object parameter)
            {
                if (parameter == null)
                    return isThemed;
                var themeResource = Application.GetResourceStream(new Uri("/ThaiSilverlight;component/Assets/" + parameter + "Theme.xaml", UriKind.Relative));
                return themeResource != null;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                if (isThemed)
                {
                    ((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.RemoveAt(((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.Count - 1);
                    isThemed = false;
                }
                if (parameter == null)
                    return;
                var themeResource = Application.GetResourceStream(new Uri("/ThaiSilverlight;component/Assets/" + parameter + "Theme.xaml", UriKind.Relative));
                ResourceDictionary rd = (ResourceDictionary)(XamlReader.Load(new StreamReader(themeResource.Stream).ReadToEnd()));
                ((FrameworkElement)Application.Current.RootVisual).Resources.MergedDictionaries.Add(rd);
                isThemed = true;
                if (CanExecuteChanged != null)
                    CanExecuteChanged(this, new EventArgs());
            }

            #endregion
        }

    Tuesday, October 26, 2010 8:24 AM