public void Replicate()
        {
            ISession  s    = OpenSession();
            Container baz  = new Container();
            Contained f    = new Contained();
            IList     list = new ArrayList();

            list.Add(baz);
            f.Bag = list;
            IList list2 = new ArrayList();

            list2.Add(f);
            baz.Bag = list2;
            s.Save(f);
            s.Save(baz);
            s.Flush();
            s.Close();

            s = OpenSession();
            s.Replicate(baz, ReplicationMode.Overwrite);
            s.Flush();
            s.Close();
            s = OpenSession();
            s.Replicate(baz, ReplicationMode.Ignore);
            s.Flush();
            s.Close();

            s = OpenSession();
            s.Delete(baz);
            s.Delete(f);
            s.Flush();
            s.Close();
        }
        public override IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as DomainResource;

            if (dest == null)
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }

            base.CopyTo(dest);
            if (Text != null)
            {
                dest.Text = (Hl7.Fhir.Model.Narrative)Text.DeepCopy();
            }
            if (Contained != null)
            {
                dest.Contained = new List <Hl7.Fhir.Model.Resource>(Contained.DeepCopy());
            }
            if (Extension != null)
            {
                dest.Extension = new List <Hl7.Fhir.Model.Extension>(Extension.DeepCopy());
            }
            if (ModifierExtension != null)
            {
                dest.ModifierExtension = new List <Hl7.Fhir.Model.Extension>(ModifierExtension.DeepCopy());
            }
            return(dest);
        }
示例#3
0
        public virtual ErrorList Validate()
        {
            var result = new ErrorList();

            result.AddRange(ValidateRules());

            if (Extension != null)
            {
                Extension.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (LanguageElement != null)
            {
                result.AddRange(LanguageElement.Validate());
            }
            if (Text != null)
            {
                result.AddRange(Text.Validate());
            }
            if (Contained != null)
            {
                Contained.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (LocalIdElement != null)
            {
                result.AddRange(LocalIdElement.Validate());
            }

            return(result);
        }
示例#4
0
        public async Task ReplicateAsync()
        {
            ISession          s    = OpenSession();
            Container         baz  = new Container();
            Contained         f    = new Contained();
            IList <Container> list = new List <Container>();

            list.Add(baz);
            f.Bag = list;
            IList <Contained> list2 = new List <Contained>();

            list2.Add(f);
            baz.Bag = list2;
            await(s.SaveAsync(f));
            await(s.SaveAsync(baz));
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();
            await(s.ReplicateAsync(baz, ReplicationMode.Overwrite));
            await(s.FlushAsync());
            s.Close();
            s = OpenSession();
            await(s.ReplicateAsync(baz, ReplicationMode.Ignore));
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();
            await(s.DeleteAsync(baz));
            await(s.DeleteAsync(f));
            await(s.FlushAsync());
            s.Close();
        }
示例#5
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // TODO: Contained resources share the same internal id resolution space as the parent
            // resource -> verify id uniqueness
            var result = new List <ValidationResult>();

            // Validate specific invariants for contained items. The content of the contained
            // items is validated by the "normal" validation triggered by the FhirElement attribute
            if (Contained != null)
            {
                foreach (var contained in Contained.OfType <DomainResource>())
                {
                    if (contained.Contained != null && contained.Contained.Any())
                    {
                        result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Contained resources cannot contain nested contained resources"));
                    }

                    if (contained.Text != null)
                    {
                        result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Contained resources should not contain narrative"));
                    }
                }
            }

            return(result);
        }
示例#6
0
        public INavigationBuilder Add(
            LocalizedString caption,
            string authority,
            int order,
            Action <INavigationItemBuilder> itemBuilder,
            IEnumerable <string> classes = null)
        {
            var childBuilder = new NavigationItemBuilder();

            childBuilder.Caption(caption);
            childBuilder.Authority(authority);
            childBuilder.Order(order);
            itemBuilder(childBuilder);
            Contained.AddRange(childBuilder.Build());

            if (classes != null)
            {
                foreach (var className in classes)
                {
                    childBuilder.AddClass(className);
                }
            }

            return(this);
        }
示例#7
0
        public async Task ManyToManyAsync()
        {
            // if( dialect is Dialect.HSQLDialect) return;

            ISession     s = OpenSession();
            ITransaction t = s.BeginTransaction();
            Container    c = new Container();

            c.ManyToMany = new List <Simple>();
            c.Bag        = new List <Contained>();
            Simple s1 = new Simple();
            Simple s2 = new Simple();

            s1.Count = 123;
            s2.Count = 654;
            Contained c1 = new Contained();

            c1.Bag = new List <Container>();
            c1.Bag.Add(c);
            c.Bag.Add(c1);
            c.ManyToMany.Add(s1);
            c.ManyToMany.Add(s2);
            object cid = await(s.SaveAsync(c));

            await(s.SaveAsync(s1, (long)12));
            await(s.SaveAsync(s2, (long)-1));
            await(t.CommitAsync());
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)await(s.LoadAsync(typeof(Container), cid));
            Assert.AreEqual(1, c.Bag.Count);
            Assert.AreEqual(2, c.ManyToMany.Count);
            foreach (object obj in c.Bag)
            {
                c1 = (Contained)obj;
                break;
            }
            c.Bag.Remove(c1);
            c1.Bag.Remove(c);
            Assert.IsNotNull(c.ManyToMany[0]);
            c.ManyToMany.RemoveAt(0);
            await(t.CommitAsync());
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)await(s.LoadAsync(typeof(Container), cid));
            Assert.AreEqual(0, c.Bag.Count);
            Assert.AreEqual(1, c.ManyToMany.Count);
            c1 = (Contained)await(s.LoadAsync(typeof(Contained), c1.Id));
            Assert.AreEqual(0, c1.Bag.Count);
            Assert.AreEqual(1, await(s.DeleteAsync("from c in class ContainerX")));
            Assert.AreEqual(1, await(s.DeleteAsync("from c in class Contained")));
            Assert.AreEqual(2, await(s.DeleteAsync("from s in class Simple")));
            await(t.CommitAsync());
            s.Close();
        }
