コード例 #1
0
        public static void DelegatesTests()
        {
            Transformer t      = Square; // Create delegate instance
            Transformer t2     = new Transformer(Square);
            int         result = t(3);   // Invoke delegate

            result = t2.Invoke(3);       // Invoke delegate

            int[] values = { 1, 2, 3 };
            Transform(values, Square);
            Transform2(values, Square);
            Transformer <double> s = Square;

            Console.WriteLine(s(3.3));

            D1 d1 = Method1;
            //D2 d2 = d1         // Compile-time error
            D2 d2 = new D2(d1);

            ObjectRetriever o       = new ObjectRetriever(GetString);
            object          result2 = o();

            Console.WriteLine(result2);

            StringAction sa = new StringAction(ActOnObject);

            sa("hello");

            Func <string> x = GetString;
            Func <object> y = x;

            Console.WriteLine(y);
            Action <object> x1 = ActOnObject;
            Action <string> y2 = x1;
        }
コード例 #2
0
 public void Show(StringAction whenDone)
 {
     doneBtn.interactable = false;
     input.text           = "";
     callback             = whenDone;
     homeCtrl.BringInView(this.transform);
 }
コード例 #3
0
        //Step 1 - skapa en metod som tar lång tid att köra (för demonstration)
        string DoTimeConsumingWork(string s, StringAction stringAction)
        {
            Console.WriteLine($"DoTimeConsumingWork Thread ID: {Thread.CurrentThread.ManagedThreadId}");
            int sleepTime = new Random().Next(5000, 10001);

            Thread.Sleep(sleepTime);

            string stringValue = string.Empty; //ett plattformsoberoende sätt att skriva  "" (en tom sträng alltså)

            switch (stringAction)
            {
            case StringAction.UpperCase:
                stringValue = s.ToUpper();
                break;

            case StringAction.LowerCase:
                stringValue = s.ToLower();
                break;

            case StringAction.Backward:
                stringValue = new string(s.Reverse().ToArray());
                break;
            }

            return(stringValue);
        }
コード例 #4
0
        public static string Method1(
            StringAction Handler1 = null,
            StringAction Handler2 = null,
            string P1 = "P1",
            string P2 = "p2"
        )
        {
            Console.WriteLine("Method1 0");

            if (Handler1 != null)
            {
                Console.WriteLine("Handler1 is not null - " + P1);

                Handler1("A " + P1);
            }
            else
                Console.WriteLine("Handler1 is null - " + P1);

            Console.WriteLine("Method1 1");

            if (Handler2 != null)
            {
                Console.WriteLine("Handler2 is not null - " + P2);

                Handler2("B" + P2);
            }
            else
                Console.WriteLine("Handler2 is null - " + P2);

            Console.WriteLine("Method1 2");

            return "!";
        }
コード例 #5
0
    static void Main()
    {
        Child        c      = new Child();
        StringAction action = new StringAction(c.Foo);

        action("x");
    }
コード例 #6
0
        private static void WriteDiagnosticsResults(StringAction Write, InternalWebMethodInfo WebMethod)
        {
            Write("<blockquote>");
            if (WebMethod.Results == null)
            {
                Write("<h2>No results from " + WebMethod.MethodName + "</h2>");
            }
            else
            {
                Write("<h2>" + WebMethod.Results.Length + " results from " + WebMethod.MethodName + "</h2>");
                Write("<blockquote>");

                foreach (var item in WebMethod.Results)
                {
                    WriteWebMethod(Write, item,
                                   Parameter =>
                    {
                        if (Parameter == null)
                        {
                            return;
                        }

                        Write(" = '<code style='color: red'>" + escapeXML(Parameter.Value) + "</code>'");
                    }
                                   );
                }
                Write("</blockquote>");
                Write("<br />");
            }
            Write("</blockquote>");
        }
コード例 #7
0
    public void Show(UnityAction onNewLayoutSelected, StringAction onEditLayoutSelected, StringAction onLoadLayoutSelected)
    {
        gameObject.SetActive(true);
        this.onNewLayoutSelected  = onNewLayoutSelected;
        this.onEditLayoutSelected = onEditLayoutSelected;
        this.onLoadLayoutSelected = onLoadLayoutSelected;

        DirectoryInfo dataDir = new DirectoryInfo(Path.Combine(Application.persistentDataPath, "Layouts"));

        layoutFileNames = new List <string>();
        List <string> layoutFileNamesWithoutExtension = new List <string>();

        if (dataDir.Exists)
        {
            FileInfo[] fileinfos = dataDir.GetFiles();
            for (int i = 0; i < fileinfos.Length; i++)
            {
                layoutFileNames.Add(fileinfos[i].Name);
                string name = Path.GetFileNameWithoutExtension(fileinfos[i].Name);
                layoutFileNamesWithoutExtension.Add(name);
            }
        }
        if (layoutFileNames.Count == 0)
        {
            dropDown.interactable = false;
        }
        else
        {
            dropDown.interactable = true;
            dropDown.ClearOptions();
            dropDown.AddOptions(layoutFileNamesWithoutExtension);
        }
    }
コード例 #8
0
        public static void WriteWebMethodForm(StringAction Write, InternalWebMethodInfo WebMethod)
        {
            Write("<form target='_blank' action='" + WebMethod.ToQueryString() + "' method='POST'>");
            WriteWebMethod(Write, WebMethod,
                           Parameter =>
            {
                if (Parameter == null)
                {
                    Write("<input type='submit' value='Invoke'  />");

                    return;
                }

                var key = "_" + WebMethod.MetadataToken + "_" + Parameter.Name;

                // C# named parameters style
                Write(": ");

                var value = "";

                Parameter.Value.With(x => value = x.Replace("'", "&apos;"));


                Write("<input type='text'  name='" + key + "' value='" + value + "' />");
            }
                           );
            Write("</form>");
        }
コード例 #9
0
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript</param>
        /// <param name="y">A callback to javascript</param>
        public void WebMethod2(string e, StringAction y)
        {
            // Send it to the caller.
            y(e + GetArray()[0]);

            // this call will be omitted for non PHP platforms
            PHP.Invoke(PHPImplementation.Method1);
        }
コード例 #10
0
 /// <summary>
 /// This Method is a javascript callable method.
 /// </summary>
 /// <param name="e">A parameter from javascript. JSC supports string data type for all platforms.</param>
 /// <param name="y">A callback to javascript. In the future all platforms will allow Action&lt;XElementConvertable&gt; delegates.</param>
 public void WebMethod2(string e, StringAction y)
 {
     foreach (var item in MemoryDatabase.CallToActionContent)
     {
         // Send it back to the caller.
         y(item);
     }
 }
コード例 #11
0
    public static void CLRMain(
         StringAction ListMethods = null
        )
    {
        System.Console.WriteLine(XML);

        MessageBox.Show("it works?!?");
    }
コード例 #12
0
        public static void CLRMain(
            StringAction ListMethods = null
            )
        {
            System.Console.WriteLine(XML);

            MessageBox.Show("it works?!?");
        }
コード例 #13
0
        private void MenuItemRemove_Click(object sender, RoutedEventArgs e)
        {
            StringAction selected = actionsListBox.SelectedItem as StringAction;

            actionSource.Remove(selected);
            actionsListBox.Items.Refresh();
            getPreviewFiles();
            getPreviewFolders();
        }
コード例 #14
0
 //Step 2, skapa en likadan metod men som är async (och heter async pga best practise)
 Task <string> DoTimeConsumingWorkAsync(string s, StringAction stringAction)
 {
     Console.WriteLine($"DoTimeConsumingWorkAsync Thread ID: {Thread.CurrentThread.ManagedThreadId}");
     //lambda anropar metoden dotimeconsumingwork
     return(Task.Run(() =>
     {
         return DoTimeConsumingWork(s, stringAction);
     }));
 }
コード例 #15
0
        public static void CLRMain(
             StringAction yield = null
            )
        {
            System.Console.WriteLine(XML);

            MessageBox.Show("CLR breakpoint");

            yield("hi from CLR");
        }
