Inheritance: PathSegment
        public void DoSearch()
        {
            UpdateRecentValues();

            Progress.Max         = 10000;
            Progress.JobProgress = 0;
            Progress.JobStatus   = JobStatus.inProgress;

            SCWrapper scWrp            = new SCWrapper(this.teamExplorer);
            Wildcard  fileNameWildCard = new Wildcard(this.FileNameFilter);

            this.FoundFiles = new ObservableCollection <SCFile>();

            CancelCallbackNotify notify = new CancelCallbackNotify();

            notify._delegate = DispatchUpdateStatus;
            notify.start     = 0;
            notify.range     = Progress.Max;

            SearchCondition s = new SearchCondition(this.SearchText, this.isCaseSensitive, this.useRegExp);

            List <SCFolder> foldersToSearch = new List <SCFolder>();

            foreach (SCFolder fld in RootFolders)
            {
                foldersToSearch.Add(fld);
            }

            scWrp.SearchForFileContent(foldersToSearch, fileNameWildCard, s, this.SearchHistory, notify);

            Progress.JobStatus = JobStatus.notStarted;
        }
Example #2
0
        public void IsMatch_returns_the_expected_value(string pattern, string value, bool shouldMatch)
        {
            var wildCard = new Wildcard(pattern);
            var isMatch  = wildCard.IsMatch(value);

            Assert.Equal(shouldMatch, isMatch);
        }
Example #3
0
        public static DcmAssociateProfile Find(DcmAssociate associate, bool matchImplentation)
        {
            List <DcmAssociateProfile> candidates = new List <DcmAssociateProfile>();

            foreach (DcmAssociateProfile profile in Profiles)
            {
                if (!Wildcard.Match(profile.CalledAE, associate.CalledAE) || !Wildcard.Match(profile.CallingAE, associate.CallingAE))
                {
                    continue;
                }
                if (matchImplentation &&
                    (!Wildcard.Match(profile.RemoteImplUID, associate.ImplementationClass.UID) ||
                     !Wildcard.Match(profile.RemoteVersion, associate.ImplementationVersion)))
                {
                    continue;
                }
                candidates.Add(profile);
            }
            if (candidates.Count > 0)
            {
                candidates.Sort(delegate(DcmAssociateProfile p1, DcmAssociateProfile p2) {
                    return(p1.GetWeight(matchImplentation) - p2.GetWeight(matchImplentation));
                });
                return(candidates[0]);
            }
            return(GenericStorage);
        }
Example #4
0

        
        public override void DeleteFiles(string domain, string path, string pattern, bool recursive)
        {
            var makedPath = MakePath(domain, path) + '/';
            var objToDel  = GetS3Objects(domain, path)
                            .Where(x =>
                                   Wildcard.IsMatch(pattern, Path.GetFileName(x.Key)) &&
                                   (recursive || !x.Key.Remove(0, makedPath.Length).Contains('/'))
                                   );

            using (var client = GetClient())
            {
                foreach (var s3Object in objToDel)
                {
                    Recycle(client, domain, s3Object.Key);

                    var deleteRequest = new DeleteObjectRequest
                    {
                        BucketName = _bucket,
                        Key        = s3Object.Key
                    };

                    client.DeleteObject(deleteRequest);

                    QuotaUsedDelete(domain, Convert.ToInt64(s3Object.Size));
                }
            }
        }
Example #6
0
        private static bool IsCurrentClient(ClaimsPrincipal principal, string clientRange)
        {
            if (String.IsNullOrWhiteSpace(clientRange))
            {
                return(true);
            }

            var currentClient = principal.Claims.FirstOrDefault(c => c.Type == "client_id")?.Value;

            if (String.IsNullOrWhiteSpace(currentClient))
            {
                return(false);
            }

            var clients = Regex.Split(clientRange, @"[,|;]").Select(c => c.Trim());

            foreach (var client in clients)
            {
                if (String.IsNullOrWhiteSpace(client))
                {
                    return(true);
                }

                if (Wildcard.Match(currentClient, client, true))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #7
0
        protected bool Equals(MagicK other)
        {
            var wildCard = new Wildcard(_target.InnerNode.GetType().Name);
            var pattern  = new Pattern(wildCard, 0, new AbsolutePath(0));

            return(Equals(GetK(pattern), other.GetK(pattern)));
        }
Example #8
0
        public IEnumerable <string> Keys(string pattern)
        {
            var items = GetItems();

            if (items.Count == 0)
            {
                yield break;
            }

            var prefixLen = RegionName.Length;

            pattern = pattern.NullEmpty() ?? "*";
            var wildcard = new Wildcard(pattern, RegexOptions.IgnoreCase);

            var enumerator = items.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Key is string key)
                {
                    if (key.StartsWith(RegionName))
                    {
                        key = key.Substring(prefixLen);
                        if (pattern == "*" || wildcard.IsMatch(key))
                        {
                            yield return(key);
                        }
                    }
                }
            }
        }
