protected override bool InternalExecute(ProcessExecutingContext context) { var pageSchemaManager = UserConnection.GetSchemaManager("PageSchemaManager") as PageSchemaManager; var pageSchema = pageSchemaManager.GetInstanceByName("SocialAccountAuthPage"); var sb = new StringBuilder(); sb.AppendFormat("Terrasoft.openWindow('ViewPage.aspx','{0}',", pageSchema.UId.ToString()); // params: sb.Append("["); bool isFirst = true; var parameters = new Dictionary <string, string> { { "userId", UserId.ToString() }, { "SocialNetwork", SocialNetwork }, { "OpenerPageId", OpenerPageId }, { "SuccessEventName", SuccessEventName }, { "FailedEventName", FailedEventName } }; foreach (var parameter in parameters) { if (isFirst) { isFirst = false; } else { sb.Append(",\n\t"); } sb.Append("{"); sb.AppendFormat("\tname: '{0}',", parameter.Key); sb.AppendFormat("\tvalue: '{0}'", parameter.Value); sb.Append("}"); } sb.Append("\t],"); var width = pageSchema.Width.ToString(CultureInfo.InvariantCulture); var height = pageSchema.Height.ToString(CultureInfo.InvariantCulture); sb.AppendFormat("{0}, {1}, ", width, height); // isCenterWindow: sb.Append("true);"); var page = (System.Web.HttpContext.Current.CurrentHandler as Terrasoft.UI.WebControls.Page).Page; ScriptManager scriptManager = page.FindControl("ScriptManager") as Terrasoft.UI.WebControls.Controls.ScriptManager; string script = sb.ToString(); scriptManager.AddScript(script); return(true); }
protected override bool InternalExecute(ProcessExecutingContext context) { // TODO: Generate exception if OpenerPage parameter is null /* * Terrasoft.UI.WebControls.PageSchemaUserControl page = null; * if (OpenerPage != null) { * //return false; * page = (Terrasoft.UI.WebControls.PageSchemaUserControl)OpenerPage; * } */ //var page = (Terrasoft.UI.WebControls.PageSchemaUserControl)OpenerPage; // TODO: Generate exception if PageUId and PageUrl parameters are (null or empty) and at same time if (PageUId.IsEmpty() && string.IsNullOrEmpty(PageUrl)) { return(false); } var sb = new StringBuilder(); /* * if (UseOpenerRegisterScript) { * sb.Append("var currentOpener = window.opener != null ? window.opener : window;\r\n"); * sb.Append("currentOpener."); * } */ sb.Append("Terrasoft.openWindow("); var sbCallback = new StringBuilder(); var sbConfig = new StringBuilder(); var nullString = "null"; var callbackString = "function(wnd) {{ {0} }}"; var window = "wnd"; // windowUrl: if (!PageUId.IsEmpty()) { sb.Append("'"); sb.Append("ViewPage.aspx"); sb.Append("'"); // id: sb.Append(", "); sb.Append("'"); sb.Append(PageUId.ToString()); sb.Append("'"); } else { sb.Append("'"); sb.Append(PageUrl); sb.Append("'"); // id: sb.Append(", "); sb.Append(nullString); } sb.Append(", "); // params: sb.Append("["); bool isFirst = true; if (PageParameters != null) { foreach (var parameter in (Dictionary <string, string>)PageParameters) { if (isFirst) { isFirst = false; } else { sb.Append(", "); } sb.Append("\n\t{name: "); sb.Append("'"); sb.Append(parameter.Key); sb.Append("'"); sb.Append(","); sb.Append(" value: "); sb.Append("'"); sb.Append(parameter.Value); sb.Append("'"); sb.Append("}"); } } sb.Append("\t]"); sb.Append(", "); var pageSchemaManager = UserConnection.GetSchemaManager("PageSchemaManager") as PageSchemaManager; if (!PageUId.IsEmpty()) { var pageSchema = pageSchemaManager.GetInstanceByUId(PageUId); if (!pageSchema.Maximized) { // width: sb.Append(pageSchema.Width.ToString(CultureInfo.InvariantCulture)); sb.Append(", "); // height: sb.Append(pageSchema.Height.ToString(CultureInfo.InvariantCulture)); sb.Append(", "); } else { // width: sb.Append(nullString); sb.Append(", "); // height: sb.Append(nullString); sb.Append(", "); } } else { // width: if (Width > 0) { sb.Append(Width.ToString(CultureInfo.InvariantCulture)); } else { sb.Append(nullString); } sb.Append(", "); // height: if (Height > 0) { sb.Append(Height.ToString(CultureInfo.InvariantCulture)); } else { sb.Append(nullString); } sb.Append(", "); } // isCenterWindow: var centered = Centered as bool?; if (!centered.HasValue) { sb.Append("true"); } else { if (centered.Value) { sb.Append("true"); } else { sb.Append("false"); } } sb.Append(", "); // isToolBarVisible: sb.Append(nullString); sb.Append(", "); // openInExistingWindow: sb.Append(nullString); // key setting: sbCallback.Append("\nvar windowKey = "); // sbCallback.Append(window); // sbCallback.Append(".key = "); sbCallback.Append("'"); if (!string.IsNullOrEmpty(OpenerInstanceId)) { sbCallback.Append(OpenerInstanceId); } else { /* * if (page != null) { * sbCallback.Append(((Terrasoft.UI.WebControls.Page)page.AspPage).InstanceId.ToString()); * sbCallback.Append(page.PageContainer.UniqueID); * }*/ } sbCallback.Append("'"); sbCallback.Append(";"); sbCallback.Append("\nwnd.key = windowKey;"); // opener closing: if (CloseOpenerOnLoad) { sbCallback.Append("\nif (window.mainPage != window) {"); sbCallback.Append("\n\tExt.lib.Event.on("); sbCallback.Append(window); sbCallback.Append(", 'load', function() {\n\t\twindow.close()\n});"); sbCallback.Append("\n}"); } // close message: if (!string.IsNullOrEmpty(CloseMessage)) { sbCallback.Append(@" var pickHoleInRegisterListener = function(attemptsCount) { setTimeout(function() { try { attemptsCount--; Ext.EventManager.on(wnd, 'beforeunload', function() { if (Terrasoft.AjaxMethods.ThrowClientEvent) { var wndKey = windowKey; setTimeout(function() { Terrasoft.AjaxMethods.ThrowClientEvent(wndKey,'" ); sbCallback.Append(CloseMessage); sbCallback.Append(@"');}, 10); } }); } catch(e) { if (attemptsCount === 0) { throw e; } pickHoleInRegisterListener(attemptsCount); } }, 200); }; pickHoleInRegisterListener(10);" ); } sb.Append(", "); sb.Append(string.Format(callbackString, sbCallback.ToString())); sb.Append(", "); // ignoreRequestId: sb.Append(nullString); sb.Append(", "); // windowName sb.Append(nullString); sb.Append(", "); // useApplicationPath sb.Append(nullString); sb.Append(", "); // config sbConfig.Append("\n{"); // config:ignoreProfile sbConfig.Append(string.Format("ignoreProfile:{0}", IgnoreProfile ? "true" : "false")); sbConfig.Append("}"); sb.Append(sbConfig); sb.Append(");"); // script adding: /* * ScriptManager scriptManager = null; * if (page == null) { * } else { * scriptManager = page.GetPropertyValue("ScriptManager") as ScriptManager; * } */ //ScriptManager scriptManager = ((Terrasoft.UI.WebControls.Page)System.Web.HttpContext.Current.CurrentHandler).FindControl("ScriptManager") as ScriptManager; //Hack: Asp.Net has an artificial limit on the size of the stack ScriptManager scriptManager = Terrasoft.UI.WebControls.Page.FindControlByClientId(((System.Web.UI.Control)System.Web.HttpContext.Current.CurrentHandler), "ScriptManager", true) as ScriptManager; string script = sb.ToString(); if (!UseCurrentActivePage) { script = "var executePage = window.mainPage || window; executePage.eval('" + script.Replace(@"\", @"\\").Replace(@"'", @"\'").Replace("\n", " ").Replace("\r", " ") + "');"; } scriptManager.AddScript(script); //OpenerPage = null; return(true); }
private void AddPlayTutorialDialogBox(object sender, EventArgs e) { ScriptManager.AddScript(new AddOptionsDialogBoxScript("Play Tutorial?", ScreenCentre, PlayGame, PlayTutorial, "No", "Yes")); }
public void AddScript(Script script, Script previousScript = null) { ScriptManager.AddScript(script, previousScript); }
protected override bool InternalExecute(ProcessExecutingContext context) { string buttonsJsString; string iconJsString; string messageBoxString = "Ext.MessageBox"; string defaultButtons = "OK"; string[] defaultButtonsArray = { "ok" }; string defaultIcon = "INFO"; string defaultMessage = "DefaultQuestionMessage"; var page = Page as Terrasoft.UI.WebControls.PageSchemaUserControl; if (MessageText == null) { return(false); } if (ProcessInstanceId == null && page != null) { var instanceId = ((Terrasoft.UI.WebControls.Page)page.AspPage).InstanceId.ToString(); ProcessInstanceId = instanceId + page.PageContainer.UniqueID; } var responseMessages = ResponseMessages as Dictionary <string, string>; if (responseMessages == null) { responseMessages = new Dictionary <string, string>(); } var parameters = PageParameters as Dictionary <string, object>; if (parameters == null) { parameters = new Dictionary <string, object>(); } if (!string.IsNullOrEmpty(Buttons)) { switch (Buttons) { case "OK": if (!responseMessages.ContainsKey("ok")) { responseMessages.Add("ok", defaultMessage); } buttonsJsString = messageBoxString + "." + Buttons; break; case "OKCANCEL": if (!responseMessages.ContainsKey("ok")) { responseMessages.Add("ok", defaultMessage); } if (!responseMessages.ContainsKey("cancel")) { responseMessages.Add("cancel", defaultMessage); } buttonsJsString = messageBoxString + "." + Buttons; break; case "YESNO": if (!responseMessages.ContainsKey("yes")) { responseMessages.Add("yes", defaultMessage); } if (!responseMessages.ContainsKey("no")) { responseMessages.Add("no", defaultMessage); } buttonsJsString = messageBoxString + "." + Buttons; break; case "YESNOCANCEL": if (!responseMessages.ContainsKey("yes")) { responseMessages.Add("yes", defaultMessage); } if (!responseMessages.ContainsKey("no")) { responseMessages.Add("no", defaultMessage); } if (!responseMessages.ContainsKey("cancel")) { responseMessages.Add("cancel", defaultMessage); } buttonsJsString = messageBoxString + "." + Buttons; break; default: foreach (string button in defaultButtonsArray) { if (!responseMessages.ContainsKey(button)) { responseMessages.Add(button, defaultMessage); } } buttonsJsString = messageBoxString + "." + defaultButtons; break; } } else { foreach (string button in defaultButtonsArray) { if (!responseMessages.ContainsKey(button)) { responseMessages.Add(button, defaultMessage); } } buttonsJsString = messageBoxString + "." + defaultButtons; } if (!string.IsNullOrEmpty(Icon)) { switch (Icon) { case "INFO": case "WARNING": case "QUESTION": case "ERROR": iconJsString = messageBoxString + "." + Icon; break; default: iconJsString = messageBoxString + "." + defaultIcon; break; } } else { iconJsString = messageBoxString + "." + defaultIcon; } var functionJsStringBuilder = new StringBuilder(); functionJsStringBuilder.Append("function(btn) {"); var isUpload = false; if (parameters.ContainsKey("IsUpload") && parameters["IsUpload"] != null) { isUpload = (bool)parameters["IsUpload"]; } foreach (KeyValuePair <string, string> responseMessage in responseMessages) { functionJsStringBuilder.Append("if (btn == '" + responseMessage.Key + "') {window.Terrasoft.AjaxMethods.ThrowClientEvent('" + ProcessInstanceId + "','" + responseMessage.Value + "', '', { isUpload : " + Json.Serialize(isUpload) + " });} else "); } functionJsStringBuilder.Append("{window.Terrasoft.AjaxMethods.ThrowClientEvent('" + ProcessInstanceId + "','DefaultQuestionMessage');}}"); WindowCaption = GetCaption(); ScriptManager scriptManager = null; if (page == null) { scriptManager = ((Terrasoft.UI.WebControls.Page)System.Web.HttpContext.Current.CurrentHandler).FindControl("ScriptManager") as ScriptManager; } else { scriptManager = page.GetPropertyValue("ScriptManager") as ScriptManager; } scriptManager.AddScript("Ext.MessageBox.message('" + WindowCaption.ToString() + "','" + MessageText.ToString().Replace("'", @"\'") + "'," + buttonsJsString + "," + iconJsString + "," + functionJsStringBuilder.ToString() + ", this);"); return(true); }
public void AddScript(Script script) { scriptManager.AddScript(script); }
public void AutoScriptOnOneCabAlreadyRunButNewerVersion() { // If the auto task sees the AutoScript.log file exists and has the same // version as the current AutoScript.xml then it shouldn't run it again. // Determine this by checking the file time after a second run. // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters(); // Standard task parameters. analyzeParams.IsBackgroundTask = true; analyzeParams.Name = "TestRunOneTask"; analyzeParams.RunInParallel = false; analyzeParams.UseSeparateThread = true; analyzeParams.AnalysisSettings = new StackHashAnalysisSettings(); analyzeParams.AnalysisSettings.ForceRerun = true; analyzeParams.ContextId = 0; analyzeParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); analyzeParams.Debugger = m_Debugger; analyzeParams.DebuggerSettings = m_DebuggerSettings; analyzeParams.TheScriptManager = scriptManager; analyzeParams.TheScriptResultsManager = scriptResultsManager; int productId = 1; analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection(); analyzeParams.ProductsToSynchronize.Add(new StackHashProductSyncData(productId)); analyzeParams.ErrorIndex = errorIndex; // Create the task and run it. AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); StackHashProductCollection products = errorIndex.LoadProductList(); StackHashFileCollection files = errorIndex.LoadFileList(products[0]); StackHashEventCollection events = errorIndex.LoadEventList(products[0], files[0]); StackHashCabCollection cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashScriptResult script1 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); // Wait for 1 second - so file time granularity exceeded. Thread.Sleep(1000); // Change the version on the autoscript. StackHashScriptSettings settings = scriptManager.LoadScript("AutoScript"); settings.LastModifiedDate = DateTime.Now; scriptManager.AddScript(settings, true, true); // Now run the task again. analyzeTask = new AnalyzeTask(analyzeParams); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted); // Refresh the cab list data. cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; Assert.AreEqual("not available", analysis.SystemUpTime); Assert.AreEqual("0 days 0:00:15.000", analysis.ProcessUpTime); Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion); StackHashScriptResult script2 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); Assert.AreEqual(true, script2.RunDate > script1.RunDate); }
protected override bool InternalExecute(ProcessExecutingContext context) { var script = @" Terrasoft.CustomMessage = function() { var windowCaption = '" + WindowCaption + @"'; var msg = '" + Message + @"'; var radio1Caption = '" + string.Format(CreateSocialAccount, SocialNetwork.ToString()) + @"'; var radio2Caption = '" + DoNotCreateAccount + @"'; var checkboxCaption = '" + DoNotShowMessage + @"'; var controlClientID = '" + ControlClientID + @"'; var createNewSocialAccountEventName = '" + CreateNewSocialAccountEvent + @"'; var discardCreationEventName = '" + DiscardCreationEvent + @"'; var showMessageAgain = true; var createNewAccount = true; var popupWindow = new Terrasoft.Window({ name: 'rrc', caption: windowCaption, resizable: false, width: 480, frame: true, height: 250, modal: true, frameStyle: 'padding: 0 0 0 0', closeAction: 'hide', //fitHeightByContent: true }); function create () { var mainLayout = new Terrasoft.ControlLayout({ id: 'mainLayout', direction: 'vertical', displayStyle: 'controls', width: '100%', layoutConfig: { padding: '5 5 5 5' }, fitHeightByContent: true }); popupWindow.add(mainLayout); addMessage(mainLayout); addRadioButtons(mainLayout); addCheckBox(mainLayout); var l = addButton(popupWindow); } function addMessage(mainLayout){ var layout = insertLayout(mainLayout); layout.add(new Terrasoft.Label( { caption:msg } )); } function addRadioButtons(mainLayout) { var radioLayout = insertLayout(mainLayout); var radio = new Terrasoft.Radio({ caption: radio1Caption, name: 'radio', checked: true }); radio.on('check', function(o,value){ createNewAccount = value; }, this); radioLayout.add(radio); radio = new Terrasoft.Radio({ caption: radio2Caption, name: 'radio' }); radioLayout.add(radio); } function addCheckBox(mainLayout) { var checkBoxLayout = insertLayout(mainLayout); var checkbox = new Terrasoft.CheckBox({ caption: checkboxCaption, name: 'checkbox' }); checkbox.on('check', function(o,value){ showMessageAgain = value; }, this, null); checkBoxLayout.add(checkbox); } function addButton(mainLayout) { var layout = insertLayout(mainLayout); var btn = new Terrasoft.Button({ caption: 'OK' }); // btn.handler = this.onOkButtonClick.createDelegate(this); btn.on('click', onOkButtonClick); layout.setAlign('center') layout.add(btn); // layout.displayStyle = 'footer'; layout.edges = '1 0 0 0'; return layout; } function onOkButtonClick(){ var component = window[controlClientID]; var signalName; if (createNewAccount){ signalName = createNewSocialAccountEventName; } else { signalName = discardCreationEventName; } component.callPageMethod( 'ThrowEvent', { formProxyArg: 'htmlForm', viewStateMode: 'include', signalName: signalName, showMessageAgain: showMessageAgain, createNewAccount: createNewAccount }, null ); popupWindow.close(); } function insertLayout(mainLayout) { var layout = new Terrasoft.ControlLayout({ direction: 'vertical', displayStyle: 'controls', width: '100%', layoutConfig: { //padding: '15 15 15 15' padding: '5 5 5 5' }, fitHeightByContent: true }); mainLayout.add(layout); return layout; } return { show: function() { create(); var mainLayout = popupWindow.items.items[0]; var l = popupWindow.items.items[1]; popupWindow.show(); var height = mainLayout.getHeight() + popupWindow.header.getHeight() + l.getHeight(); popupWindow.suspendEvents(); popupWindow.setHeight(height); popupWindow.resumeEvents(); popupWindow.doLayout(true); } } }(); Ext.onReady(function() { Terrasoft.CustomMessage.show(); }); " ; ScriptManager scriptManager = ((Terrasoft.UI.WebControls.Page)System.Web.HttpContext.Current.CurrentHandler).FindControl("ScriptManager") as ScriptManager; scriptManager.AddScript(script); return(true); }