├── .gitattributes ├── .gitignore ├── HITScheduleMaster.sln ├── HITScheduleMaster.sln.DotSettings ├── HITScheduleMaster ├── Annotations.cs ├── App.xaml ├── App.xaml.cs ├── ExportWindow.xaml ├── ExportWindow.xaml.cs ├── HITScheduleMaster.csproj ├── LoginWindow.xaml ├── LoginWindow.xaml.cs └── ReferenceTime.cs ├── HITScheduleMasterCLI ├── Driver.cs ├── HITScheduleMasterCLI.csproj └── Program.cs ├── LICENSE ├── README.md ├── ScheduleTranslator ├── Class1.cs ├── Schedule.cs ├── ScheduleEntry.cs └── ScheduleTranslator.csproj ├── _config.yml └── images ├── image-1.png ├── image-2.png ├── image-3.png ├── image-4.png └── image-5.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /HITScheduleMaster.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29215.179 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HITScheduleMaster", "HITScheduleMaster\HITScheduleMaster.csproj", "{B95F04B3-C42A-485E-89A4-D01429B406C5}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HITScheduleMasterCLI", "HITScheduleMasterCLI\HITScheduleMasterCLI.csproj", "{F9DE89DE-7201-4A8B-83C1-D099FA15672D}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScheduleTranslator", "ScheduleTranslator\ScheduleTranslator.csproj", "{94D665B1-E2B2-4444-BB1C-7DD0499811F0}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Debug|ARM = Debug|ARM 16 | Debug|ARM64 = Debug|ARM64 17 | Debug|x64 = Debug|x64 18 | Debug|x86 = Debug|x86 19 | Release|Any CPU = Release|Any CPU 20 | Release|ARM = Release|ARM 21 | Release|ARM64 = Release|ARM64 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|ARM.ActiveCfg = Debug|Any CPU 29 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|ARM.Build.0 = Debug|Any CPU 30 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|ARM64.ActiveCfg = Debug|Any CPU 31 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|ARM64.Build.0 = Debug|Any CPU 32 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|x64.ActiveCfg = Debug|Any CPU 33 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|x64.Build.0 = Debug|Any CPU 34 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|x86.ActiveCfg = Debug|Any CPU 35 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Debug|x86.Build.0 = Debug|Any CPU 36 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|ARM.ActiveCfg = Release|Any CPU 39 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|ARM.Build.0 = Release|Any CPU 40 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|ARM64.ActiveCfg = Release|Any CPU 41 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|ARM64.Build.0 = Release|Any CPU 42 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|x64.ActiveCfg = Release|Any CPU 43 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|x64.Build.0 = Release|Any CPU 44 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|x86.ActiveCfg = Release|Any CPU 45 | {B95F04B3-C42A-485E-89A4-D01429B406C5}.Release|x86.Build.0 = Release|Any CPU 46 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|ARM.ActiveCfg = Debug|Any CPU 49 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|ARM.Build.0 = Debug|Any CPU 50 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|ARM64.ActiveCfg = Debug|Any CPU 51 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|ARM64.Build.0 = Debug|Any CPU 52 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|x64.ActiveCfg = Debug|Any CPU 53 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|x64.Build.0 = Debug|Any CPU 54 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|x86.ActiveCfg = Debug|Any CPU 55 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Debug|x86.Build.0 = Debug|Any CPU 56 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|ARM.ActiveCfg = Release|Any CPU 59 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|ARM.Build.0 = Release|Any CPU 60 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|ARM64.ActiveCfg = Release|Any CPU 61 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|ARM64.Build.0 = Release|Any CPU 62 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|x64.ActiveCfg = Release|Any CPU 63 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|x64.Build.0 = Release|Any CPU 64 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|x86.ActiveCfg = Release|Any CPU 65 | {F9DE89DE-7201-4A8B-83C1-D099FA15672D}.Release|x86.Build.0 = Release|Any CPU 66 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|ARM.ActiveCfg = Debug|Any CPU 69 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|ARM.Build.0 = Debug|Any CPU 70 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|ARM64.ActiveCfg = Debug|Any CPU 71 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|ARM64.Build.0 = Debug|Any CPU 72 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|x64.ActiveCfg = Debug|Any CPU 73 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|x64.Build.0 = Debug|Any CPU 74 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|x86.ActiveCfg = Debug|Any CPU 75 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Debug|x86.Build.0 = Debug|Any CPU 76 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|ARM.ActiveCfg = Release|Any CPU 79 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|ARM.Build.0 = Release|Any CPU 80 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|ARM64.ActiveCfg = Release|Any CPU 81 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|ARM64.Build.0 = Release|Any CPU 82 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|x64.ActiveCfg = Release|Any CPU 83 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|x64.Build.0 = Release|Any CPU 84 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|x86.ActiveCfg = Release|Any CPU 85 | {94D665B1-E2B2-4444-BB1C-7DD0499811F0}.Release|x86.Build.0 = Release|Any CPU 86 | EndGlobalSection 87 | GlobalSection(SolutionProperties) = preSolution 88 | HideSolutionNode = FALSE 89 | EndGlobalSection 90 | GlobalSection(ExtensibilityGlobals) = postSolution 91 | SolutionGuid = {4CF24C46-9E66-4FBB-8C8A-9EA5BB328CDD} 92 | EndGlobalSection 93 | EndGlobal 94 | -------------------------------------------------------------------------------- /HITScheduleMaster.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /HITScheduleMaster/Annotations.cs: -------------------------------------------------------------------------------- 1 | /* MIT License 2 | 3 | Copyright (c) 2016 JetBrains http://www.jetbrains.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. */ 22 | 23 | using System; 24 | 25 | // ReSharper disable InheritdocConsiderUsage 26 | 27 | #pragma warning disable 1591 28 | // ReSharper disable UnusedMember.Global 29 | // ReSharper disable MemberCanBePrivate.Global 30 | // ReSharper disable UnusedAutoPropertyAccessor.Global 31 | // ReSharper disable IntroduceOptionalParameters.Global 32 | // ReSharper disable MemberCanBeProtected.Global 33 | // ReSharper disable InconsistentNaming 34 | 35 | namespace HCGStudio.HITScheduleMaster.Annotations 36 | { 37 | /// 38 | /// Indicates that the value of the marked element could be null sometimes, 39 | /// so checking for null is required before its usage. 40 | /// 41 | /// 42 | /// 43 | /// [CanBeNull] object Test() => null; 44 | /// 45 | /// void UseTest() { 46 | /// var p = Test(); 47 | /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' 48 | /// } 49 | /// 50 | /// 51 | [AttributeUsage( 52 | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | 53 | AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | 54 | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] 55 | public sealed class CanBeNullAttribute : Attribute 56 | { 57 | } 58 | 59 | /// 60 | /// Indicates that the value of the marked element can never be null. 61 | /// 62 | /// 63 | /// 64 | /// [NotNull] object Foo() { 65 | /// return null; // Warning: Possible 'null' assignment 66 | /// } 67 | /// 68 | /// 69 | [AttributeUsage( 70 | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | 71 | AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | 72 | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] 73 | public sealed class NotNullAttribute : Attribute 74 | { 75 | } 76 | 77 | /// 78 | /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task 79 | /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property 80 | /// or of the Lazy.Value property can never be null. 81 | /// 82 | /// 83 | /// 84 | /// public void Foo([ItemNotNull]List<string> books) 85 | /// { 86 | /// foreach (var book in books) { 87 | /// if (book != null) // Warning: Expression is always true 88 | /// Console.WriteLine(book.ToUpper()); 89 | /// } 90 | /// } 91 | /// 92 | /// 93 | [AttributeUsage( 94 | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | 95 | AttributeTargets.Delegate | AttributeTargets.Field)] 96 | public sealed class ItemNotNullAttribute : Attribute 97 | { 98 | } 99 | 100 | /// 101 | /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task 102 | /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property 103 | /// or of the Lazy.Value property can be null. 104 | /// 105 | /// 106 | /// 107 | /// public void Foo([ItemCanBeNull]List<string> books) 108 | /// { 109 | /// foreach (var book in books) 110 | /// { 111 | /// // Warning: Possible 'System.NullReferenceException' 112 | /// Console.WriteLine(book.ToUpper()); 113 | /// } 114 | /// } 115 | /// 116 | /// 117 | [AttributeUsage( 118 | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | 119 | AttributeTargets.Delegate | AttributeTargets.Field)] 120 | public sealed class ItemCanBeNullAttribute : Attribute 121 | { 122 | } 123 | 124 | /// 125 | /// Indicates that the marked method builds string by the format pattern and (optional) arguments. 126 | /// The parameter, which contains the format string, should be given in constructor. The format string 127 | /// should be in -like form. 128 | /// 129 | /// 130 | /// 131 | /// [StringFormatMethod("message")] 132 | /// void ShowError(string message, params object[] args) { /* do something */ } 133 | /// 134 | /// void Foo() { 135 | /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string 136 | /// } 137 | /// 138 | /// 139 | [AttributeUsage( 140 | AttributeTargets.Constructor | AttributeTargets.Method | 141 | AttributeTargets.Property | AttributeTargets.Delegate)] 142 | public sealed class StringFormatMethodAttribute : Attribute 143 | { 144 | /// 145 | /// Specifies which parameter of an annotated method should be treated as the format string 146 | /// 147 | public StringFormatMethodAttribute([NotNull] string formatParameterName) 148 | { 149 | FormatParameterName = formatParameterName; 150 | } 151 | 152 | [NotNull] public string FormatParameterName { get; } 153 | } 154 | 155 | /// 156 | /// Use this annotation to specify a type that contains static or const fields 157 | /// with values for the annotated property/field/parameter. 158 | /// The specified type will be used to improve completion suggestions. 159 | /// 160 | /// 161 | /// 162 | /// namespace TestNamespace 163 | /// { 164 | /// public class Constants 165 | /// { 166 | /// public static int INT_CONST = 1; 167 | /// public const string STRING_CONST = "1"; 168 | /// } 169 | /// 170 | /// public class Class1 171 | /// { 172 | /// [ValueProvider("TestNamespace.Constants")] public int myField; 173 | /// public void Foo([ValueProvider("TestNamespace.Constants")] string str) { } 174 | /// 175 | /// public void Test() 176 | /// { 177 | /// Foo(/*try completion here*/);// 178 | /// myField = /*try completion here*/ 179 | /// } 180 | /// } 181 | /// } 182 | /// 183 | /// 184 | [AttributeUsage( 185 | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field, 186 | AllowMultiple = true)] 187 | public sealed class ValueProviderAttribute : Attribute 188 | { 189 | public ValueProviderAttribute([NotNull] string name) 190 | { 191 | Name = name; 192 | } 193 | 194 | [NotNull] public string Name { get; } 195 | } 196 | 197 | /// 198 | /// Indicates that the function argument should be a string literal and match one 199 | /// of the parameters of the caller function. For example, ReSharper annotates 200 | /// the parameter of . 201 | /// 202 | /// 203 | /// 204 | /// void Foo(string param) { 205 | /// if (param == null) 206 | /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol 207 | /// } 208 | /// 209 | /// 210 | [AttributeUsage(AttributeTargets.Parameter)] 211 | public sealed class InvokerParameterNameAttribute : Attribute 212 | { 213 | } 214 | 215 | /// 216 | /// Indicates that the method is contained in a type that implements 217 | /// System.ComponentModel.INotifyPropertyChanged interface and this method 218 | /// is used to notify that some property value changed. 219 | /// 220 | /// 221 | /// The method should be non-static and conform to one of the supported signatures: 222 | /// 223 | /// 224 | /// NotifyChanged(string) 225 | /// 226 | /// 227 | /// NotifyChanged(params string[]) 228 | /// 229 | /// 230 | /// NotifyChanged{T}(Expression{Func{T}}) 231 | /// 232 | /// 233 | /// NotifyChanged{T,U}(Expression{Func{T,U}}) 234 | /// 235 | /// 236 | /// SetProperty{T}(ref T, T, string) 237 | /// 238 | /// 239 | /// 240 | /// 241 | /// 242 | /// public class Foo : INotifyPropertyChanged { 243 | /// public event PropertyChangedEventHandler PropertyChanged; 244 | /// 245 | /// [NotifyPropertyChangedInvocator] 246 | /// protected virtual void NotifyChanged(string propertyName) { ... } 247 | /// 248 | /// string _name; 249 | /// 250 | /// public string Name { 251 | /// get { return _name; } 252 | /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } 253 | /// } 254 | /// } 255 | /// 256 | /// Examples of generated notifications: 257 | /// 258 | /// 259 | /// NotifyChanged("Property") 260 | /// 261 | /// 262 | /// NotifyChanged(() => Property) 263 | /// 264 | /// 265 | /// NotifyChanged((VM x) => x.Property) 266 | /// 267 | /// 268 | /// SetProperty(ref myField, value, "Property") 269 | /// 270 | /// 271 | /// 272 | [AttributeUsage(AttributeTargets.Method)] 273 | public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute 274 | { 275 | public NotifyPropertyChangedInvocatorAttribute() 276 | { 277 | } 278 | 279 | public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) 280 | { 281 | ParameterName = parameterName; 282 | } 283 | 284 | [CanBeNull] public string ParameterName { get; } 285 | } 286 | 287 | /// 288 | /// Describes dependency between method input and output. 289 | /// 290 | /// 291 | ///

