示例#1
0
        public virtual async Task <TEntity> Save(TEntityDTO data, bool autoSave = true, Func <IQueryable <TEntity>, IIncludableQueryable <TEntity, object> > include = null)
        {
            var isNewEntity = data.Id == null || data.Id.Equals(Guid.Empty);

            var entityToSave = isNewEntity
                ? new TEntity()
                : await GetById(data.Id ?? Guid.Empty, false, include)
            ;

            ProjectExceptions.ThrowNotFoundIfNull(entityToSave);

            Mapper.Map(data, entityToSave);


            if (isNewEntity)
            {
                await IsNewEntity(data, entityToSave);

                DB.Set <TEntity>().Add(entityToSave);
            }
            else
            {
                await IsExistingEntity(data, entityToSave);

                DB.Set <TEntity>().Update(entityToSave);
            }

            if (autoSave)
            {
                await DB.SaveChangesAsync();
            }

            return(entityToSave);
        }
        public void InsertAfterChild(VcProjectElement element,
                                     VcProjectElement reference)
        {
            ProjectExceptions.NotNull(element, "element");
            if (reference == null)
            {
                this.PrependChild(element);
                return;
            }

            if (element.Parent != this || reference.Parent != this)
            {
                throw new InvalidOperationException(
                          "The element is not created by this container.");
            }

            if (_children.Count != 0 && _children.Contains(element))
            {
                return;
            }

            int index = _children.IndexOf(reference);

            if (index < 0)
            {
                throw new InvalidOperationException(
                          "The referenced child is not found.");
            }

            _children.Insert(index + 1, element);
        }
示例#3
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            //if (this.IsEmpty)
            //{
            //    return;
            //}

            writer.WriteStartElement(this.XmlTagName);  // start - reference

            foreach (KeyValuePair <string, string> item in _properties)
            {
                writer.WriteAttributeString(item.Key, item.Value);
            }

            if (base.IsEmpty)
            {
                writer.WriteEndElement();               // end - reference
            }
            else
            {
                for (int i = 0; i < this.Count; i++)
                {
                    this[i].WriteXml(writer);
                }

                writer.WriteFullEndElement();           // end - reference
            }
        }
示例#4
0
        public virtual async Task <List <TEntity> > Get(Expression <Func <TEntity, bool> > predicate = null,
                                                        bool disableTracking = true,
                                                        Func <IQueryable <TEntity>, IIncludableQueryable <TEntity, object> > include = null)
        {
            var entityQuery = DB.Set <TEntity>()
                              .AsQueryable()
            ;

            if (predicate != null)
            {
                entityQuery = entityQuery.Where(predicate);
            }

            if (disableTracking)
            {
                entityQuery = entityQuery.AsNoTracking();
            }

            // We assign all passed includes (if there are any)
            entityQuery = entityQuery.AssignIncludes(include);
            var entitiesList = await entityQuery.ToListAsync();

            ProjectExceptions.ThrowNotFoundIfNull(entitiesList);

            return(entitiesList);
        }
示例#5
0
        public override void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Keep this, after reading the attributes, the reader will be
            // on the last attribute, and this property will return false...
            bool isEmptyElement = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                _properties.Add(reader.Name, reader.Value);
            }

            if (isEmptyElement)
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (this.IsChildElement(reader.Name))
                    {
                        VcProjectElement element = this.CreateChildElement(reader.Name);
                        element.ReadXml(reader);

                        this.AppendChild(element);
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format(
                                                                "The element '{0}' is not a child element of {1}", reader.Name,
                                                                TagName));
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
示例#6
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            if (!String.IsNullOrEmpty(_comment))
            {
                writer.WriteComment(_comment);
            }
        }
        internal VcProjectConfigurationElement(VcProjectContainerElement parent,
                                               VcProjectRootElement root, string tagName)
            : base(parent, root)
        {
            ProjectExceptions.NotNullNotEmpty(tagName, "tagName");

            _tagName    = tagName;
            _properties = new ProjectProperties();
        }
        public int IndexOfChild(VcProjectElement element)
        {
            ProjectExceptions.NotNull(element, "element");

            if (_children.Count == 0)
            {
                return(-1);
            }

            return(_children.IndexOf(element));
        }
        public bool RemoveChild(VcProjectElement element)
        {
            ProjectExceptions.NotNull(element, "element");

            if (_children.Count == 0)
            {
                return(false);
            }

            return(_children.Remove(element));
        }
示例#10
0
        public override void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Comment);
            if (reader.NodeType != XmlNodeType.Comment)
            {
                return;
            }

            _comment = reader.Value;
        }
示例#11
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            if (this.IsEmpty)
            {
                return;
            }

            writer.WriteStartElement(TagName);  // start - Platform
            writer.WriteAttributeString("Name", _name);
            writer.WriteEndElement();           // end - Platform
        }
示例#12
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            if (this.IsEmpty)
            {
                return;
            }

            writer.WriteStartElement(TagName);  // start - DefaultToolFile
            writer.WriteAttributeString("FileName", _fileName);
            writer.WriteEndElement();           // end - DefaultToolFile
        }
