Ejemplo n.º 1
0
        string IReplacer.Replace(string input, ReplaceTemplateItem item)
        {
            if (item.Replace.Length == 0)
            {
                return(input);
            }

            MatchCollection matches = item.Matches(input);

            Dictionary <Capture, string> map = new Dictionary <Capture, string>();

            foreach (Match match in matches)
            {
                if (ReplaceFilter.CanReplace(input, match, item))
                {
                    Dictionary <int, string> pair = ReplaceReference.Reference(item, match);

                    map[match] = ReplaceUtils.ReplaceMatchValue(match, pair);
                }
            }

            return(ReplaceUtils.GetReplaced(input, map));
        }
Ejemplo n.º 2
0
        public async void InnerExecuteReplace()
        {
            Owner.Executing = true;
            try
            {
                var result = await Owner.Service.ReplaceOneAsync(Owner.Database, Owner.Collection, ReplaceFilter.Deserialize <BsonDocument>(Constants.ReplaceFilterProperty), Replacement.Deserialize <BsonDocument>(Constants.ReplacementProperty), Owner.Cts.Token);

                Owner.RawResult  = result.ToJson(Options.JsonWriterSettings);
                Owner.RawResult += Environment.NewLine;
                Owner.RawResult += Environment.NewLine;
                Owner.RawResult += "Modified Count: " + result.ModifiedCount;

                Owner.SelectedViewIndex = 1;
                Owner.Root = null;
            }
            catch (BsonExtensions.BsonParseException ex)
            {
                LoggerHelper.Logger.Error("Exception while executing Replace command", ex);
                Owner.SelectedViewIndex = 1;
                Owner.RawResult         = ex.Message;
                Owner.Root = null;
                Messenger.Default.Send(new NotificationMessage <BsonExtensions.BsonParseException>(this, ex, Constants.ReplaceParseException));
            }
            catch (Exception ex)
            {
                LoggerHelper.Logger.Error("Exception while executing Replace command", ex);
                Owner.RawResult         = ex.Message;
                Owner.SelectedViewIndex = 1;
                Owner.Root = null;
            }
            finally
            {
                Owner.Executing = false;
                Owner.ShowPager = false;
            }
        }