コード例 #16
0
 public static Storage Of(string Target, StorageTargetExists Exists, StringAction Delete, StorageTargetReader Reader, StorageTargetWriter Writer)
 {
     return(new Storage
     {
         Delete = () => Delete(Target),
         Exists = () => Exists(Target),
         Reader = () => Reader(Target),
         Writer = bytes => Writer(Target, bytes)
     });
 }
コード例 #17
0
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript. JSC supports string data type for all platforms.</param>
        /// <param name="y">A callback to javascript. In the future all platforms will allow Action&lt;XElementConvertable&gt; delegates.</param>
        public void WebMethod2(string e, StringAction y)
        {
            foreach (var item in MemoryDatabase.CallToActionContent)
            {
                // Send it back to the caller.
                y(item);
            }


        }
コード例 #18
0
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript. JSC supports string data type for all platforms.</param>
        /// <param name="y">A callback to javascript. In the future all platforms will allow Action&lt;XElementConvertable&gt; delegates.</param>
        public void WebMethod2(string po, StringAction y)
        {
            // Send it back to the caller.
            COM46.po = int.Parse(po);
            var x = COM46.Line;
            COM46.Rx++;
            //Console.WriteLine("WebMethod2: #" + COM46.Rx + " @" + Thread.CurrentThread.ManagedThreadId);

            y(x);
        }
コード例 #19
0
        public static StringsPacket Create(uint _uid, StringAction _type, string _value)
        {
            var packet = new StringsPacket();

            packet.UID     = _uid;
            packet.Type    = _type;
            packet.Strings = new NetStringPacker();
            packet.Strings.AddString(_value);
            return(packet);
        }
コード例 #20
0
			public static Storage Of(string Target, StorageTargetExists Exists, StringAction Delete, StorageTargetReader Reader, StorageTargetWriter Writer)
			{
				return new Storage
				{
					Delete = () => Delete(Target),
					Exists = () => Exists(Target),
					Reader = () => Reader(Target),
					Writer = bytes => Writer(Target, bytes)
				};
			}
コード例 #21
0
        public static void CLRMain(
            StringAction yield = null
            )
        {
            System.Console.WriteLine(XML);

            MessageBox.Show("CLR breakpoint");

            yield("hi from CLR");
        }
コード例 #22
0
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript. JSC supports string data type for all platforms.</param>
        /// <param name="y">A callback to javascript. In the future all platforms will allow Action&lt;XElementConvertable&gt; delegates.</param>
        public void WebMethod2(string po, StringAction y)
        {
            // Send it back to the caller.
            COM46.po = int.Parse(po);
            var x = COM46.Line;

            COM46.Rx++;
            //Console.WriteLine("WebMethod2: #" + COM46.Rx + " @" + Thread.CurrentThread.ManagedThreadId);

            y(x);
        }
コード例 #23
0
        static void Main(string[] args)
        {
            // input more specific parameter types than the delegate target
            StringAction sa = new StringAction(ActOnObject);
            sa("hello");

            // return a more specific type than described by the delegate
            ObjectRetriever o = new ObjectRetriever(RetriveString);
            object result = o();
            Console.WriteLine(result);
        }
コード例 #24
0
        static void Main(string[] args)
        {
            Transformer t = Square; //Create delegate instance; shorthand for
            //Transformer t = new Transformer(Square);
            int result = t(3);      //t(3) shorthand for t.Invoke(3);

            Console.WriteLine(result);
            int[] values = { 1, 2, 3 };
            Transform(values, Square);
            foreach (int i in values)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine("\n");

            //multicast delegate
            ProgressReporter p = WriteProgressToFile;

            p += WriteProgressToConsole;
            HardWrok(p);

            X x = new X();
            ProgressReporter p1 = x.InstanceProgress;

            p(99);
            Console.WriteLine(p1.Target == x);//delegate must maintain instance to which the method
            //belongs; not only to method
            Console.Write(p1.Method);

            //delegate TResult Func<int T, out TResult>(T arg)
            //delegate void Action <in T> (T arg);

            Util.TransformAll(values, new Squarer());

            //parameter Compatibility(Contravariance)
            StringAction sa = new StringAction(Util.ActOnObject);

            //StringAction sa = Util.ActOnObject;
            Console.WriteLine("\n");
            sa("Hello Jeevan");//When the argument is then
            //relayed to the target method, the argument gets
            //implicitly upcast to an object.
            //or StringAction sa = Util.ActOnObject

            //Return Type Compatibility (Covariance)
            ObjectRetreiver o            = new ObjectRetreiver(Util.RetrieveString);
            object          resultString = o();

            Console.WriteLine(resultString);
            Console.ReadKey();
        }