Example #9
0
        public override IList <SrcOp> Wildcard(GrammarAST ast, GrammarAST labelAST)
        {
            Wildcard wild = new Wildcard(this, ast);

            // TODO: dup with tokenRef
            if (labelAST != null)
            {
                string label = labelAST.Text;
                Decl   d     = GetTokenLabelDecl(label);
                wild.labels.Add(d);
                GetCurrentRuleFunction().AddContextDecl(ast.GetAltLabel(), d);
                if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
                {
                    TokenListDecl l = GetTokenListLabelDecl(label);
                    GetCurrentRuleFunction().AddContextDecl(ast.GetAltLabel(), l);
                }
            }
            if (controller.NeedsImplicitLabel(ast, wild))
            {
                DefineImplicitLabel(ast, wild);
            }
            AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(wild, labelAST);

            return(List(wild, listLabelOp));
        }
Example #10
0
        /// <summary>
        /// process remove
        /// </summary>
        /// <param name="selector">css selector</param>
        /// <param name="result">pre process result</param>
        /// <returns>new process result</returns>
        public override ProcessResult ProcessRemove(ExpressionSelector selector, ProcessResult result)
        {
            var pr = new ProcessResult();

            if (string.IsNullOrEmpty(selector.Expression))
            {
                return(pr);
            }

            foreach (var item in result.Matches)
            {
                var ary = new string[] { item };

                if (!string.IsNullOrEmpty(selector.Split))
                {
                    ary = item.Split(new string[] { selector.Split }, StringSplitOptions.RemoveEmptyEntries);
                }

                foreach (var it in ary)
                {
                    var m = Wildcard.IsMatch(it, new string[] { selector.Expression });
                    if (!m)
                    {
                        pr.Matches.Add(it);
                    }
                }
            }

            return(pr);
        }
