public void WriteToActivityLog(string message, string stackTrace)
 {
     try
     {
         _log?.LogEntry(3, "VsExtAutoShelvePackage", string.Format(CultureInfo.CurrentCulture, "Message: {0} Stack Trace: {1}", message, stackTrace));
     }
     catch
     {
         // swallow exceptions
     }
 }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task LogAsync(string message, string source, LogType logType)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsActivityLog log = serviceProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            if (log == null)
            {
                return;
            }
            int hr = log.LogEntry((UInt32)ToEntryType(logType), source, message);
        }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task LogAsync(string message, string source, Exception e)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            string         format = "Message: {0} \n Exception Message: {1} \n Stack Trace: {2}";
            IVsActivityLog log    = serviceProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            if (log == null)
            {
                return;
            }
            int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, source, string.Format(CultureInfo.CurrentCulture, format, message, e.Message, e.StackTrace));
        }
Ejemplo n.º 4
0
        private void LogError(string message)
        {
            try {
                IVsActivityLog _log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;

                _log.LogEntry(
                    (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                    this.ToString(),
                    string.Format(CultureInfo.CurrentCulture, "{0}", message));
            }
            catch (Exception) {
                // there was likely an error getting the activity service, ignore it so it won't throw
            }
        }
Ejemplo n.º 5
0
        private void LogInfo(string text)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsActivityLog log = this.GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            if (log == null)
            {
                return;
            }

            log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                         this.ToString(),
                         text);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a log message to the activity log.
        /// </summary>
        /// <param name="message"></param>
        internal void Log(string message)
        {
            IVsActivityLog log = this.ActivityLog;

            if (log != null)
            {
                log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), message);
            }
            else
            {
#if DEBUG
                Trace.WriteLine("Failed to log: " + message);
#endif
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new log entry
        /// </summary>
        /// <param name="type">Category of the entry</param>
        /// <param name="message">Message</param>
        public static void Log(EntryType type, string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (Source == null)
            {
                throw new InvalidOperationException("ActivityLogger is not sufficiently initialized.");
            }

            int hr = logService.LogEntry((uint)type, Source, message);

            Marshal.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            IVsActivityLog log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            log.LogEntry(3, "Octane", "Started Octane plugin");

            MainWindowCommand.Initialize(this);
            base.Initialize();
            OctaneCommand.Initialize(this);

            var optionsPage = (ConnectionSettings)GetDialogPage(typeof(ConnectionSettings));

            optionsPage.LoadSettingsFromStorage();

            optionsPage.setOldCredentials();
        }
Ejemplo n.º 9
0
 public SdkPage()
 {
     try
     {
         plcncliCommunication = Package.GetGlobalService(typeof(SPlcncliCommunication)) as IPlcncliCommunication;
         model       = new SDKPageModel(plcncliCommunication);
         viewModel   = new SDKPageViewModel(model);
         PageControl = new SDKPageControl(viewModel);
     }
     catch (Exception e)
     {
         ThreadHelper.ThrowIfNotOnUIThread();
         IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
         log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(),
                      "An error occurred while creating the sdk page: " + e.Message);
     }
 }
Ejemplo n.º 10
0
            private void Log(string text, __ACTIVITYLOG_ENTRYTYPE type)
            {
                if (!this.IsForeground())
                {
                    this.InvokeBelowInputPriority(() => Log(text, type));
                    return;
                }

                AssertIsForeground();
                _activityLog?.LogEntry((uint)type, HostId, text);

                // Keep a running in memory log as well for debugging purposes.
                s_log.AddLast(text);
                while (s_log.Count > 100)
                {
                    s_log.RemoveFirst();
                }
            }
Ejemplo n.º 11
0
        public void ReinitializeControl()
        {
            try
            {
                model.Initialize();
                viewModel.Initialize();
            }
            catch (Exception e)
            {
                if (ThreadHelper.CheckAccess())
                {
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
                    IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                    log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(),
                                 "An error occurred while loading the sdk page: " + e.Message);
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
                }
            }
        }
Ejemplo n.º 12
0
 public SDKPageControl(SDKPageViewModel viewModel)
 {
     this.DataContext = viewModel;
     try
     {
         InitializeComponent();
     }
     catch (Exception e)
     {
         ThreadHelper.ThrowIfNotOnUIThread();
         IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
         if (log == null)
         {
             return;
         }
         log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(),
                      "Component initialization failed: " + e.Message);
     }
 }
