private void parseRepositoryDirectory(JSONResponse jresponse, ref RRepositoryDirectoryDetails directoryDetails)
        {
            Boolean systemDirectory      = default(Boolean);
            List <RRepositoryFile> files = new List <RRepositoryFile>();

            JObject jdir = jresponse.JSONMarkup;

            if (!(jdir == null))
            {
                String name = JSONUtilities.trimXtraQuotes(jdir["directory"].ToString());
                if ((name == Constants.SYSTEM_SHARED) || (name == Constants.SYSTEM_RESTRICTED) || (name == Constants.SYSTEM_PUBLIC))
                {
                    systemDirectory = true;
                }
                else
                {
                    systemDirectory = false;
                }

                if (!(jdir["files"] == null))
                {
                    JArray jvalues = jdir["files"].Value <JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            RRepositoryFile file = new RRepositoryFile(new JSONResponse(j.Value <JObject>(), true, "", 0), m_client);
                            files.Add(file);
                        }
                    }
                }

                directoryDetails = new RRepositoryDirectoryDetails(name, systemDirectory, files);
            }
        }
Example #2
0
        static public void copyDirectory(String source, String destination, List <RRepositoryFile> files, RClient client, String uri)
        {
            StringBuilder data      = new StringBuilder();
            StringBuilder filenames = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&directory=" + HttpUtility.UrlEncode(source));
            data.Append("&destination=" + HttpUtility.UrlEncode(destination));

            if (!(files == null))
            {
                foreach (var file in files)
                {
                    if (filenames.Length != 0)
                    {
                        filenames.Append(",");
                        filenames.Append(file.about().filename);
                    }
                    else
                    {
                        filenames.Append(file.about().filename);
                    }
                }
            }
            data.Append("&filename=" + HttpUtility.UrlEncode(filenames.ToString()));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
        }
Example #3
0
        static public String ping(RProjectDetails details, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            RProjectDetails projectDetails = default(RProjectDetails);

            RProjectBaseImpl.parseProject(jresponse, ref projectDetails);
            String returnValue = "";

            if (!(projectDetails == null))
            {
                returnValue = System.Convert.ToString(projectDetails.islive);
            }
            else
            {
                returnValue = System.Convert.ToString(false);
            }

            return(returnValue);
        }
        /// <summary>
        /// Lists the results associated with this Execution
        /// </summary>
        /// <returns>List of RProjectResult objects</returns>
        /// <remarks></remarks>
        public List <RProjectResult> listResults()
        {
            StringBuilder data = new StringBuilder();

            //set the url
            String uri = Constants.RPROJECTEXECUTERESULTLIST;

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&execution=" + HttpUtility.UrlEncode(m_executionDetails.id));
            data.Append("&project=" + HttpUtility.UrlEncode(m_projectDetails.id));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref m_client);

            List <RProjectResult> returnValue = new List <RProjectResult>();

            if (!(jresponse.JSONMarkup["execution"] == null))
            {
                JObject jexec = jresponse.JSONMarkup["execution"].Value <JObject>();
                if (!(jexec["results"] == null))
                {
                    JArray jvalues = jexec["results"].Value <JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            returnValue.Add(new RProjectResult(new JSONResponse(j.Value <JObject>(), true, "", 0), m_client));
                        }
                    }
                }
            }

            return(returnValue);
        }