示例#8
0
 protected override void DrawSelf(SpriteBatch spriteBatch)
 {
     if (Visible)
     {
         spriteBatch.Draw(BackgroundTexture, GetDimensions().ToRectangle(), null, Color.White);
         Contained?.Draw(spriteBatch);
     }
 }
示例#9
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (!ReferenceEquals(Contained?.Container, this))
            {
                Contained = null;
            }

            Contained?.Update();
        }
示例#10
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List <ValidationResult>(base.Validate(validationContext));

            if (this.Contained != null)
            {
                if (!Contained.OfType <DomainResource>().All(dr => dr.Text == null))
                {
                    result.Add(new ValidationResult("Resource has contained resources with narrative"));
                }

                if (!Contained.OfType <DomainResource>().All(cr => cr.Contained == null || !cr.Contained.Any()))
                {
                    result.Add(new ValidationResult("Resource has contained resources with nested contained resources"));
                }
            }

            return(result);
        }
示例#11
0
        /// <summary>
        /// Finds a Resource amongst this Resource's contained resources
        /// </summary>
        /// <param name="containedReference">A string containing an anchored resource id.</param>
        /// <returns>The found resource, or null if no matching contained resource was found. Will throw an exception if there's more than
        /// one matching contained resource</returns>
        public Resource FindContainedResource(string containedReference)
        {
            if (containedReference == null)
            {
                throw new ArgumentNullException("containedReference");
            }
            if (!containedReference.StartsWith("#"))
            {
                throw new ArgumentException("Reference is not a local anchored reference", "containedReference");
            }

            var rref = containedReference.Substring(1);

            if (Contained == null)
            {
                return(null);
            }

            return(Contained.SingleOrDefault(r => r.Id != null && r.Id == rref));
        }
