Exemple #1
0
        private Node ParseUnary()
        {
            if (Match(TokenType.Unary))
            {
                Token op = Previous();
                Node  argument;
                try { argument = ParseUnary(); }
                catch (NoElementException) { argument = new DynamicElement("&", History, false); }

                switch (op.Source[1])
                {
                case '^': return(new Reverse(argument));

                case '\\': return(new RegexEscape(argument));

                case 'l': return(new LowerCaseHead(argument));

                case 'L': return(new LowerCaseAll(argument));

                case 'u': return(new UpperCaseHead(argument));

                case 'U': return(new UpperCaseAll(argument));

                case 'T': return(new TitleCaseAll(argument));

                default: throw new ParserError("Unknown unary operator encountered.");
                }
            }
            else
            {
                return(ParseRepeat());
            }
        }
Exemple #2
0
        private Node ParseRepeat()
        {
            try
            {
                Node leftArgument = ParseElement();
                if (Match(TokenType.Repeat))
                {
                    Node rightArgument;
                    try { rightArgument = ParseUnary(); }
                    catch (NoElementException) { rightArgument = new Literal("_"); }
                    return(new Repetition(leftArgument, rightArgument));
                }

                return(leftArgument);
            }
            catch (NoElementException e)
            {
                // We only end up here if the parsing attempt for leftArgument failed.
                if (Match(TokenType.Repeat))
                {
                    Node leftArgument = new DynamicElement("&", History, false);
                    Node rightArgument;
                    try { rightArgument = ParseUnary(); }
                    catch (NoElementException) { rightArgument = new Literal("_"); }
                    return(new Repetition(leftArgument, rightArgument));
                }

                // If there is no "*", we propagate the exception outwards.
                throw e;
            }
        }
        public override void Setup()
        {
            //base.Setup();

            AddState("ResultsAvaible", "false");

            SearchBar = new DynamicElement(Driver, "SearchBar").AddSearch(By.Id("lst-ib"))
                        .AddSearch(By.CssSelector("input[id='lst-ib']"));
            SearchButton = new DynamicElement(Driver, "SearchButton")
                           .AddSearch(By.CssSelector("input[value='Google Search']"));
            Result = new DynamicElement(Driver, "Search Result")
                     .AddSearch(By.CssSelector("div[class='g'] div[class='rc'] a"));
        }
Exemple #4
0
        /// <summary>
        /// 设置动画开始和暂停
        /// </summary>
        /// <param name="isPlay"></param>
        public void setTrackPlay(int isPlay)
        {
            switch (isPlay)
            {
            case 0:
                Debug.Log("开始播放");
                elementContainer.SetTrackPlay(isPlay);
                break;

            case 1:
                Debug.Log("暂停播放");
                elementContainer.SetTrackPlay(isPlay);
                break;

            case 2:
                Debug.Log("停止播放");
                DynamicElement.GetInstance().ResetStart();
                break;

            default:
                break;
            }
        }
Exemple #5
0
 public UseKeyArg(DynamicElement character, MapElements keyType, MapElements doorType)
     : base(character)
 {
     KeyType  = keyType;
     DoorType = doorType;
 }
 protected void RemoveObject(Scenario scenario, DynamicElement obj)
 {
     scenario.RemObjectFromScenario(obj);
     obj.Disable();
 }
 protected void RemoveCharacter(Scenario scenario, DynamicElement character)
 {
     scenario.RemCharacterFromScenario(character);
     character.Disable();
 }
 private void OpenDoor(Scenario scenario, DynamicElement door)
 {
     RemoveObject(scenario, door);
 }
        internal IEnumerable <DynamicElement> GetProviders(DynamicElement document)
        {
            var artifacts = document.XPath("/swid:SoftwareIdentity/swid:Link[@rel='component' and @oneget:type='provider']").GetAttributes("artifact").Distinct().ToArray();

            return(artifacts.Select(each => GetProvider(document, each)).Where(each => each != null));
        }
Exemple #10
0
 private void KillEnemy(Scenario scenario, DynamicElement enemy)
 {
     RemoveCharacter(scenario, enemy);
 }
Exemple #11
0
 public PullLeverArg(DynamicElement character)
     : base(character)
 {
 }
