public virtual void testCreateMatcherForSuffix()
        {
            const string pattern = "helloworld";

            var matcher = new FileNameMatcher(pattern, null);

            matcher.Append("hello");

            FileNameMatcher childMatcher = matcher.CreateMatcherForSuffix();

            Assert.AreEqual(false, matcher.IsMatch());
            Assert.AreEqual(true, matcher.CanAppendMatch());
            Assert.AreEqual(false, childMatcher.IsMatch());
            Assert.AreEqual(true, childMatcher.CanAppendMatch());
            matcher.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(false, childMatcher.IsMatch());
            Assert.AreEqual(true, childMatcher.CanAppendMatch());
            childMatcher.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(true, childMatcher.IsMatch());
            Assert.AreEqual(false, childMatcher.CanAppendMatch());
            childMatcher.Reset();
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(false, childMatcher.IsMatch());
            Assert.AreEqual(true, childMatcher.CanAppendMatch());
            childMatcher.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(true, childMatcher.IsMatch());
            Assert.AreEqual(false, childMatcher.CanAppendMatch());
        }
Beispiel #2
0
        public FtpJob(
            FtpLoader ftpLoader,
            FileNameMatcher fileNameMatcher,
            IFtpJobRepository ftpJobRepository)
        {
            var fromDateSetting = ConfigurationManager.AppSettings["startDate"];

            if (string.IsNullOrEmpty(fromDateSetting))
            {
                throw new ConfigurationErrorsException("Please add 'startDate' settigns to .config file.");
            }

            var jobInterval = ConfigurationManager.AppSettings["job:FtpJobInterval"];

            if (string.IsNullOrEmpty(jobInterval))
            {
                throw new ConfigurationErrorsException("Please add 'job:FtpJobInterval' settigns to .config file.");
            }

            _fromDate   = DateTime.ParseExact(fromDateSetting, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            JobInterval = int.Parse(jobInterval);

            _ftpJobRepository = ftpJobRepository;
            _ftpLoader        = ftpLoader;
            _fileNameMatcher  = fileNameMatcher;
        }
        private MatchResult matchFileName(MergeRequestKey mrk, Core.Matching.DiffRefs refs,
                                          string originalLeftFileName, string originalRightFileName, bool isLeftSideLine,
                                          out string leftFileName, out string rightFileName)
        {
            leftFileName = rightFileName = null;
            FileNameMatcher fileNameMatcher = getFileNameMatcher(_git, mrk);

            try
            {
                if (!fileNameMatcher.Match(refs, originalLeftFileName, originalRightFileName, isLeftSideLine,
                                           out leftFileName, out rightFileName))
                {
                    return(MatchResult.Cancelled);
                }
                return(MatchResult.Success);
            }
            catch (ArgumentException ex)
            {
                ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
            }
            catch (MatchingException ex)
            {
                ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
            }
            return(MatchResult.Error);
        }
        public virtual void testCopyConstructor()
        {
            const string pattern = "helloworld";

            var matcher = new FileNameMatcher(pattern, null);

            matcher.Append("hello");

            var copy = new FileNameMatcher(matcher);

            Assert.AreEqual(false, matcher.IsMatch());
            Assert.AreEqual(true, matcher.CanAppendMatch());
            Assert.AreEqual(false, copy.IsMatch());
            Assert.AreEqual(true, copy.CanAppendMatch());
            matcher.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(false, copy.IsMatch());
            Assert.AreEqual(true, copy.CanAppendMatch());
            copy.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(true, copy.IsMatch());
            Assert.AreEqual(false, copy.CanAppendMatch());
            copy.Reset();
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(false, copy.IsMatch());
            Assert.AreEqual(true, copy.CanAppendMatch());
            copy.Append("helloworld");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            Assert.AreEqual(true, copy.IsMatch());
            Assert.AreEqual(false, copy.CanAppendMatch());
        }
        private static void AssertFileNameMatch(string pattern, string input, char excludedCharacter, bool matchExpected, bool appendCanMatchExpected)
        {
            var matcher = new FileNameMatcher(pattern, excludedCharacter);

            matcher.Append(input);
            Assert.AreEqual(matchExpected, matcher.IsMatch());
            Assert.AreEqual(appendCanMatchExpected, matcher.CanAppendMatch());
        }
Beispiel #6
0
 /// <summary>Create a new ignore rule with the given pattern.</summary>
 /// <remarks>
 /// Create a new ignore rule with the given pattern. Assumes that
 /// the pattern is already trimmed.
 /// </remarks>
 /// <param name="pattern">
 /// Base pattern for the ignore rule. This pattern will
 /// be parsed to generate rule parameters.
 /// </param>
 public IgnoreRule(string pattern)
 {
     this.pattern = pattern;
     negation     = false;
     nameOnly     = false;
     dirOnly      = false;
     matcher      = null;
     Setup();
 }
Beispiel #7
0
        public ImportJob(
            IImportJobRepository importJobRepository,
            InMemoryCache <TradeAccountModel> tradeAcccountModel,
            InMemoryCache <TradeMasterAccountModel> tradeMasterAccountModel,
            InMemoryCache <TradeInstrumentModel> tradeInstrumentModel,
            InMemoryCache <TradeFeeTypeModel> tradeFeeTypesModel,
            IContract wcf,
            FileNameMatcher fileNameMatcher,
            IExtractFileService extractFileService) : base(wcf)
        {
            _job = Job.Import;

            _tradeAccountModel       = tradeAcccountModel;
            _tradeInstrumentModel    = tradeInstrumentModel;
            _tradeFeeTypesModel      = tradeFeeTypesModel;
            _tradeMasterAccountModel = tradeMasterAccountModel;
            _importJobRepository     = importJobRepository;
            _extractFileService      = extractFileService;
            _fileNameMatcher         = fileNameMatcher;
            using (var tradeContext = _importJobRepository.BeginOperation())
            {
                foreach (var masterAccount in _importJobRepository.GetAllMasterAccounts())
                {
                    _tradeMasterAccountModel.Add(masterAccount.AccountName,
                                                 new TradeMasterAccountModel {
                        Id = masterAccount.Id
                    });
                }

                foreach (var instrument in _importJobRepository.GetTradeInstrument())
                {
                    _tradeInstrumentModel.Add(instrument.InstrumentName,
                                              new TradeInstrumentModel {
                        Id = instrument.Id
                    });
                }

                foreach (var trade in _importJobRepository.GetTradeAccount())
                {
                    _tradeAccountModel.Add(trade.AccountName, new TradeAccountModel {
                        Id = trade.Id
                    });
                }

                foreach (var tradeFeeType in _importJobRepository.GetTradeFeeType())
                {
                    _tradeFeeTypesModel.Add(tradeFeeType.TradeFeeTypeName,
                                            new TradeFeeTypeModel {
                        Id = tradeFeeType.Id
                    });
                }
            }
        }
Beispiel #8
0
        public ImportJob(
            IImportJobRepository importJobRepository,
            InMemoryCache <TradeAccountModel> tradeAcccountModel,
            InMemoryCache <TradeInstrumentModel> tradeInstrumentModel,
            InMemoryCache <TradeFeeTypeModel> tradeFeeTypesModel,
            FileNameMatcher fileNameMatcher,
            IExtractFileService extractFileService)
        {
            var jobInterval = ConfigurationManager.AppSettings["job:ImportJobInterval"];

            if (string.IsNullOrEmpty(jobInterval))
            {
                throw new ConfigurationErrorsException("Please add 'job:ImportJobInterval' settigns to .config file.");
            }

            JobInterval = int.Parse(jobInterval);

            _tradeAccountModel    = tradeAcccountModel;
            _tradeInstrumentModel = tradeInstrumentModel;
            _tradeFeeTypesModel   = tradeFeeTypesModel;
            _importJobRepository  = importJobRepository;
            _extractFileService   = extractFileService;
            _fileNameMatcher      = fileNameMatcher;

            using (var tradeContext = _importJobRepository.BeginOperation())
            {
                foreach (var instrument in _importJobRepository.GetTradeInstrument())
                {
                    _tradeInstrumentModel.Add(instrument.InstrumentName,
                                              new TradeInstrumentModel {
                        Id = instrument.Id
                    });
                }

                foreach (var trade in _importJobRepository.GetTradeAccount())
                {
                    _tradeAccountModel.Add(trade.AccountName, new TradeAccountModel {
                        Id = trade.Id
                    });
                }

                foreach (var tradeFeeType in _importJobRepository.GetTradeFeeType())
                {
                    _tradeFeeTypesModel.Add(tradeFeeType.TradeFeeTypeName,
                                            new TradeFeeTypeModel {
                        Id = tradeFeeType.Id
                    });
                }
            }
        }
Beispiel #9
0
        public void Handle(MatchInfo matchInfo, Snapshot snapshot)
        {
            FileNameMatcher   fileNameMatcher   = getFileNameMatcher(_git, getMergeRequestKey(snapshot));
            LineNumberMatcher lineNumberMatcher = new LineNumberMatcher(_git);

            DiffPosition position = new DiffPosition(null, null, null, null, snapshot.Refs);

            try
            {
                if (!fileNameMatcher.Match(matchInfo, position, out position))
                {
                    return;
                }

                lineNumberMatcher.Match(matchInfo, position, out position);
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is MatchingException)
                {
                    ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
                    MessageBox.Show("Cannot create a discussion. Unexpected file name and/or line number passed",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }
                throw;
            }

            NewDiscussionForm form = new NewDiscussionForm(
                matchInfo.LeftFileName, matchInfo.RightFileName, position, _git,
                async(body, includeContext) =>
            {
                try
                {
                    await submitDiscussionAsync(matchInfo, snapshot, position, body, includeContext);
                    _onDiscussionSubmitted?.Invoke(getMergeRequestKey(snapshot));
                }
                catch (DiscussionCreatorException ex)
                {
                    string message = "Cannot create a discussion at GitLab";
                    ExceptionHandlers.Handle(message, ex);
                    MessageBox.Show(String.Format("{0}. Check your connection and try again.", message),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                }
            });

            form.Show();
        }
Beispiel #10
0
        private static bool IsHostMatch(string pattern, string name)
        {
            FileNameMatcher fn;

            try
            {
                fn = new FileNameMatcher(pattern, null);
            }
            catch (InvalidPatternException)
            {
                return(false);
            }
            fn.Append(name);
            return(fn.IsMatch());
        }
Beispiel #11
0
        public FsCopyFromFtpJob(IFileSystemManager systemManager, IContract wcf, ICopyJobRepository copyJobRepository, FileNameMatcher fileNameMatcher) :
            base(wcf)
        {
            _job = Job.Copy;
            lock (_syncRoot)
            {
                if (!Directory.Exists(_historyDir))
                {
                    Directory.CreateDirectory(_historyDir);
                }
            }

            _systemManager     = systemManager;
            _copyJobRepository = copyJobRepository;
            _fileNameMatcher   = fileNameMatcher;
        }
Beispiel #12
0
        public CopyFromFtpJob(
            ICopyJobRepository copyJobRepository,
            IFileManagerService systemManager,
            FileNameMatcher fileNameMatcher)
        {
            var jobInterval = ConfigurationManager.AppSettings["job:CopyFromFtpJobInterval"];

            if (string.IsNullOrEmpty(jobInterval))
            {
                throw new ConfigurationErrorsException("Please add 'job:CopyFromFtpJobInterval' settigns to .config file.");
            }

            JobInterval = int.Parse(jobInterval);

            _copyJobRepository = copyJobRepository;
            _systemManager     = systemManager;
            _fileNameMatcher   = fileNameMatcher;
        }
Beispiel #13
0
        /// <summary>Remove leading/trailing characters as needed.</summary>
        /// <remarks>
        /// Remove leading/trailing characters as needed. Set up
        /// rule variables for later matching.
        /// </remarks>
        private void Setup()
        {
            int startIndex = 0;
            int endIndex   = pattern.Length;

            if (pattern.StartsWith("!"))
            {
                startIndex++;
                negation = true;
            }
            if (pattern.EndsWith("/"))
            {
                endIndex--;
                dirOnly = true;
            }
            pattern = Sharpen.Runtime.Substring(pattern, startIndex, endIndex);
            bool hasSlash = pattern.Contains("/");

            if (!hasSlash)
            {
                nameOnly = true;
            }
            else
            {
                if (!pattern.StartsWith("/"))
                {
                    //Contains "/" but does not start with one
                    //Adding / to the start should not interfere with matching
                    pattern = "/" + pattern;
                }
            }
            if (pattern.Contains("*") || pattern.Contains("?") || pattern.Contains("["))
            {
                try
                {
                    matcher = new FileNameMatcher(pattern, '/');
                }
                catch (InvalidPatternException e)
                {
                    Sharpen.Runtime.PrintStackTrace(e);
                }
            }
        }
Beispiel #14
0
 public FtpJob(
     FtpLoader ftpLoader,
     InMemoryCache <TradeMasterAccountModel> tradeMasterAccountModel,
     IContract wcf,
     FileNameMatcher fileNameMatcher,
     IFtpJobRepository ftpJobRepository,
     IImportRepository importRepository) : base(wcf)
 {
     _job       = Job.Ftp;
     _ftpLoader = ftpLoader;
     _tradeMasterAccountModel = tradeMasterAccountModel;
     _ftpJobRepository        = ftpJobRepository;
     _importRepository        = importRepository;
     _fileNameMatcher         = fileNameMatcher;
     //using (_ftpJobRepository.BeginOperation())
     //{
     //    foreach (var ftpFile in ftpJobRepository.ImportedFilesQuery())
     //    {
     //        _existingFiles.Add(ftpFile.OriginalFileName);
     //    }
     //}
 }
Beispiel #15
0
        public virtual void testReset()
        {
            const string pattern = "helloworld";

            var matcher = new FileNameMatcher(pattern, null);

            matcher.Append("helloworld");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            matcher.Reset();
            matcher.Append("hello");
            Assert.AreEqual(false, matcher.IsMatch());
            Assert.AreEqual(true, matcher.CanAppendMatch());
            matcher.Append("world");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            matcher.Append("to much");
            Assert.AreEqual(false, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
            matcher.Reset();
            matcher.Append("helloworld");
            Assert.AreEqual(true, matcher.IsMatch());
            Assert.AreEqual(false, matcher.CanAppendMatch());
        }
 public FnMatchPattern(string line)
 {
     _matcher = new FileNameMatcher(line, null);
 }
Beispiel #17
0
 public FtpLoader(FileNameMatcher fileNameMatcher)
 {
     _fileNameMatcher = fileNameMatcher;
 }