Ejemplo n.º 1
0
        //****************************************************************
        // GENERAL HELPER METHOD SECTION
        //****************************************************************
        #region GeneralHelper

        // Downloads the customer files syncronously & then displays it.
        private void LoadGroupSync(string groupName)
        {
            try
            {
                _appDeployment.DownloadFileGroup(groupName);

                switch (groupName)
                {
                case "customer":
                    customerLocalBox.Text = "True";
                    ShowCustomers();
                    break;

                case "order":
                    orderLocalBox.Text = "True";
                    ShowOrders();
                    break;
                }
            }
            catch (Exception e)
            {
                //Exception here is most likely due to networking problems
                MessageBox.Show("Failed to download application components:  " + e.Message);
            }
        }
Ejemplo n.º 2
0
        //</SNIPPET8>

        //<SNIPPET9>
        private void DownloadFileGroupSync(string fileGroup)
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;

                if (deployment.IsFirstRun)
                {
                    try
                    {
                        if (deployment.IsFileGroupDownloaded(fileGroup))
                        {
                            deployment.DownloadFileGroup(fileGroup);
                        }
                    }
                    catch (InvalidOperationException ioe)
                    {
                        MessageBox.Show("This application is not a ClickOnce application. Error: " + ioe.Message);
                        return;
                    }

                    downloadStatus.Text = String.Format("Download of file group {0} complete.", fileGroup);
                }
            }
        }
Ejemplo n.º 3
0
        /*
         * Use ClickOnce APIs to download the assembly on demand.
         */
        private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Assembly newAssembly = null;

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment deploy = ApplicationDeployment.CurrentDeployment;

                // Get the DLL name from the Name argument.
                string[] nameParts         = args.Name.Split(',');
                string   dllName           = nameParts[0];
                string   downloadGroupName = DllMapping[dllName];

                try
                {
                    deploy.DownloadFileGroup(downloadGroupName);
                }
                catch (DeploymentException de)
                {
                    MessageBox.Show("Downloading file group failed. Group name: " + downloadGroupName + "; DLL name: " + args.Name);
                    throw (de);
                }

                // Load the assembly.
                // Assembly.Load() doesn't work here, as the previous failure to load the assembly
                // is cached by the CLR. LoadFrom() is not recommended. Use LoadFile() instead.
                try
                {
                    newAssembly = Assembly.LoadFile(Application.StartupPath + @"\" + dllName + ".dll," +
                                                    "Version=1.0.0.0, Culture=en, PublicKeyToken=03689116d3a4ae33");
                }
                catch (Exception e)
                {
                    throw (e);
                }
            }
            else
            {
                //Major error - not running under ClickOnce, but missing assembly. Don't know how to recover.
                throw (new Exception("Cannot load assemblies dynamically - application is not deployed using ClickOnce."));
            }


            return(newAssembly);
        }
Ejemplo n.º 4
0
        static void GetSatelliteAssemblies(string groupName)
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment deploy = ApplicationDeployment.CurrentDeployment;

                if (deploy.IsFirstRun)
                {
                    try
                    {
                        deploy.DownloadFileGroup(groupName);
                    }
                    catch (DeploymentException de)
                    {
                        // Log error. Do not report error to the user, as there may not be a satellite
                        // assembly if the user's culture and the application's default culture match.
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called after OnStartup()
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnApplicationStartup(object sender, StartupEventArgs e)
        {
            if (Tobi.Common.Settings.Default.UpgradeSettings)
            {
                if (!ApplicationDeployment.IsNetworkDeployed)
                {
                    // ClickOnce automatically Upgrades.

                    Settings.Default.Upgrade();
                    Tobi.Common.Settings.Default.Upgrade();
                }

                Tobi.Common.Settings.Default.UpgradeSettings = true; // ensure settings aggregator does its job of upgrading the other providers
            }

            try
            {
                SettingsPropertyCollection col1 = Settings.Default.Properties;
                IEnumerator enume1 = col1.GetEnumerator();
                while (enume1.MoveNext())
                {
                    var current = (SettingsProperty)enume1.Current;
                    Console.WriteLine("--- " + current.Name + ":");
                    Console.WriteLine(current.DefaultValue);
                    Console.WriteLine(Settings.Default[current.Name]);
                }
                //Settings.Default.Reload();
            }
            catch (ConfigurationErrorsException ex)
            {
                HandleConfigurationErrorsException(ex);
            }

            Console.WriteLine("<RESOURCE SET LANGs>");
            var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            foreach (var culture in cultures)
            {
                try
                {
                    var rs = Tobi_Lang.ResourceManager.GetResourceSet(culture, true, false);
                    if (rs != null)
                    {
                        Console.WriteLine(culture.Name + " ==> " + culture.NativeName);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            Console.WriteLine("</RESOURCE SET LANGs>");

#if DEBUG
            var keys = Tobi_Lang.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, true)
                       .Cast <DictionaryEntry>()
                       .Select(entry => entry.Key)
                       .Cast <string>();
            var resources = keys.ToDictionary(key => key, key => Tobi_Lang.ResourceManager.GetString(key, CultureInfo.GetCultureInfo("fr")));

            var str = Tobi_Lang.LangStringKey1;
#endif
            try
            {
#if DEBUG
                SetCulture("fr");
                str = Tobi_Lang.LangStringKey1;

                SetCulture("hi");
                str = Tobi_Lang.LangStringKey1;
#endif
                SetCulture(Settings.Default.Lang);
            }
            catch (ConfigurationErrorsException ex)
            {
                HandleConfigurationErrorsException(ex);
#if DEBUG
                MessageBox.Show(ex.Message);

                Process.GetCurrentProcess().Kill();
                return;
#endif
            }
#if NET40
            catch (CultureNotFoundException ex2)
            {
#if DEBUG
                Debugger.Break();
#endif
                Settings.Default.Lang = "en";
                SetCulture(Settings.Default.Lang);
            }
#else
            catch (ArgumentException ex2)
            {
#if DEBUG
                Debugger.Break();
#endif
                Settings.Default.Lang = "en";
                SetCulture(Settings.Default.Lang);
            }
#endif

#if DEBUG
            str = Tobi_Lang.LangStringKey1;
#endif
            if (false && ApplicationDeployment.IsNetworkDeployed)
            {
                string lang = Thread.CurrentThread.CurrentUICulture.ToString();

                ApplicationDeployment deploy = ApplicationDeployment.CurrentDeployment;
                try
                {
                    if (!deploy.IsFileGroupDownloaded(lang)) //deploy.IsFirstRun
                    {
                        deploy.DownloadFileGroup(lang);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);

                    MessageBox.Show(ex.Message);

                    // Log error. Do not report this error to the user, because a satellite
                    // assembly may not exist if the user's culture and the application's
                    // default culture match.
                }
            }

            //to use on individual forms: this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.IetfLanguageTag);
            FrameworkElement.LanguageProperty.OverrideMetadata(
                typeof(FrameworkElement),
                new FrameworkPropertyMetadata(
                    XmlLanguage.GetLanguage(
                        CultureInfo.CurrentUICulture.IetfLanguageTag)));

            Timeline.DesiredFrameRateProperty.OverrideMetadata(
                typeof(Timeline),
                new FrameworkPropertyMetadata {
                DefaultValue = 20
            }
                );

            //AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

            SplashScreen = new SplashScreen(Assembly.GetExecutingAssembly(), "TobiSplashScreen.png");
            SplashScreen.Show(false);

            ShutdownMode = ShutdownMode.OnMainWindowClose;

            runBootstrapper();
        }