Exemplo n.º 1
0
        // Find the control with ID name, taking care of the presence of master pages
        private static object LocateControl(Control control, string name, int depth)
        {
            // First, we recurse as long as we find master pages, keeping track of the depth
            ScriptMaster master = GetMasterFromPageOrMaster(control);

            if (master != null)
            {
                return(LocateControl(master, name, depth + 1));
            }

            // Now find the control by traversing the same number of ContentPlaceHolders
            return(LocateControlInContentPlaceHolders(control as ScriptMaster, control, name, depth));
        }
Exemplo n.º 2
0
        public async Task UpdateScript()
        {
            var devSmartAgent     = "SmartAgentDev";
            var prodAppConfigName = "SmartAgentProd";
            var container         = new UnityContainer();
            var newScript         = new StringBuilder()
                                    .Append(@"SET !TIMEOUT_STEP 4\nURL GOTO %%websiteDomain%%\nWAIT SECONDS=1\nTAG POS=1 TYPE=INPUT:TEXT FORM=NAME:* ATTR=NAME:username CONTENT=%%websiteUsername%%\n")
                                    .Append(@"TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:* ATTR=NAME:password CONTENT=%%websitePassword%%\\nTAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:* ATTR=NAME:btnLogIn\n")
                                    .Append(@"TAG POS=1 TYPE=B FORM=NAME:Login ATTR=TXT:Invalid<SP>User<SP>ID<SP>or<SP>password* EXTRACT=TXT")
                                    .ToString();

            ScriptMaster script = ScriptMaster
                                  .Build()
                                  .WithScriptKey(new Guid("60b5331b-e52c-e211-b35b-000c29729dff"))
                                  .WithWebsiteKey(new Guid("5608f070-e12c-e211-b35b-000c29729dff"))
                                  .WithScriptCode(newScript)
                                  .Build();

            var scriptKey = new Guid("60b5331b-e52c-e211-b35b-000c29729dff");

            Func <ScriptMaster, string, Task> UpdateScriptCode = async(sm, dataSource) =>
            {
                using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings[dataSource].ConnectionString))
                {
                    container.RegisterType <IAsyncRepository <ScriptMaster>, ScriptMasterRepository>(new InjectionConstructor(db));
                    var repo = container.Resolve <IAsyncRepository <ScriptMaster> >();
                    await repo.UpdateAsync(sm);
                }
            };

            Func <Guid, string, Task <Script> > GetScriptCode = async(key, dataSource) =>
            {
                using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings[dataSource].ConnectionString))
                {
                    var repo = new ScriptMasterRepository(db);
                    return(await repo.GetScript(key));
                }
            };

            await UpdateScriptCode(script, devSmartAgent);

            Console.WriteLine("complete");
            var updatedScript = await GetScriptCode(script.ScriptKey, devSmartAgent);

            Console.WriteLine(updatedScript);

            Assert.Equal(script.ScriptCode, updatedScript.Code);
        }
Exemplo n.º 3
0
        // Helper method to get the Master from either a MasterPage or a Page (if any)
        private static ScriptMaster GetMasterFromPageOrMaster(Control control)
        {
            Page page = control as Page;

            if (page != null)
            {
                return(page.Master as ScriptMaster);
            }

            ScriptMaster master = control as ScriptMaster;

            if (master != null)
            {
                return(master.Master as ScriptMaster);
            }

            return(null);
        }
Exemplo n.º 4
0
        private static Control LocateControlInContentPlaceHolders(
            ScriptMaster master, Control control, string name, int depth)
        {
            // If we're back to zero depth, just look for the id'ed control right here
            if (depth == 0)
            {
                // If it's a special MerlinWeb user control, use the true user control instead
                Microsoft.Scripting.AspNet.UI.Controls.UserControl uc = control as Microsoft.Scripting.AspNet.UI.Controls.UserControl;
                if (uc != null)
                {
                    control = uc.UC;
                    if (control == null)
                    {
                        return(null);
                    }
                }

                return(control.FindControl(name));
            }

            // While we search for the control deeper into the tree, we also walk back
            // in the opposite direction to find the master that defines the current ContentPlaceHolder
            ScriptMaster parentMaster = master.Parent as ScriptMaster;

            // Recurse on each ContentPlaceHolder owned by the current master
            foreach (string s in master.ContentPlaceHolders)
            {
                ContentPlaceHolder cph = (ContentPlaceHolder)control.FindControl(s);
                if (cph == null)
                {
                    continue;
                }

                Control c = LocateControlInContentPlaceHolders(parentMaster, cph, name, depth - 1);
                if (c != null)
                {
                    return(c);
                }
            }

            return(null);
        }
Exemplo n.º 5
0
 public override void Start()
 {
     ScriptMaster = Camera.main.GetComponent <M22.ScriptMaster>();
 }