Beispiel #1
0
        public string ReceiveFileFromClient(List <IFormFile> files)
        {
            string        fileName        = "";
            string        savePath        = "";
            string        localPath       = "";
            string        targetDirectory = "";
            string        fileInput       = "";
            string        callDate        = "";
            string        callTime        = "";
            FileInfo      info;
            List <string> fileformat = new List <string>();

            foreach (IFormFile file in files)
            {
                targetDirectory = _state.StoragePath._localPath;

                fileName = file.FileName;

                localPath = Path.Combine(targetDirectory, fileName);

                if (!_func.CheckExistingDirectory(targetDirectory))
                {
                    _func.DirectoryCreate(targetDirectory);
                }
                if (_func.CheckExistingFile(targetDirectory, fileName))
                {
                    continue;
                    //_func.DestroyFileFromName(targetDirectory, fileName);
                }
                using (var fileStream = new FileStream(localPath, FileMode.Create))
                {
                    file.CopyTo(fileStream);
                }
                using (var client = new WebClient())
                {
                    savePath           = string.Format("{0}/{1}", _state.FtpConfig._ftpPath, fileName);
                    client.Credentials = new NetworkCredential(_state.FtpConfig._username, _state.FtpConfig._password);
                    client.UploadFile(savePath, WebRequestMethods.Ftp.UploadFile, localPath);
                }

                _func.DestroyFileFromName(targetDirectory, fileName);
                info = _func.GetFileInformation(fileName);
                // Log File for Other Process
                fileformat = fileName.Split('_').ToList();

                fileInput = string.Format("{0}_{1}{2}", fileformat[1], fileformat[2], info.Extension);

                callDate = DateTime.ParseExact(fileformat[1], "yyMMdd", new CultureInfo("en-US")).ToString("yyyy-MM-dd");
                callTime = string.Format(
                    "{0}:{1}:{2}",
                    string.Concat(fileformat[2][0], fileformat[2][1]),
                    string.Concat(fileformat[2][2], fileformat[2][3]),
                    string.Concat(fileformat[2][4], fileformat[2][5])
                    );



                _file.REST_InsertFileLog(
                    FileName: fileInput,
                    OriginalFile: fileName,
                    fileSize: info.Length,
                    PhoneNumber: "0941610031",
                    CallDate: callDate,
                    CallTime: callTime,
                    CreateBy: "0941610031"
                    );
            }


            return(fileName);
        }
Beispiel #2
0
        public string ReceiveFileFromClient(List <IFormFile> files, string username)
        {
            string        fileName        = "";
            string        savePath        = "";
            string        localPath       = "";
            string        targetDirectory = "";
            string        fileInput       = "";
            string        callDate        = "";
            string        callTime        = "";
            string        strTelephone    = "";
            string        fileforInsert   = "";
            FileInfo      info;
            List <string> fileformat    = new List <string>();
            List <string> strInputFile  = new List <string>();
            List <string> strOriginFile = new List <string>();
            List <string> strPhone      = new List <string>();

            foreach (IFormFile file in files)
            {
                try{
                    targetDirectory = _state.StoragePath.localPath;

                    fileName = file.FileName;

                    localPath = Path.Combine(targetDirectory, fileName);

                    fileformat = fileName.Split('_').ToList();
                    strPhone   = fileformat[0].Split(" ").ToList();
                    callDate   = DateTime.ParseExact(fileformat[1], "yyMMdd", new CultureInfo("en-US")).ToString("yyyy-MM-dd");
                    callTime   = string.Format(
                        "{0}:{1}:{2}",
                        string.Concat(fileformat[2][0], fileformat[2][1]),
                        string.Concat(fileformat[2][2], fileformat[2][3]),
                        string.Concat(fileformat[2][4], fileformat[2][5])
                        );

                    if (strPhone.Count > 2)
                    {
                        for (int i = 1; i < strPhone.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(strTelephone))
                            {
                                strTelephone += " ";
                            }
                            strTelephone += strPhone[i];
                        }
                    }
                    else
                    {
                        strTelephone = strPhone[1];
                    }

                    fileInput = string.Format("{0}_{1}", fileformat[1], fileformat[2]);

                    strInputFile = fileInput.Split(".").ToList();


                    if (!_func.CheckExistingDirectory(targetDirectory))
                    {
                        _func.DirectoryCreate(targetDirectory);
                    }
                    if (_func.CheckExistingFile(targetDirectory, fileName))
                    {
                        _func.DestroyFileFromName(targetDirectory, fileName);
                        // continue;
                    }
                    using (var fileStream = new FileStream(localPath, FileMode.Create))
                    {
                        file.CopyTo(fileStream);
                    }
                    using (var client = new WebClient())
                    {
                        fileforInsert      = string.Format("{0}_{1}_{2}", username, strTelephone, strInputFile[0]);
                        savePath           = string.Format("{0}/{1}.m4a", _state.FtpConfig.ftpPath, fileforInsert);
                        client.Credentials = new NetworkCredential(_state.FtpConfig.username, _state.FtpConfig.password);
                        client.UploadFile(savePath, WebRequestMethods.Ftp.UploadFile, localPath);
                    }

                    info = _func.GetFileInformation(localPath);
                    // Log File for Other Process
                    strOriginFile = fileName.Split(".").ToList();

                    _file.REST_InsertFilelog(
                        FileName: fileforInsert,
                        OriginalFile: strOriginFile[0],
                        FileSize: info.Length,
                        Extension: strInputFile[1],
                        PhoneNumber: strTelephone,
                        CallDate: callDate,
                        CallTime: callTime,
                        CreateBy: username
                        );
                    _func.DestroyFileFromName(targetDirectory, fileName);
                }
                catch (Exception e) {
                    return(e.Message);
                }
            }


            return(username);
        }