/// <summary>
        /// Initialize the simple logger by passing in a logging handler.
        /// </summary>
        /// <param name="handler">The logging handler must be type of LoggingHandler</param>
        public static void Init(LoggingHandler handler)
        {
            lock (locker)
            {

                if (null != instance)
                {
                    throw new InvalidOperationException("SimpleLogger has been initialized.");
                }

                instance = new SimpleLogger(handler);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            ILogger logger = new SimpleLogger("processservice.log");
            logger.Log("startup", "-------- Starting Dryad Process Service --------");

            var directory = Directory.GetCurrentDirectory();

            if (!GetEnvironmentDetails(logger))
            {
                logger.Log("Failed to read environment variables");
                logger.Stop();
                return;
            }

            XDocument config;
            try
            {
                string configFile = args[0];
                logger.Log("Opening config file " + configFile);
                config = XDocument.Load(configFile);
                logger.Log("Opened config file " + configFile);
            }
            catch (Exception e)
            {
                logger.Log("Failed to read config file: " + e.ToString());
                logger.Stop();
                return;
            }

            using (var processService = new ProcessService(logger))
            {
                string processUri;
                string fileUri;

                logger.Log("starting process service");
                if (processService.Start(config, groupName, identifier, out processUri, out fileUri))
                {
                    logger.Log("done starting process service");

                    if (!RendezvousWithParent(processUri, fileUri, directory, logger))
                    {
                        processService.ShutDown();
                    }
                }
                else
                {
                    logger.Log("process service start failed");
                }

                logger.Log("waiting for process service to exit");
                processService.WaitForExit();
                logger.Log("process service has exited");
            }

            logger.Log("-------- Stopping Dryad Process Service --------");
            logger.Stop();
        }
        protected void configureSMLogger()
        {
            SimpleLogger wl = new SimpleLogger();
            wl.Log = Log;

            Logger = wl;
        }
        public void ResolveConflictsPerTF(string rootPath)
        {
            try
            {
                _attachedFrames.Clear();
                string pathToTools = Environment.GetEnvironmentVariable("VS140COMNTOOLS");
                if (String.IsNullOrEmpty(pathToTools))
                {
                    pathToTools = Environment.GetEnvironmentVariable("VS150COMNTOOLS");
                }
                if (String.IsNullOrEmpty(pathToTools))
                {
                    pathToTools = Environment.GetEnvironmentVariable("VS130COMNTOOLS");
                }
                if (String.IsNullOrEmpty(pathToTools))
                {
                    pathToTools = Environment.GetEnvironmentVariable("VS100COMNTOOLS");
                }
                if (String.IsNullOrEmpty(pathToTools))
                {
                    throw new Exception("VS1X0COMNTOOLS not found");
                }
                string pathToTF = Path.GetFullPath(Path.Combine(pathToTools, "..\\IDE\\TF.exe"));

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.WorkingDirectory = rootPath;
                psi.Arguments        = "resolve /recursive /prompt";
                psi.FileName         = pathToTF;
                psi.CreateNoWindow   = true;
                psi.UseShellExecute  = false;
                Process p      = Process.Start(psi);
                bool    hasSet = false;

                while (!p.WaitForExit(10))
                {
                    SetMergeDiffWindowsToFloatOnly();

                    bool setForeground = true;
                    foreach (EnvDTE.Window w1 in Dte.Windows)
                    {
                        EnvDTE80.Window2 window = w1 as EnvDTE80.Window2;
                        if (window.Caption.StartsWith("Merge - ") || window.Caption.StartsWith("Diff - "))
                        {
                            if (!hasSet || window.WindowState != EnvDTE.vsWindowState.vsWindowStateMaximize)
                            {
                                hasSet             = true;
                                window.IsFloating  = true;
                                window.WindowState = EnvDTE.vsWindowState.vsWindowStateMaximize;
                            }
                            setForeground = false;
                        }
                    }
                    if (setForeground)
                    {
                        var  foregroundWindow  = GetForegroundWindow();
                        var  mainWindowHandle  = Process.GetCurrentProcess().MainWindowHandle;
                        uint foregroundProcess = 0;
                        uint mainWindowProcess = 0;
                        GetWindowThreadProcessId(foregroundWindow, out foregroundProcess);
                        GetWindowThreadProcessId(mainWindowHandle, out mainWindowProcess);

                        if (foregroundProcess == mainWindowProcess)
                        {
                            SetForegroundWindow(p.MainWindowHandle);
                        }
                    }
                    Application.DoEvents();
                }

                foreach (var frame in _attachedFrames.Keys)
                {
                    frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, null);
                }
                _attachedFrames.Clear();
            }
            catch (Exception ex)
            {
                SimpleLogger.Log(ex, true);
            }
        }
        private void SetMergeDiffWindowsToFloatOnly()
        {
            if (vMergePackage.MergeToolWindowIsVisible)
            {
                return;
            }

            IVsWindowFrame[]  frames = new IVsWindowFrame[1];
            uint              numFrames;
            IEnumWindowFrames ppenum;

            UIShell.GetDocumentWindowEnum(out ppenum);

            while (ppenum.Next(1, frames, out numFrames) == VSConstants.S_OK && numFrames == 1)
            {
                var    frame = frames[0] as IVsWindowFrame;
                object title;
                frame.GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out title);
                var window = VsShellUtilities.GetWindowObject(frame);

                if (window.Caption.StartsWith("Merge - ") || window.Caption.StartsWith("Diff - "))
                {
                    if (!_attachedFrames.ContainsKey(frame))
                    {
                        window.IsFloating = true;
                        var windowEvents = new ToolWindowEvents(frame);
                        windowEvents.OnDockableChange = (fDockable, x, y, w, h) =>
                        {
                            if (_attachedFrames.ContainsKey(frame) && !_attachedFrames[frame])
                            {
                                try
                                {
                                    _attachedFrames[frame] = true;
                                    if (fDockable)
                                    {
                                        window.IsFloating = true;
                                    }
                                }
                                catch (Exception)
                                {
                                }
                                finally
                                {
                                    _attachedFrames[frame] = false;
                                }
                            }
                            return(VSConstants.S_OK);
                        };
                        windowEvents.OnClose = (options) =>
                        {
                            windowEvents.OnDockableChange = null;
                            windowEvents.OnClose          = null;
                            _attachedFrames.Remove(frame);
                            windowEvents.Dispose();
                            return(VSConstants.S_OK);
                        };
                        try
                        {
                            frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, windowEvents);
                            _attachedFrames[frame] = false;
                        }
                        catch (Exception ex)
                        {
                            SimpleLogger.Log(ex, true);
                        }
                    }
                }
            }
        }
        public bool ShowDifferencesPerTF(string rootPath, string sourcePath, string targetPath)
        {
            try
            {
                _attachedFrames.Clear();
                string pathToTools = Environment.GetEnvironmentVariable("VS120COMNTOOLS");
                string pathToTF    = Path.GetFullPath(Path.Combine(pathToTools, "..\\IDE\\TF.exe"));

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.WorkingDirectory = rootPath;
                psi.Arguments        = String.Format("diff \"{0}\" \"{1}\"", sourcePath, targetPath);
                psi.FileName         = pathToTF;
                psi.CreateNoWindow   = true;
                psi.UseShellExecute  = false;
                Process p      = Process.Start(psi);
                bool    hasSet = false;

                while (!p.WaitForExit(10))
                {
                    SetMergeDiffWindowsToFloatOnly();

                    bool setForeground = true;
                    foreach (EnvDTE.Window w1 in Dte.Windows)
                    {
                        EnvDTE80.Window2 window = w1 as EnvDTE80.Window2;
                        if (window.Caption.StartsWith("Merge - ") || window.Caption.StartsWith("Diff - "))
                        {
                            if (!hasSet || window.WindowState != EnvDTE.vsWindowState.vsWindowStateMaximize)
                            {
                                hasSet             = true;
                                window.IsFloating  = true;
                                window.WindowState = EnvDTE.vsWindowState.vsWindowStateMaximize;
                            }
                            setForeground = false;
                        }
                    }
                    if (setForeground)
                    {
                        var  foregroundWindow  = GetForegroundWindow();
                        var  mainWindowHandle  = Process.GetCurrentProcess().MainWindowHandle;
                        uint foregroundProcess = 0;
                        uint mainWindowProcess = 0;
                        GetWindowThreadProcessId(foregroundWindow, out foregroundProcess);
                        GetWindowThreadProcessId(mainWindowHandle, out mainWindowProcess);

                        if (foregroundProcess == mainWindowProcess)
                        {
                            SetForegroundWindow(p.MainWindowHandle);
                        }
                    }
                    Application.DoEvents();
                }

                foreach (var frame in _attachedFrames.Keys)
                {
                    frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, null);
                }
                _attachedFrames.Clear();

                if (p.ExitCode == 100)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SimpleLogger.Log(ex, true);
            }
            return(true);
        }