コード例 #25
0
        private void MenuItemMoveBottom_Click(object sender, RoutedEventArgs e)
        {
            StringAction selected = actionsListBox.SelectedItem as StringAction;

            //actionsListBox.Items.Remove(selected);
            //actionsListBox.Items.Add(selected);
            //actionsListBox.SelectedIndex = actionsListBox.Items.Count - 1;
            actionSource.Remove(selected);
            actionSource.Add(selected);
            actionsListBox.SelectedIndex = actionSource.Count - 1;
            actionsListBox.Items.Refresh();
            getPreviewFiles();
            getPreviewFolders();
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: WindWalkero0/Demo
        static void Main(string[] args)
        {
            int[] values = { 1, 2, 3, 4 };
            Utility.Calculator(values, Double);

            foreach (int i in values)
            {
                Console.Write(i + " ");
            }
            StringAction ac = new StringAction(ActOnObject);

            ac("Hello");
            Console.ReadKey();
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: AsyncTaskSola/PlaySomeTest
        static void Main(string[] args)
        {
            int[] values = { 1, 2, 3 };
            //Util.Transform<int>(values,Square);
            Util.Transform(values, Square);
            foreach (var VARIABLE in values)
            {
                Console.WriteLine("i" + "  ");
            }


            StringAction s = new StringAction(ActOnObject);

            s("hello");
        }
コード例 #28
0
        public void GetTitleFromServer(StringAction result)
        {
            var r = new Random();

            var Targets = new[]
            {
                "javascript",
                "java",
                "actionscript",
                "php"
            };

            result("jsc solutions - C# to " + Targets[r.Next(0, Targets.Length)]);

            // should we add timing information if we use Thread.Sleep to the results?
        }
コード例 #29
0
        public void GetTitleFromServer(StringAction result)
        {
            var r = new Random();

            var Targets = new[]
			{
				"javascript",
				"java",
				"actionscript",
				"php"
			};

            result("jsc solutions - C# to " + Targets[r.Next(0, Targets.Length)]);

            // should we add timing information if we use Thread.Sleep to the results?

        }
コード例 #30
0
        public static void WriteWebMethod(StringAction Write, InternalWebMethodInfo item, InternalWebMethodParameterInfoAction more)
        {
            Write("<br /> ");

            if (string.IsNullOrEmpty(item.MetadataToken))
            {
                // when does this happen?

                Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubdelegate(en-us,VS.90).gif' />");
                Write(" <code>" + item.MethodName + "</code>");
            }
            else
            {
                Write("<img src='http://i.msdn.microsoft.com/deshae98.pubmethod(en-us,VS.90).gif' /> <code><a style='text-decoration: none;' href='" + item.ToQueryString() + "'>" + item.MethodName + "</a></code>");
            }

            if (more != null)
            {
                more(null);
            }

            if (item.Parameters != null)
            {
                foreach (var p in item.Parameters)
                {
                    Write("<br /> &nbsp;&nbsp;&nbsp;&nbsp;");

                    if (p.IsDelegate)
                    {
                        Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubdelegate(en-us,VS.90).gif' />");
                        Write(" <code>" + p.Name + "</code>");
                    }
                    else
                    {
                        Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubclass(en-us,VS.90).gif' />");
                        Write(" <code>" + p.Name + "</code>");

                        if (more != null)
                        {
                            more(p);
                        }
                    }
                }
            }
        }
コード例 #31
0
        public virtual ChapterList LinqGetByNameStringAction(StringAction stringAction, string name = null)
        {
            var q = this.CreateLinqQuery();

            switch (stringAction)
            {
            case StringAction.Contains:
                q = q.Where(c => c.Name.Contains(name) && c.BookId > 0);
                break;

            case StringAction.StartsWith:
                q = q.Where(c => c.Name.StartsWith(name) && c.BookId > 0);
                break;

            case StringAction.EndsWith:
                q = q.Where(c => c.Name.EndsWith(name) && c.BookId > 0);
                break;

            case StringAction.NotEmpty:
                q = q.Where(c => !string.IsNullOrEmpty(c.Name) && c.BookId > 0);
                break;

            case StringAction.LengthNotSupport:
                q = q.Where(c => c.Name.Length > 0 && c.BookId > 0);
                break;

            case StringAction.RefContains:
                q = q.Where(c => c.Book.Name.Contains(name) && c.BookId > 0);
                break;

            case StringAction.ObjectEquals:
                q = q.Where(c => name.Equals(c.Name));
                break;

            case StringAction.ObjectEquals_Reverse:
                q = q.Where(c => c.Name.Equals(name));
                break;

            default:
                break;
            }

            return((ChapterList)this.QueryData(q));
        }
コード例 #32
0
        private static void WriteDefaultPageSource(StringAction WriteLine)
        {
            WriteLine(@"<body style='margin: 0; overflow: hidden;'><noscript>ScriptApplication cannot run without JavaScript!</noscript>");

            // should we display custom logo?
            // only the first image will be fetched, then the script...
            //WriteLine(@"<div style='border-style: none; position: absolute; left: 50%; top: 50%;' >");
            //WriteLine(@"<img class='LoadingAnimation' src='/assets/ScriptCoreLib/jsc.png' title='jsc' style='border-style: none; margin-left: -48px; margin-top: -48px; ' /> ");
            //WriteLine(@"</div>");

            // http://www.ajaxload.info/
            WriteLine(@"<div style='border-style: none; position: absolute; left: 50%; top: 50%;' >");
            WriteLine(@"<img class='LoadingAnimation' src='/assets/ScriptCoreLib/loading.gif' title='loading...'  style='border-style: none; margin-left: -16px; margin-top: -16px; ' /> ");
            WriteLine(@"</div>");



            WriteLine(@"</body>");
        }
コード例 #33
0
        public static void Main(string[] args)
        {
            CalllingWithPrimitives();

            // Use Release Build to use jsc to generate java program
            // Use Debug Build to develop on .net

            // doubleclicking on the jar will not show the console

            var        i       = 0;
            StringFunc GetText =
                delegate
            {
                return("Hello world (" + (i++) + ")");
            };


            StringAction h = Say;

            h(GetText());

            StringAction x = "hey!".Say;

            x(GetText());


            Do(() => Console.WriteLine(prefix + ":)"));

            WithClosure.Test();

            using ("Broadcasting...".Measure())
            {
                StringAction y = h;
                y += x;
                y("Broadcasting!!");

                y -= h;
                y("Broadcasting once?!!");
            }
        }
コード例 #34
0
        public static void Generate(
            TupleAction AtEvent1
            )
        {
            StringAction Notify =
                text =>
            {
                Console.WriteLine(text);

                var a = new Tuple {
                    Data1 = text
                };

                if (AtEvent1 != null)
                {
                    AtEvent1(a);
                }
            };

            Notify("  beginning");

            for (int i = 0; i < 8; i++)
            {
                Thread.Sleep(500);
                Console.Write(".");
            }
            Console.WriteLine();

            Notify("  middle");

            for (int i = 0; i < 8; i++)
            {
                Thread.Sleep(500);
                Console.Write(".");
            }
            Console.WriteLine();

            Notify("  end");
        }
コード例 #35
0
        public void MoveItem(int direction)
        {
            if (actionsListBox.SelectedItem == null || actionsListBox.SelectedIndex < 0)
            {
                return;
            }

            int newIndex = actionsListBox.SelectedIndex + direction;

            if (newIndex < 0 || newIndex >= actionSource.Count)
            {
                return;
            }

            StringAction selected = actionsListBox.SelectedItem as StringAction;

            actionSource.Remove(selected);
            actionSource.Insert(newIndex, selected);
            actionsListBox.SelectedIndex = newIndex;
            actionsListBox.Items.Refresh();
            getPreviewFiles();
            getPreviewFolders();
        }
コード例 #36
0
        public static string Method1(
            StringAction Handler1 = null,
            StringAction Handler2 = null,
            string P1             = "P1",
            string P2             = "p2"
            )
        {
            Console.WriteLine("Method1 0");

            if (Handler1 != null)
            {
                Console.WriteLine("Handler1 is not null - " + P1);

                Handler1("A " + P1);
            }
            else
            {
                Console.WriteLine("Handler1 is null - " + P1);
            }

            Console.WriteLine("Method1 1");

            if (Handler2 != null)
            {
                Console.WriteLine("Handler2 is not null - " + P2);

                Handler2("B" + P2);
            }
            else
            {
                Console.WriteLine("Handler2 is null - " + P2);
            }

            Console.WriteLine("Method1 2");

            return("!");
        }
コード例 #37
0
        //Y:\PromotionWebApplication1.ApplicationWebService\staging.java\web\files
        //C:\Program Files (x86)\Java\jdk1.7.0_45\bin\javac.exe  -encoding UTF-8 -cp Y:\PromotionWebApplication1.ApplicationWebService\staging.java\web\release;C:\util\appengine-java-sdk-1.9.9\lib\impl\*;C:\util\appengine-java-sdk-1.9.9\lib\shared\* -d "Y:\PromotionWebApplication1.ApplicationWebService\staging.java\web\release" @"Y:\PromotionWebApplication1.ApplicationWebService\staging.java\web\files"


        public void Hello(string data, StringAction result)
        {
            result(data + " hello");
            result(data + " world");
        }
コード例 #38
0
		public void PlayerGotItem(string x, StringAction result)
		{
			Console.WriteLine(x);

			result("yay - " + x);
		}
コード例 #39
0
		public void GetTime(string x, StringAction result)
		{
			result(x + DateTime.Now);
		}
コード例 #40
0
        public static void WriteWebMethod(StringAction Write, InternalWebMethodInfo item, InternalWebMethodParameterInfoAction more)
        {
            Write("<br /> ");

            if (string.IsNullOrEmpty(item.MetadataToken))
            {
                // when does this happen?

                Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubdelegate(en-us,VS.90).gif' />");
                Write(" <code>" + item.MethodName + "</code>");

            }
            else
            {
                Write("<img src='http://i.msdn.microsoft.com/deshae98.pubmethod(en-us,VS.90).gif' /> <code><a style='text-decoration: none;' href='" + item.ToQueryString() + "'>" + item.MethodName + "</a></code>");
            }

            if (more != null)
                more(null);

            if (item.Parameters != null)
                foreach (var p in item.Parameters)
                {
                    Write("<br /> &nbsp;&nbsp;&nbsp;&nbsp;");

                    if (p.IsDelegate)
                    {
                        Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubdelegate(en-us,VS.90).gif' />");
                        Write(" <code>" + p.Name + "</code>");


                    }
                    else
                    {
                        Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubclass(en-us,VS.90).gif' />");
                        Write(" <code>" + p.Name + "</code>");

                        if (more != null)
                            more(p);

                    }

                }


        }
コード例 #41
0
        private static void WriteXDocument(InternalGlobal g, StringAction Write, InternalWebMethodInfo WebMethod)
        {
            var that    = g.InternalApplication;
            var Context = that.Context;

            #region document
            var w = new StringBuilder();


            w.Append("<document>");



            if (WebMethod.Results == null)
            {
                //Console.WriteLine("WriteXDocument Results null");
            }
            else
            {
                //Console.WriteLine("WriteXDocument Results " + new { WebMethod.Results.Length });

                foreach (var item in WebMethod.Results)
                {
                    w.Append("<" + item.MethodName + ">");

                    if (item.Parameters != null)
                    {
                        foreach (var p in item.Parameters)
                        {
                            if (p.Value == null)
                            {
                                // no parameter?
                                // X:\jsc.svn\examples\javascript\WebMethodXElementTransferExperiment\WebMethodXElementTransferExperiment\ApplicationWebService.cs
                            }
                            else
                            {
                                w.Append("<" + p.Name + ">");
                                w.Append(escapeXML(p.Value));
                                w.Append("</" + p.Name + ">");
                            }
                        }
                    }

                    w.Append("</" + item.MethodName + ">");
                }
            }

            if (WebMethod.TaskComplete)
            {
                w.Append("<TaskComplete>");

                if (WebMethod.TaskResult != null)
                {
                    //Console.WriteLine(new { WebMethod.TaskResult });

                    w.Append("<TaskResult>");
                    w.Append(escapeXML(WebMethod.TaskResult));
                    w.Append("</TaskResult>");
                }

                w.Append("</TaskComplete>");
            }

            w.Append("</document>");
            #endregion



            var ws      = w.ToString();
            var wsbytes = Encoding.UTF8.GetBytes(ws);


            // http://stackoverflow.com/questions/1999824/whats-the-shortest-pair-of-strings-that-causes-an-md5-collision

            var ETagbytes = wsbytes.ToMD5Bytes();
            var newETag   = ETagbytes.ToHexString();
            // does the client already have a copy of the same response?
            // if so, send 304 ?
            // http://www.codeproject.com/Articles/23857/The-Performance-Woe-of-Binary-XML
            // are we ready for encrypted binary xml?
            // http://msdn.microsoft.com/en-us/library/cc219210.aspx
            // file:///C:/Users/Arvo/Downloads/03-002r9_Binary_Extensible_Markup_Language_BXML_Encoding_Specification.pdf
            // is this the beginning of a binary diff service?


            // allow http to https calls
            Context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            Context.Response.AddHeader("ETag", Convert.ToBase64String(ETagbytes));

            var hasETag = Context.Request.Form.AllKeys.Contains("ETag");
            if (hasETag)
            {
                var oldETag64    = Context.Request.Form["ETag"];
                var oldETagbytes = Convert.FromBase64String(oldETag64);
                var clientETag   = oldETagbytes.ToHexString();

                //{ MethodName = Gravatar, MetadataToken = 06000001, oldETag = 1706b464adc232a9df3dd4539a206569 }
                //{ MethodName = Gravatar, MetadataToken = 06000001, ETag = 1706b464adc232a9df3dd4539a206569 }

                //Console.WriteLine(new { WebMethod.MethodName, WebMethod.MetadataToken, clientETag });

                //I/System.Console( 3988): #17 POST /xml/Gravatar HTTP/1.1
                //D/FastDormancy(  220):  before ======= ENTER DORMANCY =======
                //W/Threeg  (  918): Failed to read packet and byte counts from wifi interface
                //D/dalvikvm( 3988): GC_CONCURRENT freed 819K, 56% free 3157K/7111K, external 2013K/2108K, paused 2ms+2ms
                //I/System.Console( 3988): { MethodName = Gravatar, MetadataToken = 06000001, oldETag = d41d8cd98f00b204e9800998ecf8427e }
                //I/System.Console( 3988): { MethodName = Gravatar, MetadataToken = 06000001, ETag = 5a62b5d768653ae632ba4ff7e0b7a03c }
                //I/Web Console( 3988): %c0:312066ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:14691/view-source:37081
                //I/Web Console( 3988): 0:312076ms { Name = Gravatar, MetadataToken = 06000001, ETag = d41d8cd98f00b204e9800998ecf8427e, ElapsedMilliseconds = 5 } at http://192.168.43.1:14691/view-source:37040

                if (clientETag == newETag)
                {
                    //Console.WriteLine("Client already has the answer, sending 304");
                    // X:\jsc.svn\examples\javascript\forms\FormsDataBindingForEnabled\FormsDataBindingForEnabled\ApplicationControl.cs

                    // what will web client do with 304?
                    g.Context.Response.StatusCode = 304;
                    g.Context.Response.Flush();

                    that.CompleteRequest();
                    return;
                }
            }

            //Console.WriteLine(new { WebMethod.MethodName, WebMethod.MetadataToken, newETag, ws.Length });

            //I/System.Console( 4563): #4 POST /xml/Gravatar HTTP/1.1
            //I/System.Console( 4563): { MethodName = Gravatar, MetadataToken = 06000001, newETag = 1706b464adc232a9df3dd4539a206569, Length = 239 }

            //I/Web Console( 4563): %c0:22236ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:6686/view-source:37081
            //I/Web Console( 4563): 0:22345ms { Name = Gravatar, MetadataToken = 06000001, ETag = d41d8cd98f00b204e9800998ecf8427e, ElapsedMilliseconds = 25 } at http://192.168.43.1:6686/view-source:37040


            Context.Response.ContentType = "text/xml";

            // https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS?redirectlocale=en-US&redirectslug=HTTP_access_control


            Write(ws);

            that.CompleteRequest();
        }
コード例 #42
0
        public static void WriteDiagnostics(InternalGlobal g, StringAction Write, InternalWebMethodInfo[] WebMethods)
        {
            // should the diagnostics be a separate rich Browser Application? :)

            var Context = g.InternalApplication.Context;

            Write("<title>jsc-solutions.net</title>");

            Write("<center>");
            Write("<div style='background-color: black; color: white; padding: 2em;'>");
            Write("&laquo; Rotate your device to left to <b>launch</b>");
            Write("</div>");
            Write("</center>");

            Write("<br/><center><a href='/'>Launch Application</a></center><br/>");

            //Write("<h1>" + Context.Request.Headers["Host"] + "</h1>");

            foreach (var HeaderKey in Context.Request.Headers.AllKeys)
            {
                var HeaderValue = Context.Request.Headers[HeaderKey];

                Write("<code style='color: gray;'>" + HeaderKey + "</code>:");
                Write("<code style='color: green;'>" + HeaderValue + "</code><br />");
            }


            Write("<a href='http://jsc-solutions.net'><img border='0' src='/assets/ScriptCoreLib/jsc.png' /></a>");

            #region Special pages
            Write("<h2>Special pages</h2>");


            Write("<br /> " + "special page: " + "<a href='/robots.txt'>/robots.txt</a>");
            Write("<br /> " + "special page: " + "<a href='/xml'>/xml</a>");
            Write("<br /> " + "special page: " + "<a href='/crossdomain.xml'>/crossdomain.xml</a>");
            Write("<br /> " + "special page: " + "<a href='/favicon.ico'>/favicon.ico</a>");
            Write("<br /> " + "special page: " + "<a href='/jsc'>/jsc</a>");
            #endregion

            Write("<h2>WebMethods (" + WebMethods.Length + ")</h2>");



            foreach (var item in WebMethods)
            {
                InternalGlobalExtensions.WriteWebMethodForm(Write, item);
            }


            //Write("<br /> Path: '" + Context.Request.Path + "'");
            //Write("<br /> HttpMethod: '" + Context.Request.HttpMethod + "'");

            Write("<h2>Form</h2>");
            foreach (var item in Context.Request.Form.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.Form[item]));
                Write("</code>");
            }

            #region QueryString
            Write("<h2>QueryString</h2>");
            foreach (var item in Context.Request.QueryString.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.QueryString[item]));
                Write("</code>");
            }
            #endregion


            Write("<h2>Script Applications</h2>");

            foreach (var item in g.GetScriptApplications())
            {
                Write("<br /> " + "script application: " + item.TypeName);

                foreach (var r in item.References)
                {
                    Write("<br /> &nbsp;&nbsp;&nbsp;&nbsp;");

                    Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubclass(en-us,VS.90).gif' /> reference: ");
                    Write(r.AssemblyFile);

                }
            }

            Write("<h2>Files</h2>");

            foreach (var item in g.GetFiles())
            {
                Write("<br /> " + " file: <a href='" + item.Name + "'>" + item.Name + "</a>");
            }



        }
