protected string GetUniqueFileName(ISerializedFile file, Object asset, string dirPath)
        {
            string fileName;

            switch (asset)
            {
            case NamedObject named:
                fileName = named.ValidName;
                break;

            case Prefab prefab:
                fileName = prefab.GetName(file);
                break;

            case MonoBehaviour monoBehaviour:
                fileName = monoBehaviour.Name;
                break;

            default:
                fileName = asset.GetType().Name;
                break;
            }
            fileName = FileNameRegex.Replace(fileName, string.Empty);

            fileName = $"{fileName}.{GetExportExtension(asset)}";
            fileName = FileUtils.GetUniqueName(dirPath, fileName);
            return(fileName);
        }
        protected string GetUniqueFileName(Object @object, string dirPath)
        {
            string fileName;

            switch (@object)
            {
            case NamedObject named:
                fileName = named.Name;
                break;

            case Prefab prefab:
                fileName = prefab.GetName();
                break;

            case MonoBehaviour monoBehaviour:
                fileName = monoBehaviour.Name;
                break;

            default:
                fileName = @object.GetType().Name;
                break;
            }
            fileName = FileNameRegex.Replace(fileName, string.Empty);

            fileName = DirectoryUtils.GetMaxIndexName(dirPath, fileName);
            fileName = $"{fileName}.{@object.ExportExtension}";
            return(fileName);
        }
Example #3
0
            public bool IsRecognizedFile(IFileInspector fileInspector)
            {
                if (FileNameRegex != null)
                {
                    FileInfo fileInfo;
                    if (!fileInspector.TryGetFileInfo(out fileInfo))
                    {
                        return(false);
                    }

                    if (!FileNameRegex.IsMatch(fileInfo.Name))
                    {
                        return(false);
                    }
                }

                if (ContentsRegex != null)
                {
                    string contents;
                    if (!fileInspector.TryGetContents(out contents))
                    {
                        return(false);
                    }

                    if (!ContentsRegex.IsMatch(contents))
                    {
                        return(false);
                    }
                }

                IFileTypeRecognizer fileTypeRecognizer = RecognizerHandle.GetComponent();

                return(fileTypeRecognizer.IsRecognizedFile(fileInspector));
            }
Example #4
0
        private async Task <string> DownloadImg(string url)
        {
            var imgSavePath = new DirectoryInfo(Program.Config["ImgSavePath"]);

            if (!imgSavePath.Exists)
            {
                imgSavePath.Create();
            }
            var filePath = Path.Combine(imgSavePath.FullName, FileNameRegex.Match(url).Value);

            if (!File.Exists(filePath))
            {
                try
                {
                    using (var httpStream = await HttpClient.GetStreamAsync(url))
                    {
                        using (var fileStream = File.Create(filePath))
                        {
                            await httpStream.CopyToAsync(fileStream);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Logger.Error(e, $"Cannot download Img: {url}");
                    return(null);
                }
            }

            return(filePath);
        }
        private void SeedFileNameRegexes(TradeModelContext context)
        {
            var transitFiles = new FileNameRegex[]
            {
                new FileNameRegex {
                    FileName = "ClientFeesRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-clientfees-det\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "AcctStatusReportNonEcaRegex", FileRegex = @"acct_status_report_non_eca\.[A-Za-z]{1}\d{5,7}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "AcctStatusReportRegex", FileRegex = @"acct_status_report\.[A-Za-z]{1}\d{5,7}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossCashReportRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Cash\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossNavRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Nav\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossTradesAsRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Trades-ass\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "CommissionsCrmRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.Commissions_CRM"
                },
                new FileNameRegex {
                    FileName = "AllKindsOfDataCrmRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.All_kinds_of_data_CRM"
                },
                new FileNameRegex {
                    FileName = "EndingValueCrmRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.Ending_value_CRM"
                },
                new FileNameRegex {
                    FileName = "SytossClientInfoRegex", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Client_info\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossOpenPositions", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Open_Positions\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossTradesEXE", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Trades-EXE\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossInterestAccrua", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-InterestAccrua\.\d{8}\.\d{8}"
                },
                new FileNameRegex {
                    FileName = "SytossCommissionsDet", FileRegex = @"[A-Za-z]{1}\d{5,7}\.[A-Za-z]{1}\d{5,7}-Sytoss-Commission_Det\.\d{8}\.\d{8}"
                }
            };

            context.FileNameRegexes.AddRange(transitFiles);
            context.SaveChanges();
        }
Example #6
0
 public static string FixInvalidNameCharacters(string path)
 {
     return(FileNameRegex.Replace(path, string.Empty));
 }
 protected string FixName(string path)
 {
     return(FileNameRegex.Replace(path, string.Empty));
 }