//[HttpGet("{playground/{hash:string}")]
  public IActionResult Index(string hash)
  {
      var result = new Fsharp();
      
      if (!string.IsNullOrEmpty(hash)){
          var match = dataContext.GetByHash(hash);
          if (match!=null){
              result = match;
          }
      }
      
      return View(result);
      
      
      /*
      string content = "";
      
      var dirs =
          from d in Directory.EnumerateDirectories("saved")
          select d.Split(new[] { '/', '\\' }).Last();
          
      if (hash!=null && dirs.Contains(hash)){
          content = System.IO.File.ReadAllText("saved/"+hash+"/saved.txt");
      }
              
      var vm = new PlaygroundViewModel(){ 
          RecentHashes = dirs,
          Content=content
      };
      
      return View(vm);
      */
  }
 public async Task<IActionResult> Share([FromBody]Command command){
                 
     var fsharp = new Fsharp(){
         Owner = command.Owner,
         Content = command.Line
     };
     
     var saved = await dataContext.SaveAsync(fsharp);
     
     return new ObjectResult(saved.Hash);
 }
Exemplo n.º 3
0
		static DataContext()
		{
				requestQueue= new BufferBlock<FsharpSaveRequest>();
				Lookup = new List<Fsharp>();
				worker = new DataContextWorker(requestQueue,Lookup);

				var dirs =
				from d in Directory.EnumerateDirectories("saved")
				select d.Split(new[] { '/', '\\' }).Last();
				
				foreach (var hash in dirs){
					
					var fsharp = new Fsharp();
				
					fsharp.Owner = File.ReadAllText("saved/"+hash+"/owner");
					fsharp.Content = File.ReadAllText("saved/"+hash+"/content");
					fsharp.Hash=hash;
					
					Lookup.Add(fsharp);
				}
				
				worker.Process();
				
		}
Exemplo n.º 4
0
		public bool SetResult(Fsharp result){
			return _result.TrySetResult(result);
		}
Exemplo n.º 5
0
		public void Save(Fsharp fsharp){
			
			Lookup.Add(fsharp);
			
			var encoded = fsharp.Hash;

            var dir = "saved/"+encoded;
            
            Directory.CreateDirectory(dir);

            using(var fs = System.IO.File.Create(dir+"/content"))
            using(var writer = new StreamWriter(fs))
            using(var sr = new StringReader(fsharp.Content)){
                
                string line;
                while((line=sr.ReadLine())!=null){
                    writer.WriteLine(line);
                }
            }
			
			using(var fs = File.Create(dir+"/owner"))
			using(var writer = new StreamWriter(fs)){
				writer.Write(fsharp.Owner);
			}
			
		}
Exemplo n.º 6
0
		public async Task<Fsharp> SaveAsync(Fsharp fsharp){
			
			var request = new FsharpSaveRequest(){fsharp=fsharp};
			await requestQueue.SendAsync(request);
			var result = await request.GetResultAsync();
			return result;
			
		}