Пример #1
0
        /// <summary>
        /// Uploads a file into the repository
        /// </summary>
        public void PutFile(FileUploadMessage msg)
        {
            string filePath = Path.Combine(RepositoryDirectoryDic[msg.fieldGuid], msg.VirtualPath);
            string dir      = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            using (var outputStream = new FileStream(filePath, FileMode.Create))
            {
                msg.DataStream.CopyTo(outputStream);
            }

            SendFileUploaded(filePath,
                             msg.startTime,
                             msg.clientIpAddress,
                             msg.fieldGuid,
                             msg.G360Index,
                             msg._fileOwnerUserName,
                             msg.watsonDateTime,
                             msg.SizeOfFile,
                             msg.TargetPath,
                             msg.VirtualPath);
        }
Пример #2
0
        public void PutFileWithPath(FileUploadMessage msg)
        {
            string dir = string.Empty;

            try
            {
                string fieldPath = RepositoryDirectoryDic[msg.fieldGuid] + "\\" + msg.fieldGuid;
                if (msg.AddDateToTargetFolder == true)
                {
                    string[] fileDate = msg.VirtualPath.Split(new Char[] { '_' });
                    //"SENSOR_888_05_05_2015_09_33_50_496.bin"
                    if (fileDate.Length == 9)
                    {
                        string dateDir = fileDate[4] + "_" + fileDate[3] + "_" + fileDate[2];
                        fieldPath += "\\" + dateDir;
                    }
                    else
                    {
                        DateTime d = msg.watsonDateTime;
                        fieldPath += "\\" + d.Year + "_" + d.Month + "_" + d.Day;
                    }
                }
                if (Directory.Exists(fieldPath) == false)
                {
                    Directory.CreateDirectory(fieldPath);
                }
                string filePath = Path.Combine(fieldPath + "\\" + msg.TargetPath, msg.VirtualPath);
                dir = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                using (var outputStream = new FileStream(filePath, FileMode.Create))
                {
                    msg.DataStream.CopyTo(outputStream);
                }

                SendFileUploaded(filePath,
                                 msg.startTime,
                                 msg.clientIpAddress,
                                 msg.fieldGuid,
                                 msg.G360Index,
                                 msg._fileOwnerUserName,
                                 msg.watsonDateTime,
                                 msg.SizeOfFile,
                                 msg.TargetPath,
                                 msg.VirtualPath);
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                File.WriteAllText("c:\\PutFileWithPath.txt", err.Message + Environment.NewLine + dir);
            }
        }