Example #1
0
 public Mediator(
     ILogger <Mediator> logger,
     ServiceFactory serviceFactory)
 {
     this.logger = logger;
     mediator    = new LoggingMediator(serviceFactory, logger);
 }
 private static GenericResponse UpdateTransferPackList(PackListInformation listinfo)
 {
     try
     {
         var response = new GenericResponse();
         using (var context = new Entities())
         {
             var plist = (from list in context.TransferPackListHeads
                          where list.Id == listinfo.Id
                          select list).FirstOrDefault();
             if (plist == null)
             {
                 var list = new TransferPackListHead();
                 Mapper.Map(listinfo, list);
                 context.TransferPackListHeads.AddObject(list);
             }
             else
             {
                 Mapper.Map(listinfo, plist);
             }
             context.SaveChanges();
         }
         response.Success = true;
         return(response);
     }
     catch (Exception ex)
     {
         LoggingMediator.Log("UpdatePack");
         LoggingMediator.Log(ex);
         return(new GenericResponse {
             Success = false, FailureInformation = "Error in PAPService:UpdateTransferPackList"
         });
     }
 }
 public ReceivePapDataResponse ReceivePapData(ReceivePapDataRequest request)
 {
     try
     {
         var response    = new ReceivePapDataResponse();
         var xmlresponse = ReadPapXml();
         response.FailureInformation = xmlresponse.FailureInformation;
         if (!xmlresponse.Success)
         {
             return(response);
         }
         response.Success = true;
         return(response);
     }
     catch (Exception ex)
     {
         LoggingMediator.Log("ReceivePapData");
         LoggingMediator.Log(ex);
         return(new ReceivePapDataResponse
         {
             Success = false,
             FailureInformation = "Error in PAPService:ReceivePapData"
         });
     }
 }
        private PAP.GenericResponse ReadPapXml()
        {
            try
            {
                var response        = new PAP.GenericResponse();
                var xmlDoc          = XDocument.Load(@"Files\ReceivePAP.xml");
                var packxmldata     = new Packs();
                var packlistxmldata = new PackLists();
                var settings        = new XmlReaderSettings {
                    IgnoreWhitespace = true
                };
                var buffer    = Encoding.ASCII.GetBytes(xmlDoc.ToString());
                var xmlStream = new MemoryStream(buffer);
                using (var xmlReader = XmlReader.Create(xmlStream, settings))
                {
                    var packXmlSerializer     = new XmlSerializer(packxmldata.GetType());
                    var packlistXmlSerializer = new XmlSerializer(packlistxmldata.GetType());
                    packxmldata                  = (Packs)packXmlSerializer.Deserialize(xmlReader);
                    packlistxmldata              = (PackLists)packlistXmlSerializer.Deserialize(xmlReader);
                    response.FailureInformation  = CreatePacksFromXml(packxmldata.PackCollection).FailureInformation;
                    response.FailureInformation += CreatePackListsFromXml(packlistxmldata.PackListCollection);
                }

                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("ReadPapXml");
                LoggingMediator.Log(ex);
                throw;
            }
        }
Example #5
0
 private ExecutionGroupLogCommand(string groupName, DirectoryInfo groupPath, LoggingMediator mediator)
 {
     this.mediator  = mediator;
     this.groupPath = groupPath;
     this.groupName = groupName;
     groupPath.Create();
     log = new StringBuilder();
 }
Example #6
0
 /// <summary>
 /// Writes event to windows event log, and broadcasts it to be traced.
 /// </summary>
 static private void RecordEvent(string message, EventLogEntryType eventType, bool isVerbose)
 {
     LoggingMediator.LogEvent(string.Format("QualityVault: {0}", message));
     if (!isVerbose)
     {
         EventLog.WriteEntry(qualityVaultSource, message, eventType); //Note: Infra does a lot of trivial logging stuff...
     }
 }
Example #7
0
        public static ProcessLogsCommand Apply(IEnumerable <TestRecord> tests, LoggingMediator mediator)
        {
            ProcessLogsCommand command = new ProcessLogsCommand();

            command.Tests    = tests;
            command.mediator = mediator;
            return(command);
        }