Ejemplo n.º 13
0
        void IProgressErrorNotifier.Notify(Exception ex)
        {
            if (ex == null)
            {
                throw new ArgumentNullException(nameof(ex));
            }

            VsThreadingHelper.RunInline(this.serviceProvider, VsTaskRunContext.UIThreadNormalPriority, () =>
            {
                IVsActivityLog log = (IVsActivityLog)this.serviceProvider.GetService(typeof(SVsActivityLog));
                if (log != null)
                {
                    log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.entrySource, ProgressControllerHelper.FormatErrorMessage(ex, messageFormat, logWholeMessage));
                }
                else
                {
                    Debug.Fail("Cannot find SVsActivityLog");
                }
            });
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 写入日志到磁盘
        /// </summary>
        /// <param name="message"></param>
        private void WriteLog(string message)
        {
            /**
             * 运行 Visual Studio 中使用/log命令行开关在会话期间将 ActivityLog.xml 写入到磁盘。
             * 关闭 Visual Studio 后, 找到活动日志的子文件夹中的 Visual Studio 数据: %appdata%\Microsoft\VisualStudio\15.0\ActivityLog.xml。
             * **/

            ThreadHelper.ThrowIfNotOnUIThread();

            IVsActivityLog log = ThreadHelper.JoinableTaskFactory.Run <object>(new Func <Task <object> >(() => this.ServiceProvider.GetServiceAsync(typeof(SVsActivityLog)))) as IVsActivityLog;

            if (log == null)
            {
                return;
            }

            int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                                  this.ToString(),
                                  message);
        }