Example #5
0
        static public RProject saveAs(RProjectDetails details, ProjectDropOptions options, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));
            data.Append("&name=" + HttpUtility.UrlEncode(details.name));
            data.Append("&descr=" + HttpUtility.UrlEncode(details.descr));
            data.Append("&longdescr=" + HttpUtility.UrlEncode(details.longdescr));
            data.Append("&projectcookie=" + HttpUtility.UrlEncode(details.cookie));
            data.Append("&shared=" + details.sharedUsers.ToString());

            if (!(options == null))
            {
                data.Append("&dropworkspace=" + options.dropWorkspace.ToString());
                data.Append("&dropdirectory=" + options.dropDirectory.ToString());
                data.Append("&drophistory=" + options.dropHistory.ToString());
            }

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);

            RProject returnValue = default(RProject);

            returnValue = new RProject(jresponse, client);
            return(returnValue);
        }
        /// <summary>
        /// Grant repository file to another user
        /// </summary>
        /// <param name="newauthor">name of the user to grant authorship</param>
        /// <param name="revokeauthor">name of the user to revoke authorship</param>
        /// <returns>RRepositoryFile object</returns>
        /// <remarks></remarks>
        public RRepositoryFile grant(String newauthor, String revokeauthor)
        {
            RRepositoryFile returnValue = default(RRepositoryFile);
            StringBuilder   data        = new StringBuilder();

            //set the url
            String uri = Constants.RREPOSITORYFILEGRANT;

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&filename=" + HttpUtility.UrlEncode(m_fileDetails.filename));
            data.Append("&directory=" + HttpUtility.UrlEncode(m_fileDetails.directory));
            data.Append("&newauthor=" + HttpUtility.UrlEncode(newauthor));
            data.Append("&revokeauthor=" + HttpUtility.UrlEncode(revokeauthor));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref m_client);

            if (!(jresponse.JSONMarkup["repository"] == null))
            {
                JObject jrepo = jresponse.JSONMarkup["repository"].Value <JObject>();
                if (!(jrepo["file"] == null))
                {
                    JObject jfile = jrepo["file"].Value <JObject>();
                    returnValue = new RRepositoryFile(new JSONResponse(jfile, true, "", 0), m_client);
                }
            }

            return(returnValue);
        }
        static public RProject createProject(String name, String descr, ProjectCreationOptions options, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&projectname=" + HttpUtility.UrlEncode(name));
            data.Append("&projectdescr=" + HttpUtility.UrlEncode(descr));

            if (!(options == null))
            {
                data.Append("&blackbox=" + options.blackbox.ToString());

                if (!(options.rinputs == null))
                {
                    if (options.rinputs.Count > 0)
                    {
                        data.Append("&inputs=");
                        String sJSON = JSONSerialize.createJSONfromRData(options.rinputs);
                        data.Append(HttpUtility.UrlEncode(sJSON));
                        if (HTTPUtilities.DEBUGMODE == true)
                        {
                            Console.Write(sJSON);
                        }
                    }
                }

                if (!(options.preloadDirectory == null))
                {
                    data.Append("&preloadfilename=" + HttpUtility.UrlEncode(options.preloadDirectory.filename));
                    data.Append("&preloadfiledirectory=" + HttpUtility.UrlEncode(options.preloadDirectory.directory));
                    data.Append("&preloadfileauthor=" + HttpUtility.UrlEncode(options.preloadDirectory.author));
                    data.Append("&preloadfileversion=" + HttpUtility.UrlEncode(options.preloadDirectory.version));
                }

                if (!(options.preloadWorkspace == null))
                {
                    data.Append("&preloadobjectname=" + HttpUtility.UrlEncode(options.preloadWorkspace.filename));
                    data.Append("&preloadobjectdirectory=" + HttpUtility.UrlEncode(options.preloadWorkspace.directory));
                    data.Append("&preloadobjectauthor=" + HttpUtility.UrlEncode(options.preloadWorkspace.author));
                    data.Append("&preloadobjectversion=" + HttpUtility.UrlEncode(options.preloadWorkspace.version));
                }

                if (!(options.adoptionOptions == null))
                {
                    data.Append("&adoptworkspace=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptWorkspace));
                    data.Append("&adoptdirectory=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptDirectory));
                    data.Append("&adoptpackages=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptPackages));
                }

                data.Append("&cluster=" + HttpUtility.UrlEncode(options.gridCluster));
            }

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);

            RProject returnValue = new RProject(jresponse, client);

            return(returnValue);
        }
        static public List <RProject> listProjects(Boolean sortByLastModified, Boolean showPublicProjects, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&publicprojectsalso=" + showPublicProjects.ToString());
            data.Append("&publicprojectsonly=false");
            data.Append("&isordered=" + sortByLastModified.ToString());

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            List <RProject> returnValue = new List <RProject>();

            //Parse the response
            if (!(jresponse.JSONMarkup["projects"] == null))
            {
                JArray jvalues = jresponse.JSONMarkup["projects"].Value <JArray>();
                foreach (var j in jvalues)
                {
                    if (j.Type != JTokenType.Null)
                    {
                        returnValue.Add(new RProject(new JSONResponse(j.Value <JObject>(), true, "", 0), client));
                    }
                }
            }

            return(returnValue);
        }
        static public RRepositoryFile storeObject(RProjectDetails details, String name, Boolean sharedUser, Boolean published, String restricted, String descr, Boolean versioning, RClient client, String uri)
        {
            RRepositoryFile returnValue = default(RRepositoryFile);
            StringBuilder   data        = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));
            data.Append("&name=" + HttpUtility.UrlEncode(name));
            data.Append("&descr=" + HttpUtility.UrlEncode(descr));
            data.Append("&version=" + versioning.ToString());
            data.Append("&shared=" + sharedUser.ToString());
            data.Append("&published=" + published.ToString());
            data.Append("&restricted=" + HttpUtility.UrlEncode(restricted));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);

            if (!(jresponse.JSONMarkup["repository"] == null))
            {
                JObject jrepo = jresponse.JSONMarkup["repository"].Value <JObject>();
                if (!(jrepo["file"] == null))
                {
                    JObject jfile = jrepo["file"].Value <JObject>();
                    returnValue = new RRepositoryFile(new JSONResponse(jfile, true, "", 0), client);
                }
            }

            return(returnValue);
        }
