Пример #1
0
        }// public void StartProcessing()

        private List <FtpSiteInfo> GetSiteInfo(List <string> sp)
        {
            List <FtpSiteInfo> si = new List <FtpSiteInfo>();

            // get the site credentials for each site
            m_ServiceProviderFTPSite     = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPSite"];
            m_ServiceProviderFTPUsername = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPUsername"];
            m_ServiceProviderFTPPassword = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPPassword"];
            List <string> m_sites  = this.ParseList(m_ServiceProviderFTPSite);
            List <string> m_unames = this.ParseList(m_ServiceProviderFTPUsername);
            List <string> m_pwds   = this.ParseList(m_ServiceProviderFTPPassword);

            try
            {
                int i = 0;
                foreach (string s in sp)
                {
                    FtpSiteInfo f = new FtpSiteInfo();
                    f.ServiceProvider = s;
                    f.Site            = m_sites[i];
                    f.Username        = m_unames[i];
                    f.Password        = m_pwds[i];

                    // add the site to our list
                    si.Add(f);
                    i++;
                }
            }
            catch (SystemException se)
            {
                LogIt("CdrHandler::GetSiteInfo()::ExceptionCaught:" + se.Message);
            }

            return(si);
        }
Пример #2
0
        }// private void ProcessServiceProviderCdrs()

        /// <summary>
        /// method to upload the contents of a file from a remote URI
        /// </summary>
        /// <param name="ftpUri"></param>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public void PostFileToSite(FtpSiteInfo si)
        {
            string parsedFileName = string.Empty;
            Uri    ftpUri         = null;

            try
            {
                parsedFileName = ParseFileName(si.Filename);

                // contains the URI path and filename to upload to the remote server
                // always using the cdrs directory below the users root directory
                UriBuilder ub = new UriBuilder("ftp", si.Site, -1, "/cdrs/" + parsedFileName + ".csv");

                ftpUri = ub.Uri;

                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri);
                request.Method = WebRequestMethods.Ftp.UploadFile;

                NetworkCredential nc = new NetworkCredential(si.Username, si.Password);
                CredentialCache   cc = new CredentialCache();
                cc.Add(ftpUri, "Basic", nc);
                request.Credentials = cc;
                //request.Timeout = 300000;
                //request.ReadWriteTimeout = 10000000;
                //request.KeepAlive = false;

                request.UseBinary  = true;
                request.UsePassive = false;

                // Copy the contents of the file to the request stream.
                StreamReader sourceStream = new StreamReader(si.Filename);
                byte[]       fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();

                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }
            catch (WebException e)
            {
                LogIt("ServiceProviderCdrHandler::PostFileToSite():ECaught: " + e.Message);
            }
            catch (UriFormatException ue)
            {
                LogIt("ServiceProviderCdrHandler::PostFileToSite():ECaught: " + ue.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// method to upload the contents of a file from a remote URI
        /// </summary>
        /// <param name="ftpUri"></param>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public void PostFileToSite( FtpSiteInfo si )
        {
            string parsedFileName = string.Empty;
            Uri ftpUri = null;

            try
            {
                parsedFileName = ParseFileName(si.Filename );

                // contains the URI path and filename to upload to the remote server
                // always using the cdrs directory below the users root directory
                UriBuilder ub = new UriBuilder("ftp", si.Site, -1, "/cdrs/" + parsedFileName + ".csv");

                ftpUri = ub.Uri;

                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri);
                request.Method = WebRequestMethods.Ftp.UploadFile;

                NetworkCredential nc = new NetworkCredential( si.Username, si.Password );
                CredentialCache cc = new CredentialCache();
                cc.Add(ftpUri, "Basic", nc);
                request.Credentials = cc;
                //request.Timeout = 300000;
                //request.ReadWriteTimeout = 10000000;
                //request.KeepAlive = false;

                request.UseBinary = true;
                request.UsePassive = false;

                // Copy the contents of the file to the request stream.
                StreamReader sourceStream = new StreamReader( si.Filename );
                byte[] fileContents = Encoding.UTF8.GetBytes( sourceStream.ReadToEnd() );
                sourceStream.Close();

                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }
            catch (WebException e)
            {
                LogIt("ServiceProviderCdrHandler::PostFileToSite():ECaught: " + e.Message );
            }
            catch( UriFormatException ue )
            {
                LogIt("ServiceProviderCdrHandler::PostFileToSite():ECaught: " + ue.Message);
            }
        }
Пример #4
0
        private void ServiceProviderCdrHandler_Click(object sender, EventArgs e)
        {
            ServiceProviderCdrHandler sp = new ServiceProviderCdrHandler();
            FtpSiteInfo si = new FtpSiteInfo();
            si.ServiceProvider = "WCI_sp";
            si.Site = "cdrftp01-sttlwa.strata8.net";
            si.Password = "******";
            si.Username = "******";

            //si.Site = "208.99.195.208";
               // si.Password = "******";
            //si.Username = "******";

            si.Filename = @"c:\logs\CDRFile01.csv";
            sp.PostFileToSite(si);
            //sp.Upload(si);

            //sp.ProcessServiceProviderCdrs( @"c:\logs\CDRFile01" , "test", "Premiere_sp" );
        }
Пример #5
0
        public void ProcessServiceProviderCdrs(string fileName, string line, FtpSiteInfo si)
        {
            try
            {
                // parse the line
                string[] controls = line.Split(m_sep);
                if (controls.GetLength(0) < 100)
                {
                    // we have a non-data line -- header or footer... so just write it
                    LogFileMgr.Instance.WriteToFile(si.Filename, line);
                }
                else if (controls[1].Trim(m_trim).Equals(si.ServiceProvider))
                {
                    LogFileMgr.Instance.WriteToFile(si.Filename, line);
                }
            }
            catch (System.Exception ex)
            {
                LogIt("ProcessServiceProviderCdrs():: " + ex.Message);
            }

            return;
        }// private void ProcessServiceProviderCdrs()
Пример #6
0
        public void Upload(FtpSiteInfo si)
        {
            Stream         requestStream  = null;
            FileStream     fileStream     = null;
            FtpWebResponse uploadResponse = null;
            string         parsedFileName = null;
            Uri            ftpUri         = null;


            try
            {
                parsedFileName = ParseFileName(si.Filename);

                // contains the URI path and filename to upload to the remote server
                //UriBuilder ub = new UriBuilder(si.Site + "//" + parsedFileName + ".csv");
                UriBuilder ub = new UriBuilder("ftp", si.Site, -1, "/cdrs/" + parsedFileName + ".csv");
                // UriBuilder ub = new UriBuilder("ftp", "208.99.195.208", -1, parsedFileName + ".csv");

                ftpUri = ub.Uri;
                FtpWebRequest uploadRequest =
                    (FtpWebRequest)WebRequest.Create(ftpUri);
                uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;

                // UploadFile is not supported through an Http proxy
                // so we disable the proxy for this request.
                uploadRequest.Proxy = null;

                NetworkCredential nc = new NetworkCredential(si.Username, si.Password);
                CredentialCache   cc = new CredentialCache();
                cc.Add(ftpUri, "Basic", nc);
                uploadRequest.Credentials = cc;
                uploadRequest.UseBinary   = true;
                uploadRequest.UsePassive  = false;

                requestStream = uploadRequest.GetRequestStream();
                fileStream    = File.Open(si.Filename, FileMode.Open);

                byte[] buffer = new byte[1024];
                int    bytesRead;
                while (true)
                {
                    bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        break;
                    }
                    requestStream.Write(buffer, 0, bytesRead);
                }

                // The request stream must be closed before getting
                // the response.
                requestStream.Close();

                uploadResponse =
                    (FtpWebResponse)uploadRequest.GetResponse();
            }
            catch (UriFormatException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);
            }
            catch (IOException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);
            }
            catch (WebException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);
            }
            finally
            {
                if (uploadResponse != null)
                {
                    uploadResponse.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                if (requestStream != null)
                {
                    requestStream.Close();
                }
            }
        }
