private void makeAsynchronousRequest(JsString url, TranslationsFileLoaded fileLoaded)
        {
            XMLHttpRequest request = new XMLHttpRequest();

            if (forceReload)
            {
                //just bust the cache for now
                url = url + "?rnd=" + JsMath.random();
            }

            request.open("GET", url, true);
            request.onreadystatechange = delegate(DOMEvent evt) {
                if (request.readyState == 4 && request.status == 200)
                {
                    parseResult(request.responseText);
                    fileLoaded();
                }
                else if (request.readyState >= 3 && request.status == 404)
                {
                    HtmlContext.alert("Required Content " + url + " cannot be loaded.");
                    throw new JsError("Cannot continue, missing required property file " + url);
                }
            };

            request.send("");
        }
Exemple #2
0
        public IActionResult ShowResult(string domain)
        {
            var db    = new HtmlContext();
            var links = new List <HtmlSource>();
            var flag  = false;

            if (domain != null)
            {
                foreach (var html in db.Htmls)
                {
                    var domainHtml = html.url.Split('/');
                    if (html.url.Contains(domain))
                    {
                        links.Add(html);
                    }
                }

                if (links.Count() == 0)
                {
                    links.Add(new HtmlSource());
                }
                else
                {
                    flag = true;
                }
            }
            else
            {
                links = db.Htmls.ToList();
            }

            ViewBag.Links = links.Distinct().ToList();
            ViewBag.Flag  = flag;
            return(View("~/Views/Home/ShowResult.cshtml"));
        }
        public static void RunSample()
        {
            HtmlDocument doc = HtmlContext.document;

            doc.write("Hello World!");
            HtmlContext.alert("Welcome!");
        }
        public TypeDefinition resolveClassName(JsString qualifiedClassName)
        {
            dynamic type = findDefinition(qualifiedClassName);

            if (type == null)
            {
                JsString classDefinition = loader.loadClass(qualifiedClassName);

                //Before we load it into memory, check on the super class and see if we need to load *that*
                //into memory. We may *NOT* have an inherit if we dont inherit from anything, that is just fine
                resolveParentClassFromDefinition(qualifiedClassName, classDefinition);

                //Load the newly found class memory
                addDefinition(classDefinition);

                //Get a reference to the newly added type
                type = findDefinition(qualifiedClassName);

                if (type == null)
                {
                    //This alert shouldnt be here, we should figure out a way to get it to the UI level
                    HtmlContext.alert(qualifiedClassName + " does not contain required injection information ");
                    throw new JsError(qualifiedClassName + " does not contain required injection information ");
                }

                var td = new TypeDefinition(type);
                if (!td.builtIn)
                {
                    //Finally, resolve any classes it references in its own code execution
                    resolveClassDependencies(td);
                }
            }

            return(new TypeDefinition(type));
        }
        private void PopulateSearchByDate(HtmlContext searchPage, FinaliseContext context)
        {
            var searchByDate  = context.MarkupContexts.OrderByDescending(c => c.PostedDate).ToList();
            var currentPeriod = searchByDate[0].PostedDate.ToString("MMMM yyyy");
            var lastPeriod    = currentPeriod;
            var sb            = new StringBuilder($"<h1>{currentPeriod}</h1>");

            foreach (var article in searchByDate)
            {
                Console.WriteLine($"\tInserting search entry for: {article.Title}");
                currentPeriod = article.PostedDate.ToString("MMMM yyyy");

                if (currentPeriod != lastPeriod)
                {
                    lastPeriod = currentPeriod;
                    sb.Append($"<h1>{currentPeriod}</h1>");
                }

                sb.Append(GetSearchCard(
                              article.Image.Url,
                              article.Image.Credit,
                              article.Image.Provider,
                              article.Title,
                              article.Slug,
                              article.GetPostedDateAsString(),
                              article.Html.Url.RelativeUrl
                              ));
            }

            searchPage.Content = searchPage.Content.Replace("$(search-by-post-date)", sb.ToString());
        }
Exemple #6
0
        static void OnReady()
        {
            // setup master volume
            new jQuery("#master").slider(new SliderOptions
            {
                value       = 60,
                orientation = "horizontal",
                range       = "min",
                animate     = true
            });

            // setup graphic EQ
            new jQuery("#eq > span").each((number, e) =>
            {
                // read initial values from markup and remove that
                var value = HtmlContext.parseInt(new jQuery(JsContext.@this).text(), 10);
                new jQuery(JsContext.@this).empty().slider(new SliderOptions
                {
                    value       = value,
                    range       = "min",
                    animate     = true,
                    orientation = "vertical"
                });
            });
        }