Exemple #12
0
 public void OnMouseUp()
 {
     Debug.Log("鼠标按下");
     foreach (KeyValuePair <string, List <ElementItem> > item in ElementContainer.GetInstance().dicElements)
     {
         foreach (ElementItem itemValue in item.Value)
         {
             if (itemValue.nowLevel == 1)
             {
                 if (itemValue != ElementContainer.GetInstance().nowElement)
                 {
                     itemValue.SetUIByLevel(0);
                 }
             }
         }
     }
     foreach (Transform item in Element.ElementContainer.GetInstance().arrayLabelParent)
     {
         if (!item.gameObject.active &&
             !DynamicElement.GetInstance().isPlay &&
             !DynamicElement.GetInstance().inPlay)
         {
             array = item;
         }
     }
     if (transform.parent.parent.GetComponent <ElementItem>() != null &&
         ElementContainer.GetInstance().isClick &&
         !DynamicElement.GetInstance().isPlay &&
         !DynamicElement.GetInstance().inPlay)
     {
         transform.parent.parent.GetComponent <ElementItem>().SetUIByLevel(1);
         if (array != null)
         {
             if (transform.parent.parent.GetComponent <ElementItem>().lineId != array.name)
             {
                 array.gameObject.SetActive(true);
             }
         }
     }
     if (transform.parent.parent.GetComponent <ElementArray>() != null &&
         ElementContainer.GetInstance().isClick &&
         !DynamicElement.GetInstance().isPlay &&
         !DynamicElement.GetInstance().inPlay)
     {
         if (array != null)
         {
             array.gameObject.SetActive(true);
         }
         transform.parent.parent.gameObject.SetActive(false);
         if (Vector3.Distance(transform.position, Camera.main.transform.position) > 1000)
         {
             Camera.main.GetComponent <BLCameraControl>().LookAtPosition3(transform.parent.parent.position);
         }
         transform.parent.parent.parent.GetComponent <ArrayParent>().WaitTime(transform.parent.parent.gameObject);
         ElementContainer.GetInstance().SceneToLevel(1);
     }
     if (transform.parent.parent.GetComponent <ElementArea>() != null &&
         ElementContainer.GetInstance().isClick &&
         !DynamicElement.GetInstance().isPlay &&
         !DynamicElement.GetInstance().inPlay)
     {
         transform.parent.parent.GetComponent <ElementArea>().SetUIByLevel(1);
     }
 }
Exemple #13
0
        private void InstallAssemblyProvider(DynamicElement provider, string fastPath, BootstrapRequest request)
        {
            if (!Directory.Exists(request.DestinationPath))
            {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.DestinationPathNotSet);
                return;
            }

            var targetFilename = provider.XPath("/swid:SoftwareIdentity/swid:Meta[@targetFilename]").GetAttribute("targetFilename");

            if (string.IsNullOrEmpty(targetFilename))
            {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.InvalidFilename);
                return;
            }
            targetFilename = Path.GetFileName(targetFilename);
            var targetFile = Path.Combine(request.DestinationPath, targetFilename);

            string tmpFile = null;
            var    failedBecauseInvalid = false;

            // download the file
            foreach (var link in provider.XPath("/swid:SoftwareIdentity/swid:Link[@rel = 'installationmedia']"))
            {
                var href = link.Attributes["href"];
                if (string.IsNullOrEmpty(href) || !Uri.IsWellFormedUriString(href, UriKind.Absolute))
                {
                    request.Debug("Bad or missing uri: {0}", href);
                    continue;
                }

                try {
                    tmpFile = targetFilename.GenerateTemporaryFilename();

                    request.Debug("Downloading '{0}' to '{1}'", href, tmpFile);

                    if (!request.DownloadFileToLocation(new Uri(href), tmpFile))
                    {
                        request.Debug("Failed download of '{0}'", href);
                        continue;
                    }

                    request.Debug("Verifying the package");

                    var valid = request.IsSignedAndTrusted(tmpFile, request);

                    if (!valid)
                    {
                        request.Debug("Not Valid file '{0}' => '{1}'", href, tmpFile);
                        failedBecauseInvalid = true;
                        request.Warning(Constants.Messages.FileFailedVerification, href);
#if !DEBUG
                        tmpFile.TryHardToDelete();
                        continue;
#endif
                    }


                    // looks good! let's keep it
                    if (File.Exists(targetFile))
                    {
                        request.Debug("Removing old file '{0}'", targetFile);
                        targetFile.TryHardToDelete();
                    }

                    // is that file still there?
                    if (File.Exists(targetFile))
                    {
                        request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.UnableToRemoveFile, targetFile);
                        return;
                    }

                    request.Debug("Copying file '{0}' to '{1}'", tmpFile, targetFile);
                    File.Copy(tmpFile, targetFile);
                    if (File.Exists(targetFile))
                    {
                        // looks good to me.
                        request.YieldFromSwidtag(provider, null, null, null, fastPath);
                        PackageManager._instance.LoadProviders(request);
                        return;
                    }
                }
                catch (Exception e) {
                    e.Dump();
                }
                finally {
                    if (!string.IsNullOrEmpty(tmpFile))
                    {
                        tmpFile.TryHardToDelete();
                    }
                }
            }
            if (failedBecauseInvalid)
            {
                request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.FileFailedVerification, fastPath);
            }
        }
