Пример #1
0
 public FileDownloadInfo(string fileName, long fileSize = 0, FileInfoType fileInfoType = FileInfoType.File)
 {
     FileName     = fileName;
     FileSize     = fileSize;
     FileParts    = new List <FilePartInfo>();
     FileInfoType = fileInfoType;
 }
        public virtual int Delete(string directory, string name, FileInfoType type)
        {
            int count = 0;

            if (!string.IsNullOrEmpty(name))
            {
                directory = Utils.FormatDirectory(directory);
                name      = Utils.FormatName(name);

                using (var db = this.CreateDbContext())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    using (db.BeginTransaction())
                    {
                        var m = db.FileInfo.Where(q => q.Directory == directory && q.Name == name && q.Type == type && q.IsDelete == false).FirstOrDefault();
                        if (m != null)
                        {
                            m.IsDelete    = false;
                            m.CheckStatus = (int)CheckStatusType.None;
                            m.UpdateTime  = DateTime.Now;
                            count        += db.SaveChanges();
                            db.Commit();
                        }
                    }
                }
            }

            return(count);
        }
Пример #3
0
 public FileInfoEx(FileSystemInfo fileSystemInfo, FileInfoType fileType, string displayName, string rootDir)
 {
     FileSysInfo = fileSystemInfo;
     FileType    = fileType;
     DisplayName = displayName;
     RootDir     = rootDir;
 }
Пример #4
0
        /// <summary>
        /// Resolves the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="type">The type.</param>
        /// <returns>VideoFileInfo.</returns>
        /// <exception cref="System.ArgumentNullException">path</exception>
        public VideoFileInfo Resolve(string path, FileInfoType type)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var    isStub    = false;
            string container = null;
            string stubType  = null;

            if (type == FileInfoType.File)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options, _logger).ResolveFile(path);

                    isStub = stubResult.IsStub;

                    // It's not supported. Check stub extensions
                    if (!isStub)
                    {
                        return(null);
                    }

                    stubType = stubResult.StubType;
                }

                container = extension.TrimStart('.');
            }

            var flags          = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options, _logger).Parse(flags);

            var extraResult = new ExtraTypeParser(_options, _logger).GetExtraInfo(path);

            var name = type == FileInfoType.File
                ? Path.GetFileNameWithoutExtension(path)
                : Path.GetFileName(path);

            var cleanDateTimeResult = CleanDateTime(name);

            name = cleanDateTimeResult.Name;
            name = CleanString(name).Name;

            return(new VideoFileInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                Name = name,
                Year = cleanDateTimeResult.Year,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                ExtraType = extraResult.ExtraType
            });
        }
        public virtual FileInfoDto Get(string directory, string name, FileInfoType type)
        {
            FileInfoDto vm = null;

            if (!string.IsNullOrEmpty(name))
            {
                directory = Utils.FormatDirectory(directory);
                name      = Utils.FormatName(name);

                using (var db = this.CreateDbContext())
                {
                    var query = from q in db.FileInfo
                                where q.Directory == directory && q.Name == name && q.Type == type && q.IsDelete == false
                                select new FileInfoDto
                    {
                        Id            = q.Id,
                        ParentId      = q.ParentId,
                        Type          = q.Type,
                        Directory     = q.Directory,
                        Name          = q.Name,
                        Length        = q.Length,
                        CreationTime  = q.CreationTime,
                        LastWriteTime = q.LastWriteTime,
                        Key           = q.Key,
                        UpdateTime    = q.UpdateTime,
                        IsDelete      = q.IsDelete
                    };

                    vm = query.FirstOrDefault();
                }
            }

            return(vm);
        }
        public EpisodeInfo Parse(string path, FileInfoType type)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            var    isStub    = false;
            string container = null;
            string stubType  = null;

            if (type == FileInfoType.File)
            {
                var extension = Path.GetExtension(path) ?? string.Empty;
                // Check supported extensions
                if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    var stubResult = new StubResolver(_options, _logger).ResolveFile(path);

                    isStub = stubResult.IsStub;

                    // It's not supported. Check stub extensions
                    if (!isStub)
                    {
                        return(null);
                    }

                    stubType = stubResult.StubType;
                }

                container = extension.TrimStart('.');
            }

            var flags          = new FlagParser(_options).GetFlags(path);
            var format3DResult = new Format3DParser(_options, _logger).Parse(flags);

            var parsingResult = new EpisodePathParser(_options, _iRegexProvider).Parse(path, type);

            return(new EpisodeInfo
            {
                Path = path,
                Container = container,
                IsStub = isStub,
                EndingEpsiodeNumber = parsingResult.EndingEpsiodeNumber,
                EpsiodeNumber = parsingResult.EpsiodeNumber,
                SeasonNumber = parsingResult.SeasonNumber,
                SeriesName = parsingResult.SeriesName,
                StubType = stubType,
                Is3D = format3DResult.Is3D,
                Format3D = format3DResult.Format3D,
                IsByDate = parsingResult.IsByDate,
                Day = parsingResult.Day,
                Month = parsingResult.Month,
                Year = parsingResult.Year
            });
        }