コード例 #43
0
        private static void WriteCacheManifest(InternalGlobal g, System.Web.HttpApplication that, StringAction WriteLine)
        {
            // should the app be able to control manifest on its own?

            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130330-cache-manifest
            // http://html5doctor.com/go-offline-with-application-cache/
            that.Response.ContentType = WebApplicationCacheManifest.ManifestContentType;
            that.Response.AddHeader("Cache-Control", "no-cache, private");
            that.Response.AddHeader("Expires", "0");
            // http://stackoverflow.com/questions/1715568/how-to-properly-invalidate-an-html5-cache-manifest-for-online-offline-web-apps
            // Cache-Control: no-cache, private

            #region w
            var w = new StringBuilder();

            // http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html

            w.AppendLine("CACHE MANIFEST");

            var files = g.GetFiles();
            var bytes = 0;

            // do we need these?
            //w.AppendLine(WebApplicationIcon.Icon);
            //w.AppendLine(WebApplicationIcon.Image);

            //Explicit entries

            w.AppendLine("/");
            w.AppendLine("/view-source");


            foreach (var item in files)
            {

                var Command = item.Name;

                bytes += item.Length;

                // webkit seems to have 5MB limit.
                // http://groups.google.com/a/chromium.org/group/chromium-html5/browse_thread/thread/e911f18b905d28ee/9f54c8cc1e8afb5d
                // http://stackoverflow.com/questions/2908459/mobile-safari-5mb-html5-application-cache-limit
                // http://www.yuiblog.com/blog/2010/07/12/mobile-browser-cache-limits-revisited/

                // hack.

                // we need to figure out how to make the application fit to the cache limits.
                // we could be optimizing javascript.

                if (Command.EndsWith(".css"))
                    w.AppendLine(Command);

                if (Command.EndsWith(".swf"))
                    w.AppendLine(Command);

                // There’s no technical benefit to WOFF over TTF.
                if (Command.EndsWith(".ttf"))
                    w.AppendLine(Command);
            }

            w.AppendLine("");


            // what about fake pages used by historic api?
            // X:\jsc.svn\examples\javascript\async\AsyncHistoricActivities\AsyncHistoricActivities\Application.cs
            //w.AppendLine("FALLBACK:");
            //w.AppendLine("/fake-right /#/fake-right");

            // Application Cache Error event: Resource fetch failed (-1) http://192.168.43.252:30821/fake-right 
            // http://alistapart.com/article/application-cache-is-a-douchebag


            w.AppendLine("SETTINGS:");
            w.AppendLine("prefer-online");

            // http://html5doctor.com/go-offline-with-application-cache/
            // The first value is the request URI to match, and the second is the resource sent upon matching. It caches the resource on the right for offline use, so this should be an explicit path.
            //w.AppendLine("FALLBACK:");
            //w.AppendLine("/ /#offline");




            w.AppendLine("");
            w.AppendLine("NETWORK:");
            w.AppendLine("*");

            var now = DateTime.Now;

            // Application Cache Error event: Manifest changed during update, scheduling retry 
            w.AppendLine("");
            w.AppendLine("# " + new { bytes });
            w.AppendLine("");
            #endregion

            //            Implementation not found for type import :
            //type: System.Text.StringBuilder
            //method: Int32 get_Length()
            //Did you forget to add the [Script] attribute?
            //Please double check the signature!


            that.Response.AddHeader("Content-Length", "" + w.Length);
            // chrome://appcache-internals/
            that.Response.Write(w.ToString());


            that.CompleteRequest();
        }