Example #8
0
 /// <summary>
 /// Removes specified dll from the GAC.
 /// </summary>
 /// <param name="settings"></param>
 public void RollbackState(StateModule settings)
 {
     LoggingMediator.LogEvent(string.Format("QualityVault: UN-GAC: {0}", settings.Path));
     //AssemblyCache.UninstallAssembly(filePath);
     //if (previousPath != null)
     //{
     //    AssemblyCache.InstallAssembly(previousPath, AssemblyCommitFlags.Refresh);
     //}
 }
Example #9
0
 /// <summary>
 /// Installs specified dll to the GAC. Nothing more is promised.
 /// </summary>
 public void ApplyState(StateModule settings)
 {
     LoggingMediator.LogEvent(string.Format("QualityVault: GAC: {0}", settings.Path));
     //if (previousPath != null)
     //{
     //    AssemblyCache.UninstallAssembly(new FileInfo(settings.Path).Name);
     //}
     //filePath = Path.Combine(settings.TestBinariesDirectory.FullName, settings.Path);
     //AssemblyCache.InstallAssembly(filePath, AssemblyCommitFlags.Refresh);
 }
Example #10
0
        public static ListenToTestsCommand Apply(List <TestRecord> tests, LoggingMediator loggingMediator, DirectoryInfo testLogDirectory, bool debugTest)
        {
            ListenToTestsCommand command = new ListenToTestsCommand();

            command.Mediator  = loggingMediator;
            command.Tests     = tests;
            command.DebugTest = debugTest;

            ExecutionEventLog.RecordStatus("Starting Test Logging Transaction.");
            command.Mediator.StartTests(tests, testLogDirectory);
            return(command);
        }
Example #11
0
        private static void WriteToDictionary(object sender, string dictionaryFile)
        {
            var item = sender as MenuItem;

            if (item == null)
            {
                return;
            }
            var textBoxBase = item.CommandTarget as TextBoxBase;

            ;
            if (textBoxBase == null)
            {
                return;
            }

            string misspelledWord = string.Empty;

            if (textBoxBase is TextBox)
            {
                var textBox = textBoxBase as TextBox;
                misspelledWord = textBox.Text.Substring(textBox.GetSpellingErrorStart(textBox.CaretIndex), textBox.GetSpellingErrorLength(textBox.CaretIndex));
            }
            else if (textBoxBase is RichTextBox)
            {
                var richTextBox = textBoxBase as RichTextBox;
                var range       = richTextBox.GetSpellingErrorRange(richTextBox.CaretPosition);
                if (range != null)
                {
                    misspelledWord = range.Text;
                }
            }
            if (string.IsNullOrWhiteSpace(misspelledWord))
            {
                return;
            }

            try
            {
                var writer = File.AppendText(dictionaryFile);
                writer.WriteLine(misspelledWord);
                writer.Close();
                if (ToggleSpellCheck != null)
                {
                    ToggleSpellCheck(textBoxBase, null);
                }
            }
            catch (Exception ex)
            {
                LoggingMediator.Log(ex);
            }
        }