Пример #7
0
        public void Upload( FtpSiteInfo si)
        {
            Stream requestStream = null;
            FileStream fileStream = null;
            FtpWebResponse uploadResponse = null;
            string parsedFileName = null;
            Uri ftpUri = null;

            try
            {
                parsedFileName = ParseFileName(si.Filename);

                // contains the URI path and filename to upload to the remote server
                //UriBuilder ub = new UriBuilder(si.Site + "//" + parsedFileName + ".csv");
                UriBuilder ub = new UriBuilder("ftp", si.Site, -1, "/cdrs/"+parsedFileName + ".csv");
                // UriBuilder ub = new UriBuilder("ftp", "208.99.195.208", -1, parsedFileName + ".csv");

                ftpUri = ub.Uri;
                FtpWebRequest uploadRequest =
                    (FtpWebRequest)WebRequest.Create( ftpUri );
                uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;

                // UploadFile is not supported through an Http proxy
                // so we disable the proxy for this request.
                uploadRequest.Proxy = null;

                NetworkCredential nc = new NetworkCredential(si.Username, si.Password);
                CredentialCache cc = new CredentialCache();
                cc.Add(ftpUri, "Basic", nc);
                uploadRequest.Credentials = cc;
                uploadRequest.UseBinary = true;
                uploadRequest.UsePassive = false;

                requestStream = uploadRequest.GetRequestStream();
                fileStream = File.Open(si.Filename, FileMode.Open);

                byte[] buffer = new byte[1024];
                int bytesRead;
                while (true)
                {
                    bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    requestStream.Write(buffer, 0, bytesRead);
                }

                // The request stream must be closed before getting
                // the response.
                requestStream.Close();

                uploadResponse =
                    (FtpWebResponse)uploadRequest.GetResponse();
            }
            catch (UriFormatException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);
            }
            catch (IOException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);
            }
            catch (WebException ex)
            {
                LogIt("Upload::PostFileToSite():ECaught: " + ex.Message);

            }
            finally
            {
                if (uploadResponse != null)
                    uploadResponse.Close();
                if (fileStream != null)
                    fileStream.Close();
                if (requestStream != null)
                    requestStream.Close();
            }
        }