コード例 #44
0
        private static void WriteXDocument(InternalGlobal g, StringAction Write, InternalWebMethodInfo WebMethod)
        {
            var that = g.InternalApplication;
            var Context = that.Context;

            #region document
            var w = new StringBuilder();


            w.Append("<document>");



            if (WebMethod.Results == null)
            {
                //Console.WriteLine("WriteXDocument Results null");
            }
            else
            {
                //Console.WriteLine("WriteXDocument Results " + new { WebMethod.Results.Length });

                foreach (var item in WebMethod.Results)
                {
                    w.Append("<" + item.MethodName + ">");

                    if (item.Parameters != null)
                    {
                        foreach (var p in item.Parameters)
                        {

                            if (p.Value == null)
                            {
                                // no parameter?
                                // X:\jsc.svn\examples\javascript\WebMethodXElementTransferExperiment\WebMethodXElementTransferExperiment\ApplicationWebService.cs
                            }
                            else
                            {
                                w.Append("<" + p.Name + ">");
                                w.Append(escapeXML(p.Value));
                                w.Append("</" + p.Name + ">");
                            }


                        }
                    }

                    w.Append("</" + item.MethodName + ">");

                }
            }

            if (WebMethod.TaskComplete)
            {
                w.Append("<TaskComplete>");

                if (WebMethod.TaskResult != null)
                {
                    //Console.WriteLine(new { WebMethod.TaskResult });

                    w.Append("<TaskResult>");
                    w.Append(escapeXML(WebMethod.TaskResult));
                    w.Append("</TaskResult>");
                }

                w.Append("</TaskComplete>");
            }

            w.Append("</document>");
            #endregion



            var ws = w.ToString();
            var wsbytes = Encoding.UTF8.GetBytes(ws);


            // http://stackoverflow.com/questions/1999824/whats-the-shortest-pair-of-strings-that-causes-an-md5-collision

            var ETagbytes = wsbytes.ToMD5Bytes();
            var newETag = ETagbytes.ToHexString();
            // does the client already have a copy of the same response?
            // if so, send 304 ?
            // http://www.codeproject.com/Articles/23857/The-Performance-Woe-of-Binary-XML
            // are we ready for encrypted binary xml?
            // http://msdn.microsoft.com/en-us/library/cc219210.aspx
            // file:///C:/Users/Arvo/Downloads/03-002r9_Binary_Extensible_Markup_Language_BXML_Encoding_Specification.pdf
            // is this the beginning of a binary diff service?


            // allow http to https calls
            Context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            Context.Response.AddHeader("ETag", Convert.ToBase64String(ETagbytes));

            var hasETag = Context.Request.Form.AllKeys.Contains("ETag");
            if (hasETag)
            {
                var oldETag64 = Context.Request.Form["ETag"];
                var oldETagbytes = Convert.FromBase64String(oldETag64);
                var clientETag = oldETagbytes.ToHexString();

                //{ MethodName = Gravatar, MetadataToken = 06000001, oldETag = 1706b464adc232a9df3dd4539a206569 }
                //{ MethodName = Gravatar, MetadataToken = 06000001, ETag = 1706b464adc232a9df3dd4539a206569 }

                //Console.WriteLine(new { WebMethod.MethodName, WebMethod.MetadataToken, clientETag });

                //I/System.Console( 3988): #17 POST /xml/Gravatar HTTP/1.1
                //D/FastDormancy(  220):  before ======= ENTER DORMANCY =======
                //W/Threeg  (  918): Failed to read packet and byte counts from wifi interface
                //D/dalvikvm( 3988): GC_CONCURRENT freed 819K, 56% free 3157K/7111K, external 2013K/2108K, paused 2ms+2ms
                //I/System.Console( 3988): { MethodName = Gravatar, MetadataToken = 06000001, oldETag = d41d8cd98f00b204e9800998ecf8427e }
                //I/System.Console( 3988): { MethodName = Gravatar, MetadataToken = 06000001, ETag = 5a62b5d768653ae632ba4ff7e0b7a03c }
                //I/Web Console( 3988): %c0:312066ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:14691/view-source:37081
                //I/Web Console( 3988): 0:312076ms { Name = Gravatar, MetadataToken = 06000001, ETag = d41d8cd98f00b204e9800998ecf8427e, ElapsedMilliseconds = 5 } at http://192.168.43.1:14691/view-source:37040


#if ETagTestedForIE11
                if (clientETag == newETag)
                {
                    //Console.WriteLine("Client already has the answer, sending 304");
                    // X:\jsc.svn\examples\javascript\forms\FormsDataBindingForEnabled\FormsDataBindingForEnabled\ApplicationControl.cs

                    // what will web client do with 304?
                    g.Context.Response.StatusCode = 304;
                    g.Context.Response.Flush();

                    that.CompleteRequest();
                    return;
                }
#endif


            }

            //Console.WriteLine(new { WebMethod.MethodName, WebMethod.MetadataToken, newETag, ws.Length });

            //I/System.Console( 4563): #4 POST /xml/Gravatar HTTP/1.1
            //I/System.Console( 4563): { MethodName = Gravatar, MetadataToken = 06000001, newETag = 1706b464adc232a9df3dd4539a206569, Length = 239 }

            //I/Web Console( 4563): %c0:22236ms InternalWebMethodRequest.Complete { Name = Gravatar, Length = 0 } at http://192.168.43.1:6686/view-source:37081
            //I/Web Console( 4563): 0:22345ms { Name = Gravatar, MetadataToken = 06000001, ETag = d41d8cd98f00b204e9800998ecf8427e, ElapsedMilliseconds = 25 } at http://192.168.43.1:6686/view-source:37040


            Context.Response.ContentType = "text/xml";

            // https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS?redirectlocale=en-US&redirectslug=HTTP_access_control


            Write(ws);

            that.CompleteRequest();
        }
