Esempio n. 1
0
        public void EFFK_InsertAddRelated()
        {
            var newCust = new EFFKClient.Customer()
            {
                ID = 11, EditTimeStamp = new byte[] { 0 }
            };
            var newOrder1 = new EFFKClient.Order()
            {
                ID = 100020, CustomerId = 11
            };
            var newOrder2 = new EFFKClient.Order()
            {
                ID = 100021, CustomerId = 1
            };
            var newOrder3 = new EFFKClient.Order()
            {
                ID = 100022
            };

            ctx.AddObject("CustomObjectContext.Customers", newCust);
            ctx.AddRelatedObject(newCust, "Orders", newOrder1);
            ctx.AddRelatedObject(newCust, "Orders", newOrder2);
            ctx.AddRelatedObject(newCust, "Orders", newOrder3);

            ctx.SaveChanges();

            VerifyServerOrderId(100020, 11);
            VerifyServerOrderId(100021, 11);
            VerifyServerOrderId(100022, 11);
        }
        private void InnerSave(DataServiceContext dataContext)
        {
            X509Certificate2 certToUse = null;

            dataContext.AddObject(JobTemplateBaseCollection.JobTemplateSet, this);

            foreach (TaskTemplateData taskTemplate in this.TaskTemplates)
            {
                dataContext.AddRelatedObject(this, TaskTemplatesPropertyName, taskTemplate);

                if (((ITaskTemplate)taskTemplate).Options.HasFlag(TaskOptions.ProtectedConfiguration) && (taskTemplate.Configuration != taskTemplate.ConfigurationCopied))
                {
                    ProtectTaskConfiguration((TaskTemplateData)taskTemplate, ref certToUse, dataContext);
                }
            }

            MatchCollection matches = Regex.Matches(this.JobTemplateBodyCopied, @"taskTemplateId=""nb:ttid:UUID:([a-zA-Z0-9\-]+)""");

            this.JobTemplateBody = this.JobTemplateBodyCopied;
            for (int i = 0; i < matches.Count; i++)
            {
                string taskTemplateId = Guid.NewGuid().ToString();

                this.TaskTemplates[i].Id = string.Concat("nb:ttid:UUID:", taskTemplateId);
                this.JobTemplateBody     = this.JobTemplateBody.Replace(matches[i].Groups[1].Value, taskTemplateId);
            }
        }
Esempio n. 3
0
        private Task <IJobTemplate> CreateJobTemplate(string templateName, JobTemplateType templateType, params ITaskTemplate[] taskTemplates)
        {
            X509Certificate2   certToUse       = null;
            DataServiceContext dataContext     = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext();
            JobTemplateData    jobTemplateData = new JobTemplateData {
                Name = templateName, TemplateType = (int)templateType
            };

            jobTemplateData.InitCloudMediaContext(this._cloudMediaContext);

            dataContext.AddObject(JobTemplateBaseCollection.JobTemplateSet, jobTemplateData);

            foreach (ITaskTemplate taskTemplate in taskTemplates)
            {
                Verify(taskTemplate);

                dataContext.AddRelatedObject(jobTemplateData, TaskTemplatesPropertyName, taskTemplate);

                if (taskTemplate.Options.HasFlag(TaskOptions.ProtectedConfiguration) && string.IsNullOrWhiteSpace(this.Id))
                {
                    ProtectTaskConfiguration((TaskTemplateData)taskTemplate, ref certToUse, dataContext);
                }
            }

            AssetNamingSchemeResolver <AssetData, OutputAsset> assetIdMap = new AssetNamingSchemeResolver <AssetData, OutputAsset>();

            jobTemplateData.JobTemplateBody = CreateJobTemplateBody(assetIdMap, taskTemplates);

            jobTemplateData.NumberofInputAssets = string.IsNullOrWhiteSpace(this.Id)
                ? assetIdMap.Inputs.Count
                : ((IJob)this).InputMediaAssets.Count;

            return(dataContext
                   .SaveChangesAsync(SaveChangesOptions.Batch, jobTemplateData)
                   .ContinueWith <IJobTemplate>(
                       t =>
            {
                t.ThrowIfFaulted();

                JobTemplateData data = (JobTemplateData)t.AsyncState;
                IJobTemplate jobTemplateToReturn = this._cloudMediaContext.JobTemplates.Where(c => c.Id == data.Id).First();

                return jobTemplateToReturn;
            }));
        }