Пример #7
0
        public FileInfoType GetFileInfo(int fileId)
        {
            FileInfoType fit      = new FileInfoType();
            var          response = _apiHelper.MakeApiCall <FileInfoType>(new Func <int, FileInfoType>(_highTailApi.GetFileInfo), fileId);

            if (!response.Error)
            {
                fit = response.Response;
            }
            return(fit);
        }
Пример #8
0
        public override string FileExtract(string extractFilePath, FileInfoType fileInfoType, string businessDate, string tableName, string fileImportFormatDirectory)
        {
            string result = string.Empty;
            string fileImportFormat = Path.Combine(fileImportFormatDirectory, "BILL_AccountBill.fmt");

            string uploadDirectoryAbs = Path.Combine(NMBConfig.UploadDirectoryAbs, businessDate);
            extractFilePath = Path.Combine(uploadDirectoryAbs, Path.GetFileName(extractFilePath));

            DCCommonTxtProcess dcCommonTxtProcess = new DCCommonTxtProcess();
            dcCommonTxtProcess.ExtractFileToDataBaseOptimize("Proc_BILL_AccountBill_Import", businessDate, extractFilePath, fileImportFormat, ref result);

            return result;
        }
        public EpisodePathParserResult Parse(string path, FileInfoType type)
        {
            var name = Path.GetFileName(path);

            var result = _options.EpisodeExpressions.Select(i => Parse(name, i))
                         .FirstOrDefault(i => i.Success);

            if (result != null)
            {
                return(result);
            }

            return(new EpisodePathParserResult
            {
            });
        }
        public virtual bool Exist(string directory, string name, FileInfoType type)
        {
            int count = 0;

            if (!string.IsNullOrEmpty(name))
            {
                directory = Utils.FormatDirectory(directory);
                name      = Utils.FormatName(name);

                using (var db = this.CreateDbContext())
                {
                    count = db.FileInfo.Where(q => q.Directory == directory && q.Name == name && q.Type == type && q.IsDelete == false).Count();
                }
            }

            return(count > 0);
        }
Пример #11
0
 /// Returns true if Poly would accept a PATCH of the specified asset
 /// from the specified user.
 ///
 /// Pass:
 ///   type -
 ///     Where you found the assetId. Necessary because of some shortcuts
 ///     taken by the implementation.
 ///   userId - Poly user id of the currently-logged-in OAuth user. Get it
 ///     with GetAccountIdAsync().
 public static async Task <bool> IsMutableAssetIdAsync(
     FileInfoType type, string assetId, string userId, string apiHost)
 {
     if (assetId == null)
     {
         return(false);
     }
     // There are too many assumptions here -- for both cloud and disk, the logic
     // should be "is it owned by me and unpublished? then it's mutable"
     if (type == FileInfoType.Cloud)
     {
         // Assumption: cloud files are immutable.
         // You can't "Like" an unpublished asset; and published assets are immutable.
         return(false);
     }
     else if (type == FileInfoType.Disk)
     {
         // Assumption: this asset is mutable because it's unlikely for a cloud-based .tilt
         // to be in the user's Sketches/ folder. Local sketches always become un-published
         // and mutable assets when uploaded (remember, publishing makes a copy).
         // If someone grabbed a .tilt from their Poly asset cache and put it in Sketches/
         // that would break this assumption and I'm not sure what would happen.
         if (userId == null)
         {
             return(false);
         }
         // It's mutable, but check whether it's mutable by _us_.
         try
         {
             // The null == null case is handled earlier
             WebRequest request = new WebRequest(
                 $"{apiHost}{kListAssetsUri}/{assetId}?key={kPolyApiKey}",
                 App.GoogleIdentity, UnityWebRequest.kHttpVerbGET);
             return((await request.SendAsync()).JObject?["accountId"].ToString() == userId);
         }
         catch (VrAssetServiceException)
         {
             return(false);
         }
     }
     else
     {
         throw new InvalidOperationException($"Unknown FileInfoType {type}");
     }
 }
Пример #12
0
        public override string FileExtract(string extractFilePath, FileInfoType fileInfoType, string businessDate, string tableName, string fileImportFormatDirectory)
        {
            string result = string.Empty;

            DCEngineExcelParam dcEngineExcelParam = new DCEngineExcelParam();
            dcEngineExcelParam.ContentRowIndexStart = 1;
            dcEngineExcelParam.EndRowExceptCount = 1;
            dcEngineExcelParam.ContentColumnIndexStart = 0;
            dcEngineExcelParam.ContentColumnIndexEnd = 5;
            dcEngineExcelParam.RowExceptSQL = string.Empty;
            dcEngineExcelParam.SheetName = "0";
            dcEngineExcelParam.FileInfoType = fileInfoType;

            DCExcelProcess dcExcelProcess = new DCExcelProcess();
            dcExcelProcess.ExtractFileToDataBase(dcEngineExcelParam, businessDate, extractFilePath, tableName, ref result);

            return result;
        }
Пример #13
0
        public static string GetFileExtension(FileInfoType type)
        {
            switch (type)
            {
            case FileInfoType.Audio:
                return("");

            case FileInfoType.Document:
                return(".gdoc");

            case FileInfoType.Drawing:
                return(".gdraw");

            case FileInfoType.File:
                return("");

            case FileInfoType.Form:
                return(".gform");

            case FileInfoType.FusionTable:
                return(".gtable");

            case FileInfoType.Photo:
                return("");

            case FileInfoType.Presentation:
                return("");

            case FileInfoType.Script:
                return(".gscript");

            case FileInfoType.Sites:
                return("");

            case FileInfoType.Spreadsheet:
                return(".gsheet");

            case FileInfoType.Video:
                return("");

            default:
                return("");
            }
        }
