Example #1
0
        public int ReadFromLocalFile(dbData3060DataContext p_dbData3060, string FilePath)
        {
            FileInfo file;

            try
            {
                file = new FileInfo(FilePath);
                if (!(file.Exists))
                {
                    return(0);
                }
            }
            catch (Exception)
            {
                return(0);
            }

            //***********************************************************************
            //  Open a local file:
            string fullpath = file.FullName;
            int    numBytes = (int)file.Length;

            byte[] b_data = new byte[numBytes];

            Program.Log(string.Format("Start Reading of {0}", fullpath));
            using (FileStream ts = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
            {
                ts.Read(b_data, 0, numBytes);
            }
            Program.Log(string.Format("{0} Reading Completed", fullpath));

            clsAzure objAzure = new clsAzure();

            objAzure.uploadBlob(file.Name, b_data, false);
            imapSaveAttachedFile(p_dbData3060, file.Name, b_data, false);
            char[] c_data      = System.Text.Encoding.GetEncoding("windows-1252").GetString(b_data).ToCharArray();
            string filecontens = new string(c_data);

            string filecontens2 = filecontens.TrimEnd('\n');
            string filecontens3 = filecontens2.TrimEnd('\r');
            string filecontens4 = filecontens3.TrimEnd('\n');

            string[] lines = filecontens4.Split('\n');
            string   ln    = null;
            int      seqnr = 0;
            string   ln0_6;

            tblpbsfilename m_rec_pbsfiles = new tblpbsfilename
            {
                type     = 8,
                path     = file.Directory.FullName,
                filename = file.Name,
                size     = (int)file.Length,
                atime    = file.LastAccessTime,
                mtime    = file.LastWriteTime
            };

            p_dbData3060.tblpbsfilenames.InsertOnSubmit(m_rec_pbsfiles);
            for (int idx = 0; idx < lines.Count(); idx++)
            {
                ln = lines[idx].TrimEnd('\r');
                try { ln0_6 = ln.Substring(0, 6); }
                catch { ln0_6 = ""; }
                if (((seqnr == 0) && !(ln0_6 == "PBCNET")) || (seqnr > 0))
                {
                    seqnr++;
                }
                if (ln.Length > 0)
                {
                    m_rec_pbsfile = new tblpbsfile
                    {
                        seqnr = seqnr,
                        data  = ln
                    };
                    m_rec_pbsfiles.tblpbsfiles.Add(m_rec_pbsfile);
                }
            }

            m_rec_pbsfiles.transmittime = DateTime.Now;
            var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);

            Program.Log(string.Format("Start Write {0} to SQL Database {1} on {2}", file.Name, cb.InitialCatalog, cb.DataSource));
            p_dbData3060.SubmitChanges();
            Program.Log(string.Format("{0} Write to SQL Database Completed", file.Name));
            return(1);
        }
Example #2
0
        public string WriteTilSFtp(dbData3060DataContext p_dbData3060, int lobnr)
        {
            string TilPBSFilename = "Unknown";
            int    FilesSize;

            var qry_selectfiles =
                from h in p_dbData3060.tblpbsforsendelses
                join d1 in p_dbData3060.tblpbsfilenames on h.id equals d1.pbsforsendelseid into details1
                from d1 in details1.DefaultIfEmpty()
                where d1.id != null && d1.filename == null
                join d2 in p_dbData3060.tbltilpbs on h.id equals d2.pbsforsendelseid into details2
                from d2 in details2.DefaultIfEmpty()
                where d2.id == lobnr
                select new
            {
                tilpbsid = (int?)d2.id,
                d2.leverancespecifikation,
                d2.delsystem,
                d2.leverancetype,
                Bilagdato        = (DateTime?)d2.bilagdato,
                Pbsforsendelseid = (int?)d2.pbsforsendelseid,
                Udtrukket        = (DateTime?)d2.udtrukket,
                pbsfilesid       = (int?)d1.id,
                Leveranceid      = (int)h.leveranceid
            };

            int antal = qry_selectfiles.Count();

            if (antal > 0)
            {
                var rec_selecfiles = qry_selectfiles.First();

                var qry_pbsfiles = from h in p_dbData3060.tblpbsfilenames
                                   where h.id == rec_selecfiles.pbsfilesid
                                   select h;
                if (qry_pbsfiles.Count() > 0)
                {
                    tblpbsfilename m_rec_pbsfiles = qry_pbsfiles.First();
                    TilPBSFilename = AddPbcnetRecords(p_dbData3060, rec_selecfiles.delsystem, rec_selecfiles.Leveranceid, m_rec_pbsfiles.id);

                    var qry_pbsfile =
                        from h in m_rec_pbsfiles.tblpbsfiles
                        orderby h.seqnr
                        select h;

                    string TilPBSFile = "";
                    int    i          = 0;
                    foreach (var rec_pbsfile in qry_pbsfile)
                    {
                        if (i++ > 0)
                        {
                            TilPBSFile += "\r\n";
                        }
                        TilPBSFile += rec_pbsfile.data;
                    }
                    char[] c_TilPBSFile = TilPBSFile.ToCharArray();
                    byte[] b_TilPBSFile = System.Text.Encoding.GetEncoding("windows-1252").GetBytes(c_TilPBSFile);
                    FilesSize = b_TilPBSFile.Length;

                    clsAzure objAzure = new clsAzure();
                    objAzure.uploadBlob(TilPBSFilename, b_TilPBSFile, true);
                    imapSaveAttachedFile(p_dbData3060, TilPBSFilename, b_TilPBSFile, true);

                    string       fullpath      = m_rec_sftp.inbound + "/" + TilPBSFilename;
                    MemoryStream ms_TilPBSFile = new MemoryStream(b_TilPBSFile);

                    Program.Log(string.Format("Start Upload of {0}", fullpath));
                    m_sftp.UploadFile(ms_TilPBSFile, fullpath);
                    Program.Log(string.Format("{0} Upload Completed", fullpath));

                    m_rec_pbsfiles.type         = 8;
                    m_rec_pbsfiles.path         = m_rec_sftp.inbound;
                    m_rec_pbsfiles.filename     = TilPBSFilename;
                    m_rec_pbsfiles.size         = FilesSize;
                    m_rec_pbsfiles.atime        = DateTime.Now;
                    m_rec_pbsfiles.mtime        = DateTime.Now;
                    m_rec_pbsfiles.transmittime = DateTime.Now;
                    p_dbData3060.SubmitChanges();
                }
            }
            return(TilPBSFilename);
        }