Esempio n. 4
0
        public virtual void AddAndRemoveBaseNavigationPropertyInDerivedType()
        {
            // clear respository
            this.ClearRepository("InheritanceTests_Cars");

            Random r = new Random(RandomSeedGenerator.GetRandomSeed());

            // post new entity to repository
            CreatorSettings creatorSettings = new CreatorSettings()
            {
                NullValueProbability = 0,
            };
            var car                = InstanceCreator.CreateInstanceOf <Car>(r, creatorSettings);
            var vehicle            = InstanceCreator.CreateInstanceOf <Vehicle>(r, creatorSettings);
            DataServiceContext ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);

            ctx.AddObject("InheritanceTests_Cars", car);
            ctx.AddRelatedObject(car, "BaseTypeNavigationProperty", vehicle);
            ctx.SaveChangesAsync().Wait();

            ctx = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);
            var cars   = ctx.CreateQuery <Car>("InheritanceTests_Cars");
            var actual = cars.ExecuteAsync().Result.First();

            ctx.LoadPropertyAsync(actual, "BaseTypeNavigationProperty").Wait();

            AssertExtension.PrimitiveEqual(vehicle, actual.BaseTypeNavigationProperty[0]);

            ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);
            ctx.AttachTo("InheritanceTests_Cars", actual);
            ctx.AttachTo("InheritanceTests_Vehicles", actual.BaseTypeNavigationProperty[0]);
            ctx.DeleteLink(actual, "BaseTypeNavigationProperty", actual.BaseTypeNavigationProperty[0]);
            ctx.SaveChangesAsync().Wait();

            ctx    = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);
            cars   = ctx.CreateQuery <Car>("InheritanceTests_Cars");
            actual = cars.ExecuteAsync().Result.First();
            ctx.LoadPropertyAsync(actual, "BaseTypeNavigationProperty").Wait();

            Assert.Empty(actual.BaseTypeNavigationProperty);

            this.ClearRepository("InheritanceTests_Cars");
        }
        private void InnerSubmit(DataServiceContext dataContext)
        {
            if (!string.IsNullOrWhiteSpace(this.TemplateId))
            {
                dataContext.AddObject(JobBaseCollection.JobSet, this);

                foreach (IAsset asset in this.InputMediaAssets)
                {
                    AssetData target = asset as AssetData;
                    if (target == null)
                    {
                        throw new ArgumentException(StringTable.ErrorInputTypeNotSupported);
                    }

                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, target);
                }
            }
            else
            {
                X509Certificate2 certToUse = null;
                Verify(this);

                dataContext.AddObject(JobBaseCollection.JobSet, this);

                List<AssetData> inputAssets = new List<AssetData>();
                AssetNamingSchemeResolver<AssetData, OutputAsset> assetNamingSchemeResolver = new AssetNamingSchemeResolver<AssetData, OutputAsset>(inputAssets);

                foreach (ITask task in ((IJob)this).Tasks)
                {
                    Verify(task);
                    TaskData taskData = (TaskData)task;

                    if (task.Options.HasFlag(TaskOptions.ProtectedConfiguration))
                    {
                        ProtectTaskConfiguration(taskData, ref certToUse, dataContext);
                    }

                    taskData.TaskBody = CreateTaskBody(assetNamingSchemeResolver, task.InputAssets.ToArray(), task.OutputAssets.ToArray());
                    taskData.InputMediaAssets.AddRange(task.InputAssets.OfType<AssetData>().ToArray());
                    taskData.OutputMediaAssets.AddRange(
                        task.OutputAssets
                            .OfType<OutputAsset>()
                            .Select(
                                c =>
                                {
                                    AssetData assetData = new AssetData { Name = c.Name, Options = (int)c.Options, AlternateId = c.AlternateId };
                                    assetData.InitCloudMediaContext(this._cloudMediaContext);

                                    return assetData;
                                })
                            .ToArray());
                    dataContext.AddRelatedObject(this, TasksPropertyName, taskData);
                }

                foreach (IAsset asset in inputAssets)
                {
                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, asset);
                }
            }
        }
 /// <summary>
 /// Adds a related object to the context and creates the link that defines the relationship between the two objects in a single request.
 /// </summary>
 /// <param name="source">The parent object that is being tracked by the context.</param>
 /// <param name="sourceProperty">The name of the navigation property that returns the related object based on an association between the two entities.</param>
 /// <param name="target">The related object that is being added.</param>
 public void AddRelatedObject(object source, string sourceProperty, object target)
 {
     _dataContext.AddRelatedObject(source, sourceProperty, target);
 }
