Example #1
0
        public void Write(string operation, string level, string message)
        {
            _counter++;

            string unwanted = "Chem4Word.V3.";

            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }
            unwanted = "Chem4WordV3.";
            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }
            unwanted = "Chem4Word.";
            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }

            try
            {
                string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                               $@"Chem4Word.V3\Telemetry\{SafeDate.ToIsoShortDate(DateTime.Now)}.log");
                using (StreamWriter w = File.AppendText(fileName))
                {
                    string logMessage = $"[{SafeDate.ToShortTime(DateTime.Now)}] {operation} - {level} - {message}";
                    w.WriteLine(logMessage);
                }
            }
            catch
            {
                //
            }

            if (_permissionGranted)
            {
                WritePrivate(operation, level, message);

                if (!_systemInfoSent)
                {
                    if (_helper.IpAddress != null && !_helper.IpAddress.Contains("0.0.0.0"))
                    {
                        WriteStartUpInfo();
                    }
                }
            }
        }
Example #2
0
        public void WriteMessage(ServiceBusMessage message)
        {
            try
            {
                BrokeredMessage bm = new BrokeredMessage(message.Message);
                bm.Properties["PartitionKey"]     = message.PartitionKey;
                bm.Properties["RowKey"]           = message.RowKey;
                bm.Properties["Chem4WordVersion"] = message.AssemblyVersionNumber;
                bm.Properties["MachineId"]        = message.MachineId;
                bm.Properties["Operation"]        = message.Operation;
                bm.Properties["Level"]            = message.Level;
#if DEBUG
                bm.Properties["IsDebug"] = "True";
#endif
                _client.Send(bm);
                // Small sleep between each message
                Thread.Sleep(25);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception in WriteMessage: {ex.Message}");

                try
                {
                    string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                   $@"Chem4Word.V3\Telemetry\{SafeDate.ToIsoShortDate(DateTime.Now)}.log");
                    using (StreamWriter w = File.AppendText(fileName))
                    {
                        w.WriteLine($"[{SafeDate.ToShortTime(DateTime.Now)}] Exception in WriteMessage: {ex.Message}");
                    }
                }
                catch
                {
                    //
                }
            }
        }
Example #3
0
        public void Write(string operation, string level, string message)
        {
            _counter++;

            string unwanted = "Chem4Word.V3.";

            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }
            unwanted = "Chem4WordV3.";
            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }
            unwanted = "Chem4Word.";
            if (operation.StartsWith(unwanted))
            {
                operation = operation.Remove(0, unwanted.Length);
            }

            try
            {
                string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                               $@"Chem4Word.V3\Telemetry\{SafeDate.ToIsoShortDate(DateTime.Now)}.log");
                using (StreamWriter w = File.AppendText(fileName))
                {
                    string logMessage = $"[{SafeDate.ToShortTime(DateTime.Now)}] {operation} - {level} - {message}";
                    w.WriteLine(logMessage);
                }
            }
            catch
            {
                //
            }

            if (_permissionGranted)
            {
                WritePrivate(operation, level, message);

                if (!_systemInfoSent &&
                    _helper?.IpAddress != null &&
                    !_helper.IpAddress.Contains("0.0.0.0"))
                {
                    WriteStartUpInfo();

                    if (!string.IsNullOrEmpty(_helper.GitStatus))
                    {
                        var tracking = _helper.GitStatus
                                       .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                       .FirstOrDefault(l => l.StartsWith("##"));

                        if (!string.IsNullOrEmpty(tracking))
                        {
                            var idxStart = tracking.IndexOf('[');
                            var idxEnd   = tracking.IndexOf(']');
                            if (idxStart > 0 && idxEnd > 0)
                            {
                                var info = tracking.Substring(idxStart, idxEnd - idxStart + 1);

                                if (info.Contains("behind"))
                                {
                                    MessageBox.Show("Your local source code is behind origin!", "WARNING",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                                if (info.Contains("gone"))
                                {
                                    MessageBox.Show("Your local source code is gone from origin!", "WARNING",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                        }
                    }
                }
            }
        }