public IHttpActionResult Delete(int id) { _pcService = new PCGameService(); _pcService.DeleteGame(id); return(Ok()); }
public SubViewModel( INavigationService navigationService, IPCService pcService) { _navigationService = navigationService; _pcService = pcService; }
internal PersonalCloud(ILogger l, IPCService pcsrv, List <StorageProviderInfo> storageProviderInfos) { CachedNodes = new List <NodeInfoForPC>(); RootFS = new RootFileSystem(pcsrv); StorageProviderInstances = new List <StorageProviderInstance>(); if (storageProviderInfos != null) { foreach (var info in storageProviderInfos) { try { if (info.Type == StorageProviderInstance.TypeAliYun) { StorageProviderInstances.Add(new StorageProviderInstance_AliyunOSS(info)); } else if (info.Type == StorageProviderInstance.TypeAzure) { StorageProviderInstances.Add(new StorageProviderInstance_AzureBlob(info)); } } catch { // Ignore any errors } } } logger = l; Apps = new List <AppLauncher>(); httpClient = new Lazy <HttpClient>(() => new HttpClient()); }
public IHttpActionResult Create([FromBody] PCCreateModel pcGameToCreate) { _pcService = new PCGameService(); _pcService.CreatePCGame(pcGameToCreate); return(Ok()); }
public IHttpActionResult Get(int id) { _pcService = new PCGameService(); _pcService.GetPCGame(id); return(Ok()); }
public MainViewModel( INavigationService navigationService, IPCService pcService) { _navigationService = navigationService; _pcService = pcService; _sampleData = _pcService.PCs; _sampleData.ForEach(PCs.Add); }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; try { if (!IPCService.StartService()) { throw new Exception(Language.Can_not_open_a_named_pipe_for_Inter_process_communication); } var profiles = Profile.GetAllProfiles().ToArray(); var profileIndex = !string.IsNullOrWhiteSpace(CommandLineOptions.Default.ProfileId) && profiles.Length > 0 ? Array.FindIndex(profiles, p => p.Id.Equals(CommandLineOptions.Default.ProfileId, StringComparison.InvariantCultureIgnoreCase)) : -1; switch (CommandLineOptions.Default.Action) { case HeliosStartupAction.SwitchProfile: SwitchProfile(profiles, profileIndex); break; case HeliosStartupAction.EditProfile: EditProfile(profiles, profileIndex); break; case HeliosStartupAction.CreateShortcut: CreateShortcut(profiles, profileIndex); break; default: IPCService.GetInstance().Status = InstanceStatus.User; Application.Run(new MainForm()); break; } } catch (Exception e) { MessageBox.Show( string.Format(Language.Operation_Failed, e.Message), Language.Fatal_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IHttpActionResult Update(int id, [FromBody] PCUpdateModel game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _pcService = new PCGameService(); _pcService.UpdatePCGame(id, game); return(Ok()); }
public PersonalCloud ToPersonalCloud(ILogger l, IPCService pcsrv) { return(new PersonalCloud(l, pcsrv, StorageProviders) { Id = Id, DisplayName = DisplayName, NodeDisplayName = NodeDisplayName, MasterKey = MasterKey, UpdateTimeStamp = TimeStamp, Apps = Apps }); }
private static void CreateShortcut(IReadOnlyList <Profile> profiles, int profileIndex) { if (profileIndex < 0) { throw new Exception(Language.Selected_profile_is_invalid_or_not_found); } IPCService.GetInstance().Status = InstanceStatus.User; new ShortcutForm(profiles[profileIndex]) { FileName = CommandLineOptions.Default.ExecuteFilename, SteamAppId = CommandLineOptions.Default.ExecuteSteamApp, Arguments = CommandLineOptions.Default.ExecuteArguments, ProcessName = CommandLineOptions.Default.ExecuteProcessName, Timeout = CommandLineOptions.Default.ExecuteProcessTimeout }.ShowDialog(); }
private static void EditProfile(IList <Profile> profiles, int profileIndex) { if (profileIndex < 0) { throw new Exception(Language.Selected_profile_is_invalid_or_not_found); } IPCService.GetInstance().Status = InstanceStatus.User; var editForm = new EditForm(profiles[profileIndex]); if (editForm.ShowDialog() == DialogResult.OK) { profiles[profileIndex] = editForm.Profile; } if (!Profile.SetAllProfiles(profiles)) { throw new Exception(Language.Failed_to_save_profile); } }
protected override void OnStartup(StartupEventArgs e) { ArgumentsHelper.SetArgs(e.Args); base.OnStartup(e); // Local method to enqueue connections specified with command-line argument bool EnqueueOpenRequestedConnections(IProcessCommander processCommander) { if (!ArgumentsHelper.HasConnectionSpecified) { return(false); } foreach (var conn in ArgumentsHelper.SpecifiedConnections) { MyLogger.Log($"Connection (Type: {conn.Type}, Id: {conn.ConnectionId}) has been enqueued."); processCommander.Invoke(conn.Type, conn.ConnectionId); } return(true); } if (SingleAppInstanceHelper.TryStart()) { // Boot as an IPC host var service = new ProcessCommander { ConnectionRequest = ConnectionRequest.Singleton, }; var serviceHost = IPCService.OpenServiceHost(service); EnqueueOpenRequestedConnections(service); } else { // Boot as an IPC client var channel = IPCService.CreateServiceChannel(); if (!EnqueueOpenRequestedConnections(channel)) { MyLogger.Log("Shutting down because another application instance has already run..."); } channel.Activate(); // Shutdown after activate the primary window Shutdown(); } }
public void StartIPCServer() { //LogableClass.ToLog("通道初始化", "准备建立");//启动所有需要获取的类 IPCService ipcsvr = new IPCService(); //ipcsvr.CreateChannel<LogInfo>(); //ipcsvr.CreateChannel<RemoteCommClass<ServiceSetting>>(); ////ipcsvr.CreateChannel<String>(); ////ipcsvr.CreateChannel<Dictionary<DateTime, string>>("LogDictionary"); ////ipcsvr.CreateChannel<GlobalClass>(); ////ipcsvr.CreateChannel<DataTable>(); ////ipcsvr.CreateChannel<ExchangeService>(); ////ipcsvr.CreateChannel<Dictionary<string, StragClass>>("StragClass"); ////ipcsvr.CreateChannel<Dictionary<string, StragRunPlanClass<T>>>("StragRunPlanClass"); ////ipcsvr.CreateChannel<Dictionary<string, CalcStragGroupClass<T>>>("CalcStragGroupClass"); ////ipcsvr.CreateChannel<Dictionary<string, ChanceClass<T>>>("ChanceClass"); ////ipcsvr.CreateChannel<LogInfo>(); //LogableClass.ToLog("通道初始化", "完成"); //RemoteCommClass<ServiceSetting>.SetRemoteInst(Program.AllServiceConfig); }
internal static bool GoProfile(Profile profile) { if (profile.IsActive) { return(true); } var instanceStatus = IPCService.GetInstance().Status; try { IPCService.GetInstance().Status = InstanceStatus.Busy; var failed = false; if (new SplashForm(() => { Task.Factory.StartNew(() => { if (!profile.Apply()) { failed = true; } }, TaskCreationOptions.LongRunning); }, 3, 30).ShowDialog() != DialogResult.Cancel) { if (failed) { throw new Exception(Language.Profile_is_invalid_or_not_possible_to_apply); } return(true); } return(false); } finally { IPCService.GetInstance().Status = instanceStatus; } }
public RootFileSystem(IPCService pcsrv) { Service = pcsrv; ClientList = new ConcurrentDictionary <string, IFileSystem>(); }
public PCWebServerAuth(string baseRoute, IPCService pcsrv) : base(baseRoute) { pCService = pcsrv; }
private static void Main(string[] args) { #region Single Instance and IPC bool hasAnotherInstance = !mutex.WaitOne(TimeSpan.Zero, true); // store args for further use Args = args; Parser.Default.ParseArguments <CommandLineOption>(args) .WithParsed(opt => Options = opt) .WithNotParsed(e => e.Output()); if (hasAnotherInstance) { if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { IPCService.RequestOpenUrl(Options.OpenUrl); } else { MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("Shadowsocks is already running.")); } return; } #endregion #region Enviroment Setup Directory.SetCurrentDirectory(WorkingDirectory); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); // .NET Framework 4.7.2 on Win7 compatibility ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; #endregion #region Compactibility Check // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) { MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."), "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check .NET Framework version if (!Utils.IsSupportedRuntimeVersion()) { if (DialogResult.OK == MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to {0} or later.", "4.7.2"), "Shadowsocks Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)) { Process.Start("https://dotnet.microsoft.com/download/dotnet-framework/net472"); } return; } #endregion #region Event Handlers Setup Utils.ReleaseMemory(true); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); #endregion #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); // Update online config Task.Run(async() => { await Task.Delay(10 * 1000); await MainController.UpdateAllOnlineConfig(); }); #region IPC Handler and Arguement Process IPCService ipcService = new IPCService(); Task.Run(() => ipcService.RunServer()); ipcService.OpenUrlRequested += (_1, e) => MainController.AskAddServerBySSURL(e.Url); if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { MainController.AskAddServerBySSURL(Options.OpenUrl); } #endregion Application.Run(); }
public ShareController(IFileSystem vfs, IPCService pcService) { pCService = pcService; fileSystem = vfs; }
// ReSharper disable once CyclomaticComplexity private static void SwitchProfile(IReadOnlyList <Profile> profiles, int profileIndex) { var rollbackProfile = Profile.GetCurrent(string.Empty); if (profileIndex < 0) { throw new Exception(Language.Selected_profile_is_invalid_or_not_found); } if (!profiles[profileIndex].IsPossible) { throw new Exception(Language.Selected_profile_is_not_possible); } if ( IPCClient.QueryAll() .Any( client => (client.Status == InstanceStatus.Busy) || (client.Status == InstanceStatus.OnHold))) { throw new Exception( Language .Another_instance_of_this_program_is_in_working_state_Please_close_other_instances_before_trying_to_switch_profile); } if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteFilename)) { if (!File.Exists(CommandLineOptions.Default.ExecuteFilename)) { throw new Exception(Language.Executable_file_not_found); } if (!GoProfile(profiles[profileIndex])) { throw new Exception(Language.Can_not_change_active_profile); } var process = Process.Start(CommandLineOptions.Default.ExecuteFilename, CommandLineOptions.Default.ExecuteArguments); var processes = new Process[0]; if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteProcessName)) { var ticks = 0; while (ticks < CommandLineOptions.Default.ExecuteProcessTimeout * 1000) { processes = Process.GetProcessesByName(CommandLineOptions.Default.ExecuteProcessName); if (processes.Length > 0) { break; } Thread.Sleep(300); ticks += 300; } } if (processes.Length == 0) { processes = new[] { process } } ; IPCService.GetInstance().HoldProcessId = processes.FirstOrDefault()?.Id ?? 0; IPCService.GetInstance().Status = InstanceStatus.OnHold; NotifyIcon notify = null; try { notify = new NotifyIcon { Icon = Properties.Resources.Icon, Text = string.Format( Language.Waiting_for_the_0_to_terminate, processes[0].ProcessName), Visible = true }; Application.DoEvents(); } catch { // ignored } foreach (var p in processes) { try { p.WaitForExit(); } catch { // ignored } } if (notify != null) { notify.Visible = false; notify.Dispose(); Application.DoEvents(); } IPCService.GetInstance().Status = InstanceStatus.Busy; if (!rollbackProfile.IsActive) { if (!GoProfile(rollbackProfile)) { throw new Exception(Language.Can_not_change_active_profile); } } } else if (CommandLineOptions.Default.ExecuteSteamApp > 0) { var steamGame = new SteamGame(CommandLineOptions.Default.ExecuteSteamApp); if (!SteamGame.SteamInstalled) { throw new Exception(Language.Steam_is_not_installed); } if (!File.Exists(SteamGame.SteamAddress)) { throw new Exception(Language.Steam_executable_file_not_found); } if (!steamGame.IsInstalled) { throw new Exception(Language.Steam_game_is_not_installed); } if (!steamGame.IsOwned) { throw new Exception(Language.Steam_game_is_not_owned); } if (!GoProfile(profiles[profileIndex])) { throw new Exception(Language.Can_not_change_active_profile); } var address = $"steam://rungameid/{steamGame.AppId}"; if (!string.IsNullOrWhiteSpace(CommandLineOptions.Default.ExecuteArguments)) { address += "/" + CommandLineOptions.Default.ExecuteArguments; } var steamProcess = Process.Start(address); // Wait for steam game to update and then run var ticks = 0; while (ticks < CommandLineOptions.Default.ExecuteProcessTimeout * 1000) { if (steamGame.IsRunning) { break; } Thread.Sleep(300); if (!steamGame.IsUpdating) { ticks += 300; } } IPCService.GetInstance().HoldProcessId = steamProcess?.Id ?? 0; IPCService.GetInstance().Status = InstanceStatus.OnHold; NotifyIcon notify = null; try { notify = new NotifyIcon { Icon = Properties.Resources.Icon, Text = string.Format( Language.Waiting_for_the_0_to_terminate, steamGame.Name), Visible = true }; Application.DoEvents(); } catch { // ignored } // Wait for the game to exit if (steamGame.IsRunning) { while (true) { if (!steamGame.IsRunning) { break; } Thread.Sleep(300); } } if (notify != null) { notify.Visible = false; notify.Dispose(); Application.DoEvents(); } IPCService.GetInstance().Status = InstanceStatus.Busy; if (!rollbackProfile.IsActive) { if (!GoProfile(rollbackProfile)) { throw new Exception(Language.Can_not_change_active_profile); } } } else { if (!GoProfile(profiles[profileIndex])) { throw new Exception(Language.Can_not_change_active_profile); } } } }
public IHttpActionResult GetAll() { _pcService = new PCGameService(); return(Ok(_pcService.GetPCGames())); }
public ShareController(Zio.IFileSystem fs, IPCService pcService, ILogger l) { logger = l; pCService = pcService; fileSystem = fs; }
public PCController(IPCService service) { _serv = service; }
static void Main(string[] args) { #region Single Instance and IPC bool hasAnotherInstance = !mutex.WaitOne(TimeSpan.Zero, true); // store args for further use Args = args; Parser.Default.ParseArguments <CommandLineOption>(args) .WithParsed(opt => Options = opt) .WithNotParsed(e => e.Output()); if (hasAnotherInstance) { if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { IPCService.RequestOpenUrl(Options.OpenUrl); } else { MessageBox.Show(I18N.GetString("Find Shadowsocks icon in your notify tray.") + Environment.NewLine + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."), I18N.GetString("Shadowsocks is already running.")); } return; } #endregion #region Enviroment Setup Directory.SetCurrentDirectory(WorkingDirectory); // todo: initialize the NLog configuartion Model.NLogConfig.TouchAndApplyNLogConfig(); #endregion #region Event Handlers Setup Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // handle UI exceptions Application.ThreadException += Application_ThreadException; // handle non-UI exceptions AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ApplicationExit += Application_ApplicationExit; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoStartup.RegisterForRestart(true); #endregion // See https://github.com/dotnet/runtime/issues/13051 // we have to do this for self-contained executables Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)); // We would use this in v5. // Parameters would have to be dropped from views' constructors (VersionUpdatePromptView) //Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly()); // Workaround for hosting WPF controls in a WinForms app. // We have to manually set the culture for the LocalizeDictionary instance. // https://stackoverflow.com/questions/374518/localizing-a-winforms-application-with-embedded-wpf-user-controls // https://stackoverflow.com/questions/14668640/wpf-localize-extension-translate-window-at-run-time LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture; #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); if (File.Exists(privoxyLogFilename)) { using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } } #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); HotKeys.Init(MainController); MainController.Start(); // Update online config Task.Run(async() => { await Task.Delay(10 * 1000); await MainController.UpdateAllOnlineConfig(); }); #region IPC Handler and Arguement Process IPCService ipcService = new IPCService(); Task.Run(() => ipcService.RunServer()); ipcService.OpenUrlRequested += (_1, e) => MainController.AskAddServerBySSURL(e.Url); if (!string.IsNullOrWhiteSpace(Options.OpenUrl)) { MainController.AskAddServerBySSURL(Options.OpenUrl); } #endregion Application.Run(); }