Beispiel #1
0
        /// <summary>
        ///     Creates a references associated to a given reference id.
        /// </summary>
        public Reference(Guid referenceId, string link, string description = null)
        {
            this.Id = SeqGuid.Create();

            this.ReferenceId = referenceId;
            this.Link        = link;
            this.Description = description ?? "";
        }
Beispiel #2
0
        public dynamic Insert <T>(IDbConnection connection, T entity, IDbTransaction transaction, int?commandTimeout)
            where T : class
        {
            var classMap = SqlGenerator.Configuration.GetMap <T>();
            var nonIdentityKeyProperties =
                classMap.LinqPropertyMaps.Where(p => p.KeyType == KeyType.Guid || p.KeyType == KeyType.Assigned)
                .ToList();
            var identityColumn = classMap.LinqPropertyMaps.SingleOrDefault(p => p.KeyType == KeyType.Identity);

            foreach (var column in nonIdentityKeyProperties)
            {
                if (column.KeyType == KeyType.Guid)
                {
                    var comb = SeqGuid.Create();
                    column.PropertyInfo.SetValue(entity, comb, null);
                }
            }

            IDictionary <string, object> keyValues = new ExpandoObject();
            var sql = SqlGenerator.Insert(classMap);

            if (identityColumn != null)
            {
                IEnumerable <long> result;
                if (SqlGenerator.SupportsMultipleStatements())
                {
                    sql   += SqlGenerator.Configuration.Dialect.BatchSeperator + SqlGenerator.IdentitySql(classMap);
                    result = connection.Query <long>(sql, entity, transaction, false, commandTimeout, CommandType.Text);
                }
                else
                {
                    connection.Execute(sql, entity, transaction, commandTimeout, CommandType.Text);
                    sql    = SqlGenerator.IdentitySql(classMap);
                    result = connection.Query <long>(sql, entity, transaction, false, commandTimeout, CommandType.Text);
                }

                var identityValue = result.First();
                var identityInt   = Convert.ToInt32(identityValue);
                keyValues.Add(identityColumn.PropertyInfo.Name, identityInt);
                identityColumn.PropertyInfo.SetValue(entity, identityInt, null);
            }
            else
            {
                connection.Execute(sql, entity, transaction, commandTimeout, CommandType.Text);
            }

            foreach (var column in nonIdentityKeyProperties)
            {
                keyValues.Add(column.PropertyInfo.Name, column.PropertyInfo.GetValue(entity, null));
            }

            if (keyValues.Count == 1)
            {
                return(keyValues.First().Value);
            }

            return(keyValues);
        }
Beispiel #3
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public ApplicationAccess(StakeholderLogin login)
        {
            Guard.ArgumentNotNull(login, nameof(login));

            this.DateLastModified   = DateTime.UtcNow;
            this.UserName           = "";
            this.StakeholderLoginId = login.Id;
            this.Id = SeqGuid.Create();
        }
Beispiel #4
0
        /// <summary>
        ///     Creates a new instance with a given display name and description.
        /// </summary>
        /// <param name="displayName">The display name of the domain.</param>
        /// <param name="description">The description of the domain.</param>
        public DesignDomain(string displayName, string description = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(displayName, nameof(displayName));

            Id = SeqGuid.Create();

            DateCreated = DateTime.UtcNow;
            DisplayName = displayName;
            Description = description ?? "";
        }
Beispiel #5
0
        public UserGroup(string displayName, string description)
        {
            this.Id = SeqGuid.Create();

            this.DisplayName      = displayName;
            this.Description      = description ?? "";
            this.DateLastModified = DateTime.UtcNow;
            this.DateCreated      = DateLastModified;
            this.UserName         = "";
        }
Beispiel #6
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        /// <param name="name">The name of the scenario.</param>
        /// <param name="description">A description of the scenario.</param>
        /// <param name="externalId">External id.</param>
        public Scenario(string name, string description, string externalId)
        {
            Id = SeqGuid.Create(); // todo: replace with combguid or snowflake

            DisplayName      = name;
            Description      = description;
            ExternalId       = externalId ?? "";
            DateCreated      = DateTime.UtcNow;
            DateLastModified = DateCreated;
        }
