Example #1
0
        private static void SetRequestFiles(FoundationDataFileState state)
        {
            string directoryPath;
            var    pathChecked = new List <string>();

            foreach (FoundationDataFileState.FileInfo requestFile in state.RequestFiles)
            {
                directoryPath = string.Format("{0}\\", state.ClientRootDirectory);
                if (!pathChecked.Contains(directoryPath))
                {
                    SetFilesFromPath(state, directoryPath);
                    pathChecked.Add(directoryPath);
                }
            }

            foreach (FoundationDataFileState.FileInfo requestSupportingFile in state.RequestSupportingFiles)
            {
                //directoryPath = string.Format("{0}\\documents\\{1}.{2}", state.ClientRootDirectory,
                //requestSupportingFile.DocumentId, requestSupportingFile.FileName.Split('.').Last());
                directoryPath = string.Format("{0}\\documents\\", state.ClientRootDirectory);
                if (!pathChecked.Contains(directoryPath))
                {
                    SetFilesFromPath(state, directoryPath);
                    pathChecked.Add(directoryPath);
                }
            }
        }
Example #2
0
        public static List <string> GetGhostInspectorSuites(FoundationDataFileState state, string folderId)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            //GET Method
            try
            {
                WebRequest requestObjGet = WebRequest.Create($"https://api.ghostinspector.com/v1/folders/{folderId}/suites/?apiKey={state.APIKey}");
                requestObjGet.Method = "GET";
                HttpWebResponse responseObjGet = null;
                requestObjGet.Timeout = 600000;
                responseObjGet        = (HttpWebResponse)requestObjGet.GetResponse();

                using (Stream stream = responseObjGet.GetResponseStream())
                {
                    StreamReader sr         = new StreamReader(stream);
                    var          resultBabe = sr.ReadToEnd();
                    sr.Close();

                    var           json   = JObject.Parse(resultBabe)["data"];
                    List <string> suites = new List <string>();
                    foreach (var result in json.Children())
                    {
                        suites.Add(result["_id"].ToString());
                    }
                    return(suites);
                };
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #3
0
        private static void SetFilesFromPath(FoundationDataFileState state, string filePath)
        {
            if (Directory.Exists(filePath))
            {
                string[] files = Directory.GetFiles(filePath, "*.*", SearchOption.AllDirectories)
                                 .ToArray();

                foreach (string fileString in files)
                {
                    var file = new FileInfo(fileString);
                    state.Files.Add(file);
                    state.TotalSize += file.Length;
                }
            }
        }
Example #4
0
        private static void SetOrganizationSupportingFiles(FoundationDataFileState state)
        {
            var pathChecked = new List <string>();

            foreach (FoundationDataFileState.FileInfo orgSupportingFile in state.OrganizationSupportingFiles)
            {
                var directoryPath = string.Format("{0}\\documents\\{1}.{2}", state.ClientRootDirectory,
                                                  orgSupportingFile.DocumentId, orgSupportingFile.FileName.Split('.').Last());
                if (!pathChecked.Contains(directoryPath))
                {
                    SetFilesFromPath(state, directoryPath);
                    pathChecked.Add(directoryPath);
                }
            }
        }
Example #5
0
        public static void RunGhostInspector(FoundationDataFileState state, string line)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            //GET Method
            try
            {
                WebRequest requestObjGet =
                    WebRequest.Create($"https://api.ghostinspector.com/v1/suites/{line}/execute/?apiKey={state.APIKey}");
                requestObjGet.Method = "POST";
                requestObjGet.GetResponseAsync();
                Thread.Sleep(3000);
                requestObjGet.Abort();
            }
            catch (Exception e)
            {
            }
        }
Example #6
0
        public static void SetFileList(FoundationDataFileState state)
        {
            ClearFiles(state);
            if (string.IsNullOrEmpty(state.FileType) || state.FileType == "All")
            {
                SetRequestFiles(state);
                SetOrganizationSupportingFiles(state);
                SetAttachmentFiles(state);
                SetMergeTemplateFiles(state);
                SetCustomPrintPacketFiles(state);
                SetSharedDocumentFiles(state);
            }
            else
            {
                switch (state.FileType)
                {
                case "answers":
                    SetRequestFiles(state);
                    break;

                case "documents":
                    SetOrganizationSupportingFiles(state);
                    break;

                case "attachments":
                    SetAttachmentFiles(state);
                    break;

                case "mergetemplates":
                    SetMergeTemplateFiles(state);
                    break;

                case "settingvalues":
                    SetCustomPrintPacketFiles(state);
                    break;

                case "shareddocuments":
                    SetSharedDocumentFiles(state);
                    break;
                }
            }
        }
