Ejemplo n.º 1
0
        public static EFDataFileInfo CreateEFDataFileInfo(int id, string name, long size, byte[] hash, global::System.DateTime creationTime, global::System.DateTime insertTime, string path, string hostName)
        {
            EFDataFileInfo eFDataFileInfo = new EFDataFileInfo();

            eFDataFileInfo.Id           = id;
            eFDataFileInfo.Name         = name;
            eFDataFileInfo.Size         = size;
            eFDataFileInfo.Hash         = hash;
            eFDataFileInfo.CreationTime = creationTime;
            eFDataFileInfo.InsertTime   = insertTime;
            eFDataFileInfo.Path         = path;
            eFDataFileInfo.HostName     = hostName;
            return(eFDataFileInfo);
        }
Ejemplo n.º 2
0
        public static FileProcessInfo StartProcess(FileProcessInfo startInfo, Stream dataStream)
        {
            if (startInfo == null)
            {
                throw new ArgumentNullException(nameof(startInfo));
            }
            if (dataStream == null)
            {
                throw new ArgumentNullException(nameof(dataStream));
            }

            //todo dir name
            var dirName = Environment.ExpandEnvironmentVariables("%temp%\\FileUploadManager");

            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }
            var tempFileName = Path.Combine(dirName, startInfo.UniqueId.ToString());

            try
            {
                using (var fs = new FileStream(tempFileName, FileMode.Create, FileAccess.Write))
                {
                    var buffer = new byte[64 * 1024];
                    int readCount;
                    while ((readCount = dataStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fs.Write(buffer, 0, readCount);
                    }
                }

                using (var db = new FileUploadDbEntities())
                {
                    db.Connection.Open();
                    using (var tran = db.Connection.BeginTransaction())
                    {
                        var fileInfo = new EFDataFileInfo();
                        fileInfo.CreationTime = startInfo.FileInfo.CreationTime;
                        fileInfo.Hash         = startInfo.FileInfo.Hash;
                        fileInfo.HostName     = Environment.MachineName;
                        fileInfo.Name         = startInfo.FileInfo.Name;
                        fileInfo.Path         = tempFileName;
                        fileInfo.Size         = startInfo.FileInfo.Size;
                        //todo: GETDATE()
                        fileInfo.InsertTime = DateTime.Now;

                        EFFileProcessInfo processInfo = new EFFileProcessInfo();
                        processInfo.DataFileInfo = fileInfo;
                        processInfo.StartTime    = startInfo.StartTime;
                        processInfo.UniqueId     = startInfo.UniqueId;
                        processInfo.State        = (byte)ProcessState.Parsing;

                        db.AddToEFFileProcessInfoes(processInfo);

                        db.SaveChanges();
                        tran.Commit();

                        startInfo.Id    = processInfo.Id;
                        startInfo.State = (ProcessState)processInfo.State;

                        return(startInfo);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    if (File.Exists(tempFileName))
                    {
                        File.Delete(tempFileName);
                    }
                }
                catch (Exception innerException)
                {
                    //todo use FT.Common
                    e.Data["InnerException"] = innerException.ToString();
                }

                throw;
            }
        }
Ejemplo n.º 3
0
 public void AddToEFDataFileInfoes(EFDataFileInfo eFDataFileInfo)
 {
     base.AddObject("EFDataFileInfoes", eFDataFileInfo);
 }