Beispiel #7
0
        /// <summary>
        ///     Creates a new instance with a given name, description and external id.
        /// </summary>
        public DeviceConnection(string displayName, string description = null)
        {
            Id = SeqGuid.Create();

            ExternalId       = "";
            DisplayName      = displayName ?? "";
            Description      = description ?? "";
            DateCreated      = DateTime.UtcNow;
            DateAdded        = DateCreated;
            DateLastModified = DateCreated;
            UserName         = "";
            TargetAddress    = "";
        }
        /// <summary>
        ///     Creates a device model dependency to a given software model.
        /// </summary>
        /// <param name="softwareModel"></param>
        /// <param name="displayName">The display name of the dependency.</param>
        /// <param name="description">An optional description of the dependency.</param>
        /// <param name="deviceModel"></param>
        public DeviceModelDependency(DeviceModel deviceModel, SoftwareModel softwareModel, string displayName, string description)
        {
            Guard.ArgumentNotNull(deviceModel, nameof(deviceModel));
            Guard.ArgumentNotNull(softwareModel, nameof(softwareModel));

            this.Id                        = SeqGuid.Create();
            this.ScenarioId                = deviceModel.ScenarioId;
            this.DeviceModelId             = deviceModel.Id;
            this.SoftwareModelDependencyId = softwareModel.Id;
            this.DisplayName               = displayName ?? $"Dependency to '{softwareModel.DisplayName}'";
            this.Description               = description ?? "";
            this.DateCreated               = DateTime.UtcNow;
        }
        /// <summary>
        ///     Creates a new instance with a given display name and description.
        /// </summary>
        public BusinessUnit(string externalId, string name, string description, string currency = "USD")
        {
            Guard.ArgumentNotNullOrEmpty(externalId, nameof(externalId));

            Id = SeqGuid.Create();

            ExternalId       = externalId;
            Currency         = currency ?? "";
            DateActive       = DateTime.UtcNow;
            DateLastModified = DateActive;
            Description      = description;
            DisplayName      = name;
        }
Beispiel #10
0
        /// <summary>
        ///     Creates a new instance with a given display name and description.
        /// </summary>
        public Policy(string externalId, string displayName, string description)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(externalId, nameof(externalId));
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(displayName, nameof(displayName));

            this.Id = SeqGuid.Create();

            this.DisplayName      = displayName ?? "";
            this.Description      = description ?? "";
            this.ExternalId       = externalId ?? "";
            this.DateAdded        = DateTime.UtcNow;
            this.DateLastModified = this.DateAdded;
            this.UserName         = "";
        }
Beispiel #11
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        /// <param name="device">Gets the device the login or group has access to.</param>
        /// <param name="deviceModelDependency">Gets the application/device model the login has access to.</param>
        /// <param name="group"></param>
        public ApplicationAccess(Device device, DeviceModelDependency deviceModelDependency, UserGroup group)
        {
            Guard.ArgumentNotNull(device, nameof(device));
            Guard.ArgumentNotNull(deviceModelDependency, nameof(deviceModelDependency));
            Guard.ArgumentNotNull(group, nameof(group));

            this.DeviceId = device.Id;
            this.DeviceModelDependencyId = deviceModelDependency.Id;
            this.UserGroupId             = group.Id;
            this.DateLastModified        = DateTime.UtcNow;
            this.UserName = "";

            this.Id = SeqGuid.Create();
        }
Beispiel #12
0
        /// <summary>
        ///     Creates a new instance with a given display name and description.
        /// </summary>
        public Project(string externalId, string displayName, string description, string currency = "USD")
        {
            Guard.ArgumentNotNullOrEmpty(externalId, nameof(externalId));

            this.Id = SeqGuid.Create();

            this.DisplayName      = displayName ?? "";
            this.Description      = description ?? "";
            this.ExternalId       = externalId ?? "";
            this.Currency         = currency;
            this.DateCreated      = DateTime.UtcNow;
            this.DateLastModified = this.DateCreated;
            this.StartDate        = this.DateCreated;
        }
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public SoftwareModelInterface(SoftwareModel model, string externalId, string displayName, string description = null)
        {
            Guard.ArgumentNotNull(model, nameof(model));

            this.Id = SeqGuid.Create();

            this.ExternalId      = externalId;
            this.DisplayName     = displayName;
            this.DateCreated     = DateTime.UtcNow;
            this.Description     = description ?? "";
            this.ScenarioId      = model.ScenarioId;
            this.SoftwareModelId = model.Id;
            this.UserName        = "";
        }