示例#12
0
        /// <summary>
        /// Finds the contained resource defined by the <paramref name="reference"/>. A reference to a contained resource starts with the
        /// character #.
        /// </summary>
        /// <param name="reference">the reference to contained resource</param>
        /// <returns>The resource referenced by <paramref name="reference"/>, null otherwise.</returns>
        public Resource FindContainedResource(ResourceReference reference)
        {
            if (reference == null)
            {
                throw Error.ArgumentNull(nameof(reference));
            }

            if (!reference.IsContainedReference)
            {
                return(null);
            }

            if (reference.Reference == "#")
            {
                return(this);
            }

            // search the contained resource by removing '#'
            return(Contained.FirstOrDefault(c => c.Id == reference.Reference.Remove(0, 1)));
        }
        public void Replicate()
        {
            if (!TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator)
            {
                Assert.Ignore("Support of empty inserts is required");
            }

            ISession          s    = OpenSession();
            Container         baz  = new Container();
            Contained         f    = new Contained();
            IList <Container> list = new List <Container>();

            list.Add(baz);
            f.Bag = list;
            IList <Contained> list2 = new List <Contained>();

            list2.Add(f);
            baz.Bag = list2;
            s.Save(f);
            s.Save(baz);
            s.Flush();
            s.Close();

            s = OpenSession();
            s.Replicate(baz, ReplicationMode.Overwrite);
            s.Flush();
            s.Close();
            s = OpenSession();
            s.Replicate(baz, ReplicationMode.Ignore);
            s.Flush();
            s.Close();

            s = OpenSession();
            s.Delete(baz);
            s.Delete(f);
            s.Flush();
            s.Close();
        }
示例#14
0
        public virtual IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as Resource;

            if (dest != null)
            {
                if (Extension != null)
                {
                    dest.Extension = new List <Hl7.Fhir.Model.Extension>(Extension.DeepCopy());
                }
                if (ModifierExtension != null)
                {
                    dest.ModifierExtension = new List <Hl7.Fhir.Model.Extension>(ModifierExtension.DeepCopy());
                }
                if (LanguageElement != null)
                {
                    dest.LanguageElement = (Hl7.Fhir.Model.Code)LanguageElement.DeepCopy();
                }
                if (Text != null)
                {
                    dest.Text = (Hl7.Fhir.Model.Narrative)Text.DeepCopy();
                }
                if (Contained != null)
                {
                    dest.Contained = new List <Hl7.Fhir.Model.Resource>(Contained.DeepCopy());
                }
                if (Id != null)
                {
                    dest.Id = Id;
                }
                return(dest);
            }
            else
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }
        }
 public void Clear()
 {
     Contained.Clear();
 }
示例#16
0
 void addFor(Patient pat)
 {
     Contained.Add(pat);
 }
 public void AddBall(Point pos)
 {
     Contained.Add(new Ball(pos));
 }
示例#18
0
 public INavigationBuilder Remove(MenuItem item)
 {
     Contained.Remove(item);
     return(this);
 }