Пример #14
0
        public override string FileExtract(string extractFilePath, FileInfoType fileInfoType, string businessDate, string tableName, string fileImportFormatDirectory)
        {
            string result = string.Empty;

            DCEngineCommonTxtParam dcEngineCommonTxtParam = new DCEngineCommonTxtParam();
            dcEngineCommonTxtParam.GetContentPattern = @"(?<key>[^\n]+(?=\n?))";
            dcEngineCommonTxtParam.FileEncoding = "gb2312";
            dcEngineCommonTxtParam.ContentSplit = "~";
            dcEngineCommonTxtParam.IsAddEnter = false;
            dcEngineCommonTxtParam.RowExcept = string.Empty;
            dcEngineCommonTxtParam.ByteSplit = string.Empty;
            dcEngineCommonTxtParam.ColumnSplitType = (byte)ColumnSplitType.按分隔符;
            dcEngineCommonTxtParam.StringSplitOptions = StringSplitOptions.None;
            dcEngineCommonTxtParam.FileInfoType = fileInfoType;

            DCCommonTxtProcess dcCommonTxtProcess = new DCCommonTxtProcess();
            dcCommonTxtProcess.ExtractFileToDataBase(dcEngineCommonTxtParam, businessDate, extractFilePath, tableName, ref result);

            return result;
        }
        private NWF CreateNwf(UserInfo user, string source, FileInfoRequest fileInfoRequest)
        {
            NWF nwf      = new NWF();
            var bodyinfo = new BodyInfoType();
            var header   = new HeaderType();

            bodyinfo.FileInfo = new List <FileInfoType>();

            nwf.BodyInfo = bodyinfo;
            nwf.Header   = header;


            header.TaskGuid     = "";
            header.ContentGuid  = fileInfoRequest.SourceId;
            header.Action       = "ImageProcess";
            header.SourceSystem = source;

            header.ExtraAttribute = new List <AttributeType>();
            header.ExtraAttribute.Add(new AttributeType()
            {
                Name = "UserID", Value = user.Id
            });
            header.ExtraAttribute.Add(new AttributeType()
            {
                Name = "SubSystem", Value = "humanfile"
            });
            bodyinfo.Priority = 0;
            bodyinfo.TaskName = fileInfoRequest.Name;
            if (String.IsNullOrEmpty(bodyinfo.TaskName))
            {
                bodyinfo.TaskName = $"{user.UserName}-{source ?? ""}";
            }

            var extra = new List <AttributeType>();

            extra.Add(new AttributeType {
                Name = "WXAppID", Value = fileInfoRequest.AppId
            });
            extra.Add(new AttributeType {
                Name = "From", Value = fileInfoRequest.From
            });
            extra.Add(new AttributeType {
                Name = "Source", Value = fileInfoRequest.Source
            });
            extra.Add(new AttributeType {
                Name = "Name", Value = fileInfoRequest.Name
            });
            extra.Add(new AttributeType {
                Name = "FileExt", Value = fileInfoRequest.FileExt
            });
            bodyinfo.ExtraAttribute = extra;

            FileInfoType fileInfoType = new FileInfoType();

            fileInfoType.FilePath       = fileInfoRequest.WXPath;
            fileInfoType.FileExt        = fileInfoRequest.FileExt;
            fileInfoType.FileGuid       = fileInfoRequest.FileGuid;
            fileInfoType.QualityType    = 0;
            fileInfoType.FileTypeId     = "ROW";
            fileInfoType.ExtraAttribute = new List <AttributeType>();

            nwf.BodyInfo.FileInfo.Add(fileInfoType);
            return(nwf);
        }
Пример #16
0
        internal static string GetLabelForFileInfoType(FileInfoType type)
        {
            var label = Enum.GetName(typeof(FileInfoType), type);

            return(label ?? "");
        }