Example #10
0
        static public RProjectFile uploadFile(RProjectDetails details, String file, DirectoryUploadOptions options, RClient client, String uri)
        {
            RProjectFile  returnValue = default(RProjectFile);
            StringBuilder data        = new StringBuilder();
            Dictionary <String, String> parameters = new Dictionary <String, String>();

            parameters.Add("format", "json");
            parameters.Add("project", HttpUtility.UrlEncode(details.id));

            //create the input String
            if (!(options == null))
            {
                parameters.Add("filename", HttpUtility.UrlEncode(options.filename));
                parameters.Add("descr", HttpUtility.UrlEncode(options.descr));
                parameters.Add("overwrite", options.overwrite.ToString());
            }
            else
            {
                parameters.Add("filename", HttpUtility.UrlEncode(Path.GetFileName(file)));
            }
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTFileUploadPost(uri, parameters, file, ref client);

            if (!(jresponse.JSONMarkup["directory"] == null))
            {
                JObject jdir = jresponse.JSONMarkup["directory"].Value <JObject>();
                if (!(jdir["file"] == null))
                {
                    JObject jfile = jdir["file"].Value <JObject>();
                    returnValue = new RProjectFile(new JSONResponse(jfile, true, "", 0), client, details.id);
                }
            }

            return(returnValue);
        }
        static public List <RData> getObject(RProjectDetails details, List <String> objectNames, Boolean encodeDataFramePrimitiveAsVector, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));
            if (!(objectNames == null))
            {
                if (objectNames.Count > 0)
                {
                    data.Append("&name=");
                    foreach (var s in objectNames)
                    {
                        data.Append(HttpUtility.UrlEncode(s) + ",");
                    }
                    data.Remove(data.Length - 1, 1);
                }
            }
            data.Append("&encodeDataFramePrimitiveAsVector=" + encodeDataFramePrimitiveAsVector.ToString());

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            List <RData> returnValue = new List <RData>();

            returnValue = JSONUtilities.parseRObjects(jresponse.JSONMarkup);

            return(returnValue);
        }
Example #12
0
        static public RProjectFile loadFile(RProjectDetails details, RRepositoryFile file, RClient client, String uri)
        {
            RProjectFile  returnValue = default(RProjectFile);
            StringBuilder data        = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));
            data.Append("&filename=" + HttpUtility.UrlEncode(file.about().filename));
            data.Append("&directory=" + HttpUtility.UrlEncode(file.about().directory));
            data.Append("&author=" + HttpUtility.UrlEncode(file.about().author));
            data.Append("&version=" + HttpUtility.UrlEncode(file.about().version));
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);

            if (!(jresponse.JSONMarkup["directory"] == null))
            {
                JObject jdir = jresponse.JSONMarkup["directory"].Value <JObject>();
                if (!(jdir["file"] == null))
                {
                    JObject jfile = jdir["file"].Value <JObject>();
                    returnValue = new RProjectFile(new JSONResponse(jfile, true, "", 0), client, details.id);
                }
            }

            return(returnValue);
        }
Example #13
0
        static public RProjectFile writeFile(RProjectDetails details, String text, DirectoryUploadOptions options, RClient client, String uri)
        {
            RProjectFile  returnValue = default(RProjectFile);
            StringBuilder data        = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));
            data.Append("&text=" + HttpUtility.UrlEncode(text));
            if (!(options == null))
            {
                data.Append("&filename=" + HttpUtility.UrlEncode(options.filename));
                data.Append("&descr=" + HttpUtility.UrlEncode(options.descr));
                data.Append("&overwrite=" + options.overwrite.ToString());
            }

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);

            if (!(jresponse.JSONMarkup["directory"] == null))
            {
                JObject jdir = jresponse.JSONMarkup["directory"].Value <JObject>();
                if (!(jdir["file"] == null))
                {
                    JObject jfile = jdir["file"].Value <JObject>();
                    returnValue = new RProjectFile(new JSONResponse(jfile, true, "", 0), client, details.id);
                }
            }

            return(returnValue);
        }