Example #12
0
        /// <summary>
        /// Gather debug information if the process was being monitored, otherwise just terminate.
        /// </summary>
        internal void OnProcessCrash(int processId)
        {
            ExecutionEventLog.RecordStatus("Process " + processId + " crash notification recieved.");
            try
            {
                if (Process.GetCurrentProcess().Id == processId)
                {
                    //It may be possible that some strange unhandled exception is arising in a background thread, leading to a debugger being launched
                    //and the infra Terminating itself. Somehow, it seems unlikely for this code to be reachable, but this case is a hypothetical possibility to account for.
                    ExecutionEventLog.RecordStatus("Catastrophic Situation: Infra has recieved notification that it's own process has crashed. ");
                }
                else if (isTestRunning && pids.Contains(processId) && accumulatedDumpCost < maxDumpCost)
                {
                    ExecutionEventLog.RecordStatus("Debugging Process: " + processId);
                    FileInfo debugLogFilePath  = new FileInfo(Path.Combine(executionDirectory.FullName, "TestInfraDebuggingLog_" + processId + ".log"));
                    FileInfo debugDumpFilePath = new FileInfo(Path.Combine(executionDirectory.FullName, "TestInfraDebuggingDump_" + processId + ".dmp"));

                    CdbUtilities.DebugProcess(processId.ToString(CultureInfo.InvariantCulture), debugLogFilePath, debugDumpFilePath);

                    accumulatedDumpCost += debugDumpFilePath.Length;
                    //

                    LoggingMediator.LogFile(debugLogFilePath.FullName);
                    LoggingMediator.LogFile(debugDumpFilePath.FullName);
                    //Dan: Is the Recording Logger guaranteed to be explicitly aware that the given test has failed if this point is reached?
                    //Getting here means a process the tester cares about has crashed.
                }
                else
                {
                    if (accumulatedDumpCost < maxDumpCost)
                    {
                        ExecutionEventLog.RecordStatus("Terminating non-monitored Process:" + processId);
                    }
                    else
                    {
                        ExecutionEventLog.RecordStatus("Dump limit exceeded - Terminating process without analysis:" + processId);
                    }
                    Process process = Process.GetProcessById(processId);
                    if (process != null && !process.HasExited)
                    {
                        process.Kill();
                        process.WaitForExit();
                    }
                }
            }
            //Uncaught exceptions in this event handler will ---- up the logging stack... Which would be bad.
            catch (Exception exception)
            {
                ExecutionEventLog.RecordException(exception);
            }
        }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestServiceHost"/> class.
        /// </summary>
        public TestServiceHost()
        {
            TypeFilter = LogEventType.Undefined;
            LoggingMediator.AddLogger(this);

            InitializeComponent();

            listView1.ListViewItemSorter = _sorter;
            _sorter.SortColumn           = 2;
            listView1.Sort();

            // In the test environment, we create default settings for the service in case those settings are not configured
            if (!ConfigurationSettings.Settings.IsSettingSupported("ServiceBaseUrl"))
            {
                ConfigurationSettings.Sources["Memory"].Settings["ServiceBaseUrl"] = "localhost";
            }
            if (!ConfigurationSettings.Settings.IsSettingSupported("ServiceBasePort"))
            {
                ConfigurationSettings.Sources["Memory"].Settings["ServiceBasePort"] = "50000";
            }
            if (!ConfigurationSettings.Settings.IsSettingSupported("ServiceBasePath"))
            {
                ConfigurationSettings.Sources["Memory"].Settings["ServiceBasePath"] = "dev";
            }

            textDomain.Items.Add("localhost");
            textDomain.Enabled = false;
            var baseUrl = ConfigurationSettings.Settings["ServiceBaseUrl"];

            if (!StringHelper.Compare(baseUrl, "localhost"))
            {
                textDomain.Items.Add(baseUrl);
            }
            textDomain.SelectedIndex = textDomain.Items.Count - 1;
            int basePort;

            if (int.TryParse(ConfigurationSettings.Settings["ServiceBasePort"], out basePort))
            {
                _basePort     = basePort;
                textPort.Text = _basePort.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                _basePort     = 50000;
                textPort.Text = "50000";
            }
            textPort.Enabled = false;
            textPath.Enabled = false;
            textPath.Text    = ConfigurationSettings.Settings["ServiceBasePath"];
        }
 private static InventoryItems.Item[] GetAvailableInventoryByYard(Entities context)
 {
     try
     {
         InventoryItems.Item[] response = null;
         var query = (from inv in context.Inventories
                      where inv.YardId == YardId
                      select inv);
         response = LoadWriteInventory(query.ToList());
         return(response);
     }
     catch (Exception ex)
     {
         LoggingMediator.Log("GetAvailableInventoryByYard");
         LoggingMediator.Log(ex);
         return(null);
     }
 }
        private PAP.GenericResponse WritePapXml()
        {
            try
            {
                var response = new PAP.GenericResponse();
                using (var context = new Entities())
                {
                    var availablePacks              = GetPacksByYard(context);
                    var availablePackLists          = GetPackListsByYard(context);
                    var availableTransfersPackLists = GetTransferPackListsByYard(context);
                    var availableContracts          = GetOpenContractsByYard(context);
                    var availableTransfers          = GetHeldTransferSentHeadByYard(context);
                    var availableInventory          = GetAvailableInventoryByYard(context);

                    var allAvailableContracts = availableContracts.Concat(availableTransfers).ToArray();
                    var allAvailablePacklists = availablePackLists.Concat(availableTransfersPackLists).ToArray();

                    var sendData = new Root
                    {
                        AvailableContracts = allAvailableContracts,
                        InventoryItems     = availableInventory,
                        PackLists          = allAvailablePacklists,
                        AvailablePacks     = availablePacks
                    };
                    var writer        = new XmlSerializer(typeof(Root));
                    var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    var fullFileName  = Path.Combine(desktopFolder, "SendPAP.xml");
                    using (var fs = new FileStream(fullFileName, FileMode.Create))
                    {
                        writer.Serialize(fs, sendData);
                        fs.Close();
                    }
                }
                response.Success = true;
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("ReadPapXml");
                LoggingMediator.Log(ex);
                throw;
            }
        }
        private static AvailableContracts.Contract[] GetOpenContractsByYard(Entities context)
        {
            try
            {
                AvailableContracts.Contract[] response = null;
                var query = (from contract in context.ContractHeads
                             where contract.YardId == YardId &&
                             !contract.IsFinished &&
                             contract.ContractStatus != (int)ContractStatus.Void
                             select contract);

                response = LoadWriteContract(query.ToList(), context);
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("GetOpenContractsByYard");
                LoggingMediator.Log(ex);
                return(null);
            }
        }
        private static PAP.GenericResponse UpdatePack(PackInformation pkinfo)
        {
            try
            {
                var response = new PAP.GenericResponse();
                using (var context = new Entities())
                {
                    var yd = (from yard in context.Yards
                              where yard.Id == pkinfo.YardId
                              select yard.CustomerNumberPrefix).First() ?? string.Empty;
                    pkinfo.NumberPrefix       = yd;
                    pkinfo.InternalPackNumber = yd.Trim() + pkinfo.TagNumber;

                    var pack = (from pk in context.Packs
                                where pk.Id == pkinfo.Id
                                select pk).FirstOrDefault();
                    if (pack == null)
                    {
                        var pk = new Pack();
                        Mapper.Map(pkinfo, pk);
                        context.Packs.AddObject(pk);
                    }
                    else
                    {
                        Mapper.Map(pkinfo, pack);
                    }
                    context.SaveChanges();
                }
                response.Success = true;
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("UpdatePack");
                LoggingMediator.Log(ex);
                return(new PAP.GenericResponse {
                    Success = false, FailureInformation = "Error in PAPService:UpdatePack"
                });
            }
        }
        private static AvailablePackLists.PackList[] GetTransferPackListsByYard(Entities context)
        {
            try
            {
                AvailablePackLists.PackList[] response = null;
                var query = (from plist in context.TransferPackListHeads
                             where plist.TransferSentHead.YardId == YardId
                             &&
                             (plist.PackListStatus == (int)PackListStatus.Held ||
                              plist.PackListStatus == (int)PackListStatus.OnShipment)
                             select plist);

                response = LoadWriteTransferPackLists(query.ToList());
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("GetTransferPackListsByYard");
                LoggingMediator.Log(ex);
                return(null);
            }
        }
        private static AvailablePacks.Pack[] GetPacksByYard(Entities context)
        {
            try
            {
                AvailablePacks.Pack[] response = null;
                var query = (from pack in context.Packs
                             where pack.YardId == YardId
                             &&
                             (pack.PackStatus == (int)PackStatus.Closed || pack.PackStatus == (int)PackStatus.Held ||
                              pack.PackStatus == (int)PackStatus.Manifest)
                             select pack);

                response = LoadWritePack(query.ToList());
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("GetPacksByYard");
                LoggingMediator.Log(ex);
                return(null);
            }
        }
        private static AvailableContracts.Contract[] GetHeldTransferSentHeadByYard(Entities context)
        {
            try
            {
                AvailableContracts.Contract[] response = null;
                var query = (from transfer in context.TransferSentHeads
                             where transfer.YardId == YardId
                             &&
                             (transfer.TransferStatus == (int)TransferSentStatus.Held ||
                              transfer.TransferStatus == (int)TransferSentStatus.Closed)
                             select transfer);

                response = LoadWriteTransfer(query.ToList());
                return(response);
            }
            catch (Exception ex)
            {
                LoggingMediator.Log("GetHeldTransferSentHeadByYard");
                LoggingMediator.Log(ex);
                return(null);
            }
        }
 public SendPapDataResponse SendPapData(SendPapDataRequest request)
 {
     try
     {
         var response    = new SendPapDataResponse();
         var xmlresponse = WritePapXml();
         response.FailureInformation = xmlresponse.FailureInformation;
         if (!xmlresponse.Success)
         {
             return(response);
         }
         response.Success = true;
         return(response);
     }
     catch (Exception ex)
     {
         LoggingMediator.Log("SendPapData");
         LoggingMediator.Log(ex);
         return(new SendPapDataResponse {
             Success = false, FailureInformation = "Error sending PAP data."
         });
     }
 }
