Пример #1
0
        private metaStoreDefinition InitializeMetaStoreDefinition(
            Guid dsdID, 
            DateTime runDate, 
            Guid systemID, 
            Dictionary<Guid, Dictionary<Guid, string>> termNameLookup,
            Dictionary<Guid /*TemplateID*/, Dictionary<Guid /*ComplexListID*/, Dictionary<Guid /*FieldID*/, string /*FieldName*/>>> fieldNameLookup)
        {
            metaStoreDefinition msd = new metaStoreDefinition();
            ITATSystem system = null;
            try
            {
                system = ITATSystem.Get(systemID);
                msd.dataStoreDefinition = DataStoreDefinition.GetDataStoreDefinitionByID(dsdID, system, termNameLookup, fieldNameLookup, true);
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("DataStoreDefinition.GetDataStoreDefinitionByID threw exception for DSDID = '{0}'.  Exception: '{1}'.   Stack Trace: {2}.", dsdID.ToString(), ex.Message, ex.StackTrace));
                throw new Exception(string.Format("DataStoreDefinition.GetDataStoreDefinitionByID halted for DSDID = '{0}'", dsdID.ToString()));
            }

            msd.orderedDSFNames = new List<string>();
            foreach (DataStoreField dsf in msd.dataStoreDefinition.DataStoreConfig.Terms)
            {
                msd.orderedDSFNames.Add(dsf.Name);
            }
            msd.requiresHeaderRow = true;
            msd.headerRowWritten = false;
            msd.dataStoreDefinition.LastRunDate = runDate;

            msd.isCompleted = false;
            msd.isMultiplexed = false;
            msd.dataRows = new List<ManagedItemStore.dataRow>();

            msd.skippedManagedItemIDs = new List<Guid>();

            //Create a new Templates Dictionary from the DataStoreConfig.Templates with the values switched, for easy Name access.
            Dictionary<string /*Template Name*/, Guid> templates = new Dictionary<string /*Template Name*/, Guid>();
            List<Guid> searchTemplateIDs = new List<Guid>();

            if (msd.dataStoreDefinition.DataStoreConfig.Templates == null || msd.dataStoreDefinition.DataStoreConfig.Templates.Count == 0)
            {
                _log.Error(string.Format("DataStoreDefinitionID = '{0}' does not contain any Templates.", dsdID.ToString()));
                throw new Exception(string.Format("InitializeMetaStoreDefinition halted for DSDID = '{0}'", dsdID.ToString()));
            }
            foreach (KeyValuePair<Guid, string> kvp in msd.dataStoreDefinition.DataStoreConfig.Templates)
            {
                templates.Add(kvp.Value, kvp.Key);
            }

            try
            {
                msd.templateStores = TemplateStore.GetTemplateStoreCollection(templates, msd.dataStoreDefinition.DataStoreConfig.Terms, msd.dataStoreDefinition.DataStoreConfig.DefaultDateFormat);
                //The returned templateStores dictionary contains the templates actually referenced within the dsfTerms.
                foreach (KeyValuePair<Guid, TemplateStore> kvp in msd.templateStores)
                {
                    searchTemplateIDs.Add(kvp.Key);
                }
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("GetTemplateStoreCollection threw exception for DSDID = '{0}'.  Exception: '{1}'.   Stack Trace: '{2}'.", dsdID.ToString(), ex.Message, ex.StackTrace));
                throw new Exception(string.Format("InitializeMetaStoreDefinition halted for DSDID = '{0}'", dsdID.ToString()));
            }

            try
            {
                msd.managedItemIDs = GetManagedItems(msd.dataStoreDefinition.DataStoreConfig.SearchCriteria, systemID, searchTemplateIDs);
                msd.managedItemIDCount = msd.managedItemIDs.Count;
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("GetManagedItems threw exception for DSDID = '{0}'.  Exception: '{1}'.   Stack Trace: '{2}'.", dsdID.ToString(), ex.Message, ex.StackTrace));
                throw new Exception(string.Format("InitializeMetaStoreDefinition halted for DSDID = '{0}'", dsdID.ToString()));
            }

            if (string.IsNullOrEmpty(msd.dataStoreDefinition.DataStoreConfig.Path))
            {
                _log.Error(string.Format("Path not defined for DSDID = '{0}'.", dsdID.ToString()));
                throw new Exception(string.Format("InitializeMetaStoreDefinition halted for DSDID = '{0}'", dsdID.ToString()));
            }
            string filePath = msd.dataStoreDefinition.DataStoreConfig.Path;
            if (!filePath.EndsWith(@"\") && !filePath.EndsWith(@"/"))
                filePath = string.Format(@"{0}\", filePath);
            string fileNameNoExtension = string.Format("{0}_{1}", msd.dataStoreDefinition.Name, msd.dataStoreDefinition.LastRunDate.Value.ToString("yyyyMMdd_HHmmss_ffff"));
            msd.emailAttachmentExtension = "csv";
            msd.dataStoreDefinition.DefinitionFilePath = string.Format("{0}{1}.{2}", filePath, fileNameNoExtension, msd.emailAttachmentExtension);
            msd.emailAttachmentFileName = string.Format("{0}_Validation_Errors", fileNameNoExtension);

            try
            {
                msd.swOutput = new StreamWriter(msd.dataStoreDefinition.DefinitionFilePath);
            }
            catch (Exception ex)
            {
                _log.Error(string.Format("StreamWriter threw exception for DSDID = '{0}', path = '{1}'.  Exception: '{2}'.   Stack Trace: '{3}'.", dsdID.ToString(), msd.dataStoreDefinition.DefinitionFilePath, ex.Message, ex.StackTrace));
                throw new Exception(string.Format("InitializeMetaStoreDefinition halted for DSDID = '{0}'", dsdID.ToString()));
            }

            msd.outputRowCount = 0;
            msd.closedOut = false;

            return msd;
        }
Пример #2
0
        private void ProcessDefinitionErrors(metaStoreDefinition definition, string systemName)
        {
            string errorReport = string.Format("There were a total of {0:D} error(s) reported for {1:D} manageditem(s) out of a total of {2:D} manageditem(s) processed.",
                GetErrorCount(definition),
                definition.dataRows.Count,
                definition.managedItemIDCount - definition.skippedManagedItemIDs.Count);

            if (definition.skippedManagedItemIDs.Count > 0)
                errorReport += string.Format("  {0:D} manageditem(s) were not processed.", definition.skippedManagedItemIDs.Count);

            if (definition.dataStoreDefinition.DataStoreConfig.ErrorLogRecepientEmailList.Count == 0)
            {
                _log.Error(string.Format("Email Not Sent - For System '{0}', Definition '{1}' ... {2}. No email recipents were listed.", systemName, definition.dataStoreDefinition.Name, errorReport));
            }
            else
            {
                _log.Error(string.Format("For System '{0}', Definition '{1}' ... {2}", systemName, definition.dataStoreDefinition.Name, errorReport));
                byte[] output = null;
                using (StringWriter sw = new StringWriter())
                {
                    sw.WriteLine("Template Name,ManagedItem Number,Term Name,Field Name,Error Message");
                    foreach (ManagedItemStore.dataRow dataRow in definition.dataRows)
                    {
                        foreach (ManagedItemStore.rowError rowError in dataRow.rowErrors)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.templateName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.managedItemNumber, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.termName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.fieldName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.message, true));
                            sw.WriteLine(sb.ToString());
                        }
                    }
                    output = Encoding.UTF8.GetBytes(sw.ToString());
                }
                Kindred.Common.Email.Email email = new Kindred.Common.Email.Email();
                email.Subject = string.Format("ITAT System {0} - Validation Errors for Interface '{1}'", systemName, definition.dataStoreDefinition.Name);
                email.Format = Common.Email.EmailFormat.Html;
                email.From = XMLNames._M_EmailFrom;
                foreach (string recipient in definition.dataStoreDefinition.DataStoreConfig.ErrorLogRecepientEmailList)
                    email.AddTo(recipient);
                email.Format = Kindred.Common.Email.EmailFormat.Html;
                email.Body = string.Format("Please find the list of validation errors attached. {0}", errorReport);
                email.ApplicationName = Business.EmailHelper.EmailName(systemName);
                email.Attachments.Add(new Common.Email.EmailAttachment(output, definition.emailAttachmentFileName, definition.emailAttachmentExtension));
                email.Send();
            }
        }
