Contains methods to start the WCF service host.
示例#1
0
        /// <summary>Connects to the <c>SevenUpdate</c>.Admin sub program.</summary>
        /// <returns><c>True</c> if the connection to <c>WcfService</c> was successful.</returns>
        internal static bool Connect()
        {
            MyServiceHost.StartService();

#if (!DEBUG)
            if (Process.GetProcessesByName("SevenUpdate.Admin").Length < 1)
            {
                IsConnected           = false;
                context               = null;
                Core.Instance.IsAdmin = false;
                bool success = Utilities.StartProcess(Path.Combine(Utilities.AppDir, @"SevenUpdate.Admin.exe"));
                if (!success)
                {
                    return(false);
                }
            }
#else
            if (Process.GetProcessesByName("SevenUpdate.Admin.vshost").Length < 1 &&
                Process.GetProcessesByName("SevenUpdate.Admin").Length < 1)
            {
                IsConnected           = false;
                context               = null;
                Core.Instance.IsAdmin = false;
                bool success = Utilities.StartProcess(Path.Combine(Utilities.AppDir, @"SevenUpdate.Admin.exe"));
                if (!success)
                {
                    return(false);
                }
            }
#endif
            return(true);
        }
示例#2
0
        /// <summary>Disconnects from <c>SevenUpdate</c>.Admin.</summary>
        internal static void Disconnect()
        {
            Core.Instance.IsAdmin = false;
            IsConnected           = false;
            try
            {
                if (context != null)
                {
                    context.Shutdown();
                }
            }
            catch (Exception ex)
            {
                if (
                    !(ex is CommunicationObjectAbortedException || ex is CommunicationObjectFaultedException ||
                      ex is ObjectDisposedException || ex is FaultException))
                {
                    ErrorOccurred(
                        null, new ErrorOccurredEventArgs(Utilities.GetExceptionAsString(ex), ErrorType.FatalError));
                    throw;
                }
            }

            MyServiceHost.StopService();
        }
示例#3
0
        /// <summary>Raises the <c>InstanceAwareApplication.Startup</c> event.</summary>
        /// <param name="e">The <c>System.Windows.StartupEventArgs</c> instance containing the event data.</param>
        /// <param name="isFirstInstance">If set to <c>True</c> the current instance is the first application instance.</param>
        protected override void OnStartup(StartupEventArgs e, bool isFirstInstance)
        {
            Init();
            if (e.Args.Length > 0)
            {
                if (e.Args[0].EndsWith(@".sua", StringComparison.OrdinalIgnoreCase))
                {
                    e.Args[0] = e.Args[0].Replace(@"sevenupdate://", null);
                    Sua app = null;
                    try
                    {
                        app = Utilities.Deserialize <Sua>(Utilities.DownloadFile(e.Args[0]));
                    }
                    catch (WebException)
                    {
                        Core.ShowMessage(
                            string.Format(
                                CultureInfo.CurrentCulture, SevenUpdate.Properties.Resources.ErrorDownloading, e.Args[0]),
                            TaskDialogStandardIcon.Error,
                            TaskDialogStandardButtons.Ok);
                        Environment.Exit(0);
                    }

                    string appName = Utilities.GetLocaleString(app.Name);
                    if (Utilities.IsRunning64BitOS == false && app.Platform == Platform.X64)
                    {
                        Core.ShowMessage(
                            string.Format(
                                CultureInfo.CurrentCulture, SevenUpdate.Properties.Resources.Not64BitCompat, appName),
                            TaskDialogStandardIcon.Error,
                            TaskDialogStandardButtons.Ok);
                        Environment.Exit(0);
                    }

                    TaskDialogResult result =
                        Core.ShowMessage(
                            string.Format(
                                CultureInfo.CurrentCulture, SevenUpdate.Properties.Resources.AddToSevenUpdate, appName),
                            TaskDialogStandardIcon.ShieldBlue,
                            TaskDialogStandardButtons.Cancel,
                            string.Format(
                                CultureInfo.CurrentCulture, SevenUpdate.Properties.Resources.AllowUpdates, appName),
                            null,
                            SevenUpdate.Properties.Resources.Add,
                            true);

                    if (result != TaskDialogResult.Cancel)
                    {
                        app.IsEnabled = true;
                        WcfService.AddSua(app);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            base.OnStartup(e, isFirstInstance);

            if (!isFirstInstance)
            {
                this.Shutdown(1);
            }
            else
            {
                RegisterApplicationRecoveryAndRestart();
                MyServiceHost.StartService();
                Args = e.Args;
                SetJumpList();
                Utilities.ErrorOccurred += LogError;
            }
        }