public static void InitializeScripts(this AjaxHelper ajaxHelper, string scriptFlavor, bool enableInlining) { if (ajaxHelper == null) { throw new ArgumentNullException("ajaxHelper"); } HttpContextBase httpContext = ajaxHelper.ViewContext.HttpContext; if (httpContext.Items[typeof(ScriptModel)] != null) { throw new InvalidOperationException("You must call InitializeScripts only once."); } ScriptSharpSection configSection = ScriptSharpSection.GetSettings(); ScriptElement coreScriptElement = configSection.Scripts.GetElement(LoaderScriptName, scriptFlavor); ScriptInliner scriptInliner = null; if (enableInlining) { string storageCookieName = configSection.ClientScriptStorageCookie; if (String.IsNullOrEmpty(storageCookieName) == false) { scriptInliner = new ScriptInliner(httpContext, storageCookieName); } } ScriptModel scriptModel = new ScriptModel(coreScriptElement.Url, scriptFlavor, scriptInliner); httpContext.Items[typeof(ScriptModel)] = scriptModel; }
/// <summary> /// /// </summary> /// <param name="id_"></param> public void OpenScriptElement(ScriptElement el_) { var list = dockingManager1.Layout.Descendents().OfType <LayoutDocument>(); foreach (LayoutDocument ld in list) { if (ld.Content is ScriptElementControl) { ScriptElementControl s = ld.Content as ScriptElementControl; if (s.Script.ID == el_.ID) { ld.IsSelected = true; return; } } } var firstDocumentPane = dockingManager1.Layout.Descendents().OfType <LayoutDocumentPane>().FirstOrDefault(); if (firstDocumentPane != null) { LayoutDocument doc = new LayoutDocument(); doc.Title = el_.Name; doc.Content = new ScriptElementControl(el_); firstDocumentPane.Children.Add(doc); doc.IsSelected = true; } }
protected string GetCombinedScriptsSource() { List <string> scriptPaths = GetScriptPaths(); StringBuilder objStrBuilder = new StringBuilder(); objStrBuilder.Append(_handlerPath); foreach (string sPath in scriptPaths) { ScriptElement element = null; string fullElementPath = ResolveUrl(sPath); if (!fullElementPath.Contains(HttpRuntime.AppDomainAppVirtualPath)) { //make sure to get full path with application root fullElementPath = HttpRuntime.AppDomainAppVirtualPath + fullElementPath; } element = OptimizerConfig.GetScriptByPath(fullElementPath); if (element != null) { objStrBuilder.Append(element.Key + "."); } } string strPath = objStrBuilder.ToString(); if (strPath.EndsWith(".")) { //remove last unnecessary "." strPath = strPath.Substring(0, strPath.LastIndexOf(".")); } return(strPath); }
public static void AddScriptReference(this AjaxHelper ajaxHelper, string scriptName, ScriptMode scriptMode) { ScriptModel scriptModel = GetScriptModel(ajaxHelper); if (String.IsNullOrEmpty(scriptName)) { throw new ArgumentNullException("scriptName"); } ScriptSharpSection configSection = ScriptSharpSection.GetSettings(); ScriptElement scriptElement = configSection.Scripts.GetElement(scriptName, scriptModel.ScriptFlavor); string actualFlavor = String.Empty; int flavorIndex = scriptElement.Name.IndexOf('.'); if (flavorIndex > 0) { actualFlavor = scriptElement.Name.Substring(flavorIndex + 1); } ScriptReference scriptReference = new ScriptReference(scriptName, scriptElement.Url, scriptMode, scriptElement.GetDependencyList(), scriptElement.Version + actualFlavor); scriptModel.AddScriptReference(scriptReference); }
private void pbSave_Click(object sender, EventArgs e) { Dictionary <ScriptElementType, string> elementValueDict = new Dictionary <ScriptElementType, string>() { { ScriptElementType.XPath, _xPath }, { ScriptElementType.Name, _name }, { ScriptElementType.ID, _id }, { ScriptElementType.TagName, _tagName }, { ScriptElementType.ClassName, _className }, { ScriptElementType.LinkText, _linkText }, { ScriptElementType.CSSSelector, _cssSelector } }; frmAddElement addElementForm = new frmAddElement(); addElementForm.ScriptElements = ScriptElements; addElementForm.ElementValueDict = elementValueDict; addElementForm.ShowDialog(); if (addElementForm.DialogResult == DialogResult.OK) { ScriptElement newElement = new ScriptElement() { ElementName = addElementForm.txtElementName.Text, ElementType = (ScriptElementType)Enum.Parse(typeof(ScriptElementType), addElementForm.cbxElementType.SelectedItem.ToString().Replace(" ", "")), ElementValue = addElementForm.txtDefaultValue.Text }; ScriptElements.Add(newElement); } }
public FrmCustomUpdateCreator() { InitializeComponent(); customUpdateElementViewer1.ElementDoubleClick += new CustomUpdateElementViewer.CustomUpdateElementViewer.ElementDoubleClickEventHandler(addElement); ExecutableElement executableElement = new ExecutableElement(); customUpdateElementViewer1.AddElement(executableElement); ScriptElement scriptElement = new ScriptElement(); customUpdateElementViewer1.AddElement(scriptElement); TextFileElement textFileElement = new TextFileElement(); customUpdateElementViewer1.AddElement(textFileElement); FileElement fileElement = new FileElement(); customUpdateElementViewer1.AddElement(fileElement); FolderElement folderElement = new FolderElement(); customUpdateElementViewer1.AddElement(folderElement); ServiceElement serviceElement = new ServiceElement(); customUpdateElementViewer1.AddElement(serviceElement); RegistryKeyElement RegKeyElement = new RegistryKeyElement(); customUpdateElementViewer1.AddElement(RegKeyElement); RegistryElement RegElement = new RegistryElement(); customUpdateElementViewer1.AddElement(RegElement); VariableElement variableElement = new VariableElement(); customUpdateElementViewer1.AddElement(variableElement); PowerManagementElement powerElement = new PowerManagementElement(); customUpdateElementViewer1.AddElement(powerElement); WaitElement waitElement = new WaitElement(); customUpdateElementViewer1.AddElement(waitElement); KillProcessElement killElement = new KillProcessElement(); customUpdateElementViewer1.AddElement(killElement); ReturnCodeElement returnCodeElement = new ReturnCodeElement(); customUpdateElementViewer1.AddElement(returnCodeElement); lnkLblHelp.Enabled = System.IO.File.Exists("Custom Updates.pdf"); }
private void pbSave_Click(object sender, EventArgs e) { if (SearchParameters == null) { return; } frmAddElement addElementForm = new frmAddElement("", SearchParameters); addElementForm.ScriptContext = (ScriptContext)ScriptContext; addElementForm.ShowDialog(); if (addElementForm.DialogResult == DialogResult.OK) { ScriptElement newElement = new ScriptElement() { ElementName = addElementForm.txtElementName.Text.Replace("<", "").Replace(">", ""), ElementValue = addElementForm.ElementValueDT }; ScriptContext.Elements.Add(newElement); } addElementForm.Dispose(); }
/// <summary> /// /// </summary> /// <returns></returns> private void SetScriptElement(ScriptElement el_) { m_ScriptElement = el_; m_ScriptElement.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnFuntionPropertyChanged); m_ScriptElement.FunctionSlotChanged += new EventHandler <FunctionSlotChangedEventArg>(OnFunctionSlotChanged); UpdateNodeSlot(); }
private static void Search(string url, Action <IEnumerable <PhotoResult> > searchCallback) { Action <SearchResponse> jsonCallback = delegate(SearchResponse response) { List <PhotoResult> photos = response.PhotoResponse.PhotoList; photos.ForEach(delegate(PhotoResult photo) { string[] tagsArray = photo.tags.Split(' '); if (tagsArray.Length > 10) { tagsArray = (string[])tagsArray.GetRange(0, 10); } photo.tags = tagsArray.Join(","); photo.Url_p = "http://flic.kr/p/" + Base58.Encode(photo.ID); }); searchCallback(photos); }; Export jsonpCallback = Delegate.Export(jsonCallback); string scriptSource = url + "&jsoncallback=" + jsonpCallback.Name; ScriptElement scriptElement = Document.CreateElement("script").As <ScriptElement>(); scriptElement.Type = "text/javascript"; scriptElement.Src = scriptSource; Document.GetElementsByTagName("head")[0].AppendChild(scriptElement); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listBoxGraphScripts_PreviewMouseMove(object sender, MouseEventArgs e) { if (m_IsDragAndDrop == true) { // Get the current mouse position Point mousePos = e.GetPosition(null); Vector diff = m_DragStartPoint - mousePos; if (e.LeftButton == MouseButtonState.Pressed && sender is ListBox && e.OriginalSource is DependencyObject && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { ListBox listBox = sender as ListBox; ListBoxItem listBoxItem = Helper.FindAnchestor <ListBoxItem>((DependencyObject)e.OriginalSource); if (listBoxItem != null) { ScriptElement var = (ScriptElement)listBox.ItemContainerGenerator. ItemFromContainer(listBoxItem); if (var != null) { DataObject dragData = new DataObject(DataFormats.Text, DragPrefixScriptElement + var.ID); DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move); } } } } }
/// <summary> /// Adds a script element to the collection. This member supports the NetRix infrastructure and is used to /// support the <see cref="System.Windows.Forms.PropertyGrid"/>. /// </summary> /// <param name="o"></param> public new void Add(ScriptElement o) { base.InnerList.Add(o); if (OnInsertHandler != null) { OnInsertHandler(base.InnerList.Count, o); } }
private ScriptElement FindScript(string scriptName, string filename, XElement xml) { var script = DbSafeManagerHelper.FindChild(xml, FileDefinitionHelper.ElementNameSripts, scriptName); if (script != null) { return(ScriptElement.Load(script, filename)); } return(null); }
public IDbSafeManager ExecuteScripts(params string[] scriptNames) { ValidateDependencies(); foreach (var scriptName in scriptNames) { ScriptElement scriptElement = FindScript(scriptName); DatabaseClient.ExecuteCommand(scriptElement.Value); } return(this); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonAddOutput_Click(object sender, RoutedEventArgs e) { if (DataContext is SequenceFunction) { SequenceFunction func = DataContext as SequenceFunction; func.AddOutput("output"); } else if (DataContext is ScriptElement) { ScriptElement el = DataContext as ScriptElement; el.AddOutput("output"); } }
public void SearchPhotos(string tags, int count, FlickrSearchCallback callback) { FlickrCallback requestCallback = delegate(PhotoSearchResponse response) { callback(response.photos.photo); }; string callbackName = Delegate.CreateExport(requestCallback); string url = String.Format(FlickrSearchURLFormat, tags.EncodeUriComponent(), count, callbackName); ScriptElement script = (ScriptElement)Document.CreateElement("script"); script.Type = "text/javascript"; script.Src = url; Document.GetElementsByTagName("head")[0].AppendChild(script); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteScript_Executed(object sender, ExecutedRoutedEventArgs e) { if (listBoxGraphScripts.SelectedItem != null && listBoxGraphScripts.SelectedItem is ScriptElement) { ScriptElement el = listBoxGraphScripts.SelectedItem as ScriptElement; if (MessageBox.Show( "Do you really want to delete the named variable " + el.Name + " ?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { GraphDataManager.Instance.RemoveScript(el); } } }
/// <summary> /// /// </summary> /// <param name="vm_"></param> public NewScriptWindow(ScriptElement var_ = null) { InitializeComponent(); if (var_ == null) { Title = "New script"; } else { InputName = var_.Name; } Closing += new CancelEventHandler(OnClosing); }
public static string GetKey(ScriptRequest request) { return(Elements.GetOrAdd(request, r => { var elem = new ScriptElement { Request = r, Content = null, Key = StringHashEncoder.Codify(request.ToString()) }; return ElementsByKey.GetOrAdd(elem.Key, elem); } ).Key); }
/** * Decompiles a binary script from a stream. */ public YukaScript FromBinary(Stream s) { BinaryReader br = new BinaryReader(s); // read header s.Seek(0x10, SeekOrigin.Begin); codeoffset = br.ReadInt32(); codecount = br.ReadInt32(); indexoffset = br.ReadInt32(); indexcount = br.ReadInt32(); dataoffset = br.ReadInt32(); datalength = br.ReadInt32(); // seek to the start of the code block s.Seek(codeoffset, SeekOrigin.Begin); // as long as we have not reached the end of the code block while (s.Position < codeoffset + codecount * 4) { // try to read the next script element. ScriptElement elem = NextScriptElement(s); // if you found one, then... if (elem != null) { // ...add it to the list of commands. commands.Add(elem); // some logging logic. if (FlagCollection.current.Has('v')) { string output = elem.ToString(); if (output.StartsWith("yuka.Script")) { Console.ForegroundColor = ConsoleColor.Cyan; } Console.WriteLine(output); Console.ResetColor(); } } else { } } // create new script instance from list of commands and attached string data and return it return(new YukaScript(commands, stringTable)); }
public void AssertDatasetVsScript(string expectedDatasetName, string actualScriptName, bool sorted, string key, params string[] otherKeys) { ValidateDependencies(); DatasetElement expectedData = FindDataset(expectedDatasetName); ScriptElement actualDataScript = FindScript(actualScriptName); DatasetElement actualData = DatabaseClient.ReadTable(actualDataScript.Value, _formatterManager); string[] keys = new string[] { key }; if (otherKeys != null) { keys = keys.Union(otherKeys).ToArray(); } DbSafeManagerHelper.CompareDatasets(expectedData, actualData, keys, sorted, false); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenameScript_Executed(object sender, ExecutedRoutedEventArgs e) { if (listBoxGraphScripts.SelectedItem != null && listBoxGraphScripts.SelectedItem is ScriptElement) { ScriptElement el = listBoxGraphScripts.SelectedItem as ScriptElement; NewScriptWindow win = new NewScriptWindow(el); //win.IsValidInputNameCallback = GraphDataManager.Instance.IsValidName; win.Owner = MainWindow.Instance; if (win.ShowDialog() == false) { return; } el.Name = win.InputName; } }
private void pbSave_Click(object sender, EventArgs e) { frmAddElement addElementForm = new frmAddElement("", SearchParameters); addElementForm.ScriptElements = ScriptElements; addElementForm.ShowDialog(); if (addElementForm.DialogResult == DialogResult.OK) { ScriptElement newElement = new ScriptElement() { ElementName = addElementForm.txtElementName.Text.Replace("<", "").Replace(">", ""), ElementValue = addElementForm.ElementValueDT }; ScriptElements.Add(newElement); } }
private void tvScriptElements_KeyDown(object sender, KeyEventArgs e) { //handling outside if (tvScriptElements.SelectedNode == null) { return; } //if parent was selected return if (tvScriptElements.SelectedNode.Parent == null) { //user selected top parent return; } //top node check var topNode = GetSelectedTopNode(); if (topNode.Text != "My Task Elements") { return; } //if user selected delete if (e.KeyCode == Keys.Delete) { //determine which node is the parent TreeNode parentNode; if (tvScriptElements.SelectedNode.Nodes.Count == 0) { parentNode = tvScriptElements.SelectedNode.Parent; } else { parentNode = tvScriptElements.SelectedNode; } //remove parent node string elementName = parentNode.Text; ScriptElement element = ScriptElements.Where(x => x.ElementName == elementName).FirstOrDefault(); ScriptElements.Remove(element); parentNode.Remove(); } }
/// <summary> /// /// </summary> public ScriptElementControl(ScriptElement el_) { DataContext = el_; InitializeComponent(); Script = el_; textEditor.Text = Script.ScriptSourceCode; SetFoldingStrategy(); textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering; textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered; DispatcherTimer foldingUpdateTimer = new DispatcherTimer(); foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2); foldingUpdateTimer.Tick += foldingUpdateTimer_Tick; foldingUpdateTimer.Start(); textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add( new SearchInputHandler(textEditor.TextArea)); }
public void CanDispatchItems() { var html = new HtmlElement(new MetaElement(new XAttribute("x", "y")), "text", new XElement("div", "a"), new XElement("HeAd", new StyleElement(".c{}")), new XAttribute("zzz", "val"), ScriptElement.RequireJs()); var res = html.ToDocument().ToString().Simplify(SimplifyOptions.SingleQuotes); Console.WriteLine(res); Assert.AreEqual(@"<!DOCTYPE html > <html zzz='val'> <head> <meta charset='utf-8' /> <meta x='y' /> <style type='text/css'>.c{}</style> <script type='text/javascript' data-main='scripts/main.js' src='scripts/require.js'></script> </head> <body>text<div>a</div></body> </html>", res); }
private ScriptElement ReadScriptElement() { var element = new ScriptElement(); element.Id = reader.ReadInt32(); Assert(reader.ReadByte() == 3); short index = reader.ReadInt16(); ReadNullBytes(1); element.Name = Strings[index]; Write(element.Name); int parameters = reader.ReadInt32(); indention++; for (int i = 0; i < parameters; i++) { element.Parameters.Add(ReadParameter()); } indention--; return(element); }
private void WriteScriptElement(ScriptElement scriptElement, int index, short magic) { var header = new Header() { Index = index, Magic = magic, Length = scriptElement.GetSize(false) }; WriteHeader(header); writer.Write(scriptElement.Id); writer.Write((byte)3); writer.Write((short)GetIndex(scriptElement.Name)); WriteNullBytes(1); writer.Write(scriptElement.Parameters.Count); foreach (var parameter in scriptElement.Parameters) { WriteParameter(parameter); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteSlot_Click(object sender, MouseButtonEventArgs e) { if (sender is Image) { Image img = sender as Image; if (img.Tag is int) { int id = (int)img.Tag; if (DataContext is SequenceFunction) { SequenceFunction func = DataContext as SequenceFunction; func.RemoveSlotById(id); } else if (DataContext is ScriptElement) { ScriptElement el = DataContext as ScriptElement; el.RemoveSlotById(id); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DropList_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { try { string data = e.Data.GetData(DataFormats.StringFormat) as string; if (data.StartsWith(FlowGraphDataControl.DragPrefixFunction) == true) { string id = data.Split('#')[1]; SequenceFunction func = GraphDataManager.Instance.GetFunctionByID(int.Parse(id)); CallFunctionNode seqNode = new CallFunctionNode(func); ViewModel.CreateNode(seqNode, e.GetPosition(networkControl), false); } else if (data.StartsWith(FlowGraphDataControl.DragPrefixNamedVar) == true) { string name = data.Split('#')[1]; NamedVariableNode seqNode = new NamedVariableNode(name); ViewModel.CreateNode(seqNode, e.GetPosition(networkControl), false); } else if (data.StartsWith(FlowGraphDataControl.DragPrefixScriptElement) == true) { string idStr = data.Split('#')[1]; int id = int.Parse(idStr); ScriptElement el = GraphDataManager.Instance.GetScriptByID(id); ScriptNode seqNode = new ScriptNode(el); ViewModel.CreateNode(seqNode, e.GetPosition(networkControl), false); } } catch (System.Exception ex) { LogManager.Instance.WriteException(ex); } } }
/// <summary> /// Copies the properties of another element. /// </summary> /// <param name="element">The element to copy</param> internal void CopyLocation(ScriptElement element) { Start = element.Start; End = element.End; }
/// <summary> /// /// </summary> /// <param name="id_"></param> public void OpenScriptElement(ScriptElement el_) { var list = dockingManager1.Layout.Descendents().OfType<LayoutDocument>(); foreach (LayoutDocument ld in list) { if (ld.Content is ScriptElementControl) { ScriptElementControl s = ld.Content as ScriptElementControl; if (s.Script.ID == el_.ID) { ld.IsSelected = true; return; } } } var firstDocumentPane = dockingManager1.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault(); if (firstDocumentPane != null) { LayoutDocument doc = new LayoutDocument(); doc.Title = el_.Name; doc.Content = new ScriptElementControl(el_); firstDocumentPane.Children.Add(doc); doc.IsSelected = true; } }
public void Add(ScriptElement script) { BaseAdd(script); }
public void Remove(ScriptElement script) { BaseRemove(GetElementKey(script)); }
private int m_ScriptElementID = -1; // used when the node is loaded, in order to retrieve the ScriptElement #endregion Fields #region Constructors /// <summary> /// /// </summary> /// <param name="el_"></param> public ScriptNode(ScriptElement el_) : base() { SetScriptElement(el_); }
/// <summary> /// /// </summary> /// <returns></returns> private void SetScriptElement(ScriptElement el_) { m_ScriptElement = el_; m_ScriptElement.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnFuntionPropertyChanged); m_ScriptElement.FunctionSlotChanged += new EventHandler<FunctionSlotChangedEventArg>(OnFunctionSlotChanged); UpdateNodeSlot(); }