예제 #1
0
        public override QueryComposerModelProcessor.DocumentEx[] OutputDocuments()
        {
            if (_currentResponse == null)
            {
                return(new QueryComposerModelProcessor.DocumentEx[0]);
            }

            return(new[] { SerializeResponse(_currentResponse, QueryComposerModelProcessor.NewGuid(), "response.json") });
        }
예제 #2
0
        public override QueryComposerModelProcessor.DocumentEx[] OutputDocuments()
        {
            List <QueryComposerModelProcessor.DocumentEx> docs = new List <QueryComposerModelProcessor.DocumentEx>();

            if (_currentViewableResponse == null || _currentNonViewableResponse == null)
            {
                return(new QueryComposerModelProcessor.DocumentEx[0]);
            }

            return(new[] { SerializeResponse(_currentViewableResponse, QueryComposerModelProcessor.NewGuid(), "response.json"), SerializeResponse(_currentNonViewableResponse, QueryComposerModelProcessor.NewGuid(), "refresh-dates.json", "SummaryTables.RefreshDates", false) });
        }
        private void LogOutputFilesCreated(List <QueryComposerModelProcessor.DocumentEx> outputDocuments)
        {
            EventLog.Add(new EventLogItem(EventLogItemTypes.OutputFilesCreated, "Output files created; ready for upload."));

            var content = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(EventLog, Newtonsoft.Json.Formatting.None));

            Guid documentID = QueryComposerModelProcessor.NewGuid();

            outputDocuments.Add(new QueryComposerModelProcessor.DocumentEx {
                ID       = documentID,
                Document = new Document(documentID, "application/json", "AdapterEvents.log", false, content.Length, EnhancedEventLogFileKind),
                Content  = content
            });
        }
        List <QueryComposerModelProcessor.DocumentEx> FilesToUpload(string directory)
        {
            List <QueryComposerModelProcessor.DocumentEx> documents = new List <QueryComposerModelProcessor.DocumentEx>();
            FileInfo fi;
            Guid     documentID;

            string manifestFilepath = Path.Combine(directory, OutputManifestFilename);

            LogDebug("Starting read of manifest file: " + manifestFilepath);
            if (!File.Exists(manifestFilepath))
            {
                LogDebug($"Manifest file cannot be read or file doesn't exists: { manifestFilepath }");
                return(documents);
            }


            //add the output manifest
            fi         = new FileInfo(manifestFilepath);
            documentID = QueryComposerModelProcessor.NewGuid();
            documents.Add(new QueryComposerModelProcessor.DocumentEx {
                ID       = documentID,
                Document = new Document(documentID, QueryComposerModelProcessor.GetMimeType(fi.Name), fi.Name, false, Convert.ToInt32(fi.Length), TranslateTriggerFilenameToDocumentKind(fi.Name)),
                FileInfo = fi
            });

            DateTime maxEndTime = DateTime.UtcNow.AddMinutes(Convert.ToDouble(_settings.GetAsString("MaxReadWaitTime", "5")));

            while (IsFileLocked(fi))
            {
                if (DateTime.UtcNow > maxEndTime)
                {
                    throw new Exception("The maximum time to wait to read the manifest file has been exceeded and it is still locked.");
                }
            }
            using (var stream = File.OpenText(manifestFilepath))
            {
                //read the header line
                stream.ReadLine();

                string line, filename;
                while (!stream.EndOfStream)
                {
                    line = stream.ReadLine();
                    string[] split = line.Split(',');
                    if (split.Length > 0)
                    {
                        //first value will be the filename relative to the folder
                        filename = split[0].Trim();
                        if (!string.IsNullOrEmpty(filename))
                        {
                            if (documents.Any(d => d.Document.Filename == filename))
                            {
                                continue;
                            }

                            fi = new FileInfo(Path.Combine(directory, filename));

                            if (!fi.Exists)
                            {
                                throw new FileNotFoundException("File not found in " + directory, filename);
                            }

                            documentID = QueryComposerModelProcessor.NewGuid();
                            var documentEx = new QueryComposerModelProcessor.DocumentEx {
                                ID       = documentID,
                                Document = new Document(documentID, QueryComposerModelProcessor.GetMimeType(fi.Name), fi.Name, false, Convert.ToInt32(fi.Length), TranslateTriggerFilenameToDocumentKind(fi.Name)),
                                FileInfo = fi
                            };

                            if (split[1].Trim() == "0")
                            {
                                documentEx.Document.Kind = TrackingTableFileKind;
                            }

                            documents.Add(documentEx);
                        }
                    }
                }
            }

            return(documents);
        }