Beispiel #14
0
        /// <summary>
        ///     Creates a new instance with a given name, description and external id.
        /// </summary>
        public Device(Network network, string name, string description, string externalId)
        {
            Guard.ArgumentNotNull(network, nameof(network));

            this.Id = SeqGuid.Create();

            this.DisplayName      = name ?? "";
            this.ScenarioId       = network.ScenarioId;
            this.NetworkId        = network.Id;
            this.Description      = description ?? "";
            this.DateAdded        = DateTime.UtcNow;
            this.AvailabilityTier = ""; // bronze etc
            this.ExternalId       = externalId ?? "";
            this.Attributes       = new List <Item>();
        }
Beispiel #15
0
        /// <summary>
        ///     Creates a new instance associated with a given architectural artefact, display name and/or description.
        /// </summary>
        public Capability(SoftwareModel softwareModel, string externalId, string displayName, string description = null)
        {
            Guard.ArgumentNotNull(softwareModel, nameof(softwareModel));
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(displayName, nameof(displayName));

            this.DisplayName      = displayName;
            this.Description      = description ?? "";
            this.DateCreated      = DateTime.UtcNow;
            this.ExternalId       = externalId ?? "";
            this.ScenarioId       = softwareModel.ScenarioId;
            this.SoftwareModelId  = softwareModel.Id;
            this.DateLastModified = DateCreated;
            this.UserName         = "";

            this.Id = SeqGuid.Create();
        }
        /// <summary>
        ///     Creates a new instance with a  given display name and description.
        /// </summary>
        public DeviceModel(string externalId, string displayName, string description = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(externalId, nameof(externalId));
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(displayName, nameof(displayName));

            // assign new id
            this.Id = SeqGuid.Create();

            this.DisplayName        = displayName;
            this.Description        = description ?? "";
            this.ModelVersion       = "";
            this.LifeCycleId        = "Research";
            this.ExternalId         = externalId ?? "";
            this.DateCreated        = DateTime.UtcNow;
            this.DateLastModified   = this.DateCreated;
            this.LifeCycleStageDate = this.DateCreated;
            this.Attributes         = new List <Item>();
        }
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        /// <param name="group">The group that owns the membership.</param>
        /// <param name="member">The group that the stakeholder belongs to.</param>
        public UserGroupMembership(UserGroup group, Stakeholder member)
        {
            Guard.ArgumentNotNull(group, nameof(group));
            Guard.ArgumentNotNull(member, nameof(member));

            if (group.ScenarioId != member.ScenarioId)
            {
                throw new InvalidOperationException("Group and member must belong to the same scenario.");
            }

            Id = SeqGuid.Create();

            ScenarioId       = group.ScenarioId;
            GroupId          = group.Id;
            MemberId         = member.Id;
            DateAdded        = DateTime.UtcNow;
            UserName         = "";
            DateLastModified = DateAdded;
        }
Beispiel #18
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public Stakeholder(string externalId, string firstName, string lastName, string displayName = null, Scenario scenario = null)
        {
            this.Id = SeqGuid.Create();

            this.FirstName   = firstName ?? "";
            this.LastName    = lastName ?? "";
            this.DateCreated = DateTime.UtcNow;
            // reserved for future use
            this.DisplayName       = displayName ?? $"{FirstName} {LastName}";
            this.StakeholderTypeId = "User";
            this.UserName          = "";
            this.ExternalId        = externalId ?? "";
            this.DateLastModified  = this.DateCreated;
            this.Description       = "";

            if (scenario != null)
            {
                ScenarioId = scenario.Id;
            }
        }
Beispiel #19
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public StakeholderLogin(Stakeholder stakeholder, string externalId, string userName, string description = null, Scenario scenario = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(userName, nameof(userName));
            Guard.ArgumentNotNull(stakeholder, nameof(stakeholder));

            this.Id = SeqGuid.Create();

            this.UserName      = userName;
            this.ExternalId    = externalId ?? "";
            this.ScenarioId    = stakeholder.ScenarioId;
            this.StakeholderId = stakeholder.Id;
            this.Description   = description ?? "";
            this.DateAdded     = DateTime.UtcNow;
            this.LoginType     = "Windows";

            if (scenario != null)
            {
                ScenarioId = scenario.Id;
            }
        }