示例#13
0
        /// <summary>
        /// This writes the current state or attributes of this object,
        /// in the <c>XML</c> format, to the media or storage accessible by the given writer.
        /// </summary>
        /// <param name="writer">
        /// The <c>XML</c> writer with which the <c>XML</c> format of this object's state
        /// is written.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            writer.WriteStartElement(TagName);  // start - properties

            foreach (KeyValuePair <string, string> item in _dictionary)
            {
                writer.WriteStartElement(ItemTagName); // start - property
                writer.WriteAttributeString("name", item.Key);
                writer.WriteString(item.Value);
                writer.WriteEndElement();              // end - property
            }

            writer.WriteEndElement();           // end - properties
        }
        public bool ContainsChild(VcProjectElement element)
        {
            ProjectExceptions.NotNull(element, "element");

            if (element.Parent == null || element.Parent != this ||
                _children.Count == 0)
            {
                return(false);
            }

            if (element.Parent == this)
            {
                return(true);
            }
            return(_children.Contains(element));
        }
        public void InsertChild(int index, VcProjectElement element)
        {
            ProjectExceptions.NotNull(element, "element");

            if (element.Parent != this)
            {
                throw new InvalidOperationException(
                          "The element is not created by this container.");
            }

            if (_children.Count != 0 && _children.Contains(element))
            {
                return;
            }
            _children.Insert(index, element);
        }
        private static void RequiresAll(string solutionFile, string platform,
                                        string configuration)
        {
            ProjectExceptions.PathMustExist(solutionFile, "solutionFile");

            string storageFile = Path.ChangeExtension(solutionFile, ".suo");

            if (File.Exists(storageFile))
            {
                // If the storage file exits, we could still extract the
                // platform and configuration information...
                return;
            }

            ProjectExceptions.NotNullNotEmpty(platform, "platform");
            ProjectExceptions.NotNullNotEmpty(configuration, "configuration");
        }
        public override void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            string tagName = this.XmlTagName;

            if (!String.Equals(reader.Name, tagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (this.IsChildElement(reader.Name))
                    {
                        VcProjectElement element = this.CreateChildElement(reader.Name);
                        element.ReadXml(reader);

                        this.AppendChild(element);
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format(
                                                                "The element '{0}' is not a child element of {1}", reader.Name,
                                                                tagName));
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, tagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
示例#18
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            writer.WriteStartElement(TagName);  // start - VisualStudioProject

            foreach (KeyValuePair <string, string> item in _properties)
            {
                writer.WriteAttributeString(item.Key, item.Value);
            }

            for (int i = 0; i < this.Count; i++)
            {
                this[i].WriteXml(writer);
            }

            writer.WriteFullEndElement();       // end - VisualStudioProject
        }
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            //if (this.IsEmpty)
            //{
            //    return;
            //}

            writer.WriteStartElement(this.XmlTagName);  // start - the collection

            for (int i = 0; i < this.Count; i++)
            {
                this[i].WriteXml(writer);
            }

            writer.WriteFullEndElement();                   // end - the collection
        }
示例#20
0
        public override void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            _fileName = reader.GetAttribute("FileName");
        }
示例#21
0
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            if (this.IsEmpty)
            {
                return;
            }

            writer.WriteStartElement(TagName);  // start - Tool

            foreach (KeyValuePair <string, string> item in _properties)
            {
                writer.WriteAttributeString(item.Key, item.Value);
            }

            writer.WriteEndElement();           // end - Tool
        }
示例#22
0
        public virtual async Task <TEntity> GetById(Guid id, bool disableTracking = true, Func <IQueryable <TEntity>, IIncludableQueryable <TEntity, object> > include = null)
        {
            var entityQuery = DB.Set <TEntity>().AsQueryable();

            if (disableTracking)
            {
                entityQuery = entityQuery.AsNoTracking();
            }

            // We assign all passed includes (if there are any)
            entityQuery = entityQuery.AssignIncludes(include);

            var entity = await entityQuery
                         .FirstOrDefaultAsync(x => x.Id == id)
            ;

            ProjectExceptions.ThrowNotFoundIfNull(entity);

            return(entity);
        }
示例#23
0
        public override void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            while (reader.MoveToNextAttribute())
            {
                _properties.Add(reader.Name, reader.Value);
            }
        }
示例#24
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public void ReadXml(XmlReader reader)
        {
            ProjectExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, ItemTagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        string name  = reader.GetAttribute("name");
                        string value = reader.ReadString();

                        this.Add(name, value);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
        public override void WriteXml(XmlWriter writer)
        {
            ProjectExceptions.NotNull(writer, "writer");

            //if (this.IsEmpty)
            //{
            //    return;
            //}

            writer.WriteStartElement(_tagName);  // start - configuration

            foreach (KeyValuePair <string, string> item in _properties)
            {
                writer.WriteAttributeString(item.Key, item.Value);
            }

            for (int i = 0; i < this.Count; i++)
            {
                this[i].WriteXml(writer);
            }

            writer.WriteEndElement();            // end - the configuration
        }