Пример #17
0
 public abstract string FileExtract(string extractFilePath, FileInfoType fileInfoType, string businessDate, string tableName, string fileImportFormatDirectory);
 private void GetServerList()
 {
     this.SetEnabled(false);
     object[] param = new object[] {
         this.dropDownList_ServerFileInfoType.SelectedValue,
         this.txt_ServerKeyword.Text.Trim(),
         this.ucPageFooter_Server.PageIndex,
         this.ucPageFooter_Server.PageSize
     };
     System.Threading.ThreadPool.QueueUserWorkItem((o) =>
     {
         object[] _param   = o as object[];
         FileInfoType type = (FileInfoType)_param[0];
         string key        = _param[1] as string;
         using (var fileclient = IocUtils.Get <IFileInfoService>(new object[] { MainForm.Current.FileClient }))
         {
             var vm = new FileInfoPageParamDto()
             {
                 Index   = (int)_param[2],
                 Size    = (int)_param[3],
                 Type    = type,
                 Keyword = key
             };
             if (this.ServerPath != null)
             {
                 vm.ParentId = this.ServerPath.Id;
             }
             var page = fileclient.GetPageList(vm);
             this.Sync.Post((obj) => {
                 var p = obj as PageListDto <FileInfoDto>;
                 List <FileInfoDto> list = new List <FileInfoDto>();
                 if (this.ServerPath != null)
                 {
                     list.Add(new FileInfoDto()
                     {
                         Type      = (int)FileInfoType.None,
                         Name      = "...",
                         Directory = this.LocalPath,
                         Key       = Guid.NewGuid().ToString("n")
                     });
                 }
                 if (p != null && p.List != null && p.List.Count > 0)
                 {
                     list.AddRange(p.List);
                 }
                 var l = this.serverList;
                 this.listView_Server.BeginUpdate();
                 this.serverList = list;
                 this.listView_Server.VirtualListSize = this.serverList.Count;
                 this.listView_Server.EndUpdate();
                 l.Clear();
                 if (p != null)
                 {
                     this.ucPageFooter_Server.SetPageIndex(p.Index, p.TotalCount);
                 }
                 else
                 {
                     this.ucPageFooter_Server.SetPageIndex(1, 0);
                 }
                 this.SetEnabled(true);
             }, page);
         }
     }, param);
 }
        private void GetLocalFileInfo(bool isLoadServer = false)
        {
            this.SetEnabled(false);
            object[] param = new object[] {
                this.dropDownList_LcoalFileInfoType.SelectedValue,
                this.txt_LocalKeyword.Text.Trim(),
                this.dropDownList_LocalDisk.SelectedValue,
                isLoadServer
            };
            System.Threading.ThreadPool.QueueUserWorkItem((o) =>
            {
                object[] _param         = o as object[];
                FileInfoType type       = (FileInfoType)_param[0];
                string key              = _param[1] as string;
                string selectDisk       = _param[2] as string;;
                List <FileInfoDto> list = new List <FileInfoDto>();
                if (!string.IsNullOrEmpty(this.LocalPath) && Directory.Exists(this.LocalPath))
                {
                    if (this.LocalPath != selectDisk)
                    {
                        list.Insert(0, new FileInfoDto()
                        {
                            Type      = FileInfoType.None,
                            Name      = "...",
                            Directory = this.LocalPath,
                            Key       = Guid.NewGuid().ToString("n")
                        });
                    }

                    if (type == FileInfoType.None || type == FileInfoType.Directory)
                    {
                        string[] arr = Directory.GetDirectories(this.LocalPath);
                        if (arr != null)
                        {
                            foreach (var s in arr)
                            {
                                DirectoryInfo d = new DirectoryInfo(s);
                                if (d.Exists && (d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    if (string.IsNullOrEmpty(key) || d.Name.Contains(key))
                                    {
                                        list.Add(new FileInfoDto()
                                        {
                                            Type          = FileInfoType.Directory,
                                            Name          = d.Name,
                                            Directory     = this.LocalPath,
                                            CreationTime  = d.CreationTime,
                                            LastWriteTime = d.LastWriteTime,
                                            Key           = Guid.NewGuid().ToString("n")
                                        });
                                    }
                                }
                            }
                        }
                    }

                    if (type == FileInfoType.None || type == FileInfoType.File)
                    {
                        string[] arr = Directory.GetFiles(this.LocalPath);
                        if (arr != null)
                        {
                            foreach (var s in arr)
                            {
                                FileInfo f = new FileInfo(s);
                                if (f.Exists && (f.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    if (string.IsNullOrEmpty(key) || f.Name.Contains(key))
                                    {
                                        list.Add(new FileInfoDto()
                                        {
                                            Type          = FileInfoType.File,
                                            Name          = f.Name,
                                            Directory     = this.LocalPath,
                                            Length        = f.Length,
                                            CreationTime  = f.CreationTime,
                                            LastWriteTime = f.LastWriteTime
                                        });
                                    }
                                }
                            }
                        }
                    }

                    list = (from q in list orderby q.Type, q.Name select q).ToList();
                }

                object[] sparam = new object[] { list, _param[3] };
                this.Sync.Post((obj) => {
                    object[] _sparam = obj as object[];
                    var l            = this.localList;
                    this.listView_Local.BeginUpdate();
                    this.localList = _sparam[0] as List <FileInfoDto>;
                    this.listView_Local.VirtualListSize = this.localList.Count;
                    this.listView_Local.EndUpdate();
                    l.Clear();
                    if ((bool)_sparam[1])
                    {
                        this.GetServerList();
                    }
                    else
                    {
                        this.SetEnabled(true);
                    }
                }, sparam);
            }, param);
        }
Пример #20
0
            protected override void Start()
            {
                try
                {
                    if (Status != StatusType.Queued)
                    {
                        throw new Exception("Stream has not been queued.");
                    }

                    base.Start();

                    List <File> children = null;

                    File parent = API.DriveService._GetCachedFile(_parentId, true, false, ref children);

                    string fileName       = System.IO.Path.GetFileNameWithoutExtension(_originalTitle);
                    string fileExtenstion = System.IO.Path.GetExtension(_originalTitle);

                    string title = fileName;

                    if (!String.IsNullOrEmpty(fileExtenstion))
                    {
                        title += fileExtenstion;
                    }

                    int index = 0;

                    while (true)
                    {
                        bool found = false;

                        foreach (File child in children)
                        {
                            if (child.Title == title)
                            {
                                FileInfoType fileInfoType = API.DriveService.GetFileInfoType(child);

                                if (IsFolder && fileInfoType == FileInfoType.Folder)
                                {
                                    found = true;
                                }
                                else if (!IsFolder && fileInfoType != FileInfoType.Folder)
                                {
                                    found = true;
                                }
                            }
                        }

                        if (!found)
                        {
                            break;
                        }

                        index++;

                        title = fileName + " (" + index + ")";

                        if (!String.IsNullOrEmpty(fileExtenstion))
                        {
                            title += fileExtenstion;
                        }
                    }

                    _title = title;

                    var file = new File();

                    var parentReference = new ParentReference {
                        Id = _parentId
                    };

                    file.Parents = new List <ParentReference> {
                        parentReference
                    };

                    file.Title         = _title;
                    file.Description   = "Created by Drive Fusion Shell Extention";
                    file.FileExtension = System.IO.Path.GetExtension(_title);
                    file.MimeType      = _mimeType;
                    file.ModifiedDate  = _lastWriteTime.ToUniversalTime();

                    _FileInfo = API.DriveService.GetFileInfo(file);

                    if (_FileInfo.IsFolder)
                    {
                        Lock();

                        using (API.DriveService.Connection connection = API.DriveService.Connection.Create())
                        {
                            FilesResource.InsertRequest request = connection.Service.Files.Insert(file);

                            request.Fields = API.DriveService.RequestFields.FileFields;

                            file = request.Execute();

                            _FileId   = file.Id;
                            _FileInfo = API.DriveService.GetFileInfo(file);

                            DriveService_ProgressChanged(UploadStatus.Completed, 0, null);
                        }
                    }
                    else
                    {
                        Lock(_filePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);

                        using (API.DriveService.Connection connection = API.DriveService.Connection.Create())
                        {
                            FilesResource.InsertMediaUpload request = connection.Service.Files.Insert(file, _FileStream, _mimeType);

                            request.Fields = API.DriveService.RequestFields.FileFields;

                            request.ProgressChanged  += DriveService_ProgressChanged;
                            request.ResponseReceived += DriveService_ResponseReceived;

                            request.ChunkSize = FilesResource.InsertMediaUpload.DefaultChunkSize;

                            request.Pinned = _parameters.Pinned;
                            request.UseContentAsIndexableText = _parameters.UseContentAsIndexableText;

                            _CancellationTokenSource = new System.Threading.CancellationTokenSource();

                            System.Threading.Tasks.Task <IUploadProgress> task = request.UploadAsync(_CancellationTokenSource.Token);
                        }
                    }
                }
                catch (Exception exception)
                {
                    try
                    {
                        _Status           = StatusType.Failed;
                        _ExceptionMessage = exception.Message;

                        DriveService_ProgressChanged(UploadStatus.Failed, 0, exception);
                    }
                    catch
                    {
                        Debugger.Break();
                    }

                    Log.Error(exception);
                }
            }