Ejemplo n.º 1
0
        /// <summary>
        /// Convert a CSharp project to Java (perform porting operation) for a project already present on codeporting.com.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="projectName"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool ConvertProject(string token, string projectName, ref string  error)
        {
            try
            {
                NameValueCollection parameters = new NameValueCollection();
                parameters.Add("token", token);
                parameters.Add("ProjectName", projectName);
                CommandHelper helper = new CommandHelper();
                string param = helper.PackCommandXML(parameters, true);
                string statusCode = string.Empty;
                string response = helper.ExecuteAPIMethod(baseURL + convertProjectCommand, param, ref statusCode);
                if (string.IsNullOrEmpty(response))
                {
                    error = "Error while conversion.";
                    return false;
                }
                Dictionary<string, string> dataDictionary = new Dictionary<string, string>();
                string get_error = string.Empty;
                string get_success = string.Empty;

                dataDictionary = helper.parseResponse(response, out get_success, out get_error);

                if (get_success.ToLower() == "false")
                {
                    error = get_error;
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                error = "Error while conversion.";
                return false;
            }

            return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Upload zipped CSharp project and add it as new project on CodePorting.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="zipFilePath"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool UploadProjectZip(string token, string zipFilePath, ref string error)
        {
            try
            {
                NameValueCollection parameters = new NameValueCollection();
                parameters.Add("token", token);
                CommandHelper helper = new CommandHelper();
                string param = helper.PackCommandXML(parameters, true);
                string statusCode = string.Empty;
                string response = string.Empty;
                string[] fileNames = new string[] { zipFilePath };

                helper.UploadFilesToRemoteUrl(baseURL + uploadZipCommand, fileNames, parameters);

            }
            catch (Exception ex)
            {
                error = "Error while uploading project";
            }
            return true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Port CSharp source string to java string.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="sourceCode"></param>
        /// <param name="error"></param>
        /// <param name="convertedCode"></param>
        /// <returns></returns>
        public bool PortSingleFile(string token, string sourceCode, ref string error, ref string convertedCode)
        {
            try
            {
                error = "";
                bool result = true;
                NameValueCollection parameters = new NameValueCollection();
                parameters.Add("token", SigninToken.Token);
                parameters.Add("SourceCode", sourceCode);
                CommandHelper helper = new CommandHelper();
                string param = helper.PackCommandXML(parameters, true);
                string statusCode = string.Empty;
                string response = helper.ExecuteAPIMethod(baseURL + snippetPortCommand, param, ref statusCode);
                if (string.IsNullOrEmpty(response))
                {
                    error = "Unable to connect to CodePorting.";
                    return false;
                }
                Dictionary<string, string> dataDictionary = new Dictionary<string, string>();
                dataDictionary = helper.parseResponse(response);

                //if (statusCode != "200")
                //{
                //    error = dataDictionary["error"];
                //    result = false;
                //}
                if (dataDictionary["success"].ToLower() == "false")
                {
                    error = dataDictionary["error"];
                    result = false;
                }

                convertedCode = dataDictionary["TargetCode"];
                return result;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            return false;
        }
Ejemplo n.º 4
0
        public string Signin(string userName, string password, ref string error)
        {
            //comboBoxListPortedFiles.Items.Clear();
            try
            {
                NameValueCollection parameters = new NameValueCollection();
                //parameters.Add("token", "5EF931D5-24D9-4640-BB21-112641312AB6");
                parameters.Add("LoginName", userName);
                parameters.Add("Password", password);
                string get_success = string.Empty;
                CommandHelper helper = new CommandHelper();
                string param = helper.PackCommandXML(parameters, true);
                string statusCode = string.Empty;
                string response = helper.ExecuteAPIMethod(baseURL + signInCommand, param, ref statusCode);

                if (string.IsNullOrEmpty(response))
                    return string.Empty;
                Dictionary<string, string> dataDictionary = new Dictionary<string, string>();
                string get_error = string.Empty;

                dataDictionary = helper.parseResponse(response, out get_success, out get_error);

                 return dataDictionary["Token"];

            }
            catch (Exception ex)
            {
                error = "Error while download ported project.";
                return string.Empty;
            }

            return string.Empty;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Download ported project as a zip from codeporting.com.
        /// </summary>
        /// <param name="token"></param>
        /// <param name="projectName"></param>
        /// <param name="fileName"></param>
        /// <param name="portedProjectsFolder"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool DownloadportedZipFile(string token,string projectName, string fileName, string portedProjectsFolder, ref string error)
        {
            //comboBoxListPortedFiles.Items.Clear();
            try
            {
                NameValueCollection parameters = new NameValueCollection();
                parameters.Add("token", SigninToken.Token);
                parameters.Add("ProjectName", projectName);
                parameters.Add("FileName", fileName);
                CommandHelper helper = new CommandHelper();
                string param = helper.PackCommandXML(parameters, true);
                string statusCode = string.Empty;
                string response = helper.ExecuteAPIMethodDownloadFile(baseURL + downloadPortedProjectCommand, param, portedProjectsFolder, ref statusCode);

                return true;
            }
            catch (Exception ex)
            {
                error = "Error while download ported project.";
                return false;
            }

            return true;
        }