Exemple #14
0
        private void InstallModuleProvider(DynamicElement provider, string fastPath, BootstrapRequest request)
        {
            // This is a prototype for a general provider installer
            // really, this is going away as soon as we have a real swidtag provider.

            // 'package' may not be the best rel= type.
            foreach (var link in provider.XPath("/swid:SoftwareIdentity/swid:Link[@rel = 'package']"))
            {
                var href = link.Attributes["href"];

                // NOT THIS -> at this point href should either be url to a location (that a provider will recognize)
                // JUST THIS -> or more likely should be a prototype canonical id: <provider>:<packagename>[/version][#source]
                //
                if (string.IsNullOrEmpty(href) || !Uri.IsWellFormedUriString(href, UriKind.Absolute))
                {
                    request.Debug("Bad or missing uri: {0}", href);
                    continue;
                }

                var artifact = link.Attributes["artifact"];

                try {
                    var uri       = new Uri(href);
                    var providers = request.SelectProviders(uri.Scheme, request).ToArray();
                    if (providers.Length == 0)
                    {
                        // no known provider by that name right now.
                        continue;
                    }

                    var packageId      = uri.Host;
                    var packageVersion = uri.PathAndQuery;
                    var source         = uri.Fragment;

                    if (string.IsNullOrEmpty(packageId))
                    {
                        continue;
                    }

                    var customRequest = request.Extend <Request>(new {
                        GetSources = new Func <IEnumerable <string> >(() => {
                            if (string.IsNullOrWhiteSpace(source))
                            {
                                return(new string[0]);
                            }
                            return(new string[] {
                                source
                            });
                        })
                    });

                    var packages = providers[0].FindPackage(packageId, packageVersion, null, null, 0, customRequest).Wait(60);

                    var pkgs = packages.ToArray();
                    if (pkgs.Length < 1)
                    {
                        if (string.IsNullOrWhiteSpace(packageVersion))
                        {
                            request.Warning("Unable to find package '{0}' to bootstrap", packageId);
                        }
                        else
                        {
                            request.Warning("Unable to find package '{0}/{1}' to bootstrap", packageId, packageVersion);
                        }
                        continue;
                    }
                    if (pkgs.Length > 1)
                    {
                        if (string.IsNullOrWhiteSpace(packageVersion))
                        {
                            request.Warning("Package '{0}' matched more than one package", packageId);
                        }
                        else
                        {
                            request.Warning("Package '{0}/{1}' matched more than one package", packageId, packageVersion);
                        }
                        continue;
                    }
                    var installedPackages = providers[0].InstallPackage(pkgs[0], customRequest).Wait(120).ToArray();
                    if (request.IsCanceled)
                    {
                        return;
                    }

                    bool installed = false;

                    foreach (var pkg in installedPackages)
                    {
                        installed = true;
                        request.YieldSoftwareIdentity(pkg.FastPackageReference, pkg.Name, pkg.Version, pkg.VersionScheme, pkg.Summary, pkg.Source, pkg.SearchKey, pkg.FullPath, pkg.PackageFilename);
                    }
                    if (request.IsCanceled)
                    {
                        return;
                    }

                    if (installed)
                    {
                        // it installed ok!
                        PackageManager._instance.LoadProviders(request);
                    }
                    else
                    {
                        request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath);
                    }
                }
                catch (Exception e) {
                    e.Dump();
                }
            }
        }
