Esempio n. 1
0
        /// <summary>
        /// Creates the fetch job for the specified entity.
        /// </summary>
        /// <param name="entityId">The entity identifier.</param>
        /// <param name="resourceUrl">The resource URL.</param>
        /// <returns></returns>
        public static async Task CreateFetchJob(long entityId, string resourceUrl)
        {
            // Validation
            Guard.GreaterThan("entityId", entityId, 0);
            Guard.NotNullOrEmpty("resourceUrl", resourceUrl);

            // Create the fetch job request
            var fjr = new WebFetchJobRequest("File", entityId);

            fjr.Urls.Add(resourceUrl);

            // Create the fetch job
            await MConnector.Client.Jobs.CreateFetchJob(fjr);
        }
Esempio n. 2
0
        public static async Task <long> CreateFetchJob(long entityId, Uri resourceUrl)
        {
            // Validation
            Guard.GreaterThan("entityId", entityId, 0);
            Guard.NotNull("resourceUrl", resourceUrl);

            // Create the fetch job request
            var fjr = new WebFetchJobRequest("File", entityId);

            fjr.Urls.Add(resourceUrl);

            // Create the fetch job
            long fetchJobId = await MConnector.Client.Jobs.CreateFetchJobAsync(fjr).ConfigureAwait(false);

            return(fetchJobId);
        }
Esempio n. 3
0
        static async Task <bool> CreateAssetsFromCSV()
        {
            // use the FileHelpers library to load data from CSV
            var engine = new FileHelperEngine <Asset>();

            var filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Data\data.csv");
            var assets   = engine.ReadFile(filePath);

            // import all the things...
            var contentRepositories = await GetDefinitionItems("M.Content.Repository");

            var enUs = CultureInfo.GetCultureInfo("en-US");

            foreach (var asset in assets)
            {
                // creates a new asset (in memory. will not persist until explicitly saved.)
                var newEntity = await _client.EntityFactory.CreateAsync(Constants.Asset.DefinitionName);

                newEntity.SetPropertyValue("FileName", asset.File);
                newEntity.SetPropertyValue("Title", asset.Title);
                newEntity.SetPropertyValue("Description", enUs, asset.Description);

                // assign the asset to a repo
                var contentRepositoryToAssetRelation = newEntity.GetRelation("ContentRepositoryToAsset", RelationRole.Child) as IChildToManyParentsRelation;
                contentRepositoryToAssetRelation.Add((long)contentRepositories.Single(s => s.Identifier == asset.ContentRepositoryToAsset).Id);

                try
                {
                    // persist the asset information
                    var entityId = await _client.Entities.SaveAsync(newEntity);

                    Console.WriteLine(String.Format("Created - Name: {0}, EntityId: {1}", asset.Title, entityId));

                    // set the lifecycle status. (it seems that assets MUST exist prior to this action.)
                    switch (asset.FinalLifeCycleStatusToAsset)
                    {
                    case "M.Final.LifeCycle.Status.UnderReview":
                        await _client.Assets.FinalLifeCycleManager.SubmitAsync(entityId);

                        break;

                    case "M.Final.LifeCycle.Status.Approved":
                        await _client.Assets.FinalLifeCycleManager.DirectPublishAsync(entityId);

                        break;
                    }

                    // fetch jobs still need to be created in order to pull the asset content... otherwise, they will just
                    // sit there, empty and alone.
                    var fetchJobRequest = new WebFetchJobRequest("Fetch file for entity.", entityId);
                    fetchJobRequest.Urls.Add(new Uri(asset.File, UriKind.Absolute));

                    var jobId = await _client.Jobs.CreateFetchJobAsync(fetchJobRequest);

                    Console.WriteLine(String.Format("Created Fetch Job - EntityId: {0} JobId: {1}", entityId, jobId));
                }
                catch (ValidationException e)
                {
                    // sad face...
                    foreach (var failure in e.Failures)
                    {
                        Console.WriteLine(String.Format("Failure - Source: {0}, Message: {1}", failure.Source, failure.Message));
                        return(false);
                    }
                }
            }

            return(true);
        }