Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Developer: Tyler Allen
Date Created: 08/24/2016
---------------------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Linq;
using CPE.App.Notify.Extensions;
using CPE.App.Notify.Models.Enums;

namespace CPE.App.NotifyConsole.Extensions {
    public static class ApplicationExtensions {
        // Identitifes the stop session parameter
        private static string[] stopParameters {
            get { return new[] {"s", "-s", "/s", "stop"}; }
        }

        // Identifies the archive parameter 
        private static string[] archiveParameters {
            get { return new[] {"a", "-a", "/a", "archive", "r", "-r", "/r", "recording"}; }
        }

        // Identifies the meeting session key parameter
        private static string[] meetingSessionParameters {
            get { return new[] {"m", "-m", "/m"}; }
        }

        // Identifies the nowait parameter
        private static string[] noWaitParameters {
            get { return new[] {"nowait", "-nowait", "/nowait", "n", "-n", "/n"}; }
        }

        // Identifies the help parameter
        private static string[] helpParameters {
            get { return new[] {"help", "-help", "/help", "?", "-?", "/?"}; }
        }

        // Identifies the help parameter
        private static string[] testParameters {
            get { return new[] {"test", "-test", "/test", "t", "-t", "/t"}; }
        }

        // Identifies unattended parameters
        // Will run without interaction
        private static string[] unattendedModeParameters {
            get { return new[] {"u", "-u", "/u"}; }
        }

        // Should the application run without any interface for user
        // Default: Interface will show and cause a stop in the thread
        public static bool Unattended(this string[] args) {
            return args.Any(x => unattendedModeParameters.Contains(x.ToLower()));
        }

        // Should the application wait based on the arguments
        // Default: Wait the determined amount of time from the app.config
        public static bool Wait(this string[] args) {
            return !args.Any(x => noWaitParameters.Contains(x.ToLower()));
        }

        // Should the application accept the key value as a MeetingSessionKey
        // This is only used for archives (recordings)
        public static bool IsMeetingSession(this string[] args) {
            return args.Any(x => meetingSessionParameters.Contains(x.ToLower()));
        }

        // This is for testing the application
        // The processes will not execute
        // This is mainly used by the windows service for testing the execution of the console application
        public static bool IsTesting(this string[] args) {
            return args.Any(x => testParameters.Contains(x.ToLower()));
        }

        // Which method of the application is being processed based on the arguments
        public static ApplicationMethods WhichMethod(this string[] args) {
            if(args.Length == 0) {
                return ApplicationMethods.NotFound;
            }

            var sessionParameters = stopParameters.Concat(archiveParameters);
            var foundParameters = args.Where(x => sessionParameters.Contains(x));
            if(foundParameters.Count() != 1) {
                "Invalid use of the application. Please try again!".Log(LoggingLevels.Error);
                return ApplicationMethods.Invalid;
            }


            return args.parse();
        }

        // Return all integer values which are the keys for processing the session end
        public static int[] ArgumentValues(this string[] args) {
            int[] returnValues = null;
            try {
                var sessionParameters = stopParameters.Concat(archiveParameters);
                var foundValues = args.Where(x => !sessionParameters.Contains(x.ToLower()));
                returnValues = foundValues
                    .Select(NullableTryParseInt32)
                    .Where(x => x.HasValue)
                    .Select(x => Convert.ToInt32(x))
                    .ToArray();
                if(returnValues.Length == 0) {
                    throw new Exception("Arugument value keys were not found");
                }
            } catch (Exception exception) {
                exception.Log(LoggingLevels.Fatal);
                throw new KeyNotFoundException("There are no valid keys!");
            }
            return returnValues;
        }

        // Parsing method for return the application methods from the arguments
        private static ApplicationMethods parse(this string[] args) {
            if(args.Any(x => stopParameters.Contains(x.ToLower()))) {
                return ApplicationMethods.StopSession;
            }

            if(args.Any(x => archiveParameters.Contains(x.ToLower()))) {
                return ApplicationMethods.ArchiveSession;
            }

            if(args.Any(x => helpParameters.Contains(x.ToLower()))) {
                return ApplicationMethods.Help;
            }

            return ApplicationMethods.NotFound;
        }

        // Utility to return only integer values from the string array
        // This is used to extract the keys from the arguments
        private static int? NullableTryParseInt32(string text) {
            int value;
            return int.TryParse(text, out value) ? (int?) value : null;
        }
    }
}

Commits for CPE_learningsiteCPE/CPE.App/CPE.App.NotifyConsole/Extensions/ApplicationExtensions.cs

Diff revisions: vs.
Revision Author Commited Message
4cd176 ... v.shishlov Fri 27 Aug, 2021 14:33:17 +0000

initial commit