Example #22
0
        public static ExecutionGroupLogCommand Apply(string groupName, DirectoryInfo groupPath, LoggingMediator mediator)
        {
            ExecutionGroupLogCommand command = new ExecutionGroupLogCommand(groupName, groupPath, mediator);

            mediator.PushListener(command);
            return(command);
        }
Example #23
0
        /// <summary>
        /// Fires when UseCustomDictionaries changes
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="a">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void UseCustomDictionariesChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs a)
        {
            var textBoxBase = dependencyObject as TextBoxBase;

            if (textBoxBase == null)
            {
                return;
            }
            var isEnabled = (bool)a.NewValue;

            if (isEnabled)
            {
                var handler = new EventHandler((s, e) =>
                {
                    SpellCheck.SetIsEnabled(textBoxBase, false);
                    SpellCheck.SetIsEnabled(textBoxBase, true);
                });

                ToggleSpellCheck     += handler;
                textBoxBase.Unloaded += (s, e) => ToggleSpellCheck -= handler;

                SpellCheck.SetIsEnabled(textBoxBase, true);

                lock (textBoxBase)
                {
                    try
                    {
                        if (_customDictionaries == null) //load custom dictionaries
                        {
                            _customDictionaries = new List <string>();
                            var customDictionaryPath = SpellCheckHelper.GetCustomDictionaryPath();
                            if (!Directory.Exists(customDictionaryPath))
                            {
                                Directory.CreateDirectory(customDictionaryPath);
                            }
                            _customDictionaryFile    = SpellCheckHelper.GetCustomDictionaryFile(customDictionaryPath);
                            _ignoreAllDictionaryFile = SpellCheckHelper.GetIgnoreAllDictionaryFile(customDictionaryPath);
                            var fs = File.Create(_ignoreAllDictionaryFile);
                            fs.Close();
                            if (!File.Exists(_customDictionaryFile))
                            {
                                fs = File.Create(_customDictionaryFile);
                                fs.Close();
                            }

                            var dir = new DirectoryInfo(customDictionaryPath);
                            foreach (var fileInfo in dir.GetFiles("*.lex"))
                            {
                                _customDictionaries.Add(fileInfo.FullName);
                            }
                        }
                        var dictionaries = SpellCheck.GetCustomDictionaries(textBoxBase);
                        dictionaries.Clear();
                        foreach (var fileName in _customDictionaries)
                        {
                            dictionaries.Add(new Uri(fileName));
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggingMediator.Log(ex);
                    }
                }

                if (textBoxBase.ContextMenu != null)
                {
                    return;
                }
                textBoxBase.ContextMenu         = new ContextMenu();
                textBoxBase.ContextMenuOpening += textBoxEx_ContextMenuOpening;
            }
        }