Esempio n. 1
0
        /// <summary>
        ///     Gets the value of all benefits provided by the device.
        /// </summary>
        /// <param name="date">The reference date to calculate the devices's total benefit.</param>
        public double GetAnnualBenefit(DateTime date)
        {
            if (this.Services == null)
            {
                throw new InvalidOperationException();
            }

            if (date < DateAdded)
            {
                return(0);
            }

            if (DateRemoved.HasValue)
            {
                if (DateRemoved.Value < date)
                {
                    return(0);
                }
            }

            var model    = this.Services.GetModel();
            var dateSart = this.DateAdded;
            var dateEnd  = this.DateAdded.AddYears(1);

            if (model.Services == null)
            {
                throw new InvalidOperationException();
            }

            bool initialYear = dateSart <= date && date < dateEnd;

            IEnumerable <DeviceModelDependency> dependencies = model.Services.GetDependencies();
            // |Year 0|Year 1
            // |fixed cost and annaul cost | annual cost

            double totalBenefit = 0;
            var    accountedFor = new HashSet <Guid>();

            foreach (DeviceModelDependency dependency in dependencies)
            {
                if (dependency.Services == null)
                {
                    throw new InvalidOperationException();
                }

                SoftwareModel sm = dependency.Services.GetSoftwareModel();

                totalBenefit = CalculateTotalBenefit(initialYear, sm, accountedFor);
            }

            return(totalBenefit);
        }
        /// <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.
        /// </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        = "";
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        double CalculateTotalBenefit(bool initialYear, SoftwareModel sm, HashSet <Guid> accountedFor)
        {
            if (accountedFor.Contains(sm.Id))
            {
                // already accounted for
                return(0);
            }

            // log account
            accountedFor.Add(sm.Id);

            double totalBenefit = 0;

            foreach (var capability in sm.Services.GetCapabilities())
            {
                // accumulate fixed cost year 1
                if (initialYear)
                {
                    if (capability.BusinessValue.HasValue)
                    {
                        totalBenefit += capability.BusinessValue.Value;
                    }
                }

                if (capability.AnnualBusinessValue.HasValue)
                {
                    totalBenefit += capability.AnnualBusinessValue.Value;
                }
            }

            // calculate benefits of all dependencies
            foreach (var dependency in sm.Services.GetDependencies())
            {
                totalBenefit += CalculateTotalBenefit(initialYear, sm, accountedFor);
            }

            return(totalBenefit);
        }
        /// <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 ?? "";
        }
Esempio n. 7
0
        /// <summary>
        ///     Gets the approximate total cost of owning a given instance of this software as of a given date.
        /// </summary>
        /// <param name="date">The reference date to calculate the devices total cost in Utc.</param>
        public double GetAnnualCost(DateTime date)
        {
            if (this.Services == null)
            {
                throw new InvalidOperationException();
            }

            if (date < DateAdded)
            {
                return(0);
            }

            if (DateRemoved.HasValue)
            {
                if (DateRemoved.Value < date)
                {
                    return(0);
                }
            }

            var model    = this.Services.GetModel();
            var dateSart = this.DateAdded;
            var dateEnd  = this.DateAdded.AddYears(1);

            if (model.Services == null)
            {
                throw new InvalidOperationException();
            }

            bool initialYear = dateSart <= date && date < dateEnd;

            var dependencies = model.Services.GetDependencies();
            // |Year 0|Year 1
            // |fixed cost and annaul cost | annual cost

            double totalCost = 0;

            foreach (DeviceModelDependency dependency in dependencies)
            {
                if (dependency.Services == null)
                {
                    throw new InvalidOperationException();
                }

                SoftwareModel softwareModel = dependency.Services.GetSoftwareModel();

                // accumulate fixed cost year 1
                if (initialYear)
                {
                    totalCost += softwareModel.FixedCost.HasValue ? softwareModel.FixedCost.Value : 0;
                }

                // annual license cost
                totalCost += softwareModel.AnnualCost.HasValue ? softwareModel.AnnualCost.Value : 0;
            }

            // add device cost
            if (initialYear)
            {
                totalCost += FixedCost.HasValue ? FixedCost.Value : 0;
            }

            totalCost += AnnualCost.HasValue ? AnnualCost.Value : 0;

            return(totalCost);
        }