Example #7
0
        /// <summary>
        ///     Web ブラウザを開く
        /// </summary>
        /// <param name="uri">Uri</param>
        public void OpenUri(string uri)
        {
            SimpleLogger.WriteLine(string.Format("open to {0}", uri));

            UIApplication.SharedApplication.OpenUrl(new NSUrl(uri));
        }
 /// <summary>
 /// Stop the agent execution
 /// </summary>
 private void Stop(object sender, EventArgs e)
 {
     SimpleLogger.Information("On stop Cancellation was requested, Disposing...", sendAsDiagnostic: true);
     Dispose();
 }
 /// <summary>
 /// Report an error when an exception goes unhandled
 /// </summary>
 private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
 {
     SimpleLogger.Fatal("An exception was not handled", exception: (Exception)e.ExceptionObject);
 }
Example #10
0
        public virtual void Initialize(IChromelyContainer container, IChromelyAppSettings appSettings, IChromelyConfiguration config, IChromelyLogger chromelyLogger)
        {
            EnsureExpectedWorkingDirectory();

            #region Container

            _container = container;
            if (_container == null)
            {
                _container = new SimpleContainer();
            }

            #endregion

            #region Configuration

            if (config == null)
            {
                var configurator = new ConfigurationHandler();
                config = configurator.Parse <DefaultConfiguration>();
            }

            if (config == null)
            {
                config = DefaultConfiguration.CreateForRuntimePlatform();
            }

            InitConfiguration(config);
            config.Platform = ChromelyRuntime.Platform;

            #endregion

            #region Application/User Settings

            if (appSettings == null)
            {
                appSettings = new DefaultAppSettings(config.AppName);
            }

            var currentAppSettings = new CurrentAppSettings();
            currentAppSettings.Properties = appSettings;
            ChromelyAppUser.App           = currentAppSettings;
            ChromelyAppUser.App.Properties.Read(config);

            #endregion

            #region Logger

            if (chromelyLogger == null)
            {
                chromelyLogger = new SimpleLogger();
            }

            var defaultLogger = new DefaultLogger();
            defaultLogger.Log = chromelyLogger;
            Logger.Instance   = defaultLogger;

            #endregion

            // Register all primary objects
            _container.RegisterInstance(typeof(IChromelyContainer), typeof(IChromelyContainer).Name, _container);
            _container.RegisterInstance(typeof(IChromelyAppSettings), typeof(IChromelyAppSettings).Name, appSettings);
            _container.RegisterInstance(typeof(IChromelyConfiguration), typeof(IChromelyConfiguration).Name, config);
            _container.RegisterInstance(typeof(IChromelyLogger), typeof(IChromelyLogger).Name, chromelyLogger);
        }