Ejemplo n.º 15
0
        private static void LogException(
            IVsActivityLog log,
            string message,
            string path,
            Exception ex,
            IEnumerable <object> data = null
            )
        {
            if (log == null)
            {
                return;
            }

            var fullMessage = string.Format("{1}:{0}{2}{0}{3}",
                                            Environment.NewLine,
                                            message,
                                            ex,
                                            data == null ? string.Empty : string.Join(Environment.NewLine, data)
                                            ).Trim();

            if (string.IsNullOrEmpty(path))
            {
                log.LogEntry(
                    (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                    "Python Tools",
                    fullMessage
                    );
            }
            else
            {
                log.LogEntryPath(
                    (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                    "Python Tools",
                    fullMessage,
                    path
                    );
            }
        }
Ejemplo n.º 16
0
        private void HandleSave(string name, string kind, string projectPath)
        {
            try
            {
                // add file to commit!
                if (provider.CopyFileToCache(name, projectPath))
                {
                    // commit to git...
                    var commitId = provider.Commit(kind);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                IVsActivityLog log = autogitPackage.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                if (log == null)
                {
                    return;
                }

                int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                                      this.ToString(), ex.Message + ":" + name + ":" + kind);
            }
        }
Ejemplo n.º 17
0
        public int OnAfterSave(uint docCookie)
        {
            try
            {
                if (vcProject == null || string.IsNullOrEmpty(projectDirectory) || wrapper == null)
                {
                    return(VSConstants.S_OK);
                }

                UpdateIncludesOnAfterSave();
                SaveAndReset();
                ProjectIncludesManager.AddTargetsFileToOldProjects(vcProject);
                vcProject = null;
                return(VSConstants.S_OK);
            }
            catch (Exception e)
            {
                Reset();
                try
                {
                    ThreadHelper.ThrowIfNotOnUIThread();
                    IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                    log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(),
                                 "An error occurred while updating the includes: " + e.Message + e.StackTrace);
                }
                catch (Exception) { /*try to log error in activity log*/ }
                return(VSConstants.S_OK);
            }

            void SaveAndReset()
            {
                projectDirectory = string.Empty;
                wrapper          = null;
                vcProject.Save();
            }
        }
Ejemplo n.º 18
0
        private void LogMessageWriteLineFormat(string message, params object[] args)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            string fullMessage = string.Format(message, args);

            Trace.WriteLine(fullMessage);
            Debug.WriteLine(fullMessage);

            IVsActivityLog log = this.GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            if (log == null)
            {
                return;
            }

            int hr = log.LogEntry(
                (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                this.ToString(),
                fullMessage);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// The event explorer user control constructor.
        /// </summary>
        public RdtEventControl()
        {
            InitializeComponent();

            // Create a selection container for tracking selected RDT events.
            selectionContainer = new MsVsShell.SelectionContainer();

            // Advise the RDT of this event sink.
            IOleServiceProvider sp =
                Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            if (sp == null)
            {
                return;
            }

            rdt = new RunningDocumentTable(new ServiceProvider(sp));
            if (rdt == null)
            {
                return;
            }

            rdtCookie = rdt.Advise(this);

            // Obtain the single instance of the options via automation.
            try
            {
                DTE dte = (DTE)Package.GetGlobalService(typeof(DTE));

                EnvDTE.Properties props =
                    dte.get_Properties("RDT Event Explorer", "Explorer Options");

                IOptions o = props.Item("ContainedOptions").Object as IOptions;
                options = (Options)o;
            }
            catch
            {
                IVsActivityLog log = Package.GetGlobalService(
                    typeof(SVsActivityLog)) as IVsActivityLog;
                if (log != null)
                {
                    log.LogEntry(
                        (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                        this.ToString(),
                        string.Format(CultureInfo.CurrentCulture,
                                      "RdtEventExplorer could not obtain properties via automation: {0}",
                                      this.ToString())
                        );
                }
                options = new Options();
            }
            // Prepare the event grid.
            eventGrid.AutoGenerateColumns = false;
            eventGrid.AllowUserToAddRows  = false;
            eventGrid.SelectionMode       = DataGridViewSelectionMode.FullRowSelect;

            eventGrid.Columns.Add("Event", Resources.EventHeader);
            eventGrid.Columns.Add("Moniker", Resources.MonikerHeader);
            eventGrid.Columns["Event"].ReadOnly   = true;
            eventGrid.Columns["Moniker"].ReadOnly = true;

            eventGrid.AllowUserToResizeRows    = false;
            eventGrid.AllowUserToResizeColumns = true;
            eventGrid.AutoSizeColumnsMode      = DataGridViewAutoSizeColumnsMode.Fill;

            int x = Screen.PrimaryScreen.Bounds.Size.Width;
            int y = Screen.PrimaryScreen.Bounds.Size.Height;

            Size = new Size(x / 3, y / 3);
        }
Ejemplo n.º 20
0
        private static void LogException(
            IVsActivityLog log,
            string message,
            string path,
            Exception ex,
            IEnumerable<object> data = null
        ) {
            if (log == null) {
                return;
            }

            var fullMessage = string.Format("{1}:{0}{2}{0}{3}",
                Environment.NewLine,
                message,
                ex,
                data == null ? string.Empty : string.Join(Environment.NewLine, data)
            ).Trim();

            if (string.IsNullOrEmpty(path)) {
                log.LogEntry(
                    (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                    "Python Tools",
                    fullMessage
                );
            } else {
                log.LogEntryPath(
                    (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                    "Python Tools",
                    fullMessage,
                    path
                );
            }
        }
Ejemplo n.º 21
0
        public async Task QuickRefreshNodesGlyphs(IVsSccProject2 project, List <string> files)
        {
            try
            {
                if (files.Count > 0)
                {
                    string[] rgpszFullPaths = new string[files.Count];
                    for (int i = 0; i < files.Count; i++)
                    {
                        rgpszFullPaths[i] = files[i];
                    }

                    VsStateIcon[] rgsiGlyphs    = new VsStateIcon[files.Count];
                    uint[]        rgdwSccStatus = new uint[files.Count];
                    GetSccGlyph(files.Count, rgpszFullPaths, rgsiGlyphs, rgdwSccStatus);

                    uint[] rguiAffectedNodes = new uint[files.Count];

                    //TODO We could/Should cache this mapping !!!!
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    IList <uint> subnodes = await SolutionExtensions.GetProjectItems((IVsHierarchy)project, VSConstants.VSITEMID_ROOT);

                    var dict = new Dictionary <string, uint>();
                    var proj = project as IVsProject2;

                    foreach (var id in subnodes)
                    {
                        string docname;
                        var    res = proj.GetMkDocument(id, out docname);

                        if (res == VSConstants.S_OK && !string.IsNullOrEmpty(docname))
                        {
                            dict[docname] = id;
                        }
                    }

                    for (int i = 0; i < files.Count; ++i)
                    {
                        uint id;
                        if (dict.TryGetValue(files[i], out id))
                        {
                            rguiAffectedNodes[i] = id;
                        }
                    }
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    project.SccGlyphChanged(files.Count, rguiAffectedNodes, rgsiGlyphs, rgdwSccStatus);
                }
            }
            catch (Exception ex)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsActivityLog log = _sccProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;
                if (log == null)
                {
                    return;
                }

                int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
                                      ex.StackTrace,
                                      string.Format(CultureInfo.CurrentCulture,
                                                    "Called for: {0}", this.ToString()));
            }
        }
Ejemplo n.º 22
0
        private void UpdateIncludesOnBeforeSave(VCProject p, string projectDirectory)
        {
            var(includesSaved, macrosSaved) = ProjectIncludesManager.CheckSavedIncludesAndMacros(p);
            IEnumerable <string> includesBefore            = null;
            IEnumerable <CompilerMacroResult> macrosBefore = null;

            try
            {
                ThreadHelper.JoinableTaskFactory.Run("Updating includes and macros", async(progress) =>
                {
                    await Task.Run(() => GetIncludesAndMacros());

                    void GetIncludesAndMacros()
                    {
                        if (!includesSaved)
                        {
                            progress.Report(new ThreadedWaitDialogProgressData("Fetching project information"));
                            ProjectInformationCommandResult projectInformationBefore = null;
                            try
                            {
                                projectInformationBefore = cliCommunication.ExecuteCommand(Resources.Command_get_project_information, null,
                                                                                           typeof(ProjectInformationCommandResult), Resources.Option_get_project_information_project,
                                                                                           $"\"{projectDirectory}\"") as ProjectInformationCommandResult;
                            }
                            catch (PlcncliException ex)
                            {
                                projectInformationBefore = cliCommunication.ConvertToTypedCommandResult <ProjectInformationCommandResult>(ex.InfoMessages);
                            }
                            includesBefore = projectInformationBefore?.IncludePaths.Select(x => x.PathValue);
                            if (includesBefore == null)
                            {
                                includesBefore = Enumerable.Empty <string>();
                            }
                        }

                        if (!macrosSaved)
                        {
                            progress.Report(new ThreadedWaitDialogProgressData("Fetching compiler information"));

                            CompilerSpecificationCommandResult compilerSpecsBefore = null;
                            try
                            {
                                compilerSpecsBefore = cliCommunication.ExecuteCommand(Resources.Command_get_compiler_specifications, null,
                                                                                      typeof(CompilerSpecificationCommandResult), Resources.Option_get_compiler_specifications_project,
                                                                                      $"\"{projectDirectory}\"") as CompilerSpecificationCommandResult;
                            }
                            catch (PlcncliException ex)
                            {
                                compilerSpecsBefore = cliCommunication.ConvertToTypedCommandResult <CompilerSpecificationCommandResult>(ex.InfoMessages);
                            }
                            macrosBefore = compilerSpecsBefore?.Specifications.FirstOrDefault()
                                           ?.CompilerMacros.Where(m => !m.Name.StartsWith("__has_include(")) ?? Enumerable.Empty <CompilerMacroResult>();
                        }
                    }
                });

                this.vcProject        = p;
                this.projectDirectory = p.ProjectDirectory;
                this.wrapper          = new IncludesAndMacrosWrapper(includesBefore, macrosBefore);
            }
            catch (Exception e)
            {
                Reset();
                try
                {
                    ThreadHelper.ThrowIfNotOnUIThread();
                    IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
                    log.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, this.ToString(),
                                 "An error occurred while updating the includes: " + e.Message + e.StackTrace);
                }
                catch (Exception) { /*try to log error in activity log*/ }
            }
        }
 public static void LogInformation(this IVsActivityLog logger, string packageName, string message)
 {
     logger.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, packageName, message);
 }
 public static void LogWarning(this IVsActivityLog logger, string packageName, string message)
 {
     logger.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING, packageName, message);
 }
Ejemplo n.º 25
0
        public async Task Info(string message)
        {
            await _joinableTaskFactory.SwitchToMainThreadAsync();

            _logger?.LogEntry((uint)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, "EditorConfig enforcer", message);
        }
Ejemplo n.º 26
0
 private static void LogToActivityLog(string message, __ACTIVITYLOG_ENTRYTYPE type)
 {
     _activityLog.LogEntry((uint)type, Vsix.Name, message);
 }