Beispiel #1
0
        /// <summary>Delete project by id.</summary>
        /// <param name="projectId">Id of the project to be deleted.</param>
        /// <returns>true if project was deleted successfully.</returns>
        /// <exception cref="Exceptions.ConnectionFailureException">Throws if network connection is down.</exception>
        /// <exception cref="Exceptions.UnathorizedException">Throws if provided cookies were obsolete.</exception>
        /// <exception cref="Exceptions.ForbiddenException">Throws if user doesn't have rights to delete this project.</exception>
        /// <exception cref="Exceptions.InternalSDKException">Throws for unhandled SDK exceptions.</exception>
        public async Task <bool> DeleteProjectAsync(string projectId)
        {
            var request = HttpWebClientHelper.CreateRequest(SdkMetadata, string.Format(FluxApiData.ProjectDeleteUrl, projectId), Cookies);

            request.Method = "DELETE";
            try
            {
                using (var response = await HttpWebClientHelper.GetResponseAsync(request))
                {
                    if (response != null)
                    {
                        var project = Projects.FirstOrDefault(x => x.Id == projectId);
                        if (projects != null && project != null)
                        {
                            project.Cookies = null;
                            projects.Remove(project);
                        }

                        return(true);
                    }
                }
            }
            catch (Exceptions.FluxException ex)
            {
                log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new Exceptions.InternalSDKException(ex.Message);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>Update list of projects for the current user. </summary>
        /// <exception cref="Exceptions.ConnectionFailureException">Throws if network connection is down.</exception>
        /// <exception cref="Exceptions.UnathorizedException">Throws if provided cookies were obsolete.</exception>
        /// <exception cref="Exceptions.ServerUnavailableException">Throws if Flux server is down.</exception>
        /// <exception cref="Exceptions.InternalSDKException">Throws for unhandled SDK exceptions.</exception>
        public async Task UpdateProjectsAsync()
        {
            var projectList = new List <Project>();
            var request     = HttpWebClientHelper.CreateRequest(SdkMetadata, FluxApiData.ProjectsUrl, Cookies);

            request.Method = "GET";
            request.Headers.Add("user", Id);
            try
            {
                using (var response = await HttpWebClientHelper.GetResponseAsync(request).ConfigureAwait(false))
                {
                    projectList = DataSerializer.Deserialize <List <Project> >(StreamUtils.GetDecompressedResponseStream(response));
                }
            }
            catch (Exceptions.FluxException ex)
            {
                log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new Exceptions.InternalSDKException(ex.Message);
            }

            Projects = projectList;
        }
Beispiel #3
0
        /// <summary>Create new project.</summary>
        /// <param name="projectName">name of the new project.</param>
        /// <returns>Porject instance if project was created successully.</returns>
        /// <exception cref="Exceptions.FluxException">Throws for internal SDK exceptions (Network is down, etc.).</exception>
        /// <exception cref="Exceptions.InternalSDKException">Throws for unhandled SDK exceptions.</exception>
        public async Task <Project> CreateNewProjectAsync(string projectName)
        {
            Project newProject = null;
            var     request    = HttpWebClientHelper.CreateRequest(SdkMetadata, FluxApiData.ProjectsUrl, Cookies);

            request.Method = "POST";

            try
            {
                string formParams = string.Format("user={0}&name={1}&app={2}", Uri.EscapeDataString(Id), Uri.EscapeDataString(projectName), Uri.EscapeDataString("blank"));
                byte[] bytes      = Encoding.ASCII.GetBytes(formParams);
                request.ContentLength = bytes.Length;
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                using (var response = await HttpWebClientHelper.GetResponseAsync(request))
                {
                    newProject = DataSerializer.Deserialize <Project>(StreamUtils.GetDecompressedResponseStream(response));
                    if (newProject != null)
                    {
                        newProject.Cookies     = Cookies;
                        newProject.SdkMetadata = SdkMetadata;
                    }

                    if (projects != null)
                    {
                        projects.Add(newProject);
                    }
                }
            }
            catch (Exceptions.FluxException ex)
            {
                log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw new Exceptions.InternalSDKException(ex.Message);
            }

            return(newProject);
        }