Esempio n. 7
0
        private void InnerSubmit(DataServiceContext dataContext)
        {
            if (!string.IsNullOrWhiteSpace(this.TemplateId))
            {
                dataContext.AddObject(JobBaseCollection.JobSet, this);

                foreach (IAsset asset in this.InputMediaAssets)
                {
                    AssetData target = asset as AssetData;
                    if (target == null)
                    {
                        throw new ArgumentException(StringTable.ErrorInputTypeNotSupported);
                    }

                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, target);
                }
            }
            else
            {
                X509Certificate2 certToUse = null;
                Verify(this);

                dataContext.AddObject(JobBaseCollection.JobSet, this);

                List <AssetData> inputAssets = new List <AssetData>();
                AssetNamingSchemeResolver <AssetData, OutputAsset> assetNamingSchemeResolver = new AssetNamingSchemeResolver <AssetData, OutputAsset>(inputAssets);

                foreach (ITask task in ((IJob)this).Tasks)
                {
                    Verify(task);
                    TaskData taskData = (TaskData)task;

                    if (task.Options.HasFlag(TaskOptions.ProtectedConfiguration))
                    {
                        ProtectTaskConfiguration(taskData, ref certToUse, dataContext);
                    }

                    taskData.TaskBody = CreateTaskBody(assetNamingSchemeResolver, task.InputAssets.ToArray(), task.OutputAssets.ToArray());
                    taskData.InputMediaAssets.AddRange(task.InputAssets.OfType <AssetData>().ToArray());
                    taskData.OutputMediaAssets.AddRange(
                        task.OutputAssets
                        .OfType <OutputAsset>()
                        .Select(
                            c =>
                    {
                        AssetData assetData = new AssetData {
                            Name = c.Name, Options = (int)c.Options, AlternateId = c.AlternateId
                        };
                        assetData.InitCloudMediaContext(this._cloudMediaContext);

                        return(assetData);
                    })
                        .ToArray());
                    dataContext.AddRelatedObject(this, TasksPropertyName, taskData);
                }

                foreach (IAsset asset in inputAssets)
                {
                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, asset);
                }
            }
        }
        private void InnerSave(DataServiceContext dataContext)
        {
            X509Certificate2 certToUse = null;

            dataContext.AddObject(JobTemplateBaseCollection.JobTemplateSet, this);

            foreach (TaskTemplateData taskTemplate in this.TaskTemplates)
            {
                dataContext.AddRelatedObject(this, TaskTemplatesPropertyName, taskTemplate);

                if (((ITaskTemplate)taskTemplate).Options.HasFlag(TaskOptions.ProtectedConfiguration) && (taskTemplate.Configuration != taskTemplate.ConfigurationCopied))
                {
                    ProtectTaskConfiguration((TaskTemplateData)taskTemplate, ref certToUse, dataContext);
                }
            }

            MatchCollection matches = Regex.Matches(this.JobTemplateBodyCopied, @"taskTemplateId=""nb:ttid:UUID:([a-zA-Z0-9\-]+)""");
            this.JobTemplateBody = this.JobTemplateBodyCopied;
            for (int i = 0; i < matches.Count; i++)
            {
                string taskTemplateId = Guid.NewGuid().ToString();

                this.TaskTemplates[i].Id = string.Concat("nb:ttid:UUID:", taskTemplateId);
                this.JobTemplateBody = this.JobTemplateBody.Replace(matches[i].Groups[1].Value, taskTemplateId);
            }
        }