Example #11
0
        public void Parse_6_SpaceTreatment()
        {
            var wc = new Wildcard(WildcardSelection.MultiAll, spaceTreatment: WildcardSpaceTreatment.Compress);

            Check(WildcardSelection.Equal, "X X", wc.Parse("X X"));
            Check(WildcardSelection.Equal, "X X", wc.Parse("X  X"));
            Check(WildcardSelection.Equal, "X X X", wc.Parse("X  X  X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.EndsWith, "*X X", wc.Parse("*X X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.StartsWith, "X X*", wc.Parse("X  X*"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X X* X", wc.Parse("X  X*  X"));

            wc = new Wildcard(WildcardSelection.MultiAll, spaceTreatment: WildcardSpaceTreatment.MultiWildcardAlways);
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X*X", wc.Parse("X X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X*X", wc.Parse("X  X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X*X*X", wc.Parse("X  X  X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded | WildcardSelection.EndsWith, "*X*X", wc.Parse("*X X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded | WildcardSelection.StartsWith, "X*X*", wc.Parse("X  X*"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X*X*X", wc.Parse("X  X*  X"));

            wc = new Wildcard(WildcardSelection.MultiAll, spaceTreatment: WildcardSpaceTreatment.MultiWildcardWhenOthers);
            Check(WildcardSelection.Equal, "X X", wc.Parse("X X"));
            Check(WildcardSelection.Equal, "X X", wc.Parse("X  X"));
            Check(WildcardSelection.Equal, "X X X", wc.Parse("X  X  X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded | WildcardSelection.EndsWith, "*X*X", wc.Parse("*X X"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded | WildcardSelection.StartsWith, "X*X*", wc.Parse("X  X*"));
            Check(WildcardSelection.MultiWildcard | WildcardSelection.Embedded, "X*X*X", wc.Parse("X  X*  X"));
        }
Example #12
0
        internal void InitValidateInternal()
        {
            string verb = Verb;

            // Remove all spaces from verbs before wildcard parsing.
            //   - We don't want get in "POST, GET" to be parsed into " GET".
            verb = verb.Replace(" ", String.Empty);     // replace all " " with String.Empty in requestType

            _requestType = new Wildcard(verb, false);   // case-sensitive wildcard
            _path        = new WildcardUrl(Path, true); // case-insensitive URL wildcard

            // if validate="false" is marked on a handler, then the type isn't created until a request
            // is actually made that requires the handler. This (1) allows us to list handlers that
            // aren't present without throwing errors at init time and (2) speeds up init by avoiding
            // loading types until they are needed.

            if (!Validate)
            {
                _type = null;
            }
            else
            {
                _type = ConfigUtil.GetType(Type, "type", this);

                if (!ConfigUtil.IsTypeHandlerOrFactory(_type))
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Type_not_factory_or_handler, Type),
                              ElementInformation.Source, ElementInformation.LineNumber);
                }
            }
        }
Example #13
0
        private void Button_Filter(object sender, RoutedEventArgs e)
        {
            lock (PauseResumeLogLock)
            {
                ucLogConsoleVM.FilterApplied = !ucLogConsoleVM.FilterApplied;
                if (ucLogConsoleVM.FilterApplied) //Show filtered logs
                {
                    tbFilter.IsEnabled = false;
                    WildCardFilter     = new Wildcard("*" + ucLogConsoleVM.FilterText + "*", RegexOptions.Multiline | RegexOptions.IgnoreCase);

                    this.ucLogConsoleVM.ConsoleFilteredLogsCollection = new ObservableCollection <ConsoleLogVM>();
                    foreach (var log in this.ucLogConsoleVM.ConsoleLogsCollection)
                    {
                        if (WildCardFilter.IsMatch(log.Entry))
                        {
                            this.ucLogConsoleVM.ConsoleFilteredLogsCollection.Add(log);
                        }
                    }
                    icLogViewer.ItemsSource = this.ucLogConsoleVM.ConsoleFilteredLogsCollection;
                }
                else // Show default logs
                {
                    tbFilter.IsEnabled        = true;
                    WildCardFilter            = null;
                    ucLogConsoleVM.FilterText = "";
                    icLogViewer.ItemsSource   = ucLogConsoleVM.ConsoleLogsCollection;
                }
            }
        }
Example #14
0

        
Example #15
0
        public override void DeleteFiles(string domain, string path, string pattern, bool recursive)
        {
            var objToDel = GetS3Objects(domain, path)
                           .Where(x => Wildcard.IsMatch(pattern, Path.GetFileName(x.Key)));

            using (var client = GetClient())
            {
                foreach (var s3Object in objToDel)
                {
                    if (QuotaController != null)
                    {
                        QuotaController.QuotaUsedDelete(_modulename, domain, _dataList.GetData(domain), Convert.ToInt64(s3Object.Size));
                    }

                    Recycle(client, domain, s3Object.Key);

                    var deleteRequest = new DeleteObjectRequest
                    {
                        BucketName = _bucket,
                        Key        = s3Object.Key
                    };

                    client.DeleteObject(deleteRequest);
                }
            }
        }
        private bool GetAllCollections()
        {
            CollectionListResult     response = null;
            IEnumerable <Collection> spList   = null;

            LocalModels.Collection collection = null;

            response = CallClient(() => Client.Collections.List(), Client.Collections);

            if (response != null)
            {
                if (UseWildcard)
                {
                    spList = response.Collections.Where(col => Wildcard.IsMatch(col.Name));
                }
                else
                {
                    spList = response.Collections;
                }

                if (spList != null && spList.Count() > 0)
                {
                    foreach (Collection c in spList)
                    {
                        collection = new LocalModels.Collection(c);
                        WriteObject(collection);
                    }
                    found = true;
                }
            }

            return(found);
        }
Example #17
0
 public static Wildcard FromDTO(this DTO.Wildcard source)
 {
     var h = new Wildcard();
     h.Enabled = source.Enabled;
     h.Pattern = source.Pattern;
     return h;
 }
        public void LoadExistingPluginDirectory()
        {
            string[] urls = new[] {
                "https://book.qidian.com/info/1030223496/",
            };

            var manager = new PluginManager();
            var plugins = manager.Load("plugins");

            foreach (var url in urls)
            {
                Uri uri   = new Uri(url, UriKind.RelativeOrAbsolute);
                var books =
                    from plugin in plugins
                    where plugin.CompatibleHosts.Any(host => Wildcard.IsMatch(uri.Host, host))
                    select plugin.CreateBook(uri);

                foreach (var book in books)
                {
                }
                if (!books.Any())
                {
                    Console.WriteLine("无适配插件可下载“{0}”", url);
                }
            }
        }
Example #19
0
        protected override void _OnEvent(object sender, NpgsqlNotificationEventArgs npgsqlNotificationEventArgs)
        {
            var notifyObject = JSON.ToObject <EventTriggerNotification>(npgsqlNotificationEventArgs.AdditionalInformation);

            if (notifyObject.Schema != _connectionBuilder.GetConnection().SchemaName)
            {
                return;
            }

            var notify = false;

            foreach (var s in _actionsToListen)
            {
                if (Wildcard.IsMatch(notifyObject.Action, s))
                {
                    notify = true;
                    break;
                }
            }

            if (notify)
            {
                _notificationSubject.OnNext(notifyObject);
            }
        }
        private bool ZipMatches(string zip, string pattern)
        {
            if (pattern.IsEmpty() || pattern == "*")
            {
                return(true); // catch all
            }

            var patterns = pattern.Contains(",")
                ? pattern.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim())
                : new string[] { pattern };

            try
            {
                foreach (var entry in patterns)
                {
                    var wildcard = new Wildcard(entry);
                    if (wildcard.IsMatch(zip))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                return(zip.IsCaseInsensitiveEqual(pattern));
            }

            return(false);
        }
Example #21
0
        public IEnumerable <IUiLeaf> EnumerateCheckedLeafs(Wildcard wildcard, bool parentChecked)
        {
            foreach (UiNode node in GetChilds())
            {
                if (!parentChecked && node.IsChecked == false)
                {
                    continue;
                }

                // Родительский контейнер может быть помечен, а вложенный нет
                // Это сделано специально для отложенной загрузки вложенных элементов
                bool isChecked = parentChecked || node.IsChecked == true;

                UiContainerNode container = node as UiContainerNode;
                if (container != null)
                {
                    foreach (IUiLeaf child in container.EnumerateCheckedLeafs(wildcard, isChecked))
                    {
                        yield return(child);
                    }
                }
                else
                {
                    IUiLeaf leaf = node as IUiLeaf;
                    if (leaf != null && isChecked && wildcard.IsMatch(leaf.Name))
                    {
                        yield return(leaf);
                    }
                }
            }
        }
Example #22
0
        public void Can_match_glob()
        {
            var w1 = new Wildcard("h[ae]llo", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("hello"));
            Assert.IsTrue(w1.IsMatch("hallo"));
            Assert.IsTrue(!w1.IsMatch("hillo"));

            w1 = new Wildcard("h[^e]llo", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("hallo"));
            Assert.IsTrue(w1.IsMatch("hbllo"));
            Assert.IsTrue(!w1.IsMatch("hello"));

            w1 = new Wildcard("h[a-d]llo", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("hallo"));
            Assert.IsTrue(w1.IsMatch("hcllo"));
            Assert.IsTrue(w1.IsMatch("hdllo"));
            Assert.IsTrue(!w1.IsMatch("hgllo"));

            w1 = new Wildcard("entry-[^0]*", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("entry-22"));
            Assert.IsTrue(w1.IsMatch("entry-9"));
            Assert.IsTrue(!w1.IsMatch("entry-0"));
        }
Example #23
0
 public override Uri[] ListFiles(string domain, string path, string pattern, bool recursive)
 {
     return(GetS3Objects(domain, path)
            .Where(x => Wildcard.IsMatch(pattern, Path.GetFileName(x.Key)))
            .Select(x => GetUriInternal(x.Key))
            .ToArray());
 }
Example #24
0
        private bool GetVNetList(bool showAllVirtualNetworks, string VNet)
        {
            VNetListResult response = null;
            bool           found    = false;

            if (showAllVirtualNetworks)
            {
                WriteVerboseWithTimestamp("Getting all VNets.");
            }
            else if (UseWildcard)
            {
                WriteVerboseWithTimestamp("Getting the matching VNets for {0}.", VNet);
            }

            response = CallClient(() => Client.VNet.List(), Client.VNet);
            if (response != null)
            {
                foreach (VNet vNet in response.VNetList)
                {
                    if (showAllVirtualNetworks || (UseWildcard && Wildcard.IsMatch(vNet.Name)))
                    {
                        WriteObject(vNet);
                        found = true;
                    }
                }
            }
            return(found);
        }
Example #25
0
    public void WHO(IMessage IMessage)
    {
        if (Database.GetDatabase().HasChannel(IMessage.Params[0]))
        {
            IChannel ch = Database.GetDatabase().GetChannel(IMessage.Params[0]);

            foreach (IClient cl in ch.Clients)
            {
                if (IMessage.Params.Length == 1 || (IMessage.Params.Length == 2 && IMessage.Params[1] == "o" && cl.Modes.Contains("o")))
                {
                    IMessage.Owner.SendMessage(IMessage.CreateMessage(IMessage.Owner, "", Reply.RPL_WHOREPLY, new string[] { IMessage.Owner.NickName, IMessage.Params[0], cl.UserName, cl.HostName, Server.GetServer().HostString, cl.NickName, (string.IsNullOrEmpty(cl.AwayMsg) ? "H" : "G"), "0 " + cl.RealName }));
                }
            }

            IMessage.Owner.SendMessage(IMessage.CreateMessage(IMessage.Owner, "", Reply.RPL_ENDOFWHO, new string[] { IMessage.Owner.NickName, "End of WHO list" }));
        }
        else
        {
            Wildcard c = new Wildcard(IMessage.Params[0]);

            foreach (IClient cl in Database.GetDatabase().Clients)
            {
                if (c.IsMatch(cl.UserString))
                {
                    if (IMessage.Params.Length == 1 || (IMessage.Params.Length == 2 && IMessage.Params[1] == "o" && cl.Modes.Contains("o")))
                    {
                        IMessage.Owner.SendMessage(IMessage.CreateMessage(IMessage.Owner, Server.GetServer().HostString, Reply.RPL_WHOREPLY, new string[] { IMessage.Owner.NickName, IMessage.Params[0], cl.UserName, cl.HostName, Server.GetServer().HostString, cl.NickName, (string.IsNullOrEmpty(cl.AwayMsg) ? "H" : "G"), "0 " + cl.RealName }));
                    }
                }
            }

            IMessage.Owner.SendMessage(IMessage.CreateMessage(IMessage.Owner, Server.GetServer().HostString, Reply.RPL_ENDOFWHO, new string[] { IMessage.Owner.NickName, "End of WHO list" }));
        }
    }
        public override string[] GetFileNames(string pattern)
        {
            string dir = Path.GetDirectoryName(pattern);

            pattern = Path.GetFileName(pattern);

            IReadOnlyList <StorageFile> files = null;

            if (dir.IsNullOrWhiteSpace())
            {
                files = Task.Run(async() => await _storage.GetFilesAsync(CommonFileQuery.DefaultQuery)).Result;
            }
            else
            {
                var folder = Task.Run(async() => await _storage.GetFolderAsync(dir)).Result;
                files = Task.Run(async() => await folder.GetFilesAsync()).Result;
            }

            List <string> filePaths = new List <string>();

            Wildcard wildcard = new Wildcard(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            foreach (var file in files)
            {
                if (wildcard.IsMatch(file.Name))
                {
                    filePaths.Add(file.Name);
                }
            }

            return(filePaths.ToArray());
        }
Example #27
0
        public void RegexWildcard_Core()
        {
            // Arrange
            var testString               = "ate Ape are";
            var fullWildcard             = new Wildcard("* are*");
            var partialWildcard          = new Wildcard("a?e", RegexOptions.IgnoreCase, false, false);
            var expected_full_IsMatch    = true;
            var expected_full_NumMatches = 1;
            var expected_part_IsMatch    = true;
            var expected_part_NumMatches = 3;
            var expected_part_2ndMatch   = "Ape";

            Console.WriteLine(fullWildcard.ToString());
            Console.WriteLine(partialWildcard.ToString());

            // Act
            var fullMatches            = fullWildcard.Matches(testString);
            var actual_full_IsMatch    = fullWildcard.IsMatch(testString);
            var actual_full_NumMatches = fullMatches.Count;

            var partialMatches         = partialWildcard.Matches(testString);
            var actual_part_IsMatch    = partialWildcard.IsMatch(testString);
            var actual_part_NumMatches = partialMatches.Count;
            var actual_part_2ndMatch   = partialMatches[1].ToString();

            // Assert
            Assert.AreEqual(expected_full_IsMatch, actual_full_IsMatch);
            Assert.AreEqual(expected_full_NumMatches, actual_full_NumMatches);
            Assert.AreEqual(expected_part_IsMatch, actual_part_IsMatch);
            Assert.AreEqual(expected_part_NumMatches, actual_part_NumMatches);
            Assert.AreEqual(expected_part_2ndMatch, actual_part_2ndMatch);
        }
Example #28
0
        private bool GetAllPublishedApps()
        {
            GetPublishedApplicationListResult         response = null;
            IEnumerable <PublishedApplicationDetails> spList   = null;

            response = CallClient(() => Client.Publishing.List(CollectionName), Client.Publishing);

            if (response != null)
            {
                if (UseWildcard)
                {
                    spList = response.ResultList.Where(app => Wildcard.IsMatch(app.Name));
                }
                else
                {
                    spList = response.ResultList;
                }

                if (spList != null && spList.Count() > 0)
                {
                    WriteObject(spList, true);
                    found = true;
                }
            }

            return(found);
        }
Example #30
0
        public void Can_match_number_range()
        {
            var w1 = new Wildcard("999-2450");

            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("999"));
            Assert.IsTrue(w1.IsMatch("1500"));
            Assert.IsTrue(w1.IsMatch("2450"));
            Assert.IsFalse(w1.IsMatch("500"));
            Assert.IsFalse(w1.IsMatch("2800"));

            w1 = new Wildcard("50000-59999");
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("59192"));
            Assert.IsTrue(w1.IsMatch("55000"));
            Assert.IsFalse(w1.IsMatch("500"));
            Assert.IsFalse(w1.IsMatch("80000"));

            w1 = new Wildcard("3266-3267");
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("3266"));
            Assert.IsTrue(w1.IsMatch("3267"));
            Assert.IsFalse(w1.IsMatch("500"));
            Assert.IsFalse(w1.IsMatch("4000"));

            w1 = new Wildcard("0001000-0005000");
            Console.WriteLine(w1.Pattern);
            Assert.IsTrue(w1.IsMatch("0001000"));
            Assert.IsTrue(w1.IsMatch("0002008"));
            Assert.IsFalse(w1.IsMatch("1000"));
            Assert.IsFalse(w1.IsMatch("5000"));
        }