Пример #8
0
        public void ProcessServiceProviderCdrs( string fileName, string line, FtpSiteInfo si )
        {
            try
            {
                // parse the line
                string[] controls = line.Split(m_sep);
                if (controls.GetLength(0) < 100)
                {
                    // we have a non-data line -- header or footer... so just write it
                    LogFileMgr.Instance.WriteToFile(si.Filename, line);
                }
                else if ( controls[1].Trim(m_trim).Equals( si.ServiceProvider ) )
                {
                    LogFileMgr.Instance.WriteToFile(si.Filename, line);
                }

            }
            catch (System.Exception ex)
            {
                LogIt("ProcessServiceProviderCdrs():: " + ex.Message);
            }

            return;
        }
Пример #9
0
        private List<FtpSiteInfo> GetSiteInfo( List<string> sp )
        {
            List<FtpSiteInfo> si = new List<FtpSiteInfo>();

            // get the site credentials for each site
            m_ServiceProviderFTPSite = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPSite"];
            m_ServiceProviderFTPUsername = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPUsername"];
            m_ServiceProviderFTPPassword = System.Configuration.ConfigurationManager.AppSettings["ServiceProviderFTPPassword"];
            List<string> m_sites = this.ParseList(m_ServiceProviderFTPSite);
            List<string> m_unames = this.ParseList(m_ServiceProviderFTPUsername);
            List<string> m_pwds = this.ParseList(m_ServiceProviderFTPPassword);

            try
            {
                int i = 0;
                foreach (string s in sp)
                {
                    FtpSiteInfo f = new FtpSiteInfo();
                    f.ServiceProvider = s;
                    f.Site = m_sites[i];
                    f.Username = m_unames[i];
                    f.Password = m_pwds[i];

                    // add the site to our list
                    si.Add(f);
                    i++;

                }
            }
            catch (SystemException se)
            {
                LogIt("CdrHandler::GetSiteInfo()::ExceptionCaught:" + se.Message);
            }

            return si;
        }