示例#19
0
 void addOwner(Practitioner pract)
 {
     Contained.Add(pract);
 }
        public void Bag()
        {
            if (!TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator)
            {
                Assert.Ignore("Support of empty inserts is required");
            }

            //if( dialect is Dialect.HSQLDialect ) return;

            ISession     s  = OpenSession();
            ITransaction t  = s.BeginTransaction();
            Container    c  = new Container();
            Contained    c1 = new Contained();
            Contained    c2 = new Contained();

            c.Bag = new List <Contained>();
            c.Bag.Add(c1);
            c.Bag.Add(c2);
            c1.Bag.Add(c);
            c2.Bag.Add(c);
            s.Save(c);
            c.Bag.Add(c2);
            c2.Bag.Add(c);
            c.LazyBag.Add(c1);
            c1.LazyBag.Add(c);
            t.Commit();
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.CreateQuery("from c in class ContainerX").List()[0];
            Assert.AreEqual(1, c.LazyBag.Count);
            t.Commit();
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.CreateQuery("from c in class ContainerX").List()[0];
            Contained c3 = new Contained();

            // commented out in h2.0.3 also
            //c.Bag.Add(c3);
            //c3.Bag.Add(c);
            c.LazyBag.Add(c3);
            c3.LazyBag.Add(c);
            t.Commit();
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.CreateQuery("from c in class ContainerX").List()[0];
            Contained c4 = new Contained();

            c.LazyBag.Add(c4);
            c4.LazyBag.Add(c);
            Assert.AreEqual(3, c.LazyBag.Count);             //forces initialization
            // s.Save(c4); commented in h2.0.3 also
            t.Commit();
            s.Close();

            // new test code in here to catch when a lazy bag has an addition then
            // is flushed and then an operation that causes it to read from the db
            // occurs - this used to cause the element in Add(element) to be in there
            // twice and throw off the count by 1 (or by however many additions were
            // made before the flush
            s = OpenSession();
            c = (Container)s.CreateQuery("from c in class ContainerX").List()[0];
            Contained c5 = new Contained();

            c.LazyBag.Add(c5);
            c5.LazyBag.Add(c);

            // this causes the additions to be written to the db - now verify
            // the additions list was cleared and the count returns correctly
            s.Flush();
            Assert.AreEqual(4, c.LazyBag.Count, "correct additions clearing after flush");
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.CreateQuery("from c in class ContainerX").List()[0];
            int j = 0;

            foreach (object obj in c.Bag)
            {
                Assert.IsNotNull(obj);
                j++;
            }

            Assert.AreEqual(3, j);

            // this used to be 3 - but since I added an item in the test above for flush
            // I increased it to 4
            Assert.AreEqual(4, c.LazyBag.Count);
            s.Delete(c);
            c.Bag.Remove(c2);

            j = 0;
            foreach (object obj in c.Bag)
            {
                j++;
                s.Delete(obj);
            }

            Assert.AreEqual(2, j);
            s.Delete(s.Load(typeof(Contained), c5.Id));
            s.Delete(s.Load(typeof(Contained), c4.Id));
            s.Delete(s.Load(typeof(Contained), c3.Id));
            t.Commit();
            s.Close();
        }
        public void ManyToMany()
        {
            if (!TestDialect.SupportsEmptyInsertsOrHasNonIdentityNativeGenerator)
            {
                Assert.Ignore("Support of empty inserts is required");
            }

            // if( dialect is Dialect.HSQLDialect) return;

            ISession     s = OpenSession();
            ITransaction t = s.BeginTransaction();
            Container    c = new Container();

            c.ManyToMany = new List <Simple>();
            c.Bag        = new List <Contained>();
            Simple s1 = new Simple();
            Simple s2 = new Simple();

            s1.Count = 123;
            s2.Count = 654;
            Contained c1 = new Contained();

            c1.Bag = new List <Container>();
            c1.Bag.Add(c);
            c.Bag.Add(c1);
            c.ManyToMany.Add(s1);
            c.ManyToMany.Add(s2);
            object cid = s.Save(c);

            s.Save(s1, (long)12);
            s.Save(s2, (long)-1);
            t.Commit();
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.Load(typeof(Container), cid);
            Assert.AreEqual(1, c.Bag.Count);
            Assert.AreEqual(2, c.ManyToMany.Count);
            foreach (object obj in c.Bag)
            {
                c1 = (Contained)obj;
                break;
            }
            c.Bag.Remove(c1);
            c1.Bag.Remove(c);
            Assert.IsNotNull(c.ManyToMany[0]);
            c.ManyToMany.RemoveAt(0);
            t.Commit();
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            c = (Container)s.Load(typeof(Container), cid);
            Assert.AreEqual(0, c.Bag.Count);
            Assert.AreEqual(1, c.ManyToMany.Count);
            c1 = (Contained)s.Load(typeof(Contained), c1.Id);
            Assert.AreEqual(0, c1.Bag.Count);
            Assert.AreEqual(1, s.Delete("from c in class ContainerX"));
            Assert.AreEqual(1, s.Delete("from c in class Contained"));
            Assert.AreEqual(2, s.Delete("from s in class Simple"));
            t.Commit();
            s.Close();
        }