/// <summary>
        /// Method:GetComponentInfo
        /// Description:Get information of all triggers files of a component.
        /// </summary>
        /// <param name="componentName">componentName</param>
        /// <returns>List of TriggerFileReader </returns>
        public List <TriggerFileReader> GetComponentTriggerFilesDetails(string componentName)
        {
            try
            {
                #region Get Componenet id by componentName

                ComponentsDal objComponentsDal = new ComponentsDal();
                ComponentTriggerAndStatusFilesDal objComponentTriggerAndStatusFilesDal = new ComponentTriggerAndStatusFilesDal();
                int ComponentId = objComponentsDal.GetComponentIdByComponentName(componentName);
                //Get Trigger File Location
                ComponentTriggerAndStatusFile objComponentTriggerAndStatusFile = objComponentTriggerAndStatusFilesDal.GetComponentTriggerAndStatusFileLocationByComponentId(ComponentId);

                #endregion

                if (objComponentTriggerAndStatusFile != null)
                {
                    TriggerFileReader objTriggerFileReader = new TriggerFileReader();
                    //
                    if (!Directory.Exists(objComponentTriggerAndStatusFile.TriggerFilelocation))
                    {
                        throw new Exception("Trigger directory not foud for Component " + componentName);
                    }

                    //Get all trigger files
                    var triggerFiles = Directory.GetFiles(objComponentTriggerAndStatusFile.TriggerFilelocation, "*.xml");
                    if (triggerFiles.Count() > 0)
                    {
                        List <TriggerFileReader> triggerFileReaderList = new List <TriggerFileReader>();

                        #region get information for all trigger file and add to TriggerFileReader list
                        foreach (var triggerFile in triggerFiles)
                        {
                            objTriggerFileReader.TriggerFileLocaton = triggerFile;
                            var triggerDetail = objTriggerFileReader.GetTriggerFileDetail();
                            Console.WriteLine("Process successfully read trigger XML file " + triggerFile);
                            triggerFileReaderList.Add(triggerDetail);
                        }
                        #endregion

                        return(triggerFileReaderList);
                    }
                    else
                    {
                        throw new Exception(" No Trigger File exists on location  " + objComponentTriggerAndStatusFile.TriggerFilelocation + "  for Component " + componentName + "  in database.");
                    }
                }
                else
                {
                    throw new Exception("Trigger location not foud for Component " + componentName + " in database.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method:GetTriggerFileDetail.
        /// Description:Collects information from the trigger file to TriggerFileReader object.
        /// </summary>
        /// <exception cref="BLW.Lib.CoreUtility.Exceptions.UnauthorizedAccessBLWException">path specified a file that is read-only and access is not Read -or- path specified a directory -or- The caller does not have the required permission.-or-mode is System.IO.FileMode.Create and the specified file is a hidden file.</exception>
        /// <returns>instance of TriggerFileReader.</returns>
        public TriggerFileReader GetTriggerFileDetail()
        {
            TriggerFileReader objTriggerFileReader = new TriggerFileReader();

            try
            {
                using (FileStream fs = File.Open(TriggerFileLocaton, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                {
                    XDocument xdocument  = XDocument.Load(fs);
                    var       allElement = xdocument.Elements("Trigger");
                    var       allTag     = allElement.First();

                    objTriggerFileReader.ClientName      = allTag.Element("ClientName").Value;
                    objTriggerFileReader.ApplicationName = allTag.Element("AppName").Value;

                    // Read run detail Element and Value
                    var runDetailelement = allTag.Element("RunDetail");
                    objTriggerFileReader.RunNumber            = runDetailelement.Element("RunNumber").Value;
                    objTriggerFileReader.RunComponentStatusId = Convert.ToInt32(runDetailelement.Element("RunComponentStatusId").Value);

                    // Read run Component Detail element
                    var componentDetailElement = allTag.Element("ComponentDetail");
                    objTriggerFileReader.ComponentName              = componentDetailElement.Element("ComponentName").Value;
                    objTriggerFileReader.ComponentExe               = componentDetailElement.Element("ComponentExe").Value;
                    objTriggerFileReader.ComponentStatusDirectory   = componentDetailElement.Element("ComponentStatusDirectory").Value;
                    objTriggerFileReader.ComponentConfigXmlFilePath = componentDetailElement.Element("ComponentConfigXmlFilePath").Value;

                    List <ComponentInLocation> objInputLocation = new List <ComponentInLocation>();
                    var inputElement = from inputelement in componentDetailElement.Descendants("InputLocation")
                                       select inputelement;

                    if (inputElement.Count() > 0)
                    {
                        foreach (var inputAtribute in inputElement)
                        {
                            ComponentInLocation objInput = new ComponentInLocation();
                            objInput.DirectoryLocation = inputAtribute.Value;
                            objInput.FileMask          = inputAtribute.FirstAttribute.Value;
                            objInputLocation.Add(objInput);
                        }

                        objTriggerFileReader.InputDetails = objInputLocation;
                    }

                    // Component Output location
                    List <ComponentOutLocation> objOutputLocation = new List <ComponentOutLocation>();
                    var outputElement = from outputelement in componentDetailElement.Descendants("OutputLocation")
                                        select outputelement;

                    if (outputElement.Count() > 0)
                    {
                        foreach (var outputAtribute in outputElement)
                        {
                            ComponentOutLocation objOutput = new ComponentOutLocation();
                            objOutput.DirectoryLocation = outputAtribute.Value;
                            objOutput.FileMask          = outputAtribute.FirstAttribute.Value;
                            objOutputLocation.Add(objOutput);
                        }

                        objTriggerFileReader.OutputDetails = objOutputLocation;
                    }

                    return(objTriggerFileReader);
                }
            }
            catch (IOException uEx)
            {
                throw new BLW.Lib.CoreUtility.Exceptions.IOBLWException("File is locked by other process.", uEx, TriggerFileLocaton, "Trigger Reader");
            }
            catch (Exception ex)
            {
                throw new Exception("Error while reading the Trigger file. File Path " + TriggerFileLocaton, ex);
            }
        }