コード例 #45
0
        public static void WriteWebMethodForm(StringAction Write, InternalWebMethodInfo WebMethod)
        {
            Write("<form target='_blank' action='" + WebMethod.ToQueryString() + "' method='POST'>");
            WriteWebMethod(Write, WebMethod,
                Parameter =>
                {
                    if (Parameter == null)
                    {
                        Write("<input type='submit' value='Invoke'  />");

                        return;
                    }

                    var key = "_" + WebMethod.MetadataToken + "_" + Parameter.Name;

                    // C# named parameters style
                    Write(": ");

                    var value = "";

                    Parameter.Value.With(x => value = x.Replace("'", "&apos;"));


                    Write("<input type='text'  name='" + key + "' value='" + value + "' />");
                }
            );
            Write("</form>");
        }
コード例 #46
0
        private static void WriteDefaultPageSource(StringAction WriteLine)
        {
            WriteLine(@"<body style='margin: 0; overflow: hidden;'><noscript>ScriptApplication cannot run without JavaScript!</noscript>");

            // should we display custom logo?
            // only the first image will be fetched, then the script...
            //WriteLine(@"<div style='border-style: none; position: absolute; left: 50%; top: 50%;' >");
            //WriteLine(@"<img class='LoadingAnimation' src='/assets/ScriptCoreLib/jsc.png' title='jsc' style='border-style: none; margin-left: -48px; margin-top: -48px; ' /> ");
            //WriteLine(@"</div>");

            // http://www.ajaxload.info/
            WriteLine(@"<div style='border-style: none; position: absolute; left: 50%; top: 50%;' >");
            WriteLine(@"<img class='LoadingAnimation' src='/assets/ScriptCoreLib/loading.gif' title='loading...'  style='border-style: none; margin-left: -16px; margin-top: -16px; ' /> ");
            WriteLine(@"</div>");



            WriteLine(@"</body>");
        }