Beispiel #20
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public Network(string externalId, string displayName, string description, Scenario scenario = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(externalId, nameof(externalId));

            Id = SeqGuid.Create();

            DisplayName      = displayName ?? "";
            Description      = description ?? "";
            ExternalId       = externalId ?? "";
            Attributes       = new List <Item>();
            Type             = "";
            UserName         = "";
            DateAdded        = DateTime.UtcNow;;
            DateLastModified = DateAdded;

            if (scenario != null)
            {
                ScenarioId = scenario.Id;
            }
        }
Beispiel #21
0
        /// <summary>
        ///     Creates a new instance with a given name and a description.
        /// </summary>
        public Protocol(string externalId, string displayName, string description = "", Protocol parent = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(externalId, nameof(externalId));

            Id = SeqGuid.Create();

            DisplayName      = displayName ?? "";
            Description      = description ?? "";
            ExternalId       = externalId ?? "";
            ProtocolTypeId   = "Other";
            DateLastModified = DateTime.UtcNow;
            UserName         = "";
            Version          = "";

            if (parent != null)
            {
                ParentId   = parent.Id;
                ScenarioId = parent.ScenarioId;
            }
        }
        public void GeneratesUniqueSeqGuids()
        {
            // arrange
            var list = new List <Guid>();

            for (var i = 0; i < 10; i++)
            {
                list.Add(SeqGuid.Create());
            }

            // assert
            for (var i = 0; i < list.Count; i++)
            {
                for (var j = i + 1; j < list.Count; j++)
                {
                    if (list[i] == list[j])
                    {
                        throw new Exception("Generated guids are not unique.");
                    }
                }
            }
        }
Beispiel #23
0
        public void Insert <T>(IDbConnection connection, IEnumerable <T> entities, IDbTransaction transaction,
                               int?commandTimeout) where T : class
        {
            var classMap   = SqlGenerator.Configuration.GetMap <T>();
            var properties = classMap.LinqPropertyMaps.Where(p => p.KeyType != KeyType.NotAKey).ToList();

            foreach (var e in entities)
            {
                foreach (var column in properties)
                {
                    if (column.KeyType == KeyType.Guid)
                    {
                        var comb = SeqGuid.Create();
                        column.PropertyInfo.SetValue(e, comb, null);
                    }
                }
            }

            var sql = SqlGenerator.Insert(classMap);

            connection.Execute(sql, entities, transaction, commandTimeout, CommandType.Text);
        }
Beispiel #24
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public SoftwareModel(string displayName, string description, Scenario scenario = null)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(displayName, nameof(displayName));

            this.Id = SeqGuid.Create();

            if (scenario != null)
            {
                this.ScenarioId = scenario.Id;
            }

            this.ExternalId           = displayName;
            this.DisplayName          = displayName;
            this.Description          = description ?? "";
            this.Version              = "";
            this.Vendor               = "";
            this.LicenseTypeId        = "";
            this.LicenseReferenceCode = "";
            this.LifeCycleId          = "Research";
            this.UserName             = "";
            this.DateLastModified     = DateTime.UtcNow;
            this.Attributes           = new List <Item>();
        }
        /// <summary>
        ///     Creates a new instance recording the dependency to a given
        /// </summary>
        /// <param name="dependendent">The software model that owns the dependency.</param>
        /// <param name="model">The software model that is depended on.</param>
        public SoftwareModelDependency(SoftwareModel dependendent, SoftwareModel model, string description = null)
        {
            Guard.ArgumentNotNull(dependendent, nameof(dependendent));
            Guard.ArgumentNotNull(model, nameof(model));

            if (dependendent.ScenarioId != model.ScenarioId)
            {
                throw new InvalidOperationException("Models belong to different scenarios.");
            }

            if (dependendent.Id == model.Id)
            {
                throw new ArgumentOutOfRangeException(nameof(dependendent), "Software models cannot depend on themselves.");
            }

            this.Id = SeqGuid.Create();
            // register to same scenario
            this.ScenarioId = dependendent.ScenarioId;

            this.SoftwareModelId           = dependendent.Id;
            this.SoftwareModelDependencyId = model.Id;
            this.Description = description ?? "";
        }