Beispiel #1
0
        public string AddPbcnetRecords(dbData3060DataContext p_dbData3060, string delsystem, int leveranceid, int pbsfilesid)
        {
            int      antal;
            int      pbcnetrecords;
            DateTime transmisionsdato;
            int      idlev;
            string   filename;
            string   rec;

            pbcnetrecords = (from h in p_dbData3060.Tblpbsfile
                             where h.Pbsfilesid == pbsfilesid & (h.Seqnr == 0 | h.Seqnr == 9999)
                             select h).Count();

            if (pbcnetrecords == 0)
            {
                // Find antal records
                antal = (from h in p_dbData3060.Tblpbsfile
                         where h.Pbsfilesid == pbsfilesid & h.Seqnr != 0 & h.Seqnr != 9999
                         select h).Count();
                transmisionsdato = DateTime.Now;

                idlev = p_dbData3060.nextval_v2("idlev");

                Tblpbsfilename rec_pbsfiles = (from h in p_dbData3060.Tblpbsfilename where h.Id == pbsfilesid select h).First();

                rec = write00(delsystem, transmisionsdato, idlev, leveranceid);
                Tblpbsfile rec_pbsfile = new Tblpbsfile {
                    Seqnr = 0, Data = rec
                };
                rec_pbsfiles.Tblpbsfile.Add(rec_pbsfile);

                rec         = write90(delsystem, transmisionsdato, idlev, leveranceid, antal);
                rec_pbsfile = new Tblpbsfile {
                    Seqnr = 9999, Data = rec
                };
                rec_pbsfiles.Tblpbsfile.Add(rec_pbsfile);

                p_dbData3060.SaveChanges();

                filename  = "D";
                filename += lpad(String.Format("{0:yyMMdd}", transmisionsdato), 6, '?');
                filename += lpad(idlev, 2, '0');
                filename += ".";
                filename += rpad(delsystem, 3, '_');
            }
            else
            {
                filename = "Unknown";
            }

            return(filename);
        }
Beispiel #2
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];

            Console.WriteLine(string.Format("Start Reading of {0}", fullpath));
            using (FileStream ts = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
            {
                ts.Read(b_data, 0, numBytes);
            }
            Console.WriteLine(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_pbsfilename = new Tblpbsfilename
            {
                Type     = 8,
                Path     = file.Directory.FullName,
                Filename = file.Name,
                Size     = (int)file.Length,
                Atime    = file.LastAccessTime,
                Mtime    = file.LastWriteTime
            };

            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_pbsfilename.Tblpbsfile.Add(m_rec_pbsfile);
                }
            }
            m_rec_pbsfilename.Transmittime = DateTime.Now;
            p_dbData3060.Tblpbsfilename.Add(m_rec_pbsfilename);
            //var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);
            Console.WriteLine(string.Format("Start Write {0} to SQL Database {1} on {2}", file.Name, "cb.InitialCatalog", "cb.DataSource"));
            try
            {
                p_dbData3060.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("p_dbData3060.SaveChanges() failed with message: {0}", e.Message));
                throw;
            }
            Console.WriteLine(string.Format("{0} Write to SQL Database Completed", file.Name));
            return(1);
        }
Beispiel #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.Tblpbsfilename.Add(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);

                    Console.WriteLine(string.Format("Start Download of {0}", fullpath));
                    m_sftp.DownloadFile(fullpath, stream);
                    Console.WriteLine(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.Tblpbsfile.Add(m_rec_pbsfile);
                        }
                    }
                    //this.Database.GetDbConnection()
                    m_rec_pbsfiles.Transmittime = DateTime.Now;
                    //var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);
                    Console.WriteLine(string.Format("Start Write {0} to SQL Database {1} on {2}", rec_pbsnetdir.Filename, "cb.InitialCatalog", "cb.DataSource"));
                    try
                    {
                        p_dbData3060.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(string.Format("p_dbData3060.SaveChanges() failed with message: {0}", e.Message));
                        throw;
                    }
                    Console.WriteLine(string.Format("{0} Write to SQL Database Completed", rec_pbsnetdir.Filename));
                }
            }
            p_dbData3060.SaveChanges();
            return(AntalFiler);
        }