Пример #3
0
 private int GetErrorCount(metaStoreDefinition definition)
 {
     int nErrorCount = 0;
     foreach (ManagedItemStore.dataRow dataRow in definition.dataRows)
     {
         nErrorCount += dataRow.rowErrors.Count;
     }
     return nErrorCount;
 }
Пример #4
0
 private int GetCountOfManagedItemsWithErrors(metaStoreDefinition definition)
 {
     List<string> managedItemNumbers = new List<string>();
     foreach (ManagedItemStore.dataRow dataRow in definition.dataRows)
     {
         if (!managedItemNumbers.Contains(dataRow.rowErrors[0].managedItemNumber))
         {
             managedItemNumbers.Add(dataRow.rowErrors[0].managedItemNumber);
         }
     }
     return managedItemNumbers.Count;
 }
Пример #5
0
        private void CloseOutMetaStoreDefinition(metaStoreDefinition metaStoreDefinition, string systemName)
        {
            if (!metaStoreDefinition.closedOut)
            {
                metaStoreDefinition.swOutput.Close();

                _log.Info(string.Format("For System '{0}', Definition '{1}': Processed file \"{2}\", excel file row count = {3:D}, ManagedItem count = {4:D}, ManagedItem's with errors count = {5:D}, total error count = {6:D}",
                    systemName,
                    metaStoreDefinition.dataStoreDefinition.Name,
                    metaStoreDefinition.dataStoreDefinition.DefinitionFilePath,
                    metaStoreDefinition.outputRowCount,
                    metaStoreDefinition.managedItemIDCount,
                    GetCountOfManagedItemsWithErrors(metaStoreDefinition),
                    GetErrorCount(metaStoreDefinition)));

                if (metaStoreDefinition.dataRows != null && metaStoreDefinition.dataRows.Count > 0)
                {
                    ProcessDefinitionErrors(metaStoreDefinition, systemName);
                }
                //Note - if we wanted to add a 'status message', this would be the place to do it.
                DataStoreDefinition.UpdateDataStoreDefinitionOnRun(metaStoreDefinition.dataStoreDefinition);
            }
        }