Example #14
0
        static public RRepositoryFile fetchFile(String filename, String author, String directory, String version, RClient client, String uri)
        {
            RRepositoryFile returnValue = default(RRepositoryFile);
            StringBuilder   data        = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&filename=" + HttpUtility.UrlEncode(filename));
            data.Append("&directory=" + HttpUtility.UrlEncode(directory));
            data.Append("&author=" + HttpUtility.UrlEncode(author));
            data.Append("&version=" + HttpUtility.UrlEncode(version));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            if (!(jresponse.JSONMarkup["repository"] == null))
            {
                JObject jrepo = jresponse.JSONMarkup["repository"].Value <JObject>();
                if (!(jrepo["file"] == null))
                {
                    JObject jfile = jrepo["file"].Value <JObject>();
                    returnValue = new RRepositoryFile(new JSONResponse(jfile, true, "", 0), client);
                }
            }

            return(returnValue);
        }
        /// <summary>
        /// Update repository file
        /// </summary>
        /// <param name="restricted">indicates if file is restricted</param>
        /// <param name="sharedUser">indicates if file is shared</param>
        /// <param name="published">indicates if file is published</param>
        /// <param name="descr">description of the file</param>
        /// <param name="inputs">description of inputs to the script</param>
        /// <param name="outputs">description of outputs from the script</param>
        /// <returns>RRepositoryFile object</returns>
        /// <remarks></remarks>
        public RRepositoryFile update(String restricted, Boolean sharedUser, Boolean published, String descr, String inputs, String outputs)
        {
            RRepositoryFile returnValue = default(RRepositoryFile);
            StringBuilder   data        = new StringBuilder();

            //set the url
            String uri = Constants.RREPOSITORYFILEUPDATE;

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&filename=" + HttpUtility.UrlEncode(m_fileDetails.filename));
            data.Append("&directory=" + HttpUtility.UrlEncode(m_fileDetails.directory));
            data.Append("&shared=" + sharedUser.ToString());
            data.Append("&published=" + published.ToString());
            data.Append("&restricted=" + HttpUtility.UrlEncode(restricted));
            data.Append("&descr=" + HttpUtility.UrlEncode(descr));
            data.Append("&inputs=" + HttpUtility.UrlEncode(inputs));
            data.Append("&outputs=" + HttpUtility.UrlEncode(outputs));
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref m_client);

            if (!(jresponse.JSONMarkup["repository"] == null))
            {
                JObject jrepo = jresponse.JSONMarkup["repository"].Value <JObject>();
                if (!(jrepo["file"] == null))
                {
                    JObject jfile = jrepo["file"].Value <JObject>();
                    returnValue = new RRepositoryFile(new JSONResponse(jfile, true, "", 0), m_client);
                }
            }

            return(returnValue);
        }
        /// <summary>
        /// Rename repository-managed user directory.
        /// </summary>
        /// <param name="destination">New name of the directory</param>
        /// <returns>RRepositoryDirectory object</returns>
        /// <remarks></remarks>
        public RRepositoryDirectory rename(String destination)
        {
            RRepositoryDirectory returnValue = default(RRepositoryDirectory);
            StringBuilder        data        = new StringBuilder();

            //set the url
            String uri = Constants.RREPOSITORYDIRECTORYRENAME;

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&directory=" + HttpUtility.UrlEncode(m_directoryDetails.name));
            data.Append("&destination=" + HttpUtility.UrlEncode(destination.Trim()));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref m_client);

            if (!(jresponse.JSONMarkup["repository"] == null))
            {
                JObject jrepo = jresponse.JSONMarkup["repository"].Value <JObject>();
                if (!(jrepo["directory"] == null))
                {
                    JObject jdir = jrepo["directory"].Value <JObject>();
                    returnValue = new RRepositoryDirectory(new JSONResponse(jdir, true, "", 0), m_client);
                }
            }

            return(returnValue);
        }
Example #17
0
        static public List <RJob> listJobs(RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            List <RJob> returnValue = new List <RJob>();

            if (!(jresponse.JSONMarkup["jobs"] == null))
            {
                JArray jvalues = jresponse.JSONMarkup["jobs"].Value <JArray>();
                foreach (var j in jvalues)
                {
                    if (j.Type != JTokenType.Null)
                    {
                        returnValue.Add(new RJob(new JSONResponse(j.Value <JObject>(), true, "", 0), client));
                    }
                }
            }


            return(returnValue);
        }
Example #18
0
        static public List <RProjectFile> listFiles(RProjectDetails details, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&project=" + HttpUtility.UrlEncode(details.id));

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTGet(uri, data.ToString(), ref client);

            List <RProjectFile> returnValue = new List <RProjectFile>();

            if (!(jresponse.JSONMarkup["directory"] == null))
            {
                JObject jdir = jresponse.JSONMarkup["directory"].Value <JObject>();
                if (!(jdir["files"] == null))
                {
                    JArray jvalues = jdir["files"].Value <JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            returnValue.Add(new RProjectFile(new JSONResponse(j.Value <JObject>(), true, "", 0), client, details.id));
                        }
                    }
                }
            }

            return(returnValue);
        }
 internal RProjectResult(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseProjectResult(jresponse, ref m_resultDetails);
     }
 }
Example #20
0
 static public void parseConsole(JSONResponse jresponse, ref String console)
 {
     if (!(jresponse.JSONMarkup["execution"] == null))
     {
         JObject jscriptexec = jresponse.JSONMarkup["execution"].Value <JObject>();
         console = JSONUtilities.trimXtraQuotes(jscriptexec["console"].Value <string>());
     }
 }
 internal RProjectResult(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseProjectResult(jresponse, ref m_resultDetails);
     }
 }
 internal RRepositoryScript(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryScript(jresponse, ref m_scriptDetails);
     }
 }
 internal RRepositoryDirectory(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryDirectory(jresponse, ref m_directoryDetails);
     }
 }