Exemple #7
0
        static void OnReady()
        {
            var win  = new jQuery("#window");
            var undo = new jQuery("#undo");

            undo.bind("click", e =>
            {
                win.data("kendoWindow").As <Window>().open();
                undo.hide();
            });

            if (win.data("kendoWindow") == null)
            {
                win.kendoWindow(new WindowConfiguration
                {
                    width   = "500px",
                    actions = new JsArray {
                        "Custom", "Minimize", "Maximize", "Close"
                    },
                    title = "About Josef Hoffmann",
                    close = () => undo.show().As <Window>()
                });
            }
            win.data("kendoWindow").As <Window>().wrapper.find(".k-i-custom").click(e =>
            {
                HtmlContext.alert("Custom action button clicked");
                e.preventDefault();
            });
        }
Exemple #8
0
        //----------------------------------------------------------------------------------------------------
        public static T GetNewGenericArray <T>(T tmpNullObj)
        {
            T rtn = tmpNullObj;

            HtmlContext.eval("rtn = new Array();");
            return(rtn);
        }
Exemple #9
0
 static void OnReady()
 {
     new jQuery("#rerun").button().click(e => HtmlContext.alert("Running the last action"))
     .next().button(new ButtonOptions {
         text = false, icons = new IconOptions {
             primary = "ui-icon-triangle-1-s"
         }
     })
     .click(e => HtmlContext.alert("Could display a menu to select an action")).parent().buttonset();
 }
Exemple #10
0
        //----------------------------------------------------------------------------------------------------
        public static int Len(object arrayObj)
        {
            int len = 0;

            try
            {
                HtmlContext.eval("len = arrayObj.length;");
            }
            catch { }
            return(len);
        }
        private void PopulateSearchByTag(HtmlContext searchPage, FinaliseContext context)
        {
            var searchTable = new StringBuilder();
            var searchList  = new StringBuilder();
            var searchByTag =
                from article in context.MarkupContexts
                from tag in article.Tags
                group article by new { tag.Value, tag.NakedValue } into articleTags
            orderby articleTags.Key.Value
                select new
            {
                Tag           = articleTags.Key.Value,
                TagId         = articleTags.Key.NakedValue,
                Articles      = articleTags.ToList(),
                ArticlesCount = articleTags.Sum(a => 1)
            }
            ;


            searchTable.Append("<div class=\"list-group\" style=\"max-width: 600px;\">");

            // To avoid iterating over the collection twice, we build the search table and the search list together.
            // The search table contains one row per tag and links to the various sections of the search list.
            // The search list appears below the search table and has tag per section.  Each section contains a series
            // of cards linking to the various articles with that tag.  Each article can appear in multiple sections.
            foreach (var tag in searchByTag)
            {
                Console.WriteLine($"\tInserting search entry for tag: {tag.Tag}");

                searchTable.Append(GetSearchTableRow(tag.TagId, tag.Tag, tag.ArticlesCount));

                searchList.Append($"<h3 id=\"{tag.TagId}\"><code>{tag.Tag}</code></h3>");
                foreach (var article in tag.Articles)
                {
                    searchList.Append(GetSearchCard(
                                          article.Image.Url,
                                          article.Image.Credit,
                                          article.Image.Provider,
                                          article.Title,
                                          article.Slug,
                                          article.GetPostedDateAsString(),
                                          article.Html.Url.RelativeUrl
                                          ));
                }
            }

            searchTable.Append("</div><hr>\n");
            searchTable.Append(searchList.ToString());

            searchPage.Content = searchPage.Content.Replace("$(search-by-tag)", searchTable.ToString());
        }
Exemple #12
0
        public static void Main()
        {
            var list = new List <Contact>();

            list.Add(new Contact {
                Name = "Asdas"
            });
            foreach (var item in list)
            {
                HtmlContext.alert(item.Name);
            }
            list.First().CallMe();
            list.First().CallMe("Hello");
        }