Function Definition Table syntax:

292 | /// 293 | /// FDT ::= FDTRow [;FDTRow]* 294 | /// FDTRow ::= Input => Output | Output <= Input 295 | /// Input ::= ParameterName: Value [, Input]* 296 | /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} 297 | /// Value ::= true | false | null | notnull | canbenull 298 | /// 299 | /// If the method has a single input parameter, its name could be omitted.
300 | /// Using halt (or void/nothing, which is the same) for the method output 301 | /// means that the method doesn't return normally (throws or terminates the process).
302 | /// Value canbenull is only applicable for output parameters.
303 | /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute 304 | /// with rows separated by semicolon. There is no notion of order rows, all rows are checked 305 | /// for applicability and applied per each program state tracked by the analysis engine.
306 | ///
307 | /// 308 | /// 309 | /// 310 | /// 311 | /// [ContractAnnotation("=> halt")] 312 | /// public void TerminationMethod() 313 | /// 314 | /// 315 | /// 316 | /// 317 | /// [ContractAnnotation("null <= param:null")] // reverse condition syntax 318 | /// public string GetName(string surname) 319 | /// 320 | /// 321 | /// 322 | /// 323 | /// [ContractAnnotation("s:null => true")] 324 | /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() 325 | /// 326 | /// 327 | /// 328 | /// 329 | /// // A method that returns null if the parameter is null, 330 | /// // and not null if the parameter is not null 331 | /// [ContractAnnotation("null => null; notnull => notnull")] 332 | /// public object Transform(object data) 333 | /// 334 | /// 335 | /// 336 | /// 337 | /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] 338 | /// public bool TryParse(string s, out Person result) 339 | /// 340 | /// 341 | /// 342 | /// 343 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 344 | public sealed class ContractAnnotationAttribute : Attribute 345 | { 346 | public ContractAnnotationAttribute([NotNull] string contract) 347 | : this(contract, false) 348 | { 349 | } 350 | 351 | public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) 352 | { 353 | Contract = contract; 354 | ForceFullStates = forceFullStates; 355 | } 356 | 357 | [NotNull] public string Contract { get; } 358 | 359 | public bool ForceFullStates { get; } 360 | } 361 | 362 | /// 363 | /// Indicates whether the marked element should be localized. 364 | /// 365 | /// 366 | /// 367 | /// [LocalizationRequiredAttribute(true)] 368 | /// class Foo { 369 | /// string str = "my string"; // Warning: Localizable string 370 | /// } 371 | /// 372 | /// 373 | [AttributeUsage(AttributeTargets.All)] 374 | public sealed class LocalizationRequiredAttribute : Attribute 375 | { 376 | public LocalizationRequiredAttribute() : this(true) 377 | { 378 | } 379 | 380 | public LocalizationRequiredAttribute(bool required) 381 | { 382 | Required = required; 383 | } 384 | 385 | public bool Required { get; } 386 | } 387 | 388 | /// 389 | /// Indicates that the value of the marked type (or its derivatives) 390 | /// cannot be compared using '==' or '!=' operators and Equals() 391 | /// should be used instead. However, using '==' or '!=' for comparison 392 | /// with null is always permitted. 393 | /// 394 | /// 395 | /// 396 | /// [CannotApplyEqualityOperator] 397 | /// class NoEquality { } 398 | /// 399 | /// class UsesNoEquality { 400 | /// void Test() { 401 | /// var ca1 = new NoEquality(); 402 | /// var ca2 = new NoEquality(); 403 | /// if (ca1 != null) { // OK 404 | /// bool condition = ca1 == ca2; // Warning 405 | /// } 406 | /// } 407 | /// } 408 | /// 409 | /// 410 | [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] 411 | public sealed class CannotApplyEqualityOperatorAttribute : Attribute 412 | { 413 | } 414 | 415 | /// 416 | /// When applied to a target attribute, specifies a requirement for any type marked 417 | /// with the target attribute to implement or inherit specific type or types. 418 | /// 419 | /// 420 | /// 421 | /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement 422 | /// class ComponentAttribute : Attribute { } 423 | /// 424 | /// [Component] // ComponentAttribute requires implementing IComponent interface 425 | /// class MyComponent : IComponent { } 426 | /// 427 | /// 428 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 429 | [BaseTypeRequired(typeof(Attribute))] 430 | public sealed class BaseTypeRequiredAttribute : Attribute 431 | { 432 | public BaseTypeRequiredAttribute([NotNull] Type baseType) 433 | { 434 | BaseType = baseType; 435 | } 436 | 437 | [NotNull] public Type BaseType { get; } 438 | } 439 | 440 | /// 441 | /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), 442 | /// so this symbol will not be reported as unused (as well as by other usage inspections). 443 | /// 444 | [AttributeUsage(AttributeTargets.All)] 445 | public sealed class UsedImplicitlyAttribute : Attribute 446 | { 447 | public UsedImplicitlyAttribute() 448 | : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) 449 | { 450 | } 451 | 452 | public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) 453 | : this(useKindFlags, ImplicitUseTargetFlags.Default) 454 | { 455 | } 456 | 457 | public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) 458 | : this(ImplicitUseKindFlags.Default, targetFlags) 459 | { 460 | } 461 | 462 | public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) 463 | { 464 | UseKindFlags = useKindFlags; 465 | TargetFlags = targetFlags; 466 | } 467 | 468 | public ImplicitUseKindFlags UseKindFlags { get; } 469 | 470 | public ImplicitUseTargetFlags TargetFlags { get; } 471 | } 472 | 473 | /// 474 | /// Can be applied to attributes, type parameters, and parameters of a type assignable from 475 | /// . 476 | /// When applied to an attribute, the decorated attribute behaves the same as . 477 | /// When applied to a type parameter or to a parameter of type , indicates that the 478 | /// corresponding type 479 | /// is used implicitly. 480 | /// 481 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter | AttributeTargets.Parameter)] 482 | public sealed class MeansImplicitUseAttribute : Attribute 483 | { 484 | public MeansImplicitUseAttribute() 485 | : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) 486 | { 487 | } 488 | 489 | public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) 490 | : this(useKindFlags, ImplicitUseTargetFlags.Default) 491 | { 492 | } 493 | 494 | public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) 495 | : this(ImplicitUseKindFlags.Default, targetFlags) 496 | { 497 | } 498 | 499 | public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) 500 | { 501 | UseKindFlags = useKindFlags; 502 | TargetFlags = targetFlags; 503 | } 504 | 505 | [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; } 506 | 507 | [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; } 508 | } 509 | 510 | /// 511 | /// Specify the details of implicitly used symbol when it is marked 512 | /// with or . 513 | /// 514 | [Flags] 515 | public enum ImplicitUseKindFlags 516 | { 517 | Default = Access | Assign | InstantiatedWithFixedConstructorSignature, 518 | 519 | /// Only entity marked with attribute considered used. 520 | Access = 1, 521 | 522 | /// Indicates implicit assignment to a member. 523 | Assign = 2, 524 | 525 | /// 526 | /// Indicates implicit instantiation of a type with fixed constructor signature. 527 | /// That means any unused constructor parameters won't be reported as such. 528 | /// 529 | InstantiatedWithFixedConstructorSignature = 4, 530 | 531 | /// Indicates implicit instantiation of a type. 532 | InstantiatedNoFixedConstructorSignature = 8 533 | } 534 | 535 | /// 536 | /// Specify what is considered to be used implicitly when marked 537 | /// with or . 538 | /// 539 | [Flags] 540 | public enum ImplicitUseTargetFlags 541 | { 542 | Default = Itself, 543 | Itself = 1, 544 | 545 | /// Members of entity marked with attribute are considered used. 546 | Members = 2, 547 | 548 | /// Entity marked with attribute and all its members considered used. 549 | WithMembers = Itself | Members 550 | } 551 | 552 | /// 553 | /// This attribute is intended to mark publicly available API 554 | /// which should not be removed and so is treated as used. 555 | /// 556 | [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] 557 | public sealed class PublicAPIAttribute : Attribute 558 | { 559 | public PublicAPIAttribute() 560 | { 561 | } 562 | 563 | public PublicAPIAttribute([NotNull] string comment) 564 | { 565 | Comment = comment; 566 | } 567 | 568 | [CanBeNull] public string Comment { get; } 569 | } 570 | 571 | /// 572 | /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack. 573 | /// If the parameter is a delegate, indicates that delegate is executed while the method is executed. 574 | /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed. 575 | /// 576 | [AttributeUsage(AttributeTargets.Parameter)] 577 | public sealed class InstantHandleAttribute : Attribute 578 | { 579 | } 580 | 581 | /// 582 | /// Indicates that a method does not make any observable state changes. 583 | /// The same as System.Diagnostics.Contracts.PureAttribute. 584 | /// 585 | /// 586 | /// 587 | /// [Pure] int Multiply(int x, int y) => x * y; 588 | /// 589 | /// void M() { 590 | /// Multiply(123, 42); // Waring: Return value of pure method is not used 591 | /// } 592 | /// 593 | /// 594 | [AttributeUsage(AttributeTargets.Method)] 595 | public sealed class PureAttribute : Attribute 596 | { 597 | } 598 | 599 | /// 600 | /// Indicates that the return value of the method invocation must be used. 601 | /// 602 | /// 603 | /// Methods decorated with this attribute (in contrast to pure methods) might change state, 604 | /// but make no sense without using their return value.
605 | /// Similarly to , this attribute 606 | /// will help detecting usages of the method when the return value in not used. 607 | /// Additionally, you can optionally specify a custom message, which will be used when showing warnings, e.g. 608 | /// [MustUseReturnValue("Use the return value to...")]. 609 | ///
610 | [AttributeUsage(AttributeTargets.Method)] 611 | public sealed class MustUseReturnValueAttribute : Attribute 612 | { 613 | public MustUseReturnValueAttribute() 614 | { 615 | } 616 | 617 | public MustUseReturnValueAttribute([NotNull] string justification) 618 | { 619 | Justification = justification; 620 | } 621 | 622 | [CanBeNull] public string Justification { get; } 623 | } 624 | 625 | /// 626 | /// Indicates the type member or parameter of some type, that should be used instead of all other ways 627 | /// to get the value of that type. This annotation is useful when you have some "context" value evaluated 628 | /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one. 629 | /// 630 | /// 631 | /// 632 | /// class Foo { 633 | /// [ProvidesContext] IBarService _barService = ...; 634 | /// 635 | /// void ProcessNode(INode node) { 636 | /// DoSomething(node, node.GetGlobalServices().Bar); 637 | /// // ^ Warning: use value of '_barService' field 638 | /// } 639 | /// } 640 | /// 641 | /// 642 | [AttributeUsage( 643 | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method | 644 | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | 645 | AttributeTargets.GenericParameter)] 646 | public sealed class ProvidesContextAttribute : Attribute 647 | { 648 | } 649 | 650 | /// 651 | /// Indicates that a parameter is a path to a file or a folder within a web project. 652 | /// Path can be relative or absolute, starting from web root (~). 653 | /// 654 | [AttributeUsage(AttributeTargets.Parameter)] 655 | public sealed class PathReferenceAttribute : Attribute 656 | { 657 | public PathReferenceAttribute() 658 | { 659 | } 660 | 661 | public PathReferenceAttribute([NotNull] [PathReference] string basePath) 662 | { 663 | BasePath = basePath; 664 | } 665 | 666 | [CanBeNull] public string BasePath { get; } 667 | } 668 | 669 | /// 670 | /// An extension method marked with this attribute is processed by code completion 671 | /// as a 'Source Template'. When the extension method is completed over some expression, its source code 672 | /// is automatically expanded like a template at call site. 673 | /// 674 | /// 675 | /// Template method body can contain valid source code and/or special comments starting with '$'. 676 | /// Text inside these comments is added as source code when the template is applied. Template parameters 677 | /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs. 678 | /// Use the attribute to specify macros for parameters. 679 | /// 680 | /// 681 | /// In this example, the 'forEach' method is a source template available over all values 682 | /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block: 683 | /// 684 | /// [SourceTemplate] 685 | /// public static void forEach<T>(this IEnumerable<T> xs) { 686 | /// foreach (var x in xs) { 687 | /// //$ $END$ 688 | /// } 689 | /// } 690 | /// 691 | /// 692 | [AttributeUsage(AttributeTargets.Method)] 693 | public sealed class SourceTemplateAttribute : Attribute 694 | { 695 | } 696 | 697 | /// 698 | /// Allows specifying a macro for a parameter of a source template. 699 | /// 700 | /// 701 | /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression 702 | /// is defined in the property. When applied on a method, the target 703 | /// template parameter is defined in the property. To apply the macro silently 704 | /// for the parameter, set the property value = -1. 705 | /// 706 | /// 707 | /// Applying the attribute on a source template method: 708 | /// 709 | /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")] 710 | /// public static void forEach<T>(this IEnumerable<T> collection) { 711 | /// foreach (var item in collection) { 712 | /// //$ $END$ 713 | /// } 714 | /// } 715 | /// 716 | /// Applying the attribute on a template method parameter: 717 | /// 718 | /// [SourceTemplate] 719 | /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) { 720 | /// /*$ var $x$Id = "$newguid$" + x.ToString(); 721 | /// x.DoSomething($x$Id); */ 722 | /// } 723 | /// 724 | /// 725 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)] 726 | public sealed class MacroAttribute : Attribute 727 | { 728 | /// 729 | /// Allows specifying a macro that will be executed for a source template 730 | /// parameter when the template is expanded. 731 | /// 732 | [CanBeNull] 733 | public string Expression { get; set; } 734 | 735 | /// 736 | /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. 737 | /// 738 | /// 739 | /// If the target parameter is used several times in the template, only one occurrence becomes editable; 740 | /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence, 741 | /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1. 742 | /// 743 | public int Editable { get; set; } 744 | 745 | /// 746 | /// Identifies the target parameter of a source template if the 747 | /// is applied on a template method. 748 | /// 749 | [CanBeNull] 750 | public string Target { get; set; } 751 | } 752 | 753 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 754 | true)] 755 | public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute 756 | { 757 | public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) 758 | { 759 | Format = format; 760 | } 761 | 762 | [NotNull] public string Format { get; } 763 | } 764 | 765 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 766 | true)] 767 | public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute 768 | { 769 | public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) 770 | { 771 | Format = format; 772 | } 773 | 774 | [NotNull] public string Format { get; } 775 | } 776 | 777 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 778 | true)] 779 | public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute 780 | { 781 | public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) 782 | { 783 | Format = format; 784 | } 785 | 786 | [NotNull] public string Format { get; } 787 | } 788 | 789 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 790 | true)] 791 | public sealed class AspMvcMasterLocationFormatAttribute : Attribute 792 | { 793 | public AspMvcMasterLocationFormatAttribute([NotNull] string format) 794 | { 795 | Format = format; 796 | } 797 | 798 | [NotNull] public string Format { get; } 799 | } 800 | 801 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 802 | true)] 803 | public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute 804 | { 805 | public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) 806 | { 807 | Format = format; 808 | } 809 | 810 | [NotNull] public string Format { get; } 811 | } 812 | 813 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = 814 | true)] 815 | public sealed class AspMvcViewLocationFormatAttribute : Attribute 816 | { 817 | public AspMvcViewLocationFormatAttribute([NotNull] string format) 818 | { 819 | Format = format; 820 | } 821 | 822 | [NotNull] public string Format { get; } 823 | } 824 | 825 | /// 826 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 827 | /// is an MVC action. If applied to a method, the MVC action name is calculated 828 | /// implicitly from the context. Use this attribute for custom wrappers similar to 829 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). 830 | /// 831 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | 832 | AttributeTargets.Property)] 833 | public sealed class AspMvcActionAttribute : Attribute 834 | { 835 | public AspMvcActionAttribute() 836 | { 837 | } 838 | 839 | public AspMvcActionAttribute([NotNull] string anonymousProperty) 840 | { 841 | AnonymousProperty = anonymousProperty; 842 | } 843 | 844 | [CanBeNull] public string AnonymousProperty { get; } 845 | } 846 | 847 | /// 848 | /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC area. 849 | /// Use this attribute for custom wrappers similar to 850 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). 851 | /// 852 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 853 | public sealed class AspMvcAreaAttribute : Attribute 854 | { 855 | public AspMvcAreaAttribute() 856 | { 857 | } 858 | 859 | public AspMvcAreaAttribute([NotNull] string anonymousProperty) 860 | { 861 | AnonymousProperty = anonymousProperty; 862 | } 863 | 864 | [CanBeNull] public string AnonymousProperty { get; } 865 | } 866 | 867 | /// 868 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is 869 | /// an MVC controller. If applied to a method, the MVC controller name is calculated 870 | /// implicitly from the context. Use this attribute for custom wrappers similar to 871 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String). 872 | /// 873 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | 874 | AttributeTargets.Property)] 875 | public sealed class AspMvcControllerAttribute : Attribute 876 | { 877 | public AspMvcControllerAttribute() 878 | { 879 | } 880 | 881 | public AspMvcControllerAttribute([NotNull] string anonymousProperty) 882 | { 883 | AnonymousProperty = anonymousProperty; 884 | } 885 | 886 | [CanBeNull] public string AnonymousProperty { get; } 887 | } 888 | 889 | /// 890 | /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC Master. Use this attribute 891 | /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, String). 892 | /// 893 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 894 | public sealed class AspMvcMasterAttribute : Attribute 895 | { 896 | } 897 | 898 | /// 899 | /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC model type. Use this attribute 900 | /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, Object). 901 | /// 902 | [AttributeUsage(AttributeTargets.Parameter)] 903 | public sealed class AspMvcModelTypeAttribute : Attribute 904 | { 905 | } 906 | 907 | /// 908 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC 909 | /// partial view. If applied to a method, the MVC partial view name is calculated implicitly 910 | /// from the context. Use this attribute for custom wrappers similar to 911 | /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String). 912 | /// 913 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | 914 | AttributeTargets.Property)] 915 | public sealed class AspMvcPartialViewAttribute : Attribute 916 | { 917 | } 918 | 919 | /// 920 | /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method. 921 | /// 922 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] 923 | public sealed class AspMvcSuppressViewErrorAttribute : Attribute 924 | { 925 | } 926 | 927 | /// 928 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. 929 | /// Use this attribute for custom wrappers similar to 930 | /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String). 931 | /// 932 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 933 | public sealed class AspMvcDisplayTemplateAttribute : Attribute 934 | { 935 | } 936 | 937 | /// 938 | /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC editor template. 939 | /// Use this attribute for custom wrappers similar to 940 | /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String). 941 | /// 942 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 943 | public sealed class AspMvcEditorTemplateAttribute : Attribute 944 | { 945 | } 946 | 947 | /// 948 | /// ASP.NET MVC attribute. Indicates that the marked parameter is an MVC template. 949 | /// Use this attribute for custom wrappers similar to 950 | /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String). 951 | /// 952 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 953 | public sealed class AspMvcTemplateAttribute : Attribute 954 | { 955 | } 956 | 957 | /// 958 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 959 | /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly 960 | /// from the context. Use this attribute for custom wrappers similar to 961 | /// System.Web.Mvc.Controller.View(Object). 962 | /// 963 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | 964 | AttributeTargets.Property)] 965 | public sealed class AspMvcViewAttribute : Attribute 966 | { 967 | } 968 | 969 | /// 970 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 971 | /// is an MVC view component name. 972 | /// 973 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 974 | public sealed class AspMvcViewComponentAttribute : Attribute 975 | { 976 | } 977 | 978 | /// 979 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 980 | /// is an MVC view component view. If applied to a method, the MVC view component view name is default. 981 | /// 982 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Field | 983 | AttributeTargets.Property)] 984 | public sealed class AspMvcViewComponentViewAttribute : Attribute 985 | { 986 | } 987 | 988 | /// 989 | /// ASP.NET MVC attribute. When applied to a parameter of an attribute, 990 | /// indicates that this parameter is an MVC action name. 991 | /// 992 | /// 993 | /// 994 | /// [ActionName("Foo")] 995 | /// public ActionResult Login(string returnUrl) { 996 | /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK 997 | /// return RedirectToAction("Bar"); // Error: Cannot resolve action 998 | /// } 999 | /// 1000 | /// 1001 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] 1002 | public sealed class AspMvcActionSelectorAttribute : Attribute 1003 | { 1004 | } 1005 | 1006 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)] 1007 | public sealed class HtmlElementAttributesAttribute : Attribute 1008 | { 1009 | public HtmlElementAttributesAttribute() 1010 | { 1011 | } 1012 | 1013 | public HtmlElementAttributesAttribute([NotNull] string name) 1014 | { 1015 | Name = name; 1016 | } 1017 | 1018 | [CanBeNull] public string Name { get; } 1019 | } 1020 | 1021 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] 1022 | public sealed class HtmlAttributeValueAttribute : Attribute 1023 | { 1024 | public HtmlAttributeValueAttribute([NotNull] string name) 1025 | { 1026 | Name = name; 1027 | } 1028 | 1029 | [NotNull] public string Name { get; } 1030 | } 1031 | 1032 | /// 1033 | /// Razor attribute. Indicates that the marked parameter or method is a Razor section. 1034 | /// Use this attribute for custom wrappers similar to 1035 | /// System.Web.WebPages.WebPageBase.RenderSection(String). 1036 | /// 1037 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] 1038 | public sealed class RazorSectionAttribute : Attribute 1039 | { 1040 | } 1041 | 1042 | /// 1043 | /// Indicates how method, constructor invocation, or property access 1044 | /// over collection type affects the contents of the collection. 1045 | /// Use to specify the access type. 1046 | /// 1047 | /// 1048 | /// Using this attribute only makes sense if all collection methods are marked with this attribute. 1049 | /// 1050 | /// 1051 | /// 1052 | /// public class MyStringCollection : List<string> 1053 | /// { 1054 | /// [CollectionAccess(CollectionAccessType.Read)] 1055 | /// public string GetFirstString() 1056 | /// { 1057 | /// return this.ElementAt(0); 1058 | /// } 1059 | /// } 1060 | /// class Test 1061 | /// { 1062 | /// public void Foo() 1063 | /// { 1064 | /// // Warning: Contents of the collection is never updated 1065 | /// var col = new MyStringCollection(); 1066 | /// string x = col.GetFirstString(); 1067 | /// } 1068 | /// } 1069 | /// 1070 | /// 1071 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] 1072 | public sealed class CollectionAccessAttribute : Attribute 1073 | { 1074 | public CollectionAccessAttribute(CollectionAccessType collectionAccessType) 1075 | { 1076 | CollectionAccessType = collectionAccessType; 1077 | } 1078 | 1079 | public CollectionAccessType CollectionAccessType { get; } 1080 | } 1081 | 1082 | /// 1083 | /// Provides a value for the to define 1084 | /// how the collection method invocation affects the contents of the collection. 1085 | /// 1086 | [Flags] 1087 | public enum CollectionAccessType 1088 | { 1089 | /// Method does not use or modify content of the collection. 1090 | None = 0, 1091 | 1092 | /// Method only reads content of the collection but does not modify it. 1093 | Read = 1, 1094 | 1095 | /// Method can change content of the collection but does not add new elements. 1096 | ModifyExistingContent = 2, 1097 | 1098 | /// Method can add new elements to the collection. 1099 | UpdatedContent = ModifyExistingContent | 4 1100 | } 1101 | 1102 | /// 1103 | /// Indicates that the marked method is assertion method, i.e. it halts the control flow if 1104 | /// one of the conditions is satisfied. To set the condition, mark one of the parameters with 1105 | /// attribute. 1106 | /// 1107 | [AttributeUsage(AttributeTargets.Method)] 1108 | public sealed class AssertionMethodAttribute : Attribute 1109 | { 1110 | } 1111 | 1112 | /// 1113 | /// Indicates the condition parameter of the assertion method. The method itself should be 1114 | /// marked by attribute. The mandatory argument of 1115 | /// the attribute is the assertion type. 1116 | /// 1117 | [AttributeUsage(AttributeTargets.Parameter)] 1118 | public sealed class AssertionConditionAttribute : Attribute 1119 | { 1120 | public AssertionConditionAttribute(AssertionConditionType conditionType) 1121 | { 1122 | ConditionType = conditionType; 1123 | } 1124 | 1125 | public AssertionConditionType ConditionType { get; } 1126 | } 1127 | 1128 | /// 1129 | /// Specifies assertion type. If the assertion method argument satisfies the condition, 1130 | /// then the execution continues. Otherwise, execution is assumed to be halted. 1131 | /// 1132 | public enum AssertionConditionType 1133 | { 1134 | /// Marked parameter should be evaluated to true. 1135 | IS_TRUE = 0, 1136 | 1137 | /// Marked parameter should be evaluated to false. 1138 | IS_FALSE = 1, 1139 | 1140 | /// Marked parameter should be evaluated to null value. 1141 | IS_NULL = 2, 1142 | 1143 | /// Marked parameter should be evaluated to not null value. 1144 | IS_NOT_NULL = 3 1145 | } 1146 | 1147 | /// 1148 | /// Indicates that the marked method unconditionally terminates control flow execution. 1149 | /// For example, it could unconditionally throw exception. 1150 | /// 1151 | [Obsolete("Use [ContractAnnotation('=> halt')] instead")] 1152 | [AttributeUsage(AttributeTargets.Method)] 1153 | public sealed class TerminatesProgramAttribute : Attribute 1154 | { 1155 | } 1156 | 1157 | /// 1158 | /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select, 1159 | /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters 1160 | /// of delegate type by analyzing LINQ method chains. 1161 | /// 1162 | [AttributeUsage(AttributeTargets.Method)] 1163 | public sealed class LinqTunnelAttribute : Attribute 1164 | { 1165 | } 1166 | 1167 | /// 1168 | /// Indicates that IEnumerable passed as a parameter is not enumerated. 1169 | /// Use this annotation to suppress the 'Possible multiple enumeration of IEnumerable' inspection. 1170 | /// 1171 | /// 1172 | /// 1173 | /// static void ThrowIfNull<T>([NoEnumeration] T v, string n) where T : class 1174 | /// { 1175 | /// // custom check for null but no enumeration 1176 | /// } 1177 | /// 1178 | /// void Foo(IEnumerable<string> values) 1179 | /// { 1180 | /// ThrowIfNull(values, nameof(values)); 1181 | /// var x = values.ToList(); // No warnings about multiple enumeration 1182 | /// } 1183 | /// 1184 | /// 1185 | [AttributeUsage(AttributeTargets.Parameter)] 1186 | public sealed class NoEnumerationAttribute : Attribute 1187 | { 1188 | } 1189 | 1190 | /// 1191 | /// Indicates that the marked parameter is a regular expression pattern. 1192 | /// 1193 | [AttributeUsage(AttributeTargets.Parameter)] 1194 | public sealed class RegexPatternAttribute : Attribute 1195 | { 1196 | } 1197 | 1198 | /// 1199 | /// Prevents the Member Reordering feature from tossing members of the marked class. 1200 | /// 1201 | /// 1202 | /// The attribute must be mentioned in your member reordering patterns. 1203 | /// 1204 | [AttributeUsage( 1205 | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)] 1206 | public sealed class NoReorderAttribute : Attribute 1207 | { 1208 | } 1209 | 1210 | /// 1211 | /// XAML attribute. Indicates the type that has ItemsSource property and should be treated 1212 | /// as ItemsControl-derived type, to enable inner items DataContext type resolve. 1213 | /// 1214 | [AttributeUsage(AttributeTargets.Class)] 1215 | public sealed class XamlItemsControlAttribute : Attribute 1216 | { 1217 | } 1218 | 1219 | /// 1220 | /// XAML attribute. Indicates the property of some BindingBase-derived type, that 1221 | /// is used to bind some item of ItemsControl-derived type. This annotation will 1222 | /// enable the DataContext type resolve for XAML bindings for such properties. 1223 | /// 1224 | /// 1225 | /// Property should have the tree ancestor of the ItemsControl type or 1226 | /// marked with the attribute. 1227 | /// 1228 | [AttributeUsage(AttributeTargets.Property)] 1229 | public sealed class XamlItemBindingOfItemsControlAttribute : Attribute 1230 | { 1231 | } 1232 | 1233 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 1234 | public sealed class AspChildControlTypeAttribute : Attribute 1235 | { 1236 | public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) 1237 | { 1238 | TagName = tagName; 1239 | ControlType = controlType; 1240 | } 1241 | 1242 | [NotNull] public string TagName { get; } 1243 | 1244 | [NotNull] public Type ControlType { get; } 1245 | } 1246 | 1247 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] 1248 | public sealed class AspDataFieldAttribute : Attribute 1249 | { 1250 | } 1251 | 1252 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] 1253 | public sealed class AspDataFieldsAttribute : Attribute 1254 | { 1255 | } 1256 | 1257 | [AttributeUsage(AttributeTargets.Property)] 1258 | public sealed class AspMethodPropertyAttribute : Attribute 1259 | { 1260 | } 1261 | 1262 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 1263 | public sealed class AspRequiredAttributeAttribute : Attribute 1264 | { 1265 | public AspRequiredAttributeAttribute([NotNull] string attribute) 1266 | { 1267 | Attribute = attribute; 1268 | } 1269 | 1270 | [NotNull] public string Attribute { get; } 1271 | } 1272 | 1273 | [AttributeUsage(AttributeTargets.Property)] 1274 | public sealed class AspTypePropertyAttribute : Attribute 1275 | { 1276 | public AspTypePropertyAttribute(bool createConstructorReferences) 1277 | { 1278 | CreateConstructorReferences = createConstructorReferences; 1279 | } 1280 | 1281 | public bool CreateConstructorReferences { get; } 1282 | } 1283 | 1284 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 1285 | public sealed class RazorImportNamespaceAttribute : Attribute 1286 | { 1287 | public RazorImportNamespaceAttribute([NotNull] string name) 1288 | { 1289 | Name = name; 1290 | } 1291 | 1292 | [NotNull] public string Name { get; } 1293 | } 1294 | 1295 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 1296 | public sealed class RazorInjectionAttribute : Attribute 1297 | { 1298 | public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) 1299 | { 1300 | Type = type; 1301 | FieldName = fieldName; 1302 | } 1303 | 1304 | [NotNull] public string Type { get; } 1305 | 1306 | [NotNull] public string FieldName { get; } 1307 | } 1308 | 1309 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 1310 | public sealed class RazorDirectiveAttribute : Attribute 1311 | { 1312 | public RazorDirectiveAttribute([NotNull] string directive) 1313 | { 1314 | Directive = directive; 1315 | } 1316 | 1317 | [NotNull] public string Directive { get; } 1318 | } 1319 | 1320 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 1321 | public sealed class RazorPageBaseTypeAttribute : Attribute 1322 | { 1323 | public RazorPageBaseTypeAttribute([NotNull] string baseType) 1324 | { 1325 | BaseType = baseType; 1326 | } 1327 | 1328 | public RazorPageBaseTypeAttribute([NotNull] string baseType, string pageName) 1329 | { 1330 | BaseType = baseType; 1331 | PageName = pageName; 1332 | } 1333 | 1334 | [NotNull] public string BaseType { get; } 1335 | [CanBeNull] public string PageName { get; } 1336 | } 1337 | 1338 | [AttributeUsage(AttributeTargets.Method)] 1339 | public sealed class RazorHelperCommonAttribute : Attribute 1340 | { 1341 | } 1342 | 1343 | [AttributeUsage(AttributeTargets.Property)] 1344 | public sealed class RazorLayoutAttribute : Attribute 1345 | { 1346 | } 1347 | 1348 | [AttributeUsage(AttributeTargets.Method)] 1349 | public sealed class RazorWriteLiteralMethodAttribute : Attribute 1350 | { 1351 | } 1352 | 1353 | [AttributeUsage(AttributeTargets.Method)] 1354 | public sealed class RazorWriteMethodAttribute : Attribute 1355 | { 1356 | } 1357 | 1358 | [AttributeUsage(AttributeTargets.Parameter)] 1359 | public sealed class RazorWriteMethodParameterAttribute : Attribute 1360 | { 1361 | } 1362 | } -------------------------------------------------------------------------------- /HITScheduleMaster/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /HITScheduleMaster/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Net.Http; 4 | using System.Reflection; 5 | using System.Windows; 6 | using Newtonsoft.Json; 7 | 8 | namespace HCGStudio.HITScheduleMaster 9 | { 10 | /// 11 | /// Interaction logic for App.xaml 12 | /// 13 | public partial class App : Application 14 | { 15 | protected override async void OnStartup(StartupEventArgs e) 16 | { 17 | base.OnStartup(e); 18 | //检查更新 19 | var currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 20 | var http = new HttpClient(); 21 | http.DefaultRequestHeaders.UserAgent.ParseAdd( 22 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"); 23 | var info = JsonConvert.DeserializeObject(await (await http.GetAsync( 24 | "https://api.github.com/repos/HCGStudio/HIT-Schedule-Master/releases/latest")).Content 25 | .ReadAsStringAsync()); 26 | if (string.Compare(currentVersion, info.tag_name as string, StringComparison.Ordinal) >= 0) return; 27 | if (MessageBox.Show("有新版本发布,是否更新?", "新版本!", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == 28 | MessageBoxResult.Yes) 29 | Process.Start("explorer", info.html_url as string ?? throw new InvalidOperationException()); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /HITScheduleMaster/ExportWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 请选择目标课表 25 | 26 | 27 | 个人课表 28 | 班级推荐课表 29 | 32 | 其它班级课表 33 | 34 | 36 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /HITScheduleMaster/ExportWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net.Http; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Windows; 10 | using ExcelDataReader; 11 | using HtmlAgilityPack; 12 | using Ical.Net; 13 | using Ical.Net.CalendarComponents; 14 | using Ical.Net.DataTypes; 15 | using Ical.Net.Serialization; 16 | using Microsoft.Win32; 17 | using Trigger = Ical.Net.DataTypes.Trigger; 18 | 19 | namespace HCGStudio.HITScheduleMaster 20 | { 21 | /// 22 | /// WinExport.xaml 的交互逻辑 23 | /// 24 | public partial class ExportWindow : Window 25 | { 26 | public ExportWindow() 27 | { 28 | InitializeComponent(); 29 | } 30 | 31 | public HttpClient Http { get; set; } 32 | 33 | private void OtherClassSchedule_OnChecked(object sender, RoutedEventArgs e) 34 | { 35 | ClassNumberInput.Visibility = Visibility.Visible; 36 | } 37 | 38 | private void OtherClassSchedule_OnUnchecked(object sender, RoutedEventArgs e) 39 | { 40 | ClassNumberInput.Visibility = Visibility.Collapsed; 41 | } 42 | 43 | private void CancelButton_OnClick(object sender, RoutedEventArgs e) 44 | { 45 | Environment.Exit(0); 46 | } 47 | 48 | 49 | private async void OnRideOn(object sender, RoutedEventArgs e) 50 | { 51 | IsEnabled = false; 52 | var saveDialog = new SaveFileDialog 53 | { 54 | Filter = "iCalendar 文件 (*.ics)|*.ics", 55 | Title = "保存文件", 56 | InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) 57 | }; 58 | 59 | var fetchSemester = await Http.GetAsync("/kbcx/queryGrkb"); 60 | var fetched = await fetchSemester.Content.ReadAsStringAsync(); 61 | var htmlDoc = new HtmlDocument(); 62 | htmlDoc.LoadHtml(fetched); 63 | var select = htmlDoc.DocumentNode.SelectSingleNode("//option[@selected]"); 64 | var semester = Regex.Match(select.OuterHtml, @"\d{4}-\d{5}").Value; 65 | var tempName = Regex.Match(htmlDoc.DocumentNode.SelectSingleNode("//span[@class='ml10 bold']").InnerHtml, 66 | @"[\u4e00-\u9fa5]{1,}课表").Value; 67 | var name = tempName.Substring(0, tempName.Length - 2); 68 | 69 | //都9012年了,某些网站仍然在使用非UTF-8编码 70 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 71 | 72 | Calendar cal; 73 | 74 | if (PersonalSchedule.IsChecked == true) 75 | { 76 | using var content = 77 | new FormUrlEncodedContent(new[] 78 | { 79 | new KeyValuePair("xnxq", semester), 80 | new KeyValuePair("fhlj", "kbcx/queryGrkb") 81 | }); 82 | var getSchedule = await Http.PostAsync("/kbcx/ExportGrKbxx", content); 83 | await using var xlsStream = await getSchedule.Content.ReadAsStreamAsync(); 84 | cal = ConvertPersonalXlsToCalendar(xlsStream, semester); 85 | saveDialog.FileName = $"{name}个人课表.ics"; 86 | } 87 | else if (RecommendSchedule.IsChecked == true) 88 | { 89 | using var content = 90 | new FormUrlEncodedContent(new[] 91 | { 92 | new KeyValuePair("xnxq", semester), 93 | new KeyValuePair("zc", string.Empty) 94 | }); 95 | var getSchedule = await Http.PostAsync("/kbcx/ExportBjKbxx", content); 96 | await using var xlsStream = await getSchedule.Content.ReadAsStreamAsync(); 97 | cal = ConvertRecommendXlsToCalendar(xlsStream, semester); 98 | saveDialog.FileName = $"{name}班级推荐课表.ics"; 99 | } 100 | else 101 | { 102 | //防止报错 103 | cal = new Calendar(); 104 | } 105 | 106 | saveDialog.ShowDialog(this); 107 | 108 | try 109 | { 110 | File.WriteAllText(saveDialog.FileName, new CalendarSerializer().SerializeToString(cal), 111 | new UTF8Encoding(false)); 112 | } 113 | catch 114 | { 115 | MessageBox.Show("写入出错!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); 116 | Environment.Exit(0); 117 | } 118 | 119 | if (MessageBox.Show("成功,您是否要了解如何将iCalendar导入到您的日历中?", "导出成功", MessageBoxButton.YesNo, 120 | MessageBoxImage.Question) == MessageBoxResult.Yes) 121 | { 122 | Process.Start("explorer", "https://github.com/HCGStudio/HIT-Schedule-Master/wiki"); 123 | Environment.Exit(0); 124 | } 125 | else 126 | { 127 | Environment.Exit(0); 128 | } 129 | } 130 | 131 | private Calendar ConvertPersonalXlsToCalendar(Stream xlsStream, string semester) 132 | { 133 | var cal = new Calendar(); 134 | 135 | var reader = ExcelReaderFactory.CreateReader(xlsStream); 136 | var table = reader.AsDataSet().Tables[0]; 137 | 138 | for (var col = 3 - 1; col < 8 - 1; ++col) 139 | for (var row = 3 - 1; row < 9 - 1; ++row) 140 | { 141 | //col - 1 : sequent 142 | //row - 1 : weekday 143 | var current = table.Rows[col][row] as string; 144 | if (string.IsNullOrWhiteSpace(current)) 145 | continue; 146 | var splitCurrent = current.Split("
"); 147 | for (var index = 0; (index + 1) * 2 <= splitCurrent.Length; ++index) 148 | { 149 | var name = splitCurrent[index * 2]; 150 | var getLocation = splitCurrent[index * 2 + 1].Split("]周"); 151 | var location = getLocation.Length == 1 ? string.Empty : getLocation.Last(); 152 | var weeks = splitCurrent[index * 2 + 1].Split("[").Last().Split("]周").First().Replace(",", "") 153 | .Split(", "); 154 | var teacher = splitCurrent[index * 2 + 1].Split("[").First(); 155 | var weekList = new List(); 156 | foreach (var week in weeks) 157 | if (Regex.IsMatch(week, @"\d{1,}-\d{1,}单")) 158 | { 159 | var contains = Regex.Matches(week, @"\d+"); 160 | var from = Convert.ToInt32(contains[0].Value); 161 | var to = Convert.ToInt32(contains[1].Value); 162 | while (from <= to) 163 | { 164 | if (from % 2 == 1) 165 | weekList.Add(from); 166 | from++; 167 | } 168 | } 169 | else if (Regex.IsMatch(week, @"\d{1,}-\d{1,}双")) 170 | { 171 | var contains = Regex.Matches(week, @"\d+"); 172 | var from = Convert.ToInt32(contains[0].Value); 173 | var to = Convert.ToInt32(contains[1].Value); 174 | while (from <= to) 175 | { 176 | if (from % 2 == 0) 177 | weekList.Add(from); 178 | from++; 179 | } 180 | } 181 | else if (Regex.IsMatch(week, @"\d{1,}-\d{1,}")) 182 | { 183 | var contains = Regex.Matches(week, @"\d+"); 184 | var from = Convert.ToInt32(contains[0].Value); 185 | var to = Convert.ToInt32(contains[1].Value); 186 | while (from <= to) 187 | { 188 | weekList.Add(from); 189 | from++; 190 | } 191 | } 192 | else 193 | { 194 | weekList.Add(Convert.ToInt32(week)); 195 | } 196 | 197 | foreach (var e in weekList.Select(i => new CalendarEvent 198 | { 199 | Location = location, 200 | Start = new CalDateTime(ReferenceTime.BaseTime[semester].AddDays((i - 1) * 7 + row - 2) + 201 | ReferenceTime.StartTimes[col - 1]), 202 | Duration = ReferenceTime.ClassLength, 203 | Summary = $"{name} by {teacher} @ {location}" 204 | })) 205 | { 206 | e.Alarms.Add(new Alarm 207 | { 208 | Summary = $"您在{location}有一节{name}课程即将开始。", 209 | Action = AlarmAction.Display, 210 | Trigger = new Trigger(TimeSpan.FromMinutes(-25)) 211 | }); 212 | cal.Events.Add(e); 213 | } 214 | } 215 | } 216 | 217 | return cal; 218 | } 219 | 220 | private Calendar ConvertRecommendXlsToCalendar(Stream xlsStream, string semester) 221 | { 222 | var cal = new Calendar(); 223 | 224 | var reader = ExcelReaderFactory.CreateReader(xlsStream); 225 | var table = reader.AsDataSet().Tables[0]; 226 | 227 | for (var col = 3 - 1; col < 8 - 1; ++col) 228 | for (var row = 3 - 1; row < 9 - 1; ++row) 229 | { 230 | //col - 1 : sequent 231 | //row - 1 : weekday 232 | var current = table.Rows[col][row] as string; 233 | if (string.IsNullOrWhiteSpace(current)) 234 | continue; 235 | var splitCurrent = current.Split("
"); 236 | foreach (var currentCourse in splitCurrent) 237 | { 238 | var name = currentCourse.Split("◇").First(); 239 | var getLocation = currentCourse.Split("◇"); 240 | var location = getLocation.Length == 1 ? string.Empty : getLocation.Last(); 241 | var b = currentCourse.Split("[").Last(); 242 | var weeks = b.Split("周]").First().Replace(",", ", ").Split(", "); 243 | var teacher = currentCourse.Split("◇")[1].Split("[").First(); 244 | var weekList = new List(); 245 | foreach (var week in weeks) 246 | if (Regex.IsMatch(week, @"\d{1,}-\d{1,}单")) 247 | { 248 | var contains = Regex.Matches(week, @"\d+"); 249 | var from = Convert.ToInt32(contains[0].Value); 250 | var to = Convert.ToInt32(contains[1].Value); 251 | while (from <= to) 252 | { 253 | if (from % 2 == 1) 254 | weekList.Add(from); 255 | from++; 256 | } 257 | } 258 | else if (Regex.IsMatch(week, @"\d{1,}-\d{1,}双")) 259 | { 260 | var contains = Regex.Matches(week, @"\d+"); 261 | var from = Convert.ToInt32(contains[0].Value); 262 | var to = Convert.ToInt32(contains[1].Value); 263 | while (from <= to) 264 | { 265 | if (from % 2 == 0) 266 | weekList.Add(from); 267 | from++; 268 | } 269 | } 270 | else if (Regex.IsMatch(week, @"\d{1,}-\d{1,}")) 271 | { 272 | var contains = Regex.Matches(week, @"\d+"); 273 | var from = Convert.ToInt32(contains[0].Value); 274 | var to = Convert.ToInt32(contains[1].Value); 275 | while (from <= to) 276 | { 277 | weekList.Add(from); 278 | from++; 279 | } 280 | } 281 | else 282 | { 283 | weekList.Add(Convert.ToInt32(week)); 284 | } 285 | 286 | foreach (var e in weekList.Select(i => new CalendarEvent 287 | { 288 | Location = location, 289 | Start = new CalDateTime(ReferenceTime.BaseTime[semester].AddDays((i - 1) * 7 + row - 2) + 290 | ReferenceTime.StartTimes[col - 1]), 291 | Duration = ReferenceTime.ClassLength, 292 | Summary = $"{name} by {teacher} @ {location}" 293 | })) 294 | //课表为班级推荐课表的时候默认禁止通知 295 | 296 | //e.Alarms.Add(new Alarm 297 | //{ 298 | // Summary = $"您在{location}有一节{name}课程即将开始。", 299 | // Action = AlarmAction.Display, 300 | // Trigger = new Ical.Net.DataTypes.Trigger(TimeSpan.FromMinutes(-25)) 301 | //}); 302 | cal.Events.Add(e); 303 | } 304 | } 305 | 306 | return cal; 307 | } 308 | } 309 | } -------------------------------------------------------------------------------- /HITScheduleMaster/HITScheduleMaster.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | netcoreapp3.0 6 | true 7 | true 8 | win-x64 9 | true 10 | HCGStudio.HITScheduleMaster 11 | HCGStudio.HITScheduleMaster.App 12 | HCG Studio 13 | https://github.com/HCGStudio/HIT-Schedule-Master 14 | https://github.com/HCGStudio/HIT-Schedule-Master 15 | 1.1.2.0 16 | 1.1.2.0 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /HITScheduleMaster/LoginWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 欢迎使用 HIT Schedule Master, 28 | 29 | 30 | 我们将自动获取课表,并导出为日历文件。 31 | 32 | 33 | 下面请输入您的统一认证登陆信息。 34 | 35 | 学号 36 | 密码 37 | 验证码 38 | 40 | 41 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /HITScheduleMaster/LoginWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.IO; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Runtime.CompilerServices; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using HCGStudio.HITScheduleMaster.Annotations; 14 | 15 | namespace HCGStudio.HITScheduleMaster 16 | { 17 | /// 18 | /// WinLogin.xaml 的交互逻辑 19 | /// 20 | public partial class LoginWindow : Window, INotifyPropertyChanged 21 | { 22 | private ImageSource _captchaImage; 23 | 24 | public LoginWindow() 25 | { 26 | InitializeComponent(); 27 | DataContext = this; 28 | Http = new HttpClient(new HttpClientHandler 29 | { 30 | UseCookies = true, 31 | AllowAutoRedirect = true, 32 | CookieContainer = new CookieContainer() 33 | }); 34 | //不要问为啥User-Agent是这玩意 35 | Http.DefaultRequestHeaders.UserAgent.ParseAdd( 36 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"); 37 | Http.BaseAddress = new Uri("http://jwts.hit.edu.cn/"); 38 | } 39 | 40 | public ImageSource CaptchaImage 41 | { 42 | get => _captchaImage; 43 | set 44 | { 45 | _captchaImage = value; 46 | NotifyPropertyChange(); 47 | } 48 | } 49 | 50 | 51 | private HttpClient Http { get; } 52 | 53 | public event PropertyChangedEventHandler PropertyChanged; 54 | 55 | private async void LoginWindow_OnLoaded(object sender, RoutedEventArgs e) 56 | { 57 | //检测是否处于校园网环境 58 | try 59 | { 60 | var fetchIsInSchool = await Http.GetAsync("/"); 61 | if (!fetchIsInSchool.IsSuccessStatusCode) 62 | { 63 | MessageBox.Show("您需要在校园网中使用本程序", "错误", MessageBoxButton.OK, MessageBoxImage.Error); 64 | Environment.Exit(0); 65 | } 66 | } 67 | catch 68 | { 69 | MessageBox.Show("您需要在校园网中使用本程序", "错误", MessageBoxButton.OK, MessageBoxImage.Error); 70 | Environment.Exit(0); 71 | } 72 | 73 | await GetAndUpdateCaptcha(); 74 | } 75 | 76 | private async Task GetAndUpdateCaptcha() 77 | { 78 | var captchaFileName = Path.GetTempFileName(); 79 | var fetchCode = await Http.GetAsync("/captchaImage"); 80 | var writeCaptcha = new FileStream(captchaFileName, FileMode.Create); 81 | await (await fetchCode.Content.ReadAsStreamAsync()).CopyToAsync(writeCaptcha); 82 | await writeCaptcha.FlushAsync(); 83 | writeCaptcha.Close(); 84 | CaptchaImage = new BitmapImage(new Uri(captchaFileName)); 85 | } 86 | 87 | private async void Login_Button_OnClick(object sender, RoutedEventArgs e) 88 | { 89 | IsEnabled = false; 90 | using var content = new FormUrlEncodedContent(new[] 91 | { 92 | new KeyValuePair("usercode", IdBox.Text), 93 | new KeyValuePair("password", PasswordBox.Password), 94 | new KeyValuePair("code", CaptchaBox.Text) 95 | }); 96 | var response = await Http.PostAsync("/loginLdap", content); 97 | if (response.RequestMessage.RequestUri.ToString() != "http://jwts.hit.edu.cn/loginLdap") 98 | { 99 | MessageBox.Show("学号、密码或者验证码输入错误!", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); 100 | await GetAndUpdateCaptcha(); 101 | IsEnabled = true; 102 | } 103 | else 104 | { 105 | new ExportWindow {Http = Http}.ShowDialog(); 106 | } 107 | } 108 | 109 | [NotifyPropertyChangedInvocator] 110 | protected virtual void NotifyPropertyChange([CallerMemberName] string propertyName = null) 111 | { 112 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 113 | } 114 | 115 | private async void Image_OnMouseDown(object sender, MouseButtonEventArgs e) 116 | { 117 | await GetAndUpdateCaptcha(); 118 | } 119 | 120 | private void Exit_Base_OnClick(object sender, RoutedEventArgs e) 121 | { 122 | Environment.Exit(0); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /HITScheduleMaster/ReferenceTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace HCGStudio.HITScheduleMaster 5 | { 6 | internal static class ReferenceTime 7 | { 8 | public static Dictionary BaseTime => new Dictionary 9 | { 10 | {"2019-20201", new DateTime(2019, 09, 02)}, //2019秋 11 | {"2019-20202", new DateTime(2020, 02, 24)}, //2020春 12 | {"2019-20203", new DateTime(2020, 06, 29)} //2020夏 13 | }; 14 | 15 | public static TimeSpan ClassLength => new TimeSpan(01, 45, 00); 16 | 17 | public static TimeSpan[] StartTimes => new[] 18 | { 19 | new TimeSpan(), 20 | new TimeSpan(08, 00, 00), 21 | new TimeSpan(10, 00, 00), 22 | new TimeSpan(13, 45, 00), 23 | new TimeSpan(15, 45, 00), 24 | new TimeSpan(18, 30, 00) 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /HITScheduleMasterCLI/Driver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using Ical.Net.Serialization; 7 | using PlasticMetal.MobileSuit; 8 | using ScheduleTranslator; 9 | using PlasticMetal.MobileSuit.IO; 10 | using PlasticMetal.MobileSuit.ObjectModel; 11 | using PlasticMetal.MobileSuit.ObjectModel.Attributes; 12 | using static Newtonsoft.Json.JsonConvert; 13 | 14 | namespace HITScheduleMasterCLI 15 | { 16 | [MsInfo("HIT-Schedule-Master")] 17 | public class Driver : MsClient 18 | { 19 | private Schedule Schedule { get; set; } 20 | 21 | public Driver() 22 | { 23 | Text = "HIT-Schedule-Master"; 24 | } 25 | [MsInfo("向课表添加一个课程")] 26 | public void Add() 27 | { 28 | var name = Io?.ReadLine("输入课程名称"); 29 | if (!int.TryParse(Io?.ReadLine("输入星期(0-6,0表示周日)"), out var week) 30 | ||week<0||week>6) goto WrongInput; 31 | var teacher = Io?.ReadLine("输入教师"); 32 | var location = Io?.ReadLine("输入地点"); 33 | if (!TimeSpan.TryParse(Io?.ReadLine("输入开始时间(hh:mm:ss)"), out var startTime)) 34 | goto WrongInput; 35 | if (!TimeSpan.TryParse(Io?.ReadLine("输入持续时间(hh:mm:ss)"), out var length)) 36 | goto WrongInput; 37 | 38 | var weekExpression = Io?.ReadLine("输入周数(周数/起始-截至[单/双/(无)])"); 39 | Schedule.Entries.Add(new ScheduleEntry((DayOfWeek) week, default, 40 | $"{name}<>{teacher}[{weekExpression}]@{location}") 41 | {StartTime = startTime, Length = length}); 42 | return; 43 | WrongInput: 44 | Io?.WriteLine("非法输入。", IoServer.OutputType.Error); 45 | 46 | } 47 | [MsInfo("向课表导入一个JSON描述的课程: ImpCse <.json>")] 48 | public void ImpCse(string path) 49 | { 50 | if (!File.Exists(path)) 51 | { 52 | Io?.WriteLine("未找到文件。", IoServer.OutputType.Error); 53 | return; 54 | } 55 | Schedule.Entries.Add(DeserializeObject(File.ReadAllText(path))); 56 | } 57 | [MsInfo("从课表导出一个JSON描述的课程:ExpCse <.json>")] 58 | public void ExpCse(string id, string path = "") 59 | { 60 | if (Schedule is null) return; 61 | 62 | if (!int.TryParse(id, out var index) || index < 0 || index >= Schedule.Entries.Count) return; 63 | if (path == "") 64 | path = Io?.ReadLine("输入保存文件位置"); 65 | try 66 | { 67 | File.WriteAllText(path, SerializeObject(Schedule.Entries[index])); 68 | } 69 | catch 70 | { 71 | Io?.WriteLine("写入错误。", IoServer.OutputType.Error); 72 | Environment.Exit(0); 73 | } 74 | } 75 | [MsInfo("从课表移除一个JSON描述的课程:Remove ")] 76 | public void Remove(string id) 77 | { 78 | if (Schedule is null) return; 79 | if (int.TryParse(id, out var index) && index >= 0 && index < Schedule.Entries.Count) 80 | { 81 | Schedule.Entries.RemoveAt(index); 82 | } 83 | } 84 | [MsInfo("编辑课表中的课程:Edit ")] 85 | public void Edit(string id) 86 | { 87 | if (Schedule is null) return; 88 | if (int.TryParse(id, out var index) && index >= 0 && index < Schedule.Entries.Count) 89 | { 90 | var course = Schedule.Entries[index]; 91 | course.CourseName = Io?.ReadLine($"输入课程名称={course.CourseName}",course.CourseName, 92 | null); 93 | if (!int.TryParse(Io?.ReadLine($"输入星期(0-6,0表示周日)={((int)course.DayOfWeek)}", 94 | ((int)course.DayOfWeek).ToString(),null) 95 | , out var week) 96 | || week < 0 || week > 6) goto WrongInput; 97 | course.DayOfWeek = (DayOfWeek) week; 98 | course.Teacher = Io?.ReadLine($"输入教师={course.Teacher}", course.Teacher,null); 99 | course.Location = Io?.ReadLine($"输入地点={course.Location}", course.Location,null); 100 | if (!TimeSpan.TryParse(Io?.ReadLine($"输入开始时间(hh:mm:ss)={course.StartTime}", 101 | course.StartTime.ToString(),null), out var startTime)) 102 | goto WrongInput; 103 | course.StartTime = startTime; 104 | if (!TimeSpan.TryParse(Io?.ReadLine($"输入持续时间(hh:mm:ss)={course.Length}", 105 | course.Length.ToString(), null), out var length)) 106 | goto WrongInput; 107 | course.Length = length; 108 | var weekExpression = Io?.ReadLine( 109 | $"输入周数(周数/起始-截至[单/双/(无)],空格隔开)={course.WeekExpression}",course.WeekExpression,null); 110 | if (weekExpression != course.WeekExpression) 111 | { 112 | course.ChangeWeek(weekExpression); 113 | } 114 | return; 115 | 116 | } 117 | WrongInput: 118 | Io?.WriteLine("非法输入。", IoServer.OutputType.Error); 119 | } 120 | [MsInfo("导出整张课表:Export <.ics>")] 121 | public void Export(string path = "") 122 | { 123 | ScheduleCheck(); 124 | if (Schedule is null) return; 125 | if (path == "") 126 | path = Io?.ReadLine("输入保存文件位置"); 127 | try 128 | { 129 | var calendar = Schedule.GetCalendar(); 130 | //calendar.Name = Io?.ReadLine($"输入课表名称(默认:{calendar.Name})", calendar.Name, null); 131 | File.WriteAllText(path, 132 | new CalendarSerializer().SerializeToString(calendar), 133 | new UTF8Encoding(false)); 134 | } 135 | catch 136 | { 137 | Io?.WriteLine("写入错误。", IoServer.OutputType.Error); 138 | Environment.Exit(0); 139 | } 140 | } 141 | [MsInfo("显示整张课表:Export <.ics>")] 142 | public void Show() 143 | { 144 | ScheduleCheck(); 145 | if (Schedule is null) return; 146 | var maxWeek = (from e in Schedule.Entries select e.MaxWeek).Max(); 147 | var outList = new List<(string, ConsoleColor?)> 148 | { 149 | ("编号",null), 150 | ("\t", null), 151 | ("课程名".PadRight(22,' '), null), 152 | ("\t", null), 153 | ("星期", null), 154 | ("\t\t", null), 155 | ("起始时间", null), 156 | ("\t", null), 157 | ("课程长度",null), 158 | ("\t", null), 159 | ("授课教师", null), 160 | ("\t", null), 161 | ("课程地点".PadRight(8,' '), null), 162 | ("\t", null) 163 | 164 | }; 165 | for (var i = 1; i <= maxWeek; i++) 166 | { 167 | outList.Add(($"{i} ".PadLeft(4, '0'), null)); 168 | } 169 | 170 | Io?.WriteLine(outList, IoServer.OutputType.ListTitle); 171 | for (var i = 0; i < Schedule.Entries.Count; i++) 172 | { 173 | ShowScheduleEntry(i, maxWeek, Schedule.Entries[i]); 174 | } 175 | } 176 | [MsInfo("从xls导入整个课表:LoadXls <.xls>")] 177 | public void LoadXls(string path) 178 | { 179 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 180 | if (!File.Exists(path)) 181 | { 182 | Io?.WriteLine("未找到文件。", IoServer.OutputType.Error); 183 | return; 184 | } 185 | 186 | using var fs = File.OpenRead(path); 187 | Schedule = new Schedule(fs); 188 | } 189 | [MsInfo("从json导入整个课表:LoadJson <.json>")] 190 | public void LoadJson(string path) 191 | { 192 | if (!File.Exists(path)) 193 | { 194 | Io?.WriteLine("未找到文件。", IoServer.OutputType.Error); 195 | return; 196 | } 197 | Schedule = DeserializeObject(File.ReadAllText(path)); 198 | } 199 | [MsInfo("创建新课表")] 200 | public void New() 201 | { 202 | if (!(int.TryParse( 203 | Io?.ReadLine("输入年份", "1", null), out var year) 204 | && year >= 2020 && year <= 2021)) 205 | { 206 | Io?.WriteLine("无效输入。", IoServer.OutputType.Error); 207 | return; 208 | } 209 | Io?.WriteLine("选择学期:", IoServer.OutputType.ListTitle); 210 | Io?.AppendWriteLinePrefix(); 211 | Io?.WriteLine("0. 春(默认)"); 212 | Io?.WriteLine("1. 夏"); 213 | Io?.WriteLine("2. 秋"); 214 | Io?.SubtractWriteLinePrefix(); 215 | if (!int.TryParse( 216 | Io?.ReadLine("", "0", null), out var s) || s > 2 || s < 0) 217 | { 218 | Io?.WriteLine("无效输入。", IoServer.OutputType.Error); 219 | return; 220 | } 221 | 222 | Schedule = new Schedule(year, (Semester)s); 223 | } 224 | [MsInfo("初始化课表")] 225 | public void Init() 226 | { 227 | Io?.WriteLine("课表尚未初始化,您可以:", IoServer.OutputType.ListTitle); 228 | Io?.AppendWriteLinePrefix(); 229 | //Io?.WriteLine("0. 自动导入(默认)"); 230 | Io?.WriteLine("1. 手动导入XLS(默认)"); 231 | Io?.WriteLine("2. 手动导入JSON"); 232 | Io?.WriteLine("3. 创建新的课表"); 233 | Io?.WriteLine("其它. 退出"); 234 | Io?.SubtractWriteLinePrefix(); 235 | if (int.TryParse(Io?.ReadLine("选择", "1", null), out var o)) 236 | { 237 | switch (o) 238 | { 239 | //case 0: 240 | // Auto(); 241 | // break; 242 | case 1: 243 | LoadXls(Io?.ReadLine("Xls位置")); 244 | break; 245 | case 2: 246 | LoadJson(Io?.ReadLine("Json位置")); 247 | break; 248 | case 3: 249 | New(); 250 | break; 251 | default: 252 | Environment.Exit(0); 253 | break; 254 | } 255 | } 256 | else 257 | { 258 | Environment.Exit(0); 259 | } 260 | 261 | } 262 | [MsInfo("保存整张课表到Json:Save <.json>")] 263 | public void Save(string path = "") 264 | { 265 | ScheduleCheck(); 266 | if (Schedule is null) return; 267 | if (path == "") 268 | path = Io?.ReadLine("输入保存JSON文件位置"); 269 | try 270 | { 271 | File.WriteAllText(path, SerializeObject(Schedule)); 272 | } 273 | catch 274 | { 275 | Io?.WriteLine("写入错误。", IoServer.OutputType.Error); 276 | Environment.Exit(0); 277 | } 278 | } 279 | private void ScheduleCheck() 280 | { 281 | if (Schedule is null) Init(); 282 | } 283 | private void ShowScheduleEntry(int index, int maxWeek, ScheduleEntry entry) 284 | { 285 | var outList = new List<(string, ConsoleColor?)> 286 | { 287 | (index.ToString(),null), 288 | ("\t", null), 289 | (entry.CourseName.PadRight(22,' '), null), 290 | ("\t", null), 291 | (entry.DayOfWeekName, null), 292 | ("\t\t", null), 293 | (entry.StartTime.ToString(), null), 294 | ("\t", null), 295 | (entry.Length.ToString(),null), 296 | ("\t", null), 297 | (entry.Teacher, null), 298 | ("\t\t", null), 299 | (entry.Location.PadRight(8,' '), null), 300 | ("\t", null) 301 | 302 | }; 303 | var week = 1; 304 | for (var i = entry.Week >> 1; week <= maxWeek; i >>= 1, week++) 305 | { 306 | 307 | if ((i & 1) == 1) 308 | { 309 | outList.Add((" 1 ", ConsoleColor.Green)); 310 | } 311 | else 312 | { 313 | outList.Add((" 0 ", ConsoleColor.Red)); 314 | } 315 | } 316 | 317 | Io?.WriteLine(outList); 318 | } 319 | 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /HITScheduleMasterCLI/HITScheduleMasterCLI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | exe 5 | netcoreapp3.1 6 | 1.1.0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | MobileSuit.dll 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /HITScheduleMasterCLI/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | using ScheduleTranslator; 4 | using PlasticMetal.MobileSuit; 5 | 6 | namespace HITScheduleMasterCLI 7 | { 8 | class Program 9 | { 10 | 11 | static void Main(string[] args) 12 | { 13 | (new MsHost(new Driver())).Run(); 14 | 15 | } 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 哈工大课表大师 ~~(打安排御主)~~ 2 | 本应用使用dotnet core编写,完全开放、开源 3 | 4 | 本应用仅适用于**哈尔滨工业大学**的课程导出,不兼容其他学校的系统 5 | 6 | **作者不对使用本程序产生的任何后果负责** 7 | 8 | ![GPL3orLater](https://www.gnu.org/graphics/gplv3-or-later.png) 9 | 10 | 如果您在使用本程序的时候遇到了BUG或者有什么好的建议,欢迎您在Issuses中提出。 11 | 12 | 如果您对本程序进行了改进,欢迎PR! 13 | 14 | [下载地址](https://github.com/HCG-Studio/HIT-Schedule-Master/releases) 15 | 16 | [Wiki](https://github.com/HCGStudio/HIT-Schedule-Master/wiki) 17 | 18 | ## 主要功能 19 | 20 | - 从校园网中下载个人课表或者班级推荐课表并将其转换为`iCalendar (RFC 5545) `格式以便导入到日历软件中 21 | - 自动检查更新 22 | 23 | ## 为什么要使用本程序? 24 | 25 | - 本程序导出的` iCalendar (RFC 5545) `格式受世界上几乎所有的现代操作系统支持,实现了真正的跨平台 26 | - 由于日历一般为系统自带应用,因此UI往往与系统原生UI相同,并且系统的日历应用往往有优化。而且若不喜欢系统的日历应用,还可以使用第三方的日历应用。 27 | - **本程序导出的课表默认在开课前进行提醒,能够有效防止忘课。** 28 | 29 | ## 一些特性 30 | 31 | - 所有通过“个人课表”生成的日历,默认在课程开始前25分钟进行提醒 32 | - 通过“班级推荐课表”生成的日历,默认不进行提醒 33 | 34 | ## 将来可能会实现的功能 35 | 36 | - 在日历导出前能够删除课程 37 | - 选择是否创建提醒以及提醒的时间 38 | 39 | ## 已知BUG 40 | 41 | - 暂无 42 | 43 | ## CLI版本使用说明 44 | 45 | 输入'ls'即可获得所有可用命令。 46 | 47 | ## Windows日历 如何导入 48 | 49 | **请注意,Windows版“日历”应用只能将事件导入到已经存在的日历中,这可能是不安全的,因此作者建议采用网页版Outlook,或者Google日历来完成事件导入。** 50 | 51 | 先使用您的**电子邮件账户**登录Windows日历程序,然后使用Windows日历打开生成的`ics`文件,自动显示导入。 52 | 53 | 根据提示,选择指定的日历即可完成导入。 54 | 55 | ![image1](./images/image-1.png) 56 | 57 | 导入后,日历将与您登录的电子邮件账户同步,在移动端登录邮箱也会同步导入的日历。 58 | 59 | ## Outlook日历如何导入 60 | 61 | 1. 首先登陆网页版[网页版Outlook日历](https://outlook.live.com/calendar/)进行导入。 62 | 2. 在左边栏中点击"添加日历"![image2](./images/image-3.png) 63 | 3. 在弹出的窗口中,如图示完成新建日历。![image3](./images/image-4.png) 64 | 4. 将ICS描述的事件导入到新建的日历中。![image4](./images/image-5.png) 65 | 66 | 67 | ## Google日历 如何导入 68 | 69 | 请参考[将活动导入到 Google 日历](https://support.google.com/calendar/answer/37118?hl=zh-Hans)进行导入。 70 | 71 | 在导入后,日历将于您的Gmail账户同步,在移动端登录Gmail账户,或者下载Google日历客户端就可以使用。 72 | 73 | ## iOS 如何导入 74 | 75 | ### 方法一 76 | 77 | 在Windows下使用Windows日历,Outlook日历或者Google日历,在iOS的'邮件'应用中登录对应的电子邮件账户就可以导入日历到iOS设备。 78 | 79 | ### 方法二 80 | 81 | 在Windows下使用电子邮件将`ics`文件通过QQ传到手机,或者作为附件发送到iOS`邮件`应用中登录的账户,按照提示即可完成导入。 82 | 83 | ## Android 如何导入 84 | 85 | ### 方法一 86 | 87 | 在Windows下使用Windows日历,Outlook日历或者Google日历,在您使用系统的`日历`应用中登录对应的电子邮件账户就可以导入日历到Android设备。 88 | 89 | ### 方法二 90 | 91 | 在Windows下使用电子邮件将`ics`文件通过QQ传到手机,选择使用`日历`打开。如果您的系统无法使用日历打开`ics`文件,建议您安装`Google 日历`(无需登录即可导入)或者其他支持的日历软件(欢迎在PR中提出)。 92 | -------------------------------------------------------------------------------- /ScheduleTranslator/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ScheduleTranslator 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ScheduleTranslator/Schedule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using ExcelDataReader; 8 | using Ical.Net; 9 | using Ical.Net.CalendarComponents; 10 | using Ical.Net.DataTypes; 11 | 12 | namespace ScheduleTranslator 13 | { 14 | public enum Semester 15 | { 16 | Spring = 0, 17 | Autumn = 2, 18 | Summer = 1 19 | } 20 | public class Schedule 21 | { 22 | private static DateTime[] SemesterStarts => new[] 23 | { 24 | new DateTime(2020, 02, 24), 25 | new DateTime(2020, 06, 29), 26 | new DateTime(2020, 08, 31), 27 | new DateTime(2021, 02, 22), 28 | new DateTime(2021, 06, 28) 29 | }; 30 | public List Entries { get; } = new List(); 31 | public int Year { get; } 32 | public DateTime SemesterStart => SemesterStarts[Year - 2020 + (int)Semester]; 33 | public Semester Semester { get; set; } 34 | public Schedule(Stream xlsStream) 35 | { 36 | var cal = new Calendar(); 37 | 38 | var reader = ExcelReaderFactory.CreateReader(xlsStream); 39 | var table = reader.AsDataSet().Tables[0]; 40 | var tableHead = table.Rows[0][0] as string; 41 | if (tableHead is null) throw new Exception("错误的文件格式。"); 42 | Year = int.Parse(tableHead[..4]); 43 | Semester = tableHead[4] switch 44 | { 45 | '春' => Semester.Spring, 46 | '夏' => Semester.Summer, 47 | _ => Semester.Autumn 48 | 49 | }; 50 | for (var i = 0; i < 7; i++)//列 51 | for (var j = 0; j < 5; j++)//行 52 | { 53 | var current = table.Rows[j + 2][i + 2] as string; 54 | if (string.IsNullOrWhiteSpace(current)) 55 | continue; 56 | var next = table.Rows[j + 3][i + 2] as string; 57 | Entries.Add(new ScheduleEntry((DayOfWeek)((i+1) % 7), 58 | (CourseTime)(j + 1), 59 | current, current == next)); 60 | if (current == next) 61 | { 62 | j++; 63 | } 64 | } 65 | 66 | } 67 | 68 | public Calendar GetCalendar() 69 | { 70 | var calendar = new Calendar(); 71 | 72 | foreach (var entry in Entries) 73 | { 74 | var i = 0; 75 | var dayOfWeek = entry.DayOfWeek == DayOfWeek.Sunday ? 6 : ((int)entry.DayOfWeek - 1); 76 | for (var w = entry.Week >> 1; w != 0; w >>= 1, i++) 77 | { 78 | if ((w & 1) != 1) continue; 79 | var cEvent = new CalendarEvent 80 | { 81 | Location = entry.Location, 82 | Start = new CalDateTime( 83 | SemesterStart.AddDays(i * 7 + dayOfWeek) + entry.StartTime), 84 | Duration = entry.Length, 85 | Summary = $"{entry.CourseName} by {entry.Teacher} at {entry.Location}" 86 | }; 87 | cEvent.Alarms.Add(new Alarm 88 | { 89 | Summary = $"您在{entry.Location}有一节{entry.CourseName}课程即将开始。", 90 | Action = AlarmAction.Display, 91 | Trigger = new Trigger(TimeSpan.FromMinutes(-25)) 92 | }); 93 | calendar.Events.Add(cEvent); 94 | } 95 | } 96 | //var sem = Semester switch 97 | //{ 98 | // Semester.Autumn => "秋", 99 | // Semester.Summer => "夏", 100 | // _ => "春" 101 | //}; 102 | //calendar.Name = $"{Year}{sem}课程表"; 103 | return calendar; 104 | } 105 | public Schedule(int year, Semester semester) 106 | { 107 | Year = year; 108 | Semester = semester; 109 | } 110 | /// 111 | /// 只用于JSON导入 112 | /// 113 | public Schedule() { } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /ScheduleTranslator/ScheduleEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using ExcelDataReader; 7 | using Ical.Net; 8 | using Ical.Net.CalendarComponents; 9 | using Ical.Net.DataTypes; 10 | using Trigger = Ical.Net.DataTypes.Trigger; 11 | 12 | namespace ScheduleTranslator 13 | { 14 | public enum CourseTime 15 | { 16 | Noon = 0, 17 | C12 = 1, 18 | C34 = 2, 19 | C56 = 3, 20 | C78 = 4, 21 | C9A = 5 22 | 23 | }; 24 | 25 | public class ScheduleEntry 26 | { 27 | /// 28 | /// 周几的数值记录 29 | /// 30 | public DayOfWeek DayOfWeek { get; set; } 31 | /// 32 | /// 周几 33 | /// 34 | public string DayOfWeekName => DayOfWeek switch 35 | { 36 | DayOfWeek.Monday => "周一", 37 | DayOfWeek.Tuesday => "周二", 38 | DayOfWeek.Wednesday => "周三", 39 | DayOfWeek.Thursday => "周四", 40 | DayOfWeek.Friday => "周五", 41 | DayOfWeek.Saturday => "周六", 42 | _ => "周日" 43 | }; 44 | /// 45 | /// 是否是三节课长度的课 46 | /// 47 | public bool IsLongCourse { get; } 48 | /// 49 | /// 课程时间 50 | /// 51 | public CourseTime CourseTime { get; } 52 | /// 53 | /// 授课教师 54 | /// 55 | public string Teacher { get; set; } 56 | /// 57 | /// 课程名 58 | /// 59 | public string WeekExpression { get; private set; } 60 | public string CourseName { get; set; } 61 | /// 62 | /// 上课的位置 63 | /// 64 | public string Location { get; set; } 65 | /// 66 | /// 最大周数 67 | /// 68 | public int MaxWeek { get; set; } 69 | /// 70 | /// 状压储存的周数。i位为1表示此周有课。 71 | /// 72 | public uint Week { get; private set; } 73 | public TimeSpan Length { get; set; } 74 | 75 | public void ChangeWeek(string weekExpression) 76 | { 77 | Week = ParseWeek(weekExpression);} 78 | public uint ParseWeek(string weekExpression) 79 | { 80 | var week = 0u; 81 | WeekExpression = weekExpression 82 | .Replace(", ", "|")//英文逗号+空格 83 | .Replace(",", "|")//中文逗号 84 | .Replace(" ", "|");//手动输入的空格 85 | 86 | var expressions = WeekExpression.Split('|'); 87 | foreach (var expression in expressions) 88 | { 89 | var singleWeek = !expression.Contains("双"); 90 | var doubleWeek = !expression.Contains("单"); 91 | var weekRange = ( 92 | from w in Regex.Matches(expression, @"\d+") 93 | select int.Parse(w.Value) 94 | ).ToList(); 95 | if (weekRange.Count == 1) 96 | { 97 | week |= 1u << weekRange[0]; 98 | } 99 | else 100 | { 101 | for (var i = weekRange[0]; i <= weekRange[1]; i++) 102 | { 103 | if ((i & 1) == 1) 104 | { 105 | if (singleWeek) week |= 1u << i; 106 | } 107 | else 108 | { 109 | if (doubleWeek) week |= 1u << i; 110 | } 111 | } 112 | } 113 | 114 | } 115 | 116 | var maxWeek = 0; 117 | for (var weekCpy = week; weekCpy != 0; maxWeek++, weekCpy >>= 1) 118 | { 119 | 120 | } 121 | 122 | maxWeek--; 123 | if (maxWeek > MaxWeek) 124 | { 125 | MaxWeek = maxWeek; 126 | } 127 | 128 | Week = week; 129 | return week; 130 | } 131 | public ScheduleEntry(DayOfWeek dayOfWeek, CourseTime courseTime, string scheduleExpression, bool isLongCourse = false) 132 | { 133 | CourseName = scheduleExpression[..scheduleExpression.IndexOf('<')]; 134 | Teacher = scheduleExpression[(1 + scheduleExpression.IndexOf('>'))..scheduleExpression.IndexOf('[')]; 135 | Week = ParseWeek( 136 | scheduleExpression[(1 + scheduleExpression.IndexOf('['))..scheduleExpression.IndexOf(']')] 137 | ); 138 | var location = scheduleExpression[(scheduleExpression.IndexOf(']')+1)..]; 139 | Location = location.Length == 1 ? "待定地点" : location[1..]; 140 | CourseTime = courseTime; 141 | DayOfWeek = dayOfWeek; 142 | IsLongCourse = isLongCourse; 143 | Length = !IsLongCourse 144 | ? new TimeSpan(1, 45, 00) 145 | : new TimeSpan(3, 30, 00); 146 | 147 | StartTime = StartTimes[(int)CourseTime]; 148 | CourseTimeName = CourseTime switch 149 | { 150 | CourseTime.C12 => "一二节", 151 | CourseTime.C34 => "三四节", 152 | CourseTime.C56 => "五六节", 153 | CourseTime.C78 => "七八节", 154 | CourseTime.C9A => "晚上", 155 | _ => "中午" 156 | }; 157 | } 158 | private static TimeSpan[] StartTimes => new[] 159 | { 160 | new TimeSpan(12, 30, 00), 161 | new TimeSpan(08, 00, 00), 162 | new TimeSpan(10, 00, 00), 163 | new TimeSpan(13, 45, 00), 164 | new TimeSpan(15, 45, 00), 165 | new TimeSpan(18, 30, 00) 166 | }; 167 | public TimeSpan StartTime { get; set; } 168 | public string CourseTimeName { get; } 169 | 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /ScheduleTranslator/ScheduleTranslator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | title: 哈工大课表大师 3 | description: 一个使用dotnet core导出课表的程序 4 | -------------------------------------------------------------------------------- /images/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HCGStudio/HIT-Schedule-Master/748f3d219dd3c56a999f12e233f5e9e24aa545fc/images/image-1.png -------------------------------------------------------------------------------- /images/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HCGStudio/HIT-Schedule-Master/748f3d219dd3c56a999f12e233f5e9e24aa545fc/images/image-2.png -------------------------------------------------------------------------------- /images/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HCGStudio/HIT-Schedule-Master/748f3d219dd3c56a999f12e233f5e9e24aa545fc/images/image-3.png -------------------------------------------------------------------------------- /images/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HCGStudio/HIT-Schedule-Master/748f3d219dd3c56a999f12e233f5e9e24aa545fc/images/image-4.png -------------------------------------------------------------------------------- /images/image-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HCGStudio/HIT-Schedule-Master/748f3d219dd3c56a999f12e233f5e9e24aa545fc/images/image-5.png --------------------------------------------------------------------------------