Exemple #15
0
        private void InstallProviderFromInstaller(DynamicElement provider, string fastPath, BootstrapRequest request)
        {
            string tmpFile = null;
            var    failedBecauseInvalid = false;

            // download the file
            foreach (var link in provider.XPath("/swid:SoftwareIdentity/swid:Link[@rel = 'installationmedia']"))
            {
                var href = link.Attributes["href"];
                if (string.IsNullOrEmpty(href) || !Uri.IsWellFormedUriString(href, UriKind.Absolute))
                {
                    request.Debug("Bad or missing uri: {0}", href);
                    continue;
                }

                var artifact = link.Attributes["artifact"];


                try {
                    tmpFile = artifact.GenerateTemporaryFilename();

                    request.Debug("Downloading '{0}' to '{1}'", href, tmpFile);

                    if (!request.DownloadFileToLocation(new Uri(href), tmpFile))
                    {
                        request.Debug("Failed download of '{0}'", href);
                        continue;
                    }

                    request.Debug("Verifying the package");

                    var valid = request.IsSignedAndTrusted(tmpFile, request);

                    if (!valid)
                    {
                        request.Debug("Not Valid file '{0}' => '{1}'", href, tmpFile);
                        failedBecauseInvalid = true;
                        request.Warning(Constants.Messages.FileFailedVerification, href);
#if !DEBUG
                        tmpFile.TryHardToDelete();
                        continue;
#endif
                    }


                    // we have a valid file.
                    // run the installer
                    if (request.Install(tmpFile, "", request))
                    {
                        // it installed ok!
                        request.YieldFromSwidtag(provider, null, null, null, fastPath);
                        PackageManager._instance.LoadProviders(request);
                    }
                    else
                    {
                        request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath);
                    }
                } catch (Exception e) {
                    e.Dump();
                }
                finally {
                    if (!string.IsNullOrEmpty(tmpFile))
                    {
                        tmpFile.TryHardToDelete();
                    }
                }
            }
            if (failedBecauseInvalid)
            {
                request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.FileFailedVerification, fastPath);
            }
        }
 public GetObjectArg(DynamicElement character)
     : base(character)
 {
 }
 public AttackActionArg(DynamicElement character, MapElements enemyType, params MapElements[] weapons)
     : base(character)
 {
     EnemyType = enemyType;
     Weapons   = new List <MapElements>(weapons);
 }
 public CharacterActionArg(DynamicElement character)
 {
     Character = character;
 }
        internal DynamicElement GetProvider(DynamicElement document, string name)
        {
            var links = document.XPath("/swid:SoftwareIdentity/swid:Link[@rel='component' and @artifact='{0}' and @oneget:type='provider']", name.ToLowerInvariant());

            return(DownloadSwidtag(links.GetAttributes("href")));
        }
 public MoveArg(DynamicElement character, Directions direction)
     : base(character)
 {
     Direction = direction;
 }
        public bool YieldFromSwidtag(DynamicElement provider, string requiredVersion, string minimumVersion, string maximumVersion, string searchKey)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            var             name            = provider.Attributes["name"];
            FourPartVersion version         = provider.Attributes["version"];
            var             versionScheme   = provider.Attributes["versionScheme"];
            var             packageFilename = provider.XPath("/swid:SoftwareIdentity/swid:Meta[@targetFilename]").GetAttribute("targetFilename");
            var             summary         = provider.XPath("/swid:SoftwareIdentity/swid:Meta[@summary]").GetAttribute("summary");

            if (AnyNullOrEmpty(name, version, versionScheme, packageFilename))
            {
                Debug("Skipping yield on swid due to missing field \r\n", provider.ToString());
                return(true);
            }

            if (!string.IsNullOrEmpty(requiredVersion) && version != requiredVersion)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(minimumVersion) && version < minimumVersion)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(maximumVersion) && version > maximumVersion)
            {
                return(true);
            }

            if (YieldSoftwareIdentity(name, name, version, versionScheme, summary, null, searchKey, null, packageFilename))
            {
                // note: temporary until we actaully support swidtags in the core.

                // yield all the meta/attributes
                if (provider.XPath("/swid:SoftwareIdentity/swid:Meta").Any(
                        meta => meta.Attributes.Any(attribute => !YieldSoftwareMetadata(name, attribute.Name.LocalName, attribute.Value))))
                {
                    return(false);
                }

                if (provider.XPath("/swid:SoftwareIdentity/swid:Link").Any(
                        link => !YieldLink(name, link.Attributes["href"], link.Attributes["rel"], link.Attributes["type"], link.Attributes["ownership"], link.Attributes["use"], link.Attributes["media"], link.Attributes["artifact"])))
                {
                    return(false);
                }

                if (provider.XPath("/swid:SoftwareIdentity/swid:Entity").Any(
                        entity => !YieldEntity(name, entity.Attributes["name"], entity.Attributes["regid"], entity.Attributes["role"], entity.Attributes["thumbprint"])))
                {
                    return(false);
                }

                if (!YieldSoftwareMetadata(name, "FromTrustedSource", true.ToString()))
                {
                    return(false);
                }
            }

            return(true);
        }
 public ClimbLadderArg(DynamicElement character, MapElements ladderType)
     : base(character)
 {
     LadderType = ladderType;
 }