Пример #1
0
        /// <summary>
        /// Loads the media bin assets asynchronously.
        /// </summary>
        /// <param name="containerUri">The container URI.</param>
        public void LoadMediaBinAssetsAsync(Uri containerUri)
        {
            DataServiceClient client = this.CreateDataServiceClient();

            client.LoadMediaBinCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, args.Error);

                    if (args.Error.GetType() == typeof(Exception))
                    {
                        throw args.Error;
                    }

                    return;
                }

                try
                {
                    MediaBin mediaBin = DataServiceTranslator.ConvertToMediaBin(args.Result);
                    this.OnLoadMediaBinAssetsCompleted(new DataEventArgs <MediaBin>(mediaBin));
                }
                catch (Exception e)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, e);
                    throw;
                }
            };

            client.LoadMediaBinAsync(containerUri);
        }
Пример #2
0
        /// <summary>
        /// Get the list of projects for the given user.
        /// </summary>
        /// <param name="userName">The username.</param>
        public void GetProjectsByUserAsync(string userName)
        {
            DataServiceClient client = this.CreateDataServiceClient();

            client.GetProjectsByUserCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, args.Error);

                    if (args.Error.GetType() == typeof(Exception))
                    {
                        throw args.Error;
                    }

                    return;
                }

                try
                {
                    List <Project> projects = DataServiceTranslator.ConvertToProjects(args.Result);
                    this.OnGetProjectsByUserCompleted(new DataEventArgs <List <Project> >(projects));
                }
                catch (Exception e)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, e);
                    throw;
                }
            };

            client.GetProjectsByUserAsync(userName);
        }
Пример #3
0
        /// <summary>
        /// Loads the title templates asynchronously.
        /// </summary>
        public void LoadTitleTemplatesAsync()
        {
            DataServiceClient client = this.CreateDataServiceClient();

            client.LoadTitleTemplatesCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, args.Error);

                    if (args.Error.GetType() == typeof(Exception))
                    {
                        throw args.Error;
                    }

                    return;
                }

                try
                {
                    List <TitleTemplate> titleTemplates = DataServiceTranslator.ConvertToTitleTemplates(args.Result);
                    this.OnLoadTitleTemplatesCompleted(new DataEventArgs <List <TitleTemplate> >(titleTemplates));
                }
                catch (Exception e)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, e);
                    throw;
                }
            };

            client.LoadTitleTemplatesAsync();
        }
Пример #4
0
        /// <summary>
        /// Saves the project asynchronously.
        /// </summary>
        /// <param name="project">The project.</param>
        public void SaveProjectAsync(Project project)
        {
            if (!this.isSaving)
            {
                this.isSaving = true;

                DataServiceClient client = this.CreateDataServiceClient();

                RCE.Services.Contracts.Project dataProject = DataServiceTranslator.ConvertToDataServiceProject(project);

                client.SaveProjectCompleted += (sender, args) =>
                {
                    this.isSaving = false;

                    if (args.Error != null)
                    {
                        client.Abort();
                        this.logger.Log(this.GetType().Name, args.Error);

                        if (args.Error.GetType() == typeof(Exception))
                        {
                            throw args.Error;
                        }

                        return;
                    }

                    this.OnSaveProjectCompleted(new DataEventArgs <bool>(args.Result));
                };

                client.SaveProjectAsync(dataProject);
            }
        }
Пример #5
0
        /// <summary>
        /// Loads the project asynchronously.
        /// </summary>
        /// <param name="projectUri">The project URI.</param>
        public void LoadProjectAsync(Uri projectUri)
        {
            this.OnLoadProjectCompleted(new DataEventArgs <Project>(null, null));

            if (projectUri == null)
            {
                return;
            }

            DataServiceClient client = this.CreateDataServiceClient();

            client.LoadProjectCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, args.Error);

                    if (args.Error.GetType() == typeof(Exception))
                    {
                        throw args.Error;
                    }

                    return;
                }

                try
                {
                    Project project = DataServiceTranslator.ConvertToProject(args.Result);
                    this.OnLoadProjectCompleted(new DataEventArgs <Project>(project));
                }
                catch (Exception e)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, e);
                    throw;
                }
            };

            client.LoadProjectAsync(projectUri);
        }
Пример #6
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (_client == null)
            {
                return;
            }
            // close connection
            switch (_client.State)
            {
            case CommunicationState.Faulted:
                _client.Abort();
                break;

            case CommunicationState.Closed:
                break;

            default:
                try
                {
                    _client.Close();
                }
                catch (CommunicationException)
                {
                    _client.Abort();
                }
                catch (TimeoutException)
                {
                    _client.Abort();
                }
                catch (Exception)
                {
                    _client.Abort();
                    throw;
                }
                break;
            }
        }
Пример #7
0
        /// <summary>
        /// Saves the project asynchronously.
        /// </summary>
        /// <param name="project">The project.</param>
        public void SaveProjectAsync(Project project)
        {
            if (!this.isSaving)
            {
                this.isSaving = true;

                DataServiceClient client = this.CreateDataServiceClient();

                RCE.Services.Contracts.Project dataProject = DataServiceTranslator.ConvertToDataServiceProject(project);

                string projectId = null;
                if (HtmlPage.Document.QueryString.TryGetValue("projectId", out projectId))
                {
                    dataProject.HighlightId = Guid.Parse(projectId);
                }

                client.SaveProjectCompleted += (sender, args) =>
                {
                    this.isSaving = false;

                    if (args.Error != null)
                    {
                        client.Abort();
                        this.logger.Log(this.GetType().Name, args.Error);

                        if (args.Error.GetType() == typeof(Exception))
                        {
                            throw args.Error;
                        }

                        return;
                    }

                    this.OnSaveProjectCompleted(new DataEventArgs <bool>(args.Result));
                };

                client.SaveProjectAsync(dataProject);
            }
        }
Пример #8
0
        /// <summary>
        /// Deletes the project.
        /// </summary>
        /// <param name="site">The uri of the poject.</param>
        public void DeleteProject(Uri site)
        {
            DataServiceClient client = this.CreateDataServiceClient();

            client.DeleteProjectCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    client.Abort();
                    this.logger.Log(this.GetType().Name, args.Error);

                    if (args.Error.GetType() == typeof(Exception))
                    {
                        throw args.Error;
                    }

                    return;
                }

                this.OnDeleteProjectCompleted(new DataEventArgs <bool>(args.Result));
            };

            client.DeleteProjectAsync(site);
        }