Example #3
0
        public int ReadFraSFtp(dbData3060DataContext p_dbData3060)
        {
            m_memPbsnetdir = new MemPbsnetdir(); //opret ny memPbsnetdir

            //  Iterate over the files.
            foreach (SftpFile fileObj in m_sftp.ListDirectory(m_rec_sftp.outbound))
            {
                if (fileObj.Name != "." && fileObj.Name != "..")
                {
                    recPbsnetdir rec = new recPbsnetdir
                    {
                        Type     = 8,
                        Path     = m_rec_sftp.outbound,
                        Filename = fileObj.Name,
                        Size     = (int)fileObj.Length,
                        Atime    = fileObj.LastAccessTime,
                        Mtime    = fileObj.LastWriteTime,
                        Gid      = fileObj.GroupId,
                        Uid      = fileObj.UserId,
                        Perm     = ""
                    };
                    m_memPbsnetdir.Add(rec);
                }
            }

            var leftqry_pbsnetdir =
                from h in m_memPbsnetdir
                //join d1 in p_dbData3060.Tblpbsfiles on new { h.Path, h.Filename } equals new { d1.Path, d1.Filename } into details
                //from d1 in details.DefaultIfEmpty(new Tblpbsfiles { Id = -1, Type = (int?)null, Path = null, Filename = null, Size = (int?)null, Atime = (DateTime?)null, Mtime = (DateTime?)null, Perm = null, Uid = (int?)null, Gid = (int?)null })
                //where d1.Path == null && d1.Filename == null
                select h;

            int AntalFiler = leftqry_pbsnetdir.Count();

            if (leftqry_pbsnetdir.Count() > 0)
            {
                foreach (var rec_pbsnetdir in leftqry_pbsnetdir)
                {
                    tblpbsfilename m_rec_pbsfiles = new tblpbsfilename
                    {
                        type     = rec_pbsnetdir.Type,
                        path     = rec_pbsnetdir.Path,
                        filename = rec_pbsnetdir.Filename,
                        size     = rec_pbsnetdir.Size,
                        atime    = rec_pbsnetdir.Atime,
                        mtime    = rec_pbsnetdir.Mtime,
                        perm     = rec_pbsnetdir.Perm,
                        uid      = rec_pbsnetdir.Uid,
                        gid      = rec_pbsnetdir.Gid
                    };
                    p_dbData3060.tblpbsfilenames.InsertOnSubmit(m_rec_pbsfiles);

                    //***********************************************************************
                    //  Open a file on the server:
                    string fullpath = rec_pbsnetdir.Path + "/" + rec_pbsnetdir.Filename;
                    int    numBytes = (int)rec_pbsnetdir.Size;

                    byte[]       b_data = new byte[numBytes];
                    MemoryStream stream = new MemoryStream(b_data, true);

                    Program.Log(string.Format("Start Download of {0}", fullpath));
                    m_sftp.DownloadFile(fullpath, stream);
                    Program.Log(string.Format("{0} Download Completed", fullpath));

                    clsAzure objAzure = new clsAzure();
                    objAzure.uploadBlob(rec_pbsnetdir.Filename, b_data, false);
                    imapSaveAttachedFile(p_dbData3060, rec_pbsnetdir.Filename, b_data, false);
                    char[] c_data      = System.Text.Encoding.GetEncoding("windows-1252").GetString(b_data).ToCharArray();
                    string filecontens = new string(c_data);

                    string filecontens2 = filecontens.TrimEnd('\n');
                    string filecontens3 = filecontens2.TrimEnd('\r');
                    string filecontens4 = filecontens3.TrimEnd('\n');

                    string[] lines = filecontens4.Split('\n');
                    string   ln    = null;
                    int      seqnr = 0;
                    string   ln0_6;
                    for (int idx = 0; idx < lines.Count(); idx++)
                    {
                        ln = lines[idx].TrimEnd('\r');
                        try { ln0_6 = ln.Substring(0, 6); }
                        catch { ln0_6 = ""; }
                        if (((seqnr == 0) && !(ln0_6 == "PBCNET")) || (seqnr > 0))
                        {
                            seqnr++;
                        }
                        if (ln.Length > 0)
                        {
                            m_rec_pbsfile = new tblpbsfile
                            {
                                seqnr = seqnr,
                                data  = ln
                            };
                            m_rec_pbsfiles.tblpbsfiles.Add(m_rec_pbsfile);
                        }
                    }

                    m_rec_pbsfiles.transmittime = DateTime.Now;
                    var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);
                    Program.Log(string.Format("Start Write {0} to SQL Database {1} on {2}", rec_pbsnetdir.Filename, cb.InitialCatalog, cb.DataSource));
                    p_dbData3060.SubmitChanges();
                    Program.Log(string.Format("{0} Write to SQL Database Completed", rec_pbsnetdir.Filename));
                }
            }
            p_dbData3060.SubmitChanges();
            return(AntalFiler);
        }