コード例 #47
0
        public void WriteTo(
            StringAction Write, bool CacheManifest = true)
        {
            var app = this;

            // http://validator.w3.org/check?uri=

            StringAction WriteLine = k => Write(k + Environment.NewLine);

            // this function is running in .net, google app engine java and php
            // this function is based on JavaScript.EntrypointProvider
            // we could show a cool loading animation?
            // can we have XElement support already`?

            // <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            //WriteLine(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">");

            // http://www.w3.org/TR/html5/offline.html

            // can we detect who is looking at us? is it a 3D view?
            // https://www.oculusvr.com/order/

            //WriteLine(@"<!DOCTYPE HTML>");
            //            WriteLine(@"<!-- 
            //
            //Hello curious person, welcome to the source code. I hope you enjoy your time here. Please close the door after you've gone. 
            //
            //--> ");

            // view-source:http://skycraft.io/


            // should we provde some statistics?

            //this.References.
            WriteLine(@"<!doctype html>
<!-- 


Hi there!

Glad to see you here, we must have some interests in common.
Welcome to the source code. I hope you enjoy your time here. Please close the door after you've gone. 

Visit http://my.jsc-solutions.net to gear up!


--> 
");



            //Console.WriteLine("WebServiceScriptAppliction WriteTo " + new { this.PageSource });
            // if XElement
            var html = XElement.Parse(this.PageSource);

            if (CacheManifest)
            {
                html.Add(
                    new XAttribute("manifest", WebApplicationCacheManifest.ManifestName)
                );

                //html.SetAttributeValue("manifest", WebApplicationCacheManifest.ManifestName);

                //  method: Void SetAttributeValue(System.Xml.Linq.XName, System.Object)
            }

            if (!string.IsNullOrEmpty(baseURI))
            {
                // X:\jsc.smokescreen.svn\market\appengine\xmoneseservicesweb\xmoneseserviceswebredirector\ApplicationWebService.cs

                var head = html.Elements("head").FirstOrDefault();
                if (head != null)
                    head.Add(
                        new XElement("base",
                            new XAttribute("href", baseURI)
                        )
                    );

            }

            // add first not yet available!
            //html.AddFirst(
            html.Add(
                new XElement("script",
                // will jvm autoclose this element?
                    new XAttribute("src",
                //global::ScriptCoreLib.j
                        "view-source"), " "
                )
            );




            var htmlString = html.ToString();

            //Console.WriteLine("WebServiceScriptAppliction WriteTo " + new { htmlString });

            WriteLine(htmlString);
            return;



            //<script src='view-source'></script>

            if (CacheManifest)
            {
                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130330-cache-manifest
                WriteLine(@"<html manifest=""" + WebApplicationCacheManifest.ManifestName + @""">");
            }
            else
            {
                WriteLine(@"<html>");
            }

            // flash cannot be reloaded for some reason? why?
            WriteLine(@"<head>");

            // do we need this?
            //WriteLine(@"<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />");

            // whats the title going to be? :)
            WriteLine(@"<title>" + app.TypeName + "</title>");
            //WriteLine(@"<title>Loading...</title>");

            // http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon

            WriteLine(@"<link rel=""icon"" href=""" + WebApplicationIcon.Icon + @""" sizes=""32x32 96x96"" type=""image/vnd.microsoft.icon"" />");
            WriteLine(@"<link rel=""icon"" href=""" + WebApplicationIcon.Image + @""" sizes=""96x96"" type=""image/png"" />");

            // http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariHTMLRef/Articles/MetaTags.html
            // http://www.viaboxxsystems.de/html-fullscreen-apps-for-the-ipad

            //WriteLine(@"<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1' />");


            WriteLine(@"<meta name='apple-mobile-web-app-capable' content='yes' />");

            //WriteLine(@"<link rel=""shortcut icon"" href=""favicon""  type=""image/x-icon"" />");

            //WriteLine(@"<title>" + this.TypeFullName + "</title>");

            //WriteLine("<meta name='google-site-verification' content='uMipBZ74jD_65lTkiAVKRHM1HSJRo_NAgpk6NChQuOA' />");

            //WriteLine(@"<script></script>");
            WriteLine(@"</head>");

            if (string.IsNullOrEmpty(this.PageSource))
            {
                WriteDefaultPageSource(WriteLine);
            }
            else
            {
                Write(this.PageSource);
            }

            // jsc bootstraps always
            //WriteLine(@"<script type='text/xml' class='" + app.TypeName + "'></script>");

            //foreach (var item in app.References)
            //{
            //    Write(@"<script type='text/javascript' src='/" + item.AssemblyFile + @".js'></script>");

            //}

            // prepeare for ChromeOS deployment. primary app script:
            WriteLine("");

            Write("<script src='view-source'></script>");


            WriteLine(@"</html>");
        }
コード例 #48
0
        private static void WriteCacheManifest(InternalGlobal g, System.Web.HttpApplication that, StringAction WriteLine)
        {
            // should the app be able to control manifest on its own?

            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201303/20130330-cache-manifest
            // http://html5doctor.com/go-offline-with-application-cache/
            that.Response.ContentType = WebApplicationCacheManifest.ManifestContentType;
            that.Response.AddHeader("Cache-Control", "no-cache, private");
            that.Response.AddHeader("Expires", "0");
            // http://stackoverflow.com/questions/1715568/how-to-properly-invalidate-an-html5-cache-manifest-for-online-offline-web-apps
            // Cache-Control: no-cache, private

            #region w
            var w = new StringBuilder();

            // http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html

            w.AppendLine("CACHE MANIFEST");

            var files = g.GetFiles();
            var bytes = 0;

            // do we need these?
            //w.AppendLine(WebApplicationIcon.Icon);
            //w.AppendLine(WebApplicationIcon.Image);

            //Explicit entries

            w.AppendLine("/");
            w.AppendLine("/view-source");


            foreach (var item in files)
            {
                var Command = item.Name;

                bytes += item.Length;

                // webkit seems to have 5MB limit.
                // http://groups.google.com/a/chromium.org/group/chromium-html5/browse_thread/thread/e911f18b905d28ee/9f54c8cc1e8afb5d
                // http://stackoverflow.com/questions/2908459/mobile-safari-5mb-html5-application-cache-limit
                // http://www.yuiblog.com/blog/2010/07/12/mobile-browser-cache-limits-revisited/

                // hack.

                // we need to figure out how to make the application fit to the cache limits.
                // we could be optimizing javascript.

                if (Command.EndsWith(".css"))
                {
                    w.AppendLine(Command);
                }

                if (Command.EndsWith(".swf"))
                {
                    w.AppendLine(Command);
                }

                // There’s no technical benefit to WOFF over TTF.
                if (Command.EndsWith(".ttf"))
                {
                    w.AppendLine(Command);
                }
            }

            w.AppendLine("");


            // what about fake pages used by historic api?
            // X:\jsc.svn\examples\javascript\async\AsyncHistoricActivities\AsyncHistoricActivities\Application.cs
            //w.AppendLine("FALLBACK:");
            //w.AppendLine("/fake-right /#/fake-right");

            // Application Cache Error event: Resource fetch failed (-1) http://192.168.43.252:30821/fake-right
            // http://alistapart.com/article/application-cache-is-a-douchebag


            w.AppendLine("SETTINGS:");
            w.AppendLine("prefer-online");

            // http://html5doctor.com/go-offline-with-application-cache/
            // The first value is the request URI to match, and the second is the resource sent upon matching. It caches the resource on the right for offline use, so this should be an explicit path.
            //w.AppendLine("FALLBACK:");
            //w.AppendLine("/ /#offline");



            w.AppendLine("");
            w.AppendLine("NETWORK:");
            w.AppendLine("*");

            var now = DateTime.Now;

            // Application Cache Error event: Manifest changed during update, scheduling retry
            w.AppendLine("");
            w.AppendLine("# " + new { bytes });
            w.AppendLine("");
            #endregion

            //            Implementation not found for type import :
            //type: System.Text.StringBuilder
            //method: Int32 get_Length()
            //Did you forget to add the [Script] attribute?
            //Please double check the signature!


            that.Response.AddHeader("Content-Length", "" + w.Length);
            // chrome://appcache-internals/
            that.Response.Write(w.ToString());


            that.CompleteRequest();
        }
コード例 #49
0
        public static void CLRMain(
            // error?
            //XElementAction xml = null,
             StringAction ListMethods = null,
             Action SwitchVM = null,
             IJavaArchiveReflector jar = null
            )
        {
            System.Console.WriteLine(XML);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(
                new Form1().With(f =>
                {
                    var n = f.treeView1.Nodes.Add(jar.FileNameString + " (" + jar.Count + ")");

                    var Namespaces = new Dictionary<string, TreeNode>();

                    for (int i = 0; i < jar.Count; i++)
                    {
                        System.Console.WriteLine("# " + i);

                        var fqn = jar.GetTypeFullName(i);

                        if (!string.IsNullOrEmpty(fqn))
                        {
                            var Namespace = fqn.TakeUntilLastOrEmpty(".");
                            var Name = fqn.SkipUntilLastIfAny(".");

                            if (!Namespaces.ContainsKey(Namespace))
                            {
                                Namespaces[Namespace] = n.Nodes.Add(Namespace);
                            }

                            Namespaces[Namespace].Nodes.Add(Name);

                            //n.Nodes.Add(fqn);
                        }
                    }

                    f.button2.Click +=
                        delegate
                        {
                            if (SwitchVM != null)
                                SwitchVM();

                            f.Close();
                        };
                    f.button1.Click +=
                        delegate
                        {
                            if (ListMethods != null)
                                ListMethods(f.textBox1.Text);
                        };
                }
            ));
        }
コード例 #50
0
        private static void WriteDiagnostics(InternalGlobal g, StringAction Write, InternalWebMethodInfo[] WebMethods)
        {
            // should the diagnostics be a separate rich Browser Application? :)

            var Context = g.InternalApplication.Context;

            Write("<title>jsc-solutions.net</title>");
            Write("<br/><center><a href='/'>Launch Application</a></center><br/>");

            Write("<a href='http://jsc-solutions.net'><img border='0' src='/assets/ScriptCoreLib/jsc.png' /></a>");


            Write("<blockquote>");
            Write("<h2>Special pages</h2>");
            Write("<blockquote>");

            // like CON in filesystem?
            Write("<br /> " + "special page: " + "<a href='/robots.txt'>/robots.txt</a>");
            Write("<br /> " + "special page: " + "<a href='/xml'>/xml</a>");
            Write("<br /> " + "special page: " + "<a href='/crossdomain.xml'>/crossdomain.xml</a>");
            Write("<br /> " + "special page: " + "<a href='/favicon.ico'>/favicon.ico</a>");
            Write("<br /> " + "special page: " + "<a href='/jsc'>/jsc</a>");
            Write("<br /> " + "special page: " + "<a href='/view-source'>/view-source</a>");
            Write("</blockquote>");

            Write("<h2>Methods</h2>");
            Write("<blockquote>");
            foreach (var item in WebMethods)
            {
                WriteWebMethodForm(Write, item);
            }
            Write("</blockquote>");


            Write("<br /> Path: '" + Context.Request.Path + "'");
            Write("<br /> HttpMethod: '" + Context.Request.HttpMethod + "'");

            Write("<h2>Form</h2>");
            foreach (var item in Context.Request.Form.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.Form[item]));
                Write("</code>");
            }

            Write("<h2>QueryString</h2>");
            foreach (var item in Context.Request.QueryString.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.QueryString[item]));
                Write("</code>");
            }

            var ff = g.GetFiles();

            // http://msdn.microsoft.com/en-us/library/y47ychfe.aspx

            Write("<h2>Applications</h2>");
            Write("<blockquote>");

            foreach (var app in g.GetScriptApplications())
            {
                Write("<br /> ");

                Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubclass(en-us,VS.90).gif' />");

                Write(" <code style='color: darkcyan;'>" + app.TypeName + "</code>");

                // var app_references = app.References.Select(
                //    item => ff.First(k => k.Name == item.AssemblyFile + ".js")
                //).ToArray();

                // var app_size = app_references.Sum(k => k.Length);

                // Write(" <span style='color: gray;'>(" + app_size + " bytes)</span>");

                foreach (var r in app.References)
                {
                    Write("<br /> &nbsp;&nbsp;&nbsp;&nbsp;");

                    Write("<img src='http://i.msdn.microsoft.com/dynimg/IC477625.png' />");
                    Write(" " + r.AssemblyFile);
                }
            }
            Write("</blockquote>");

            Write("<h2>Files</h2>");
            Write("<blockquote>");

            Action <string> separator = delegate { };

            foreach (var item in g.GetFiles())
            {
                separator(item.Name);

                Write(
                    "<br /> "
                    + " file: <a href='" + item.Name + "'>" + item.Name + "</a>" + " size: " + item.Length
                    );


                // do we need this?
                //var itemref_csharp4 = item;

                separator =
                    next =>
                {
                    if (next.TakeUntilLastOrEmpty("/") == item.Name.TakeUntilLastOrEmpty("/"))
                    {
                        return;
                    }

                    Write(
                        "<br /> "
                        );
                };
            }
            Write("</blockquote>");
            Write("</blockquote>");
        }
コード例 #51
0
        public void GetCaptions(string video, StringAction result)
        {
            if (string.IsNullOrEmpty(video))
                video = "LT_x9s67yWA";

            var uri = video.ToYoutubeVideo();

            var c = new WebClient();

            var html = c.DownloadString(uri);

            var ttsurl = Uri.UnescapeDataString(html.SkipUntilIfAny("\"ttsurl\":").SkipUntilIfAny("\"").TakeUntilIfAny("\""));

            // 20151115 broken again?
            // 20131011 they changed it!
            ttsurl = ttsurl.Replace(@"\/", "/");
            // http://video.google.com/timedtext?
            //	sparams=caps%2Cexpire%2Cv&
            //	expire=1268420400&
            //	caps=asr&
            //	key=yttt1&
            //	signature=8F7DADCF868F8302AD31C92F5D4F54532F24583E.9AD0492582C05330E9CFA753B1298D71BE71FD5F

            // http://video.google.com/timedtext?
            //	sparams=caps%2Cexpire%2Cv
            //	expire=1268420400&
            //	caps=asr&
            //	key=yttt1&
            //	signature=8F7DADCF868F8302AD31C92F5D4F54532F24583E.9AD0492582C05330E9CFA753B1298D71BE71FD5F&

            //	name=&
            //	v=LT_x9s67yWA&
            //	lang=en&
            //	type=track&
            //	hl=en&
            //	kind=asr&
            //	ts=1268397349057&

            ttsurl += "&name=" + "";
            ttsurl += "&v=" + video;
            ttsurl += "&lang=" + "en";
            ttsurl += "&type=" + "track";
            ttsurl += "&hl=" + "en";
            ttsurl += "&kind=" + "asr";
            ttsurl += "&ts=" + "";

            // http:\/\/www.youtube.com\/api\/timedtext?expire=1381505182\u0026signature=A76A5798EECE7ADFE877BC5BC190A6C26F68FB65.7D5595D5BFA370BDA21BBE053E77C7A57CCB40C1\u0026asr_langs=ja,de,pt,ru,ko,en,nl,es,fr,it\u0026hl=en_US\u0026sparams=asr_langs,caps,v,expire\u0026v=COzgtcZzOZw\u0026caps=asr\u0026key=yttt1&name=&v=COzgtcZzOZw&lang=en&type=track&hl=en&kind=asr&ts=

            //Request URL:http://www.youtube.com/api/timedtext?
            // hl=en-US&
            // asr_langs=pt%2Ces%2Cnl%2Cfr%2Cru%2Cja%2Cen%2Cit%2Cko%2Cde&
            // caps=asr&
            // key=yttt1&
            // signature=15D631B86414ABBAEE1AC9D89767A4D4B65EE3CB.89D937A606E2B198CFC6392E70B9F791B4C17F99&
            // v=COzgtcZzOZw&
            // expire=1381505508&
            // sparams=asr_langs%2Ccaps%2Cv%2Cexpire&type=track&
            // lang=en&
            // name&
            // kind

            Console.WriteLine(new { ttsurl });

            // The remote server returned an error: (404) Not Found.
            // do we have to send a cookie?
            var tts = c.DownloadString(new Uri(ttsurl));

            result(tts);
        }
コード例 #52
0
        private static void WriteDiagnosticsResults(StringAction Write, InternalWebMethodInfo WebMethod)
        {
            Write("<blockquote>");
            if (WebMethod.Results == null)
            {

                Write("<h2>No results from " + WebMethod.MethodName + "</h2>");
            }
            else
            {
                Write("<h2>" + WebMethod.Results.Length + " results from " + WebMethod.MethodName + "</h2>");
                Write("<blockquote>");

                foreach (var item in WebMethod.Results)
                {
                    WriteWebMethod(Write, item,
                        Parameter =>
                        {
                            if (Parameter == null)
                                return;

                            Write(" = '<code style='color: red'>" + escapeXML(Parameter.Value) + "</code>'");
                        }
                    );
                }
                Write("</blockquote>");
                Write("<br />");
            }
            Write("</blockquote>");
        }
コード例 #53
0
        // action fails?
        public void SendCTAContent(string e, StringAction done)
        {
            MemoryDatabase.CallToActionContent.Add(e);

            done("");
        }
コード例 #54
0
 /// <summary>
 /// This Method is a javascript callable method.
 /// </summary>
 /// <param name="e">A parameter from javascript. JSC supports string data type for all platforms.</param>
 /// <param name="y">A callback to javascript. In the future all platforms will allow Action&lt;XElementConvertable&gt; delegates.</param>
 public void WebMethod2(string e, StringAction y)
 {
     // Send it back to the caller.
     y(e);
 }
コード例 #55
0
        private static void WriteDiagnostics(InternalGlobal g, StringAction Write, InternalWebMethodInfo[] WebMethods)
        {
            // should the diagnostics be a separate rich Browser Application? :)

            var Context = g.InternalApplication.Context;

            Write("<title>jsc-solutions.net</title>");
            Write("<br/><center><a href='/'>Launch Application</a></center><br/>");

            Write("<a href='http://jsc-solutions.net'><img border='0' src='/assets/ScriptCoreLib/jsc.png' /></a>");


            Write("<blockquote>");
            Write("<h2>Special pages</h2>");
            Write("<blockquote>");

            // like CON in filesystem?
            Write("<br /> " + "special page: " + "<a href='/robots.txt'>/robots.txt</a>");
            Write("<br /> " + "special page: " + "<a href='/xml'>/xml</a>");
            Write("<br /> " + "special page: " + "<a href='/crossdomain.xml'>/crossdomain.xml</a>");
            Write("<br /> " + "special page: " + "<a href='/favicon.ico'>/favicon.ico</a>");
            Write("<br /> " + "special page: " + "<a href='/jsc'>/jsc</a>");
            Write("<br /> " + "special page: " + "<a href='/view-source'>/view-source</a>");
            Write("</blockquote>");

            Write("<h2>Methods</h2>");
            Write("<blockquote>");
            foreach (var item in WebMethods)
            {
                WriteWebMethodForm(Write, item);
            }
            Write("</blockquote>");


            Write("<br /> Path: '" + Context.Request.Path + "'");
            Write("<br /> HttpMethod: '" + Context.Request.HttpMethod + "'");

            Write("<h2>Form</h2>");
            foreach (var item in Context.Request.Form.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.Form[item]));
                Write("</code>");
            }

            Write("<h2>QueryString</h2>");
            foreach (var item in Context.Request.QueryString.AllKeys)
            {
                Write("<br /> " + "<img src='http://i.msdn.microsoft.com/w144atby.pubproperty(en-us,VS.90).gif' /> <code>");
                Write(item);
                Write(" = ");
                Write(escapeXML(Context.Request.QueryString[item]));
                Write("</code>");
            }

            var ff = g.GetFiles();

            // http://msdn.microsoft.com/en-us/library/y47ychfe.aspx

            Write("<h2>Applications</h2>");
            Write("<blockquote>");

            foreach (var app in g.GetScriptApplications())
            {
                Write("<br /> ");

                Write("<img src='http://i.msdn.microsoft.com/yxcx7skw.pubclass(en-us,VS.90).gif' />");

                Write(" <code style='color: darkcyan;'>" + app.TypeName + "</code>");

                // var app_references = app.References.Select(
                //    item => ff.First(k => k.Name == item.AssemblyFile + ".js")
                //).ToArray();

                // var app_size = app_references.Sum(k => k.Length);

                // Write(" <span style='color: gray;'>(" + app_size + " bytes)</span>");

                foreach (var r in app.References)
                {
                    Write("<br /> &nbsp;&nbsp;&nbsp;&nbsp;");

                    Write("<img src='http://i.msdn.microsoft.com/dynimg/IC477625.png' />");
                    Write(" " + r.AssemblyFile);

                }
            }
            Write("</blockquote>");

            Write("<h2>Files</h2>");
            Write("<blockquote>");

            Action<string> separator = delegate { };

            foreach (var item in g.GetFiles())
            {
                separator(item.Name);

                Write(
                    "<br /> "
                    + " file: <a href='" + item.Name + "'>" + item.Name + "</a>" + " size: " + item.Length
                );


                // do we need this?
                //var itemref_csharp4 = item;

                separator =
                    next =>
                    {
                        if (next.TakeUntilLastOrEmpty("/") == item.Name.TakeUntilLastOrEmpty("/"))
                        {
                            return;
                        }

                        Write(
                            "<br /> "
                        );

                    };

            }
            Write("</blockquote>");
            Write("</blockquote>");

        }