Exemple #13
0
        public IActionResult SaveChanges(List <HtmlSource> data, string dataser)
        {
            var links = JsonConvert.DeserializeObject <List <HtmlSource> >(dataser);
            var db    = new HtmlContext();

            foreach (var link in links)
            {
                db.Add(link);
            }
            db.SaveChanges();
            ViewBag.Links = db.Htmls.Distinct().ToList();
            ViewBag.Flag  = true;
            return(View("~/Views/Home/ShowResult.cshtml"));
        }
Exemple #14
0
 public static void OnLoad()
 {
     jQuery.ajax(new AjaxSettings
     {
         url      = "Handler.ashx",
         dataType = "text",
         success  = (js, b, cc) =>
         {
             var func = new JsFunction(js.As <JsString>());
             var x    = func.call();
             var c    = x.As <Contact>();
             HtmlContext.alert(c.GetType().FullName + "," + c.Name);
         }
     });
 }
Exemple #15
0
        public void verifyAndRegister()
        {
            foreach (var id in viableInjectionPoints)
            {
                if (viableInjectionPoints[id].As <JsString>() == "req")
                {
                    dynamic instance       = this;
                    var     typeDefinition = new TypeDefinition(instance.constructor);

                    HtmlContext.alert(typeDefinition.getClassName() + " requires a [View] element with the id of " + id + " but it could not be found");
                    return;
                }
                JsContext.delete(viableInjectionPoints[id]);
            }

            this.viableInjectionPoints = null;
            onRegister();
        }
        private void makeSynchronousRequest(JsString url)
        {
            XMLHttpRequest request = new XMLHttpRequest();

            if (forceReload)
            {
                //just bust the cache for now
                url = url + "?rnd=" + JsMath.random();
            }

            request.open("GET", url, false);
            request.send("");

            if (request.status == 404)
            {
                HtmlContext.alert("Required Content " + url + " cannot be loaded.");
                throw new JsError("Cannot continue, missing required property file " + url);
            }

            parseResult(request.responseText);
        }
        public string loadClass(JsString qualifiedClassName)
        {
            JsRegExp classNameRegex = new JsRegExp("\\.", "g");
            var      potentialURL   = qualifiedClassName.replace(classNameRegex, "/");

            potentialURL  = dynamicClassBaseUrl + potentialURL;
            potentialURL += ".js";

            xmlHttpRequest.open("GET", potentialURL, false);
            xmlHttpRequest.send("");

            //Todo Need to handle other status than just 404
            if (xmlHttpRequest.status == 404)
            {
                //Todo This alert shouldnt be here, we should figure out a way to get it to the UI level
                HtmlContext.alert("Required Class " + qualifiedClassName + " cannot be loaded.");
                throw new JsError("Cannot continue, missing required class " + qualifiedClassName);
            }

            return(xmlHttpRequest.responseText + "\n//@ sourceURL=" + potentialURL);
        }
Exemple #18
0
        static void OnReady2()
        {
            // Include http module,
            var http = require("http");
// And mysql module you've just installed.
            var fs = require("fs").As <SharpKit.NodeJs.fs.Utils>();

// Create the http server.
            http.As <SharpKit.NodeJs.http.Utils>().createServer((request, response) => {
                // Attach listener on end event.
                request.As <EventEmitter>().on("end", () => {
                    // Check if user requests /
                    if (request.As <Request>().url.ExactEquals('/'))
                    {
                        // Read the file.
                        fs.readFile("test.txt", "utf-8", (error, data) => {
                            // Write headers.
                            response.writeHead(200, new {
                                ContentType = "text/plain"
                            });
                            // Increment the number obtained from file.
                            data = (HtmlContext.parseInt(data) + 1).As <JsString>();
                            // Write incremented number to file.
                            fs.writeFile("test.txt", data);
                            // End response with some nice message.
                            response.end("This page was refreshed " + data + " times!");
                        });
                    }
                    else
                    {
                        // Indicate that requested file was not found.
                        response.writeHead(404);
                        // And end request without sending any data.
                        response.end();
                    }
                });
// Listen on the 8080 port.
            }).As <Server>().listen(8080);
        }
Exemple #19
0
 public void CallMe(string s)
 {
     HtmlContext.alert("CallMe2 " + s);
 }
Exemple #20
0
 public void CallMe()
 {
     HtmlContext.alert("CallMe1");
 }
Exemple #21
0
        static void Main()
        {
            var geo = HtmlContext.navigator.geolocation;

            geo.getCurrentPosition(pos => HtmlContext.alert(pos));
        }