public void TestNested() { var code = @"IterateRooms() { const runtime = this._runtime; const eventSheetManager = runtime.GetEventSheetManager(); const currentEvent = runtime.GetCurrentEvent(); const solModifiers = currentEvent.GetSolModifiers(); const eventStack = runtime.GetEventStack(); const oldFrame = eventStack.GetCurrentStackFrame(); const newFrame = eventStack.Push(currentEvent); var index = 0; for (const room of this.rooms) { this.curRoomIndex = index; //console.log(this.curRoomIndex); this.curRoom = room; //console.log(this.curRoom); eventSheetManager.PushCopySol(solModifiers); currentEvent.Retrigger(oldFrame, newFrame); eventSheetManager.PopSol(solModifiers); index++; } eventStack.Pop(); return false; },"; var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 1); }
public void TestCompleteFile() { var code = System.IO.File.ReadAllText("TestFiles\\rotjs_conditions.js"); var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 26); }
public void TestActionParseDuplicateFunction() { var code = @"C3.Plugins.aaXe_Log.Acts = { writeLog (log, type) /* test */ { if (!this._loggingActive) return; console.log("" % c"" + this.iconTypes[type] + "" "" + log, this.logTypes[type]); }, writeLog (log, type) /* test */ { if (!this._loggingActive) return; console.log("" % c"" + this.iconTypes[type] + "" "" + log, this.logTypes[type]); }, };"; var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 2); Assert.IsNotNull(funcs["writeLog"]); Assert.IsNotNull(funcs["writeLog@"]); }
public void TestActionParseAsyncFunction() { var code = @"C3.Plugins.aaXe_Log.Acts = { async writeLog (log, type) /* test */ { if (!this._loggingActive) return; console.log("" % c"" + this.iconTypes[type] + "" "" + log, this.logTypes[type]); } };"; var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 1); Assert.AreEqual(funcs.FirstOrDefault().Key, "writeLog"); }
public void QuickFunctionTest() { var code = @"""use strict""; { C3.Plugins.aaXe_RotJs.Cnds = { //triggers MapGenerated() { return true; }, ArenaGenerated() { return true; }, MazeGenerated() { return true; } } }"; var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 3); }
public void TestActionParseHappyPathComplex() { var code = @"C3.Plugins.aaXe_Log.Acts = { GenerateArenaToTileMap(width, height, tm) { this._clearRooms(); this.width = width; this.height = height; var instance = tm.GetInstances()[0].GetSdkInstance(); this.gen = new ROT.Map.Arena(width, height); this.map = {}; this.gen.create((x, y, value) => { var key = x + "","" + y; this.map[key] = { x: x, y: y, value: value, type: value === 1 ? 'wall' : 'floor' }; //populate tilemap value? instance.SetTileAt(x, y, this._getWallTile()) : instance.SetTileAt(x, y, this._getFloorTile()); }); this.Trigger(C3.Plugins.aaXe_RotJs.Cnds.MapGenerated); this.Trigger(C3.Plugins.aaXe_RotJs.Cnds.ArenaGenerated); } };"; var funcs = JavascriptManager.GetAllFunction(code); Assert.AreEqual(funcs.Count, 1); Assert.AreEqual(funcs.FirstOrDefault().Key, "GenerateArenaToTileMap"); }
public List<String> Import(ImportSiteMessage message) { Data.Hash importHash = Data.Hash.New(message.ImportHash); Data.Guid subscriptionId = Data.Guid.New(message.SubscriptionId); Boolean deleteExisting = message.DeleteExisting; List<String> status = new List<String>(); byte[] data; AddStatus(importHash, status, "Site import started at " + UtcDateTime.Now.ToString()); CmsSubscription subscription = SubscriptionManager.GetSubscription(subscriptionId); CmsTheme defaultTheme = ThemeManager.Instance.GetDefaultBySite(subscriptionId); //Check if the import-template already exists CmsTemplate template = TemplateManager.Instance.GetTemplate(subscriptionId, "import-template"); if (template == null) { template = new CmsTemplate(); template.Content = "{content}"; template.Name = "import-template"; template.IsGlobalTemplateType = false; template.LastSaved = UtcDateTime.Now; template.SubscriptionGuid = subscriptionId.Value; template.Theme = defaultTheme; TemplateManager.Instance.Save(template); AddStatus(importHash, status, "Successfully created and associated import template to deafult theme"); } IDictionary<ImportType, IList<ImportedItem>> items = this.GetImportedItems(importHash); //Check if we need to delete the existing site if (deleteExisting) { //Erase all of the existing data SubscriptionManager.Erase(subscription.Guid, false, false); SessionProvider.Instance.Close(); SessionProvider.Instance.GetOpenSession(); //Setup the default SiteHelper.Configure(subscription.Guid); } //First, import all of the images IList<ImportedItem> images = items[ImportType.Image]; foreach (ImportedItem image in images) { CmsUrl uri = new CmsUrl(image.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); ImageManager.Instance.AddImage(subscriptionId, StorageClientConst.RootFolder, uri.Path, image.ContentType, data); AddStatus(importHash, status, "Successfully imported image: " + uri.ToString() + " (" + image.ContentType + ")"); } //Create the sitemap and then add the page itself CmsSitePath root = CmsSiteMap.Instance.GetPath(subscriptionId, CmsSiteMap.RootPath); Dictionary<CmsUrl, int> cssUses = new Dictionary<CmsUrl, int>(); Dictionary<CmsUrl, int> jsUses = new Dictionary<CmsUrl, int>(); IList<ImportedItem> pages = NormalizeImport(items[ImportType.Page]); foreach (ImportedItem page in pages) { try { CmsUrl uri = new CmsUrl(page.Uri); CmsUrlWalker walker = new CmsUrlWalker(uri); while (walker.Next()) { String parent = walker.GetParentPath(); String current = walker.GetIndividualPath(); String fullpath = CmsSiteMap.PathCombine(parent, current); int depth = walker.Depth; if (!walker.IsLast) { //Check if the current path exists, if not, create it if (!CmsSiteMap.Instance.Exists(subscriptionId, fullpath)) CmsSiteMap.Instance.AddChildDirectory(subscriptionId, parent, current); } } String pageName = walker.GetIndividualPath(); CmsPage newpage = GetPage(template.Name, subscription.Culture, pageName, message.ReplacePhoneNumbers, page, cssUses, jsUses); newpage.SubscriptionId = subscriptionId.Value; //Add the page to the cms system PageManager.Instance.AddNewPage(walker.GetParentPath(), pageName, newpage); AddStatus(importHash, status, "Successfully imported page " + page.Uri); } catch (Exception ex) { if (!ex.Message.Contains("404")) Logging.Database.Write("import-site-manager", "Failed to import page: " + page.Uri + ", cause:" + ex.Message + ", stack:" + ex.StackTrace); AddStatus(importHash, status, "Failed to import page " + page.Uri + ", Reason:" + ex.Message); } } //Import the css IList<ImportedItem> css = items[ImportType.Css]; int sortOrder = 0; CssManager cssManager = new CssManager(null); cssManager.SubscriptionId = subscriptionId; foreach (ImportedItem item in css) { CmsUrl uri = new CmsUrl(item.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); cssManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0); cssManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++); AddStatus(importHash, status, "Successfully imported css file: " + uri.ToString()); } //Import the javascript IList<ImportedItem> js = items[ImportType.Javascript]; sortOrder = 0; JavascriptManager jsManager = new JavascriptManager(null); jsManager.SubscriptionId = subscriptionId; foreach (ImportedItem item in js) { CmsUrl uri = new CmsUrl(item.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); jsManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0); jsManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++); AddStatus(importHash, status, "Successfully imported javascript file: " + uri.ToString()); } //Import any documents IList<ImportedItem> documents = items[ImportType.Document]; foreach (ImportedItem item in documents) { CmsUrl uri = new CmsUrl(item.Uri); ContentFileUploadImpl handler = new ContentFileUploadImpl(); String filename = uri.Path; if (ContentFileUploadImpl.IsValidFileType(filename)) { data = SimpleWebClient.GetResponse(uri.ToUri()); handler.Save(subscriptionId, data, uri.Path, true); } } AddStatus(importHash, status, "Site import completed successfully at " + UtcDateTime.Now.ToString()); ImportedItemDao dao = new ImportedItemDao(); dao.DeleteAllByImportHash(importHash); return status; }
public MainWindow() { InitializeComponent(); jsmanager = new JavascriptManager(uiWebView); }