Click here to Skip to main content
15,894,410 members
Articles / Desktop Programming / Windows Forms

Visual Application Launcher

Rate me:
Please Sign up or sign in to vote.
4.91/5 (37 votes)
23 Jan 2012CPOL23 min read 107.9K   3.7K   116  
A WinForms UI using WCF services, Entity Framework, repository data access, repository caching, Unit of Work, Dependency Injection, and every other buzz work you can think of!
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Runtime.Serialization;

namespace VAL.Model
{
    [DataContract()]
    public partial class File : PocoEntityBase
    {
        #region Primitive Properties

        [EntityKey]
        [DataMember()]
        public virtual int Id
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Name
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Path
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Description
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string DistributeTo
        {
            get;
            set;
        }

        [DataMember()]
        public virtual bool DistributeToUserProfile
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Notes
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Workgroup
        {
            get;
            set;
        }

        [DataMember()]
        public virtual string Command
        {
            get;
            set;
        }

        [DataMember()]
        public virtual int FileTypeID
        {
            get { return _fileTypeID; }
            set
            {
                if (_fileTypeID != value)
                {
                    if (FileType != null && FileType.Id != value)
                    {
                        FileType = null;
                    }
                    _fileTypeID = value;
                }
            }
        }
        private int _fileTypeID;

        [DataMember()]
        public virtual bool IsActive
        {
            get;
            set;
        }

        [DataMember()]
        public virtual byte[] Icon
        {
            get;
            set;
        }

        #endregion
        #region Navigation Properties

        [DataMember()]
        public virtual FileType FileType
        {
            get { return _fileType; }
            set
            {
                if (!ReferenceEquals(_fileType, value))
                {
                    var previousValue = _fileType;
                    _fileType = value;
                    FixupFileType(previousValue);
                }
            }
        }
        private FileType _fileType;

        [IgnoreDataMember()]
        public virtual ICollection<Permission> Permissions
        {
            get
            {
                if (_permissions == null)
                {
                    var newCollection = new FixupCollection<Permission>();
                    newCollection.CollectionChanged += FixupPermissions;
                    _permissions = newCollection;
                }
                return _permissions;
            }
            set
            {
                if (!ReferenceEquals(_permissions, value))
                {
                    var previousValue = _permissions as FixupCollection<Permission>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupPermissions;
                    }
                    _permissions = value;
                    var newValue = value as FixupCollection<Permission>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupPermissions;
                    }
                }
            }
        }
        private ICollection<Permission> _permissions;

        [IgnoreDataMember()]
        public virtual ICollection<UserActivity> UserActivities
        {
            get
            {
                if (_userActivities == null)
                {
                    var newCollection = new FixupCollection<UserActivity>();
                    newCollection.CollectionChanged += FixupUserActivities;
                    _userActivities = newCollection;
                }
                return _userActivities;
            }
            set
            {
                if (!ReferenceEquals(_userActivities, value))
                {
                    var previousValue = _userActivities as FixupCollection<UserActivity>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupUserActivities;
                    }
                    _userActivities = value;
                    var newValue = value as FixupCollection<UserActivity>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupUserActivities;
                    }
                }
            }
        }
        private ICollection<UserActivity> _userActivities;

        #endregion
        #region Association Fixup
    
        private void FixupFileType(FileType previousValue)
        {
            if (previousValue != null && previousValue.Files.Contains(this))
            {
                previousValue.Files.Remove(this);
            }
    
            if (FileType != null)
            {
                if (!FileType.Files.Contains(this))
                {
                    FileType.Files.Add(this);
                }
                if (FileTypeID != FileType.Id)
                {
                    FileTypeID = FileType.Id;
                }
            }
        }
    
        private void FixupPermissions(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Permission item in e.NewItems)
                {
                    item.File = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Permission item in e.OldItems)
                {
                    if (ReferenceEquals(item.File, this))
                    {
                        item.File = null;
                    }
                }
            }
        }
    
        private void FixupUserActivities(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (UserActivity item in e.NewItems)
                {
                    item.File = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (UserActivity item in e.OldItems)
                {
                    if (ReferenceEquals(item.File, this))
                    {
                        item.File = null;
                    }
                }
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions