Exemple #1
0
 public void StopSingleInstance()
 {
     System.Console.WriteLine("Start Test : StopSingleInstance");
     Tasks.ITask JupyterNotebookTask = JupyterNotebookTool.FindTask(JNBFirstFile);
     Assert.True(JupyterNotebookTask.IsAlive());
     Assert.False(JupyterNotebookTask.IsEmpty());
     JupyterNotebookTool.StopTask(JNBFirstFile);
     System.Threading.Thread.Sleep(2000);
     JupyterNotebookTask = JupyterNotebookTool.FindTask(JNBFirstFile);
     Assert.False(JupyterNotebookTask.IsAlive());
     Assert.True(JupyterNotebookTask.IsEmpty());
     System.Console.WriteLine("End Test : StopSingleInstance");
 }
Exemple #2
0
        public bool StopJupyter(string id)
        {
            bool   result       = false;
            string ResourceName = $"{id}.ipynb";
            string ResourceNameWithoutExtension = id;
            string notebookDir  = DirectoryHelper.GetCodeDirectoryPath() + ResourceNameWithoutExtension;
            string ResourcePath = notebookDir + System.IO.Path.DirectorySeparatorChar + ResourceName;
            string Message      = "Error";

            System.Console.WriteLine("Resource Path " + ResourcePath);
            Dictionary <string, string> Result = new Dictionary <string, string>();
            //
            var obj = new
            {
                base_url     = "/",
                NotebookDir  = $"{notebookDir}",
                ResourcePath = $"{ResourcePath}"
            };

            //
            try
            {
                JupyterNotebook JNBTool             = this.jupyterClient.GetJupyterNotebookTool();
                ITask           JupyterNoteBookTask = JNBTool.FindTask(ResourcePath);
                if (JupyterNoteBookTask.IsEmpty())
                {
                    Message = "Error : There is no such task running";
                    // var inst = InstancePayload.Get();
                    // foreach(var item in inst)
                    // {
                    //     if(item.Id == id)
                    //     {
                    //         InstancePayload.Delete(id);
                    //         result = true;
                    //     }
                    // }
                }
                else
                {
                    JNBTool.StopTask(ResourcePath);
                    result = true;
                    InstancePayload.Delete(id);
                    Message = "Notebook successfully stop";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
            // Result.Add("Result", Message);
            return(result);
        }
Exemple #3
0
        public JsonResult Stop()
        {
            string ResourceName = Request.Query["name"].ToString();
            string ResourceNameWithoutExtension = ResourceName.Substring(0, ResourceName.LastIndexOf("."));
            string notebookDir  = DirectoryHelper.GetCodeDirectoryPath() + ResourceNameWithoutExtension;
            string ResourcePath = notebookDir + System.IO.Path.DirectorySeparatorChar + ResourceName; //http://localhost:5000//uploads/TestUser/code/HelloClass2.ipynb
            string Message      = "Error";

            System.Console.WriteLine("Resource Path " + ResourcePath);
            Dictionary <string, string> Result = new Dictionary <string, string>();
            var obj = new
            {
                base_url     = "/",
                NotebookDir  = $"{notebookDir}",
                ResourcePath = $"{ResourcePath}"
            };

            try
            {
                JupyterNotebook JNBTool             = this.jupyterClient.GetJupyterNotebookTool();
                ITask           JupyterNoteBookTask = JNBTool.FindTask(ResourcePath);
                if (JupyterNoteBookTask.IsEmpty())
                {
                    Message = "Error : There is no such task running";
                }
                else
                {
                    JNBTool.StopTask(ResourcePath);
                    Message = "Notebook successfully stop";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
            Result.Add("Result", Message);
            return(new JsonResult(Result));
        }