Example #24
0
 internal RScriptExecution(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseScriptExecution(jresponse, ref m_executionDetails, ref m_projectDetails);
     }
 }
 internal RRepositoryDirectory(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryDirectory(jresponse, ref m_directoryDetails);
     }
 }
 internal RJob(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseJob(jresponse, ref m_jobDetails);
     }
 }
 internal RProjectPackage(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseProjectPackage(jresponse, ref m_packageDetails);
     }
 }
 internal RRepositoryScript(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryScript(jresponse, ref m_scriptDetails);
     }
 }
 internal RScriptExecution(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseScriptExecution(jresponse, ref m_executionDetails, ref m_projectDetails);
     }
 }
Example #30
0
 internal RUser(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseUser(jresponse, ref m_userDetails);
     }
 }
 internal RRepositoryFile(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryFile(jresponse, ref m_fileDetails);
     }
 }
Example #32
0
 internal RJob(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseJob(jresponse, ref m_jobDetails);
     }
 }
 internal RRepositoryFile(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseRepositoryFile(jresponse, ref m_fileDetails);
     }
 }
 internal RProjectPackage(JSONResponse jresponse, RClient client)
 {
     m_client = client;
     if (!(jresponse == null))
     {
         parseProjectPackage(jresponse, ref m_packageDetails);
     }
 }
        static public void releaseProjects(RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
        }
 internal RProjectFile(JSONResponse jresponse, RClient client, String project)
 {
     m_client = client;
     m_project = project;
     if (!(jresponse == null))
     {
         parseProjectFile(jresponse, ref m_fileDetails);
     }
 }
