public IniFile(string path) { if (OSUtil.IsWindows() == false) { throw new Exception("This class can be only use on win os."); } this.path = path; }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (!DesignMode && OSUtil.IsWindowsVistaOrLater()) { NativeMethods.SetWindowTheme(Handle, "explorer", null); } }
public async Task Fact_OnMTAThread() { var expectedApartment = OSUtil.IsWindows() ? ApartmentState.MTA : ApartmentState.Unknown; Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); await Task.Yield(); Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); }
protected override IEnumerable <IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { if (testMethod.Method.ReturnType.Name == "System.Void" && testMethod.Method.GetCustomAttributes(typeof(AsyncStateMachineAttribute)).Any()) { yield return(new ExecutionErrorTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, "Async void methods are not supported.")); } yield return(OSUtil.IsWindows() ? (IXunitTestCase) new UITheoryTestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) : new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "STA threads only exist on Windows.")); }
public async Task UIFact_OnSTAThread() { int initialThread = Environment.CurrentManagedThreadId; Assert.NotNull(SynchronizationContext.Current); var expectedApartment = OSUtil.IsWindows() ? ApartmentState.STA : ApartmentState.Unknown; Assert.Equal(expectedApartment, Thread.CurrentThread.GetApartmentState()); await Task.Yield(); Assert.Equal(initialThread, Environment.CurrentManagedThreadId); Assert.NotNull(SynchronizationContext.Current); }
static AppRuntimeContext() { string path; try { path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); } catch (NotSupportedException) { path = Directory.GetCurrentDirectory(); } _executingPath = path; if (OSUtil.IsMacOS()) { _executingPath = path.Replace("file:", string.Empty); } if (OSUtil.IsWindows()) { _executingPath = new Uri(path).LocalPath; } }
private static Task <decimal> RunOnStaIfPossibleOtherwiseUseMta(Func <decimal> action) { if (OSUtil.IsWindows()) { var tcs = new TaskCompletionSource <decimal>(); var sta = new Thread(() => { try { tcs.SetResult(action()); } catch (Exception ex) { tcs.SetException(ex); } }); sta.SetApartmentState(ApartmentState.STA); sta.Start(); return(tcs.Task); } return(Task.Run(action)); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { string extension = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetExtension(OSUtil.GetValidFileName(headers.ContentDisposition.FileName)) : ""; return(Guid.NewGuid().ToString() + extension); }
static void Main(string[] args) { //application state trackers bool shutdown = false; bool serverstarted = false; bool clientstarted = false; os_util = new OSUtil(); //Intialize your settings and settings file //Settings. intSettings = new Settings(); String path = Directory.GetCurrentDirectory(); String setFile = @"\settings.xml"; String ComPath = path + setFile; var registry = new Registry(); registry = _repository.GetRegistry(); registry.Status = "ON"; registry.ErrorMessage = ""; registry.ErrorState = ""; registry.HeartBeat = System.DateTime.Now; _repository.CreateRegistry(registry); // set timer to mantain the heartBeat now _timerHeartBeat.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed); _timerHeartBeat.Interval = 15000; _timerHeartBeat.Start(); //Check for config file and if it doesn't exist then create it if (File.Exists(ComPath)) { Settings intSet = Settings._instance.Deserialize(ComPath); Settings._instance = intSet; } else { //Might want to end here or do something with no config Settings._instance.Serialize(ComPath, Settings._instance); // to shut down just call os_server.Stop(); } if (Settings._instance.Type.ToUpper().Trim() == "SERVER") { os_server = new OSServer(_repository); bool started = os_server.Start(); if (!started) { ErrorHandler._ErrorHandler.LogInfo(os_server.GetLastError()+ "-Failed to Start Server."); } else { ErrorHandler._ErrorHandler.LogInfo(string.Format("Server started successfully.\nRunning on Port:{0} and IP:{1}", Settings._instance.LocalPort, Settings._instance.LocalIPAddress)); serverstarted = true; } } if (Settings._instance.Type.ToUpper().Trim() == "CLIENT") { var os_client = new OSClient(_repository); os_client.fileWatcherStart(); bool connected = os_client.Connect(Settings._instance.RemoteIPAddress, Convert.ToInt32(Settings._instance.RemotePort)); if (!connected) { ErrorHandler._ErrorHandler.LogInfo("Failed to Start Client."); } else { ErrorHandler._ErrorHandler.LogInfo(string.Format("Client started successfully.\nRunning on Port:{0} and IP:{1}", Settings._instance.RemoteIPAddress, Settings._instance.RemotePort)); //connected = true; clientstarted = true; os_client.StarStopTimer("Stop"); os_client.SendMessages(); os_client.StarStopTimer("START"); } } while (!shutdown) { string userinput = Console.ReadLine(); if (!string.IsNullOrEmpty(userinput)) { switch (os_util.ParseCommand(userinput)) { case OSUtil.os_cmd.OS_EXIT: { if (serverstarted) { registry.Status = "OFF"; registry.HeartBeat = System.DateTime.Now; _repository.CreateRegistry(registry); os_server.Stop(); } if (clientstarted) { os_client.DisConnect(); registry.Status = "OFF"; registry.HeartBeat = System.DateTime.Now; _repository.CreateRegistry(registry); } shutdown = true; break; } } } } }
protected override IEnumerable <IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { yield return(OSUtil.IsWindows() ? (IXunitTestCase) new UITheoryTestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) : new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WinForms only exists on Windows.")); }