Example #31
0
        protected void Run(bool runTestsViewOut, string pspAutoTestsFolder, string wildCardFilter)
        {
            foreach (var fileNameExpected in Directory.GetFiles(pspAutoTestsFolder, "*.expected",
                                                                SearchOption.AllDirectories))
            {
                var fileNameBaseBase   = Path.GetFileNameWithoutExtension(fileNameExpected);
                var fileNameBase       = Path.GetDirectoryName(fileNameExpected) + @"\" + fileNameBaseBase;
                var fileNameExecutable = fileNameBase + ".prx";
                var fileNameSourceCode = fileNameBase + ".c";

                var matchName = fileNameBase.Substr(pspAutoTestsFolder.Length).Replace("\\", "/");

                //Console.WriteLine(MatchName + " ~ " + Wildcard.WildcardToRegex(WildCardFilter));
                if (!new Regex(Wildcard.WildcardToRegex(wildCardFilter)).IsMatch(matchName))
                {
                    continue;
                }

                var recompile = false;
                //bool Recompile = true;

                if (File.GetLastWriteTime(fileNameExecutable) != File.GetLastWriteTime(fileNameSourceCode))
                {
                    recompile = true;
                }

#if ENABLE_RECOMPILE
                if (recompile)
                {
                    //PspAutoTestsFolder + @"\make.bat"
                    // FileNameBase
                    try { File.Delete(FileNameExecutable); } catch (Exception e) { Console.WriteLine(e); }
                    var Output = ExecuteBat(PspAutoTestsFolder + @"\build.bat", FileNameBase);
                    if (!string.IsNullOrEmpty((Output)))
                    {
                        Console.Write("Compiling {0}...", FileNameBase);
                        Console.WriteLine("Result:");
                        Console.WriteLine("{0}", Output);
                    }
                    try
                    {
                        File.SetLastWriteTime(FileNameExecutable, File.GetLastWriteTime(FileNameSourceCode));
                    }
                    catch
                    {
                    }
                }
#endif

                if (File.Exists(fileNameExecutable))
                {
                    RunFile(runTestsViewOut, pspAutoTestsFolder, fileNameExecutable, fileNameExpected, fileNameBase);
                }
                else
                {
                    Console.WriteLine("Can't find executable for '{0}' '{1}'", fileNameExpected, fileNameExecutable);
                }
            }
        }
 public static bool IsMatch(string pattern, string input)
 {
     Wildcard wildcard;
     if (!dict.ContainsKey(pattern))
     {
         wildcard = new Wildcard(pattern, RegexOptions.IgnoreCase);
         dict.Add(pattern, wildcard);
     }
     wildcard = dict[pattern];
     return wildcard.IsMatch(input);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExclusionViewModel"/> class.
 /// </summary>
 /// <param name="exclusion">The exclusion.</param>
 public ExclusionViewModel(Wildcard exclusion)
 {
     this.data = exclusion;
 }
    // ------------------------------------------------------------------------
    /// <summary>
    /// Recursive method adds objects to goList if their name matches the wildcard.
    /// </summary>
    /// <param name='obj'>
    /// The current object to check.
    /// </param>
    /// <param name='wildcard'>
    /// The wildcard used for matching.
    /// </param>
    /// <param name='goList'>
    /// Holds all matching object transform.
    /// </param>
    // ------------------------------------------------------------------------
    private void addObjectsToSet( Transform obj, Wildcard wildcard, HashSet<string> objectSet )
    {
        if( wildcard.IsMatch( obj.name ) )
            objectSet.Add( obj.name );

        foreach( Transform child in obj )
            addObjectsToSet( child, wildcard, objectSet );
    }
    // ------------------------------------------------------------------------
    /// <summary>
    /// Replaces the object.
    /// </summary>
    /// <param name='obj'>
    /// Object.
    /// </param>
    /// <param name='transition'>
    /// Transition.
    /// </param>
    /// <param name='wildcard'>
    /// Wildcard.
    /// </param>
    // ------------------------------------------------------------------------
    private void replaceObject( Transform obj, Transition transition, Wildcard wildcard )
    {
        if( wildcard.IsMatch( obj.name ) )
        {
            // we have to replace the object
            if( transition.Replacement == null )
            {
                DestroyImmediate( obj.gameObject, true );
            }
            else
            {
                Quaternion localRotation = Quaternion.identity;
                Vector3 localPosition = Vector3.zero;
                Vector3 localScale = Vector3.zero;

                switch( transition.TransformationType )
                {
                case 0: // source
                    {
                        localRotation = obj.localRotation;
                        localPosition = obj.localPosition;
                        localScale = obj.localScale;
                    }
                    break;
                case 1: // target
                    {
                        localRotation = transition.Replacement.transform.localRotation;
                        localPosition = transition.Replacement.transform.localPosition;
                        localScale = transition.Replacement.transform.localScale;
                    }
                    break;
                case 2: // combine
                    {
                        localRotation = transition.Replacement.transform.localRotation * obj.localRotation;
                        localPosition = obj.localRotation * transition.Replacement.transform.localPosition + obj.localPosition;
                        localScale = Vector3.Scale( transition.Replacement.transform.localScale, obj.localScale );
                    }
                    break;
                }

                Transform parent = obj.parent;
                DestroyImmediate( obj.gameObject, true );

                GameObject replacement = Instantiate( transition.Replacement ) as GameObject;
                replacement.name = transition.Replacement.name;
                replacement.transform.parent = parent;
                replacement.transform.localRotation = localRotation;
                replacement.transform.localPosition = localPosition;
                replacement.transform.localScale = localScale;
            }
        }
        else
        {
            // we have to use a separat list here because the internal child list might change while iterating
            List<Transform> children = new List<Transform>( obj.childCount );
            foreach( Transform child in obj )
                children.Add( child );

            foreach( Transform child in children )
                replaceObject( child, transition, wildcard );
        }
    }
 // ------------------------------------------------------------------------
 /// <summary>
 /// Apply object replacement settings to selected prefab.
 /// </summary>
 // ------------------------------------------------------------------------
 private void applyChanges()
 {
     foreach( Transition transition in mTransitionList )
     {
         Wildcard wildcard = new Wildcard( transition.Name, RegexOptions.IgnoreCase );
         replaceObject( mObject.transform, transition, wildcard );
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InclusionViewModel"/> class.
 /// </summary>
 /// <param name="inclusion">The inclusion.</param>
 public InclusionViewModel(Wildcard inclusion)
 {
     this.data = inclusion;
 }
    // ------------------------------------------------------------------------
    /// <summary>
    /// OnGUI renders the editor window.
    /// </summary>
    // ------------------------------------------------------------------------
    private void OnGUI()
    {
        //create an object field for the prefab/object
        GUILayout.BeginHorizontal();
        GameObject obj = (GameObject)EditorGUILayout.ObjectField( "Select or drop object:", mObject, typeof(GameObject), true );

        // if something changed
        if( obj != mObject )
        {
            // ignore model prefabs
            if( PrefabUtility.GetPrefabType( obj ) == PrefabType.ModelPrefab )
            {
                Debug.LogError( "ObjectReplacer, Object cannot be a model file. Please create a prefab first or select an instance from scene" );
                mObject = null;
            }
            else
            {
                mObject = obj;
            }

            mObjectList.Clear();
            mObjectListScrollPos = Vector2.zero;
        }
        GUILayout.EndHorizontal();

        GUILayout.Space( 7 );

        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical();

        // Create the Headings for displaying the transition list
        GUILayout.BeginHorizontal();
        GUILayout.Label( "ObjectName", GUILayout.MaxWidth( 200 ), GUILayout.ExpandWidth( true ) );
        GUILayout.Label( "Replacement", GUILayout.MaxWidth( 200 ), GUILayout.ExpandWidth( true ) );
        GUILayout.Space( 10 );
        GUILayout.Label( "Transform", GUILayout.Width( 80 ) );
        GUILayout.Space( 50 );
        GUILayout.EndHorizontal();

        // Create scroll view for the transitions
        mTransitionListScrollPos = GUILayout.BeginScrollView( mTransitionListScrollPos, false, true, GUILayout.ExpandWidth( true ) );
        GUILayout.BeginVertical();

        for( int i = 0; i < mTransitionList.Count; i++ )
        {
            Transition transition = mTransitionList[i];
            GUILayout.BeginHorizontal();
            transition.Name = GUILayout.TextField( transition.Name, GUILayout.MaxWidth( 200 ), GUILayout.ExpandWidth( true ) );
            GameObject newReplacement = ( (GameObject)EditorGUILayout.ObjectField( new GUIContent( "", "Prefab replacing all objects mathing the name." ), transition.Replacement, typeof(GameObject), false, GUILayout.MaxWidth( 200 ), GUILayout.ExpandWidth( true ) ) );
            GUILayout.Space( 10 );
            transition.TransformationType = GUILayout.Toolbar( transition.TransformationType, mTransformationTypes, GUILayout.Width( 80 ) );

            if( GUILayout.Button( new GUIContent( ">", "List matching objects." ), GUILayout.Width( 25 ) ) && ( mObject != null ) )
            {
                Wildcard wildcard = new Wildcard( transition.Name, RegexOptions.IgnoreCase );

                HashSet<string> objectSet = new HashSet<string>();
                addObjectsToSet( mObject.transform, wildcard, objectSet );

                mObjectList.Clear();
                mObjectList.AddRange( objectSet );
                mObjectList.Sort();
            }

            GUILayout.EndHorizontal();

            if( newReplacement == transition.Replacement )
                continue;

            if( ( newReplacement != null ) && ( PrefabUtility.GetPrefabType( newReplacement ) != PrefabType.Prefab ) )
            {
                Debug.LogError( "ObjectReplacer, Given object needs to be a prefab." );
                continue;
            }

            transition.Replacement = newReplacement;
        }

        if( GUILayout.Button( "+" ) )
        {
            mTransitionList.Add( new Transition( "", null, 0 ) );
        }

        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        GUILayout.EndVertical();

        // object list
        GUILayout.BeginVertical( GUILayout.MinWidth( 200 ), GUILayout.ExpandWidth( true ) );
        GUILayout.Label( "Replaceable Objects", GUILayout.MinWidth( 200 ), GUILayout.ExpandWidth( true ) );
        mObjectListScrollPos = GUILayout.BeginScrollView( mObjectListScrollPos, false, true, GUILayout.MinWidth( 200 ), GUILayout.ExpandWidth( true ), GUILayout.ExpandHeight( true ) );
        foreach( string objName in mObjectList )
            GUILayout.Label( objName );
        GUILayout.EndScrollView();
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        // load previously saved transitions from xml file
        if( GUILayout.Button( "Load" ) )
            loadTransitionList();

        // save the current transition map to xml file
        if( GUILayout.Button( "Save" ) )
            saveTransitionList();

        GUILayout.EndHorizontal();

        // Buttons //
        if( GUILayout.Button( "Apply Changes" ) && ( mObject != null ) ) // Save the transition changes
            applyChanges();
    }
Example #39
0
 public IEnumerable<FileSystemEntry> FindFiles(String Path, Wildcard Wildcard)
 {
     return FindFiles(Path, (Regex)Wildcard);
 }