Example #37
0
 internal RProjectFile(JSONResponse jresponse, RClient client, String project)
 {
     m_client  = client;
     m_project = project;
     if (!(jresponse == null))
     {
         parseProjectFile(jresponse, ref m_fileDetails);
     }
 }
        static public void autosaveProjects(Boolean save, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&enable=" + save.ToString().ToLower());
            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
        }
        private void parseRepositoryScript(JSONResponse jresponse, ref RRepositoryScriptDetails scriptDetails)
        {
            List<Dictionary<String, String>> inputs = new List<Dictionary<String, String>>();
            List<Dictionary<String, String>> outputs = new List<Dictionary<String, String>>();
            Dictionary<String, String> dic = new Dictionary<String, String>();

            JObject jscript = jresponse.JSONMarkup;
            if (!(jscript == null))
            {
                String name = JSONUtilities.trimXtraQuotes(jscript["name"].Value<string>());
                String descr = JSONUtilities.trimXtraQuotes(jscript["descr"].Value<string>());

                if (!(jscript["inputs"] == null))
                {
                    JArray jvalues = jscript["inputs"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            dic = new Dictionary<String, String>();
                            dic.Add("name", JSONUtilities.trimXtraQuotes(j["name"].Value<String>()));
                            dic.Add("rclass", JSONUtilities.trimXtraQuotes(j["rclass"].Value<String>()));
                            dic.Add("descr", JSONUtilities.trimXtraQuotes(j["descr"].Value<String>()));
                            dic.Add("type", JSONUtilities.trimXtraQuotes(j["type"].Value<String>()));
                            inputs.Add(dic);
                        }
                    }
                }

                if (!(jscript["outputs"] == null))
                {
                    JArray jvalues = jscript["outputs"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            dic = new Dictionary<String, String>();
                            dic.Add("name", JSONUtilities.trimXtraQuotes(j["name"].Value<String>()));
                            dic.Add("rclass", JSONUtilities.trimXtraQuotes(j["rclass"].Value<String>()));
                            dic.Add("descr", JSONUtilities.trimXtraQuotes(j["descr"].Value<String>()));
                            dic.Add("type", JSONUtilities.trimXtraQuotes(j["type"].Value<String>()));
                            outputs.Add(dic);
                        }
                    }
                }

                scriptDetails = new RRepositoryScriptDetails(descr, inputs, name, outputs);

            }
        }
        private void parseProjectPackage(JSONResponse jresponse, ref RProjectPackageDetails packageDetails)
        {
            JObject jprojectfile = jresponse.JSONMarkup;
            if (!(jprojectfile == null))
            {
                String descr = JSONUtilities.trimXtraQuotes(jprojectfile["descr"].Value<String>());
                String name = JSONUtilities.trimXtraQuotes(jprojectfile["name"].Value<String>());
                String repo = JSONUtilities.trimXtraQuotes(jprojectfile["repo"].Value<String>());
                String status = JSONUtilities.trimXtraQuotes(jprojectfile["status"].Value<String>());
                String version = JSONUtilities.trimXtraQuotes(jprojectfile["version"].Value<String>());
                Boolean attached = jprojectfile["attached"].Value<Boolean>();

                packageDetails = new RProjectPackageDetails(descr, name, repo, status, version, attached);
            }
        }
        /// <summary>
        /// Take the response from an HTTP POST/GET and check the "success" and "error" properties,  then create a 'JSONResponse instance
        /// </summary>
        /// <param name="responseText">JSON markup to parse</param>
        /// <returns>JSONRepsonse object</returns>
        /// <remarks></remarks>
        public static JSONResponse checkForSuccess(String responseText)
        {
            JObject jresponse = default(JObject);
            String sSuccess = "";
            String errormsg = "";
            String console = "";
            int errorcode = 0;
            Boolean success = false;

            JObject deployrRoot = null;

            try
            {
                //let json.net parse the response
                jresponse = JObject.Parse(responseText);
                //get the deployr/response tree
                deployrRoot = jresponse["deployr"]["response"].Value<JObject>();

                //check for success
                sSuccess = deployrRoot["success"].Value<String>();
                if (sSuccess.ToLower() == "false")
                {
                    errormsg = deployrRoot["error"].Value<string>();
                    errorcode = deployrRoot["errorCode"].Value<int>();
                    success = false;
                }
                else
                {
                    success = true;
                }
                if (!(deployrRoot["execution"] == null))
                {
                    JObject jscriptexec = deployrRoot["execution"].Value<JObject>();
                    console = jscriptexec["console"].Value<string>();
                }

            }
            catch
            {
            }

            //create the JSONResponse class
            JSONResponse returnValue = new JSONResponse(deployrRoot, success, errormsg, console, errorcode);

            return returnValue;
        }
        private void parseProjectFile(JSONResponse jresponse, ref RProjectFileDetails fileDetails)
        {
            JObject jprojectfile = jresponse.JSONMarkup;
            if (!(jprojectfile == null))
            {
                String descr = JSONUtilities.trimXtraQuotes(jprojectfile["descr"].Value<String>());
                String name = JSONUtilities.trimXtraQuotes(jprojectfile["filename"].Value<String>());
                int size = jprojectfile["length"].Value<int>();
                String type = JSONUtilities.trimXtraQuotes(jprojectfile["type"].Value<String>());
                String url = JSONUtilities.trimXtraQuotes(jprojectfile["url"].Value<String>());
                String category = JSONUtilities.trimXtraQuotes(jprojectfile["category"].Value<String>());

                fileDetails = new RProjectFileDetails(descr, name, size, type, url, category);
            }
        }
 private void parseScriptExecution(JSONResponse jresponse, ref RProjectExecutionDetails executionDetails, ref RProjectDetails projectDetails)
 {
     RProjectBaseImpl.parseProjectExecution(jresponse, ref executionDetails, ref projectDetails, m_client);
 }
 private void parseProject(JSONResponse jresponse, ref RProjectDetails m_projectDetails)
 {
     RProjectBaseImpl.parseProject(jresponse, ref m_projectDetails);
 }
        private void parseJob(JSONResponse jresponse, ref RJobDetails jobDetails)
        {
            String descr = "";
            String id = "";
            String name = "";
            int onrepeat = 0;
            String project = "";
            long schedinterval = 0;
            int schedrepeat = 0;
            long schedstart = 0;
            String status = "";
            String statusMsg = "";
            long timeStart = 0;
            long timeCode = 0;
            long timeTotal = 0;
            String tag = "";
            JObject jjob = default(JObject);

            if (jresponse.JSONMarkup["job"].Type == JTokenType.Object)
            {
                jjob = jresponse.JSONMarkup["job"].Value<JObject>();
            }
            else
            {
                jjob = jresponse.JSONMarkup;
            }
            if (!(jjob == null))
            {
                descr = JSONUtilities.trimXtraQuotes(jjob["descr"].Value<String>());
                id = JSONUtilities.trimXtraQuotes(jjob["job"].Value<String>());
                name = JSONUtilities.trimXtraQuotes(jjob["name"].Value<String>());
                onrepeat = Convert.ToInt32(jjob["onrepeat"].Value<String>());
                project = JSONUtilities.trimXtraQuotes(jjob["project"].Value<String>());
                schedinterval = Convert.ToInt64(jjob["schedinterval"].Value<String>());
                schedrepeat = Convert.ToInt32(jjob["schedrepeat"].Value<String>());
                schedstart = Convert.ToInt64(jjob["schedstart"].Value<String>());
                status = JSONUtilities.trimXtraQuotes(jjob["status"].Value<String>());
                statusMsg = JSONUtilities.trimXtraQuotes(jjob["statusMsg"].Value<String>());
                timeStart = Convert.ToInt64(jjob["timeStart"].Value<String>());
                timeCode = Convert.ToInt64(jjob["timeCode"].Value<String>());
                timeTotal = Convert.ToInt64(jjob["timeTotal"].Value<String>());
                tag = JSONUtilities.trimXtraQuotes(jjob["tag"].Value<String>());

                jobDetails = new RJobDetails(descr, id, name, onrepeat, project, schedinterval, schedrepeat, schedstart, status, statusMsg, timeStart, timeCode, timeTotal, tag);

            }
        }
        public static void parseProjectExecution(JSONResponse jresponse, ref RProjectExecutionDetails executionDetails, ref RProjectDetails projectDetails, RClient client)
        {
            List<RProjectFile> projectfiles = new List<RProjectFile>();
            List<RRepositoryFile> repositoryFiles = new List<RRepositoryFile>();
            List<RProjectResult> results = new List<RProjectResult>();
            List<String> warnings = new List<String>();
            List<RData> workspaceObjects = new List<RData>();
            JArray jvalues;
            JObject jrepo;

            if (!(jresponse.JSONMarkup["execution"] == null))
            {
                JObject jscriptexec = jresponse.JSONMarkup["execution"].Value<JObject>();

                String code = JSONUtilities.trimXtraQuotes(jscriptexec["code"].Value<string>());
                long timeStart = jscriptexec["timeStart"].Value<long>();
                long timeCode = jscriptexec["timeCode"].Value<long>();
                long timeTotal = jscriptexec["timeTotal"].Value<long>();
                String tag = JSONUtilities.trimXtraQuotes(jscriptexec["tag"].Value<string>());
                String console = JSONUtilities.trimXtraQuotes(jscriptexec["console"].Value<string>());
                String errorDescr = jresponse.ErrorMsg;
                int errorCode = jresponse.ErrorCode;
                String id = JSONUtilities.trimXtraQuotes(jscriptexec["execution"].Value<string>());
                Boolean interrupted = Convert.ToBoolean(jscriptexec["interrupted"].Value<string>());

                if (!(jscriptexec["results"] == null))
                {
                    jvalues = jscriptexec["results"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            results.Add(new RProjectResult(new JSONResponse(j.Value<JObject>(), true, "", 0), client));
                        }
                    }
                }

                if (!(jscriptexec["artifacts"] == null))
                {
                    jvalues = jscriptexec["artifacts"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            projectfiles.Add(new RProjectFile(new JSONResponse(j.Value<JObject>(), true, "", 0), client, id));
                        }
                    }
                }

                if (!(jscriptexec["warnings"] == null))
                {
                    jvalues = jscriptexec["warnings"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            warnings.Add(j.Value<string>());
                        }
                    }
                }

                if (!(jscriptexec["repository"] == null))
                {
                    jrepo = jscriptexec["repository"].Value<JObject>();

                    if (!(jrepo["files"] == null))
                    {
                        jvalues = jrepo["files"].Value<JArray>();
                        foreach (var j in jvalues)
                        {
                            if (j.Type != JTokenType.Null)
                            {
                                repositoryFiles.Add(new RRepositoryFile(new JSONResponse(j.Value<JObject>(), true, "", 0), client));
                            }
                        }
                    }
                }

                workspaceObjects = JSONUtilities.parseRObjects(jresponse.JSONMarkup);
                parseProject(jresponse, ref projectDetails);

                executionDetails = new RProjectExecutionDetails(projectfiles, code, timeStart, timeCode, timeTotal, tag, console, errorDescr, errorCode, id, interrupted, null, results, warnings, workspaceObjects);

            }
        }
        public static void parseProject(JSONResponse jresponse, ref RProjectDetails projectDetails)
        {
            List<String> authors = new List<String>();
            JObject jproject = default(JObject);

            if (jresponse.JSONMarkup["project"].Type == JTokenType.Object)
            {
                jproject = jresponse.JSONMarkup["project"].Value<JObject>();
            }
            else
            {
                jproject = jresponse.JSONMarkup;
            }
            if (!(jproject == null))
            {
                String cookie = JSONUtilities.trimXtraQuotes(jproject["cookie"].Value<string>());
                String descr = JSONUtilities.trimXtraQuotes(jproject["descr"].Value<string>());
                String id = JSONUtilities.trimXtraQuotes(jproject["project"].Value<string>());
                Boolean live = jproject["live"].Value<bool>();
                Boolean sharedUsers = jproject["shared"].Value<bool>();
                String longdescr = JSONUtilities.trimXtraQuotes(jproject["longdescr"].Value<string>());
                String modified = JSONUtilities.trimXtraQuotes(jproject["lastmodified"].Value<string>());
                String name = JSONUtilities.trimXtraQuotes(jproject["name"].Value<string>());
                String origin = JSONUtilities.trimXtraQuotes(jproject["origin"].Value<string>());

                if (!(jproject["authors"] == null))
                {
                    JArray jvalues = jproject["authors"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            authors.Add(j.Value<String>());
                        }
                    }
                }

                projectDetails = new RProjectDetails(cookie, descr, id, live, longdescr, modified, name, origin, sharedUsers, authors);

            }
        }
        private void parseRepositoryFile(JSONResponse jresponse, ref RRepositoryFileDetails fileDetails)
        {
            List<String> authors = new List<String>();

            JObject jfile = jresponse.JSONMarkup;
            if (!(jfile == null))
            {

                String category = JSONUtilities.trimXtraQuotes(jfile["category"].Value<string>());
                String filename = JSONUtilities.trimXtraQuotes(jfile["filename"].Value<string>());
                String author = JSONUtilities.trimXtraQuotes(jfile["author"].Value<string>());
                int length = jfile["length"].Value<int>();
                String type = JSONUtilities.trimXtraQuotes(jfile["type"].Value<string>());
                String url = JSONUtilities.trimXtraQuotes(jfile["url"].Value<string>());
                String latestby = JSONUtilities.trimXtraQuotes(jfile["latestby"].Value<string>());
                String lastModified = JSONUtilities.trimXtraQuotes(jfile["lastModified"].Value<string>());
                Boolean sharedUsers = jfile["shared"].Value<Boolean>();
                Boolean published = jfile["published"].Value<Boolean>();
                String restricted = JSONUtilities.trimXtraQuotes(jfile["restricted"].Value<string>());
                String access = JSONUtilities.trimXtraQuotes(jfile["access"].Value<string>());
                String directory = JSONUtilities.trimXtraQuotes(jfile["directory"].Value<string>());
                String inputs = "";
                if (!(jfile["inputs"] == null))
                {
                    inputs = JSONUtilities.trimXtraQuotes(jfile["inputs"].Value<string>());
                }
                String outputs = "";
                if (!(jfile["outputs"] == null))
                {
                    outputs = JSONUtilities.trimXtraQuotes(jfile["outputs"].Value<string>());
                }
                String version = JSONUtilities.trimXtraQuotes(jfile["version"].Value<string>());
                if (version == "null")
                {
                    version = "";
                }

                if (!(jfile["authors"] == null))
                {
                    JArray jvalues = jfile["authors"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            authors.Add(j.Value<string>());
                        }
                    }
                }

                fileDetails = new RRepositoryFileDetails(category,
                    filename,
                    author,
                    version,
                    latestby,
                    lastModified,
                    length,
                    type,
                    url,
                    sharedUsers,
                    published,
                    restricted,
                    access,
                    authors,
                    inputs,
                    outputs,
                    directory);

            }
        }
        private void parseProjectResult(JSONResponse jresponse, ref RProjectResultDetails resultDetails)
        {
            JObject jresult = jresponse.JSONMarkup;
            if (!(jresult == null))
            {
                String execution = JSONUtilities.trimXtraQuotes(jresult["execution"].Value<string>());
                String  name = JSONUtilities.trimXtraQuotes(jresult["filename"].Value<string>());
                int size = jresult["length"].Value<int>();
                String type = JSONUtilities.trimXtraQuotes(jresult["type"].Value<string>());
                String url = JSONUtilities.trimXtraQuotes(jresult["url"].Value<string>());

                resultDetails = new RProjectResultDetails(execution, name, size, type, url);
            }
        }
        private void parseRepositoryDirectory(JSONResponse jresponse, ref RRepositoryDirectoryDetails directoryDetails)
        {
            Boolean systemDirectory = default(Boolean);
            List<RRepositoryFile> files = new List<RRepositoryFile>();

            JObject jdir = jresponse.JSONMarkup;
            if (!(jdir == null))
            {

                String name = JSONUtilities.trimXtraQuotes(jdir["directory"].ToString());
                if ((name == Constants.SYSTEM_SHARED) || (name == Constants.SYSTEM_RESTRICTED) || (name == Constants.SYSTEM_PUBLIC))
                {
                    systemDirectory = true;
                }
                else
                {
                    systemDirectory = false;
                }

                if (!(jdir["files"] == null))
                {
                    JArray jvalues = jdir["files"].Value<JArray>();
                    foreach (var j in jvalues)
                    {
                        if (j.Type != JTokenType.Null)
                        {
                            RRepositoryFile file = new RRepositoryFile(new JSONResponse(j.Value<JObject>(), true, "", 0), m_client);
                            files.Add(file);
                        }
                    }
                }

                directoryDetails = new RRepositoryDirectoryDetails(name, systemDirectory, files);

            }
        }
 public static void parseConsole(JSONResponse jresponse, ref String console)
 {
     if (!(jresponse.JSONMarkup["execution"] == null))
     {
         JObject jscriptexec = jresponse.JSONMarkup["execution"].Value<JObject>();
         console = JSONUtilities.trimXtraQuotes(jscriptexec["console"].Value<string>());
     }
 }