コード例 #1
0
        protected override void _AddUsageInterval(
            int startHr, int startMin, int endHr, int endMin,
            UsageKind usageKind
            )
        {
            var ti = new TimeInterval(startHr, startMin, endHr, endMin);

            // If we're trying to add a UsageInterval that's UsingSolar
            if (usageKind == UsageKind.UsingSolar)
            {
                // but it starts before the PeakSolarInterval start
                // or ends after the PeakSolarInterval end
                if (ti.Start <
                    ReadOnlySiteSettings.PeakSolarInterval.Start ||
                    ti.End >
                    ReadOnlySiteSettings.PeakSolarInterval.End)
                {
                    // bad
                    throw new TimeIntervalArgumentInvalidException("When adding a UsageTimeInterval that is UsingSolar, the start/end cannot be before/after the Site's PeakSolarInterval start/end, respectively.");
                }
            }

            var newUTI = new UsageTimeInterval(ti, usageKind);

            for (int i = 0; i < _usageIntervals.Count; ++i)
            {
                var currTI = _usageIntervals[i].TimeInterval;

                // So now we know that either
                // * We have a UsingSolar interval but it's within the
                //   PeakSolarInterval, or
                // * We have an arbitrarily shaped Non-UsingSolar interval

                // If our new time interval starts before the current interval,
                if (ti.Start < currTI.Start)
                {
                    // and it also ends before the current interval
                    if (ti.End <= currTI.Start)
                    {
                        // Just insert it and return
                        _usageIntervals.Insert(i, newUTI);
                        return;
                    }
                    else // it ends after the current interval
                    {
                        throw new TimeIntervalArgumentInvalidException("It is not possible to add a new UsageTimeInterval that overlaps with an existing UsageTimeInterval.");
                    }
                }
                // Else if our new time intervals starts in the middle of an
                // existing interval
                else if (ti.Start < currTI.End)
                {
                    // bad
                    throw new TimeIntervalArgumentInvalidException("It is not possible to add a new UsageTimeInterval that overlaps with an existing UsageTimeInterval.");
                }
            }
            // If we're here then we're past all the intervals. So OK to Add.
            _usageIntervals.Add(newUTI);
        }
コード例 #2
0
 public void AddUsageInterval(
     int startHr, int startMin, int endHr, int endMin,
     UsageKind usageKind
     )
 {
     _AddUsageInterval(startHr, startMin, endHr, endMin, usageKind);
     RecalculateTotalTimes();
 }
コード例 #3
0
        public void ShouldAddUsageIntervalToEmpty(
            int peakStartHr, int peakStartMin, int peakEndHr, int peakEndMin,
            int startHr, int startMin, int endHr, int endMin,
            UsageKind usageKind)
        {
            var aus =
                new ApplianceUsageSchedule(
                    new MockReadOnlySiteSettings(
                        peakStartHr, peakStartMin, peakEndHr, peakEndMin
                        )
                    );

            aus.AddUsageInterval(startHr, startMin, endHr, endMin, usageKind);
            Assert.Single(aus.UsageIntervals);
            Assert.Equal(new UsageTimeInterval(
                             new TimeInterval(startHr, startMin, endHr, endMin), usageKind),
                         aus.UsageIntervals.First());
        }
コード例 #4
0
        public static void IncrementUsage(UsageKind usage, params object[] values)
        {
            try
            {
                var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Constants.AppDataDirName);
                Directory.CreateDirectory(dir);

                var usageLine = string.Format("{0}	{1}	{2}	{3}\n", DateTimeOffset.Now.Ticks, ProductVersion, usage, string.Join("|", values.Select(v => v.ToString())));
                var path = Path.Combine(dir, "usage-metrics.txt");

                lock (Lock)
                {
                    if (File.Exists(path))
                        File.AppendAllText(path, usageLine);
                    else
                        File.WriteAllText(path, usageLine);
                }
            }
            catch
            {
            }
        }
コード例 #5
0
        private void PrintUsage(UsageKind usageKind)
        {
            var prog = Path.GetFileName(Assembly.GetExecutingAssembly().Location);

            switch (usageKind)
            {
            case UsageKind.User:
                Console.WriteLine("Usage: dotnet {0} user <operation> [arguments...]", prog);
                Console.WriteLine();
                Console.WriteLine("Available operations on users:");
                Console.WriteLine("  list           Lists all existing users");
                Console.WriteLine("  create         Creates a new user");
                Console.WriteLine("  delete         Deletes a user and all of their associated authentication tokens");
                break;

            case UsageKind.Token:
                Console.WriteLine("Usage: dotnet {0} token <operation> [arguments...]", prog);
                Console.WriteLine();
                Console.WriteLine("Available operations on tokens:");
                Console.WriteLine("  list           Lists authentication tokens associated with a given user");
                Console.WriteLine("  issue          Issues a new authentcation token for an existing user");
                Console.WriteLine("  revoke         Revokes a previously-issued authentication token");
                break;

            case UsageKind.UserList:
                Console.WriteLine("Usage: dotnet {0} user list", prog);
                break;

            case UsageKind.UserCreate:
                Console.WriteLine("Usage: dotnet {0} user create <username> <email address>", prog);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                Console.WriteLine("  username       Username of the new user; can only consist of a-z A-Z 0-9 - and _");
                Console.WriteLine("  email address  Email address of the new user; must be valid");
                break;

            case UsageKind.UserDelete:
                Console.WriteLine("Usage: dotnet {0} user delete <username>", prog);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                Console.WriteLine("  username       Username of the user to delete");
                break;

            case UsageKind.TokenList:
                Console.WriteLine("Usage: dotnet {0} token list <username>", prog);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                Console.WriteLine("  username       Username of the user whose authentication tokens to list");
                break;

            case UsageKind.TokenIssue:
                Console.WriteLine("Usage: dotnet {0} token issue <username>", prog);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                Console.WriteLine("  username       Username of the user for whom to issue an authentication token");
                break;

            case UsageKind.TokenRevoke:
                Console.WriteLine("Usage: dotnet {0} token revoke <token>", prog);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                Console.WriteLine("  token          Authentication token to revoke");
                break;

            case UsageKind.General:
            default:
                Console.WriteLine("Usage: dotnet {0} <entity> <operation> [arguments...]", prog);
                Console.WriteLine();
                Console.WriteLine("Available entities:");
                Console.WriteLine("  user           Provides ability to manage users");
                Console.WriteLine("  token          Provides ability to manage authentication tokens");
                Console.WriteLine();
                Console.WriteLine("Available operations on users:");
                Console.WriteLine("  list           Lists all existing users");
                Console.WriteLine("  create         Creates a new user");
                Console.WriteLine("  delete         Deletes a user and all of their associated authentication tokens");
                Console.WriteLine();
                Console.WriteLine("Available operations on tokens:");
                Console.WriteLine("  list           Lists authentication tokens associated with a given user");
                Console.WriteLine("  issue          Issues a new authentcation token for an existing user");
                Console.WriteLine("  revoke         Revokes a previously-issued authentication token");
                break;
            }
        }
コード例 #6
0
 protected abstract void _AddUsageInterval(int startHr, int startMin,
                                           int endHr, int endMin, UsageKind usageKind);
コード例 #7
0
 public UsageTimeInterval(TimeInterval timeInterval,
                          UsageKind usageKind = UsageKind.UsingSolar)
 {
     TimeInterval = timeInterval;
     UsageKind    = usageKind;
 }