GetFreshId() public method

public GetFreshId ( ) : int
return int
示例#1
0
文件: Main.cs 项目: fsoikin/Shovel
        static Session FreshSession(FileSystemDatabase fsd, Shovel.Instruction[] bytecode, string program)
        {
            var session = new Session();

            session.Id = fsd.GetFreshId();
            session.ShovelVmSources  = program;
            session.ShovelVmBytecode = Shovel.Api.SerializeBytecode(bytecode);
            return(session);
        }
示例#2
0
文件: Main.cs 项目: fsoikin/Shovel
        static void ServeSession(HttpListenerContext ctx, FileSystemDatabase fsd, Session session, string userInput)
        {
            var vm = Shovel.Api.RunVm(
                Shovel.Api.DeserializeBytecode(session.ShovelVmBytecode),
                ProgramSources(session.ShovelVmSources),
                Udps(session, userInput),
                session.ShovelVmState,
                totalTicksQuota: null,
                ticksUntilNextNapQuota: null,
                usedCellsQuota: null);

            if (Shovel.Api.VmProgrammingError(vm) != null)
            {
                ServeError(ctx, session, Shovel.Api.VmProgrammingError(vm).Message);
            }
            else if (Shovel.Api.VmUserDefinedPrimitiveError(vm) != null)
            {
                ServeError(ctx, session, Shovel.Api.VmUserDefinedPrimitiveError(vm).Message);
            }
            else if (Shovel.Api.VmExecutionComplete(vm))
            {
                using (var sw = new StreamWriter(ctx.Response.OutputStream)) {
                    sw.Write("<!DOCTYPE html>\n");
                    sw.Write(session.PageContent.ToString());
                    sw.Write("<p>Program execution completed.</p>");
                    sw.Write("<a href='/' id='restart-link'>Enter another program.</p>");
                    sw.Write("<script>\n");
                    sw.Write("document.getElementById('restart-link').focus()\n");
                    sw.Write("</script>\n");
                }
            }
            else
            {
                session.ShovelVmState = Shovel.Api.SerializeVmState(vm);
                session.Id            = fsd.GetFreshId();
                session.Save(fsd);
                using (var sw = new StreamWriter(ctx.Response.OutputStream)) {
                    sw.Write("<!DOCTYPE html>\n");
                    sw.Write(session.PageContent.ToString());
                    sw.Write("<form action='/' method='get'>");
                    sw.Write("<input type='text' name='input' id='shovel-input'/>");
                    sw.Write("<input type='submit' value='Submit'/>");
                    sw.Write(String.Format(
                                 "<input type='hidden' name='sessionid' value='{0}' id='shovel-input'/>",
                                 session.Id)
                             );
                    sw.Write("</form>");
                    sw.Write("<script>\n");
                    sw.Write("document.getElementById('shovel-input').focus()\n");
                    sw.Write("</script>\n");
                }
            }
            ctx.Response.OutputStream.Close();
        }
示例#3
0
文件: Main.cs 项目: ichaos/Shovel
 static Session FreshSession(FileSystemDatabase fsd, Shovel.Instruction[] bytecode, string program)
 {
     var session = new Session ();
     session.Id = fsd.GetFreshId ();
     session.ShovelVmSources = program;
     session.ShovelVmBytecode = Shovel.Api.SerializeBytecode (bytecode);
     return session;
 }
示例#4
0
文件: Main.cs 项目: ichaos/Shovel
 static void ServeSession(HttpListenerContext ctx, FileSystemDatabase fsd, Session session, string userInput)
 {
     var vm = Shovel.Api.RunVm (
         Shovel.Api.DeserializeBytecode (session.ShovelVmBytecode),
         ProgramSources (session.ShovelVmSources),
         Udps (session, userInput),
         session.ShovelVmState,
         totalTicksQuota: null,
         ticksUntilNextNapQuota: null,
         usedCellsQuota: null);
     if (Shovel.Api.VmProgrammingError (vm) != null) {
         ServeError (ctx, session, Shovel.Api.VmProgrammingError (vm).Message);
     } else if (Shovel.Api.VmUserDefinedPrimitiveError (vm) != null) {
         ServeError (ctx, session, Shovel.Api.VmUserDefinedPrimitiveError (vm).Message);
     } else if (Shovel.Api.VmExecutionComplete (vm)) {
         using (var sw = new StreamWriter(ctx.Response.OutputStream)) {
             sw.Write ("<!DOCTYPE html>\n");
             sw.Write (session.PageContent.ToString ());
             sw.Write ("<p>Program execution completed.</p>");
             sw.Write ("<a href='/' id='restart-link'>Enter another program.</p>");
             sw.Write ("<script>\n");
             sw.Write ("document.getElementById('restart-link').focus()\n");
             sw.Write ("</script>\n");
         }
     } else {
         session.ShovelVmState = Shovel.Api.SerializeVmState (vm);
         session.Id = fsd.GetFreshId ();
         session.Save (fsd);
         using (var sw = new StreamWriter(ctx.Response.OutputStream)) {
             sw.Write ("<!DOCTYPE html>\n");
             sw.Write (session.PageContent.ToString ());
             sw.Write ("<form action='/' method='get'>");
             sw.Write ("<input type='text' name='input' id='shovel-input'/>");
             sw.Write ("<input type='submit' value='Submit'/>");
             sw.Write (String.Format (
                 "<input type='hidden' name='sessionid' value='{0}' id='shovel-input'/>",
                 session.Id)
             );
             sw.Write ("</form>");
             sw.Write ("<script>\n");
             sw.Write ("document.getElementById('shovel-input').focus()\n");
             sw.Write ("</script>\n");
         }
     }
     ctx.Response.OutputStream.Close ();
 }