Example #7
0
        public static DataTable GetGhostInspectorFolders(FoundationDataFileState state)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            //GET Method
            try
            {
                WebRequest requestObjGet = WebRequest.Create($"https://api.ghostinspector.com/v1/folders/?apiKey={state.APIKey}");
                requestObjGet.Method = "GET";
                HttpWebResponse responseObjGet = null;
                requestObjGet.Timeout = 600000;
                responseObjGet        = (HttpWebResponse)requestObjGet.GetResponse();

                using (Stream stream = responseObjGet.GetResponseStream())
                {
                    StreamReader sr         = new StreamReader(stream);
                    var          resultBabe = sr.ReadToEnd();
                    sr.Close();

                    var       json  = JObject.Parse(resultBabe)["data"];
                    DataTable table = new DataTable();
                    table.Columns.Add("folderId");
                    table.Columns.Add("folderName");
                    foreach (var result in json.Children())
                    {
                        DataRow row = table.NewRow();
                        row["folderName"] = result["name"].ToString();
                        row["folderId"]   = result["_id"].ToString();

                        table.Rows.Add(row);
                    }
                    return(table);
                };
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #8
0
        public static void ReconcileFileListToDatabase(FoundationDataFileState state, Dictionary <string, string> fileList)
        {
            ClearFiles(state);
            SetFilesFromPath(state, state.ClientRootDirectory);

            foreach (FileInfo file in state.Files)
            {
                string partialFileName = "\\" + file.FullName.Replace(state.ClientRootDirectory, string.Empty)
                                         .ToLower();
                if (!fileList.Keys.Contains(partialFileName))
                {
                    state.SequesterFiles.Add(file);
                }
                else
                {
                    fileList.Remove(partialFileName);
                }
            }

            if (fileList.Count > 0)
            {
                state.FilesNotFound = fileList;
            }
        }
Example #9
0
        private static void CopyFilesToDestination(FoundationDataFileState state, string destinationFolder)
        {
            string sourcePath = "";

            try
            {
                if (state.Files == null || state.Files.Count == 0)
                {
                    Logger.Log("CopyFilesToDestination: no files selected to copy", LogLevel.Warn);
                    return;
                }

                if (string.IsNullOrEmpty(destinationFolder))
                {
                    Logger.Log("CopyFilesToDestination: No destination selected for copy", LogLevel.Error);
                    throw new ArgumentNullException("destinationFolder");
                }

                if (!Directory.Exists(destinationFolder))
                {
                    Directory.CreateDirectory(destinationFolder);
                }

                string[] fileTypes = state.FileType != "All" ? new[] { state.FileType } : new[] { "answers", "documents" };

                foreach (var fileyType in fileTypes)
                {
                    var sb = new StringBuilder();
                    switch (fileyType)
                    {
                    case "answers":
                        List <string> faildList = new List <string>();
                        sb.AppendLine("Request Id, Request Guid,Submission Id,Answer Id, User Id, Question, File Path, File Name");

                        foreach (FoundationDataFileState.FileInfo file in state.RequestFiles)
                        {
                            sourcePath = string.Format("{0}\\answers\\{1}.{2}",
                                                       state.ClientRootDirectory, file.AnswerId, file.FileName.Split('.').Last());
                            try
                            {
                                CopyFile(sourcePath, destinationFolder, file);
                                if (!string.IsNullOrWhiteSpace(file.FileName))
                                {
                                    sb.AppendLine(string.Format("{0},{1},{2},{3},{4},\"{5}\",\"{6}\",\"{7}\",\"{8}\"", file.RequestId,
                                                                file.RequestGuid, file.SubmissionId, file.AnswerId, file.ActorGuid, file.Question, file.FilePath,
                                                                file.FileName, file.ProcessId));
                                }
                            }
                            catch (Exception e)
                            {
                                faildList.Add(sourcePath);
                            }
                        }
                        File.WriteAllText(destinationFolder + "\\Request.csv", sb.ToString());
                        break;

                    case "documents":
                        sb = new StringBuilder();
                        sb.AppendLine("Request Id, Request Guid, User Id, Description,File Path, File Name");
                        foreach (FoundationDataFileState.FileInfo file in state.RequestSupportingFiles)
                        {
                            sourcePath = string.Format("{0}\\documents\\{1}.{2}",
                                                       state.ClientRootDirectory, file.DocumentId, file.FileName.Split('.').Last());
                            CopyFile(sourcePath, destinationFolder, file);
                            if (!string.IsNullOrWhiteSpace(file.FileName))
                            {
                                if (!string.IsNullOrWhiteSpace(file.FileName))
                                {
                                    sb.AppendLine(string.Format("{0},{1},{2},\"{3}\",\"{4}\",\"{5}\"", file.RequestId, file.RequestGuid, file.ActorGuid, file.Description, file.FilePath, file.FileName));
                                }
                            }
                        }
                        File.WriteAllText(destinationFolder + "\\RequestSupporting.csv", sb.ToString());
                        sb = new StringBuilder();
                        sb.AppendLine("Organization Id,Organization Name Id,Organization Tax Id, Description, File Path, File Name");

                        foreach (FoundationDataFileState.FileInfo file in state.OrganizationSupportingFiles)
                        {
                            sourcePath = string.Format("{0}\\documents\\{1}.{2}",
                                                       state.ClientRootDirectory, file.DocumentId, file.FileName.Split('.').Last());
                            CopyFile(sourcePath, destinationFolder, file);
                            sb.AppendLine(string.Format("{0},\"{1}\",{2},\"{3}\",\"{4}\",\"{5}\"", file.OrganizationId, file.OrganizationName,
                                                        file.OrganizationTaxId, file.Description, file.FilePath, file.FileName));
                        }

                        File.WriteAllText(destinationFolder + "\\Organization.csv", sb.ToString());
                        foreach (FoundationDataFileState.FileInfo file in state.SharedFiles)
                        {
                            sourcePath = string.Format("{0}\\shareddocuments\\document.{1}", state.ClientRootDirectory, file.DocumentId);
                            CopyFile(sourcePath, destinationFolder, file);
                        }
                        break;

                    case "mergetemplates":
                        foreach (FoundationDataFileState.FileInfo file in state.MergeTemplateFiles)
                        {
                            sourcePath = string.Format("{0}\\mergetemplates\\mergetemplate.{1}", state.ClientRootDirectory,
                                                       file.MergeTemplateId);
                            CopyFile(sourcePath, destinationFolder, file);
                        }
                        break;

                    case "attachments":
                        foreach (FoundationDataFileState.FileInfo file in state.AttachmentFiles)
                        {
                            sourcePath = string.Format("{0}\\attachments\\attachment.{1}", state.ClientRootDirectory, file.AttachmentId);
                            CopyFile(sourcePath, destinationFolder, file);
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Format("Unable to copy file: {0}\n{1}", sourcePath, e.Message), "Unable to copy file", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Example #10
0
        private static void SetSharedDocumentFiles(FoundationDataFileState state)
        {
            string directoryPath = string.Format("{0}\\shareddocuments", state.ClientRootDirectory);

            SetFilesFromPath(state, directoryPath);
        }
Example #11
0
        private static void SetMergeTemplateFiles(FoundationDataFileState state)
        {
            string directoryPath = string.Format("{0}\\mergetemplates", state.ClientRootDirectory);

            SetFilesFromPath(state, directoryPath);
        }
Example #12
0
        private static void SetCustomPrintPacketFiles(FoundationDataFileState state)
        {
            string directoryPath = string.Format("{0}\\settingvalues", state.ClientRootDirectory);

            SetFilesFromPath(state, directoryPath);
        }
Example #13
0
 public static void CopyApplicationProcessFiles(FoundationDataFileState state)
 {
     CopyFilesToDestination(state, state.OutputDirectory);
 }
Example #14
0
 private static void ClearFiles(FoundationDataFileState state)
 {
     state.Files          = new List <FileInfo>();
     state.SequesterFiles = new List <FileInfo>();
     state.TotalSize      = 0;
 }