Ejemplo n.º 1
0
        public string ImportFile(string FilePath, string ImportTitle, string ImportNotes, BackgroundWorker BW)
        {
            TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Start Call: ImportFile");
            string response;

            byte[] hashBytes;
            string hashish;
            var    md5 = MD5.Create();

            TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Open Import File: " + FilePath);
            using (var inputFileStream = File.Open(FilePath, FileMode.Open))
            {
                hashBytes = md5.ComputeHash(inputFileStream);
                hashish   = BitConverter.ToString(hashBytes).Replace("-", String.Empty);
                TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Import File Hash: " + hashish);
            }
            int IsFileImportedResult = IsFileImported(hashish);

            TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "IsFileImportedResult :" + IsFileImportedResult);
            if (IsFileImportedResult == 0)
            {
                BW.ReportProgress(0, "newrow|~|" + FilePath + "|~|" + hashish);
                string RawResponse = WDBAPIObj.ApiImportFile(FilePath, ImportTitle, ImportNotes);

                TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), RawResponse);

                response = WDBAPIObj.ParseApiResponse(RawResponse);

                TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Parse Response Result: " + response);

                BW.ReportProgress(0, response + "::" + FilePath);
                ArchiveImportedFile(FilePath);
            }
            else if (IsFileImportedResult == 2)
            {
                response = "error|~|Already Local Imported.-~-" + FilePath;
                BW.ReportProgress(0, response);
            }
            else
            {
                response = "error|~|Already Imported.-~-" + FilePath;
                BW.ReportProgress(0, response);
            }
            TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "File Import Response return: " + response);
            TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "End Call: ImportFile");
            return(response);
        }