-
Notifications
You must be signed in to change notification settings - Fork 1
/
1.System_Extensions.vb
5626 lines (4839 loc) · 234 KB
/
1.System_Extensions.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Drawing
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Web.Script.Serialization
Imports System.Windows.Forms
Imports System.Xml.Serialization
Imports SystemExtensions.AI_SDK_EXTENSIONS.MathsExt.Maths
Imports SystemExtensions.AI_SDK_EXTENSIONS.Strings
Imports SystemExtensions.AI_SDK_EXTENSIONS.Strings.Grammar
Namespace DesignPatterns
Namespace StateMachinePattern
''' <summary>
''' Can be inherited or Used as is
''' </summary>
Public Class State
''' <summary>
''' Name of State (also used as Identity)
''' </summary>
''' <returns></returns>
Public Property StateName As String = ""
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
End Class
''' <summary>
''' State Machine
''' </summary>
Public Class StateMachine
''' <summary>
''' Current State of the machine
''' </summary>
Private CurrentState As State
Private mMachineName As String = ""
''' <summary>
''' Current states held in the Machine
''' </summary>
Private States As New List(Of State)
''' <summary>
''' </summary>
''' <param name="State">
''' IEmotionalState.EmotionalStateName used to set the initial state
''' </param>
''' <param name="StatesList"></param>
Public Sub New(ByRef State As String, ByRef StatesList As List(Of State))
If StatesList IsNot Nothing Then
States = StatesList
If State IsNot Nothing Then
If CheckState(State) = True Then
ChangeState(State)
End If
End If
Else
End If
End Sub
''' <summary>
''' Informs The Controller that the state as been changed
''' </summary>
''' <param name="Sender"></param>
''' <param name="CurrentState"></param>
Public Event StateChanged(ByRef Sender As StateMachine, ByRef CurrentState As State)
Public Property MachineName As String
Get
Return mMachineName
End Get
Set(value As String)
mMachineName = value
End Set
End Property
''' <summary>
''' Adds a new state to the state machines held possible states
''' </summary>
''' <param name="State"></param>
Public Function AddState(ByRef State As State) As Boolean
Dim Added As Boolean = False
If State IsNot Nothing Then
If State.StateName IsNot Nothing Then
If CheckState(State) = False Then
States.Add(State)
Added = True
Else
End If
Else
End If
Else
End If
Return Added
End Function
''' <summary>
''' Changes the state to the specified State, which must exist in the state machine
''' </summary>
''' <param name="State">IEmotionalState.EmotionalStateName</param>
Public Function ChangeState(ByRef State As String) As Boolean
Dim StateChange As Boolean = False
If State IsNot Nothing Then
For Each item In States
If item.StateName = State Then
CurrentState = item
StateChange = True
RaiseEvent StateChanged(Me, item)
Else
End If
Next
Else
End If
Return StateChange
End Function
''' <summary>
''' Returns the current state
''' </summary>
''' <returns></returns>
Public Function GetState() As State
Return CurrentState
End Function
''' <summary>
''' checks if the state exists in the the list of states
''' </summary>
''' <param name="State">State To be checked</param>
''' <returns></returns>
Private Function CheckState(ByRef State As State) As Boolean
Dim found As Boolean = False
For Each item In States
If item.StateName = State.StateName = True Then
found = True
Else
End If
Next
Return found
End Function
''' <summary>
''' checks if the state exists in the the list of states
''' </summary>
''' <param name="State">IEmotionalState.EmotionalStateName</param>
''' <returns></returns>
Private Function CheckState(ByRef State As String) As Boolean
Dim found As Boolean = False
For Each item In States
If item.StateName = State = True Then
found = True
Else
End If
Next
Return found
End Function
End Class
''' <summary>
''' Controller for the state machine, Adds/Removes states / Changes States
''' </summary>
Public Class StateMachineController
''' <summary>
''' State machine
''' </summary>
Private WithEvents StateMachine As StateMachine
Public MachineState As String = ""
Public Sub New(ByRef InitialState As String, ByRef States As List(Of String))
CreateStateMachine(InitialState, CreateStates(States))
End Sub
Public Sub New(ByRef InitialState As String, ByRef States As List(Of State))
CreateStateMachine(InitialState, States)
End Sub
Public Event Err(ByRef Err As String)
''' <summary>
''' State Machine State Changed
''' </summary>
''' <param name="Sender"></param>
''' <param name="Changed"></param>
Public Event MachineStateChanged(ByRef Sender As StateMachineController, ByRef Changed As Boolean)
''' <summary>
''' Current state machine
''' </summary>
''' <returns></returns>
Public ReadOnly Property CurrentStateMachine As StateMachine
Get
If StateMachine IsNot Nothing Then
Return StateMachine
Else
Return Nothing
End If
End Get
End Property
''' <summary>
''' Creates a List of states for the state machine given a list of StateNames Req. for
''' creating a state machine
''' </summary>
''' <param name="ListOfStates"></param>
''' <returns></returns>
Public Shared Function CreateStates(ByRef ListOfStates As List(Of String)) As List(Of State)
Dim Lst As New List(Of State)
For Each item In ListOfStates
Dim NewState As New State
NewState.StateName = item
Next
Return Lst
End Function
''' <summary>
''' Adds as new state to the state machine
''' </summary>
''' <param name="State"></param>
Public Function AddState(ByRef State As State) As Boolean
Return StateMachine.AddState(State)
End Function
''' <summary>
''' Changes current state of the state machine
''' </summary>
''' <param name="State"></param>
Public Function ChangeState(ByRef State As String) As Boolean
Return StateMachine.ChangeState(State)
End Function
''' <summary>
''' Returns current state of the state machine
''' </summary>
''' <returns></returns>
Public Function GetCurrentState() As State
If StateMachine IsNot Nothing Then
Return StateMachine.GetState()
End If
Return Nothing
End Function
''' <summary>
''' Creates a new state machine to be controlled by the state machine controller;
''' </summary>
''' <param name="InitialState">initial state of the state machine</param>
''' <param name="States">list of states held in the state machine rto be created</param>
Private Sub CreateStateMachine(ByRef InitialState As String, ByRef States As List(Of State))
StateMachine = New StateMachine(InitialState, States)
End Sub
Private Sub StateMachine_StateChanged(ByRef Sender As StateMachine, ByRef CurrentState As State) Handles StateMachine.StateChanged
MachineState = CurrentState.StateName
RaiseEvent MachineStateChanged(Me, True)
End Sub
End Class
End Namespace
Namespace InferenceEngines
''' <summary>
''' Based on the inference engine paradigm: Under Construction / Research
''' </summary>
Public Class InferenceEngineParadigm
Public Function StartInferenceEngine() As Boolean
Dim ResultsFound As Boolean = False
'1. Enter data into matches: Generate ConflictSet
'2. Add ConflictSet to Resolve : Generate Results
'3. Execute Results
Return ResultsFound
End Function
''' <summary>
''' Conflict items (Ruleset - RulesetItems should be the same shape)
''' </summary>
Public Structure ConflictSet
Public items As List(Of ConflictItem)
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
''' <summary>
''' items to be in Conflct set (Ruleset - RulesetItems should be the same shape)
''' </summary>
Public Structure ConflictItem
Public cItem As String
Public Rating As Integer
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
End Structure
End Structure
''' <summary>
''' Execute Results
''' </summary>
Public Class Execute
'Execute result
End Class
''' <summary>
''' Enter data into matches: Generate ConflictSet
''' </summary>
Public Class Matches
Private mGeneratedConflictSet As ConflictSet
Public Sub New()
End Sub
''' <summary>
''' returned ConflictSet
''' </summary>
''' <returns></returns>
Public ReadOnly Property GeneratedConflictSet As ConflictSet
Get
Return mGeneratedConflictSet
End Get
End Property
''' <summary>
''' Check data vs rules
''' </summary>
Public Sub Data()
'Get The data
End Sub
''' <summary>
''' Keep items fitting the Rule conditions (add to conflict Set)
''' </summary>
Public Sub GenerateConflictSet()
'Check data vs rules
'Keep items fitting the Rule conditions (add to conflict Set)
End Sub
''' <summary>
''' Check set against ruleset
''' </summary>
Public Sub Rules()
'List of rules and conditions
End Sub
End Class
''' <summary>
''' Add ConflictSet to Resolve : Generate Results
''' </summary>
Public Class Resolve
'Interrogate ConflictSet :
':use strategy :
Private mResults As New ConflictSet.ConflictItem
Public ReadOnly Property Results As ConflictSet.ConflictItem
Get
Return mResults
End Get
End Property
Public Sub Interrogate(ByVal _ConflictSet As ConflictSet, ByVal _Strategy As String)
Select Case _Strategy
Case "LEX:"
'LEX: Pick the rule that passes the most amounts of required tests
Case "RECENCY"
'RECENCY: Pick the rule that is the most common or Recent
Case "MeanEndsAynalasis"
'Means End Analysis : Combine rules (Lex & Recency)
End Select
End Sub
End Class
End Class
End Namespace
''' <summary>
''' Abstract Class: Publisher / Subscriber DesignPattern subscribers implement this
''' interface to receive notifications from the publisher
''' </summary>
Public Interface Observer
#Region "Public Methods"
''' <summary>
''' This is the channel to receive data from the publisher this variable needs to match
''' the data being updated from the publisher
''' </summary>
''' <param name="Data"></param>
Sub Update(ByVal Data As String)
#End Region
End Interface
'Publisher & Subscriber DesignPattern
'Author : Leroy S Dyer
'Year : 2017
''' <summary>
''' Abstract Class: Publisher / Subscriber DesignPattern this interface is used as the main
''' task manager for the subscriber classes the subject is the information provider or Publisher
''' </summary>
Public Interface Publisher
#Region "Public Methods"
Sub NotifyObservers()
Sub RegisterObserver(ByVal mObserver As Observer)
Sub RemoveObserver(ByVal mObserver As Observer)
#End Region
End Interface
''' <summary>
''' Abstract Class: Mediator Implements Both Subscriber and publisher patterns
'''
''' </summary>
Public Class Mediator
Implements Observer
Implements Publisher
#Region "Public Methods"
Public Sub NotifyObservers() Implements Publisher.NotifyObservers
Throw New NotImplementedException()
End Sub
Public Sub RegisterObserver(mObserver As Observer) Implements Publisher.RegisterObserver
Throw New NotImplementedException()
End Sub
Public Sub RemoveObserver(mObserver As Observer) Implements Publisher.RemoveObserver
Throw New NotImplementedException()
End Sub
Public Sub Update(Data As String) Implements Observer.Update
Throw New NotImplementedException()
End Sub
#End Region
End Class
End Namespace
Namespace Web
Public Structure Bookmark
Dim Name As String
Dim Url As String
End Structure
Public Class GoogleMaps
'Data query is to be returned to sender for use in a WebBrowser
Private street As String = ""
Private City As String = ""
Private State As String = ""
Private Zip As String = ""
Public Query As String
Private GoogleQuery As New StringBuilder
Public Sub New(_street As String, _city As String, _State As String, _Zip As String)
GoogleQuery.Append("Http://maps.google.com/maps?q=")
Try
If _street <> "" Then GoogleQuery.Append(_street + "," & "+")
If _street <> "" Then GoogleQuery.Append(_city + "," & "+")
If _street <> "" Then GoogleQuery.Append(_State + "," & "+")
If _street <> "" Then GoogleQuery.Append(_Zip + "," & "+")
Query = GoogleQuery.ToString
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
End Class
Public Module WebSearch
Public SearchVideo As String = ""
Public SearchNews As String = ""
Public SearchPictures As String = ""
Public SearchRadio As String = ""
Public SearchPhone As String = ""
Public SearchBusiness As String = ""
Public SearchLocation As String = ""
Public SearchProduct As String = ""
Public VideoSearch = "http://video.google.com/videosearch?q=" & SearchVideo & "&hl=en&emb=0&aq=f#"
Public RadioSearch = "http://www.radioteam.eu/?action=archive&search=" & SearchRadio
Public NewsSearch = "http://news.google.com/news?hl=en&tab=wn&ned=us&nolr=1&q=" & SearchNews & "&btnG=Search"
Public PicSearch = "http://www.images.google.com/images?svnum=10&hl=en&lr=&q=" & SearchPictures & "&btnG=Search"
Public PhoneSearch = "http://search.yahoo.com/search?p=phone%3A%22" & SearchPhone & "%22+&phone=" & SearchPhone & "&meta=pplt%3Dr&fr=php-rplu"
Public ProductSearch = "http://www.google.com/products?q=" & SearchProduct & "&btnG=Search+Products&hl=en"
Public BusinessSearch = "http://www.yellowpages.com/name/" & SearchLocation & "/" & SearchBusiness
Public BbcSearch = "http://www.bbc.co.uk/mediaselector/ondemand/worldservice/meta/tx/live_news?bgc=003399&lang=en-ws&nbram=1&nbwm=1&ms3=2&ms_javascript=true&bbcws=1&size=au"
Public WebSiteSearch = "www."
Public Mapsearch = "http://www.google.com/local?q="
Public FilipinoSearch = "http://www.eradioportal.com/index.php?p=2&aid=1/"
Public WikiSearch = "http://en.wikipedia.org/wiki/"
Public GoogleSearch = "http://www.google.com/search?q="
Public StockSearch = "http://finance.google.com/finance?q="
Public BookSearch = "http://www.google.com/books?q="
Public YellowPagesSearch = "http://www.yellowpages.com/nationwide/name_search/"
Public PersonSearch = "http://www.whitepages.com/5116/"
Public SearchTextAol As String = "http://search.aol.co.uk/aol/search?"
Public SearchTextGoogle As String = "https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q="
Public SearchTextBing As String = "http://www.bing.com/search?q="
Public Searchwikipedia As String = "http://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=default&search="
Public SearchYoutube As String = "https://www.youtube.com/results?search_query="
Public SearchGoogleMaps As String = "https://www.google.co.uk/maps/place/"
Public InfoWarsSite = "http://www.infowars.com/"
Public FacebookSite = "http://www.facebook.com/"
Public PrisonPlanetSite = "http://www.prisonplanet.com/"
Public VirtualhumansforumSite = "http://www.vrconsulting.it/vhf/"
Public MsnSite = "http://www.msn.com/"
Public GoogleSite = "http://www.google.com/"
Public ZabawareforumSite = "http://www.zabaware.com/forum/"
Public NationalnewsSite = "http://www.foxnews.com/"
End Module
Public Module Internet_News_Searching
Public Function OpeningSite() As String
OpeningSite = ""
Select Case (Int(Rnd() * 4) + 1)
Case 1
OpeningSite = "Here is the page you asked me for." & vbCrLf
Case 2
OpeningSite = "Here it is. Now you can access it." & vbCrLf
Case 3
OpeningSite = "I am accessing it for you." & vbCrLf
Case 4
OpeningSite = "OK. Here it is." & vbCrLf
Case 5
OpeningSite = "I am opening the connection." & vbCrLf
End Select
End Function
Dim SearchWebSite As String = ""
Dim SearchVideo As String = ""
Dim SearchNews As String = ""
Dim SearchPictures As String = ""
Dim SearchMaps As String = ""
Dim SearchRadio As String = ""
Dim SearchWiki As String = ""
Dim UserInput As String = ""
Dim SearchGoogle As String = ""
Dim SearchPhone As String = ""
Dim SearchStock As String = ""
Dim SearchBusiness As String = ""
Dim SearchLocation As String = ""
Dim SearchProduct As String = ""
Dim SearchBook As String = ""
Dim SearchNation As String = ""
Dim BbcSearch = "http://www.bbc.co.uk/mediaselector/ondemand/worldservice/meta/tx/live_news?bgc=003399&lang=en-ws&nbram=1&nbwm=1&ms3=2&ms_javascript=true&bbcws=1&size=au"
Dim VideoSearch = "http://video.google.com/videosearch?q=" & SearchVideo & "&hl=en&emb=0&aq=f#"
Dim RadioSearch = "http://www.windowsmedia.com/radiotuner/FindStations.asp?locale=409&search=" & SearchRadio
Dim NewsSearch = "http://news.google.com/news?hl=en&tab=wn&ned=us&nolr=1&q=" & SearchNews & "&btnG=Search"
Dim WebSiteSearch = "www." & SearchWebSite
Dim Mapsearch = "http://www.google.com/local?q=" & SearchMaps
Dim PicSearch = "http://www.images.google.com/images?svnum=10&hl=en&lr=&q=" & SearchPictures & "&btnG=Search"
Dim WikiSearch = "http://en.wikipedia.org/wiki/" & SearchWiki
Dim GoogleSearch = "http://www.google.com/search?q=" & SearchGoogle
Dim FilipinoSearch = "http://www.eradioportal.com/index.php?p=2&aid=1"
Dim PhoneSearch = "http://search.yahoo.com/search?p=phone%3A%22" & SearchPhone & "%22+&phone=" & SearchPhone & "&meta=pplt%3Dr&fr=php-rplu"
Dim StockSearch = "http://finance.google.com/finance?q=" & SearchStock
Dim BookSearch = "http://www.google.com/books?q=" & SearchBook
Dim ProductSearch = "http://www.google.com/products?q=" & SearchProduct & "&btnG=Search+Products&hl=en"
Dim BusinessSearch = "http://www.yellowpages.com/name/" & SearchLocation & "/" & SearchBusiness
Dim NationSearch = "http://www.yellowpages.com/nationwide/name_search/" & SearchNation
Dim PersonSearch = "http://www.whitepages.com/5116"
Public Function NewsReader(ByRef Userinput As String) As String
Dim NewsTopic As String = ""
Dim NewsRead As String = Userinput
If InStr(1, NewsRead, "CURRENT NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/topNews"
If InStr(1, NewsRead, "CURRENT NATIONAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/domesticNews"
If InStr(1, NewsRead, "CURRENT FINANCIAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/businessNews"
If InStr(1, NewsRead, "CURRENT WORLD NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/worldNews"
If InStr(1, NewsRead, "CURRENT ENTERTAINMENT NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/entertainment"
If InStr(1, NewsRead, "CURRENT SPORTS NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/sportsNews"
If InStr(1, NewsRead, "CURRENT TECHNOLOGY NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/technologyNews"
If InStr(1, NewsRead, "CURRENT POLITICAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/politicsNews"
If InStr(1, NewsRead, "CURRENT SCIENCE NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/scienceNews"
If InStr(1, NewsRead, "CURRENT HEALTH NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/healthNews"
If InStr(1, NewsRead, "CURRENT ODD NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/oddlyEnoughNews"
If InStr(1, NewsRead, "LATEST NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/topNews"
If InStr(1, NewsRead, "LATEST NATIONAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/domesticNews"
If InStr(1, NewsRead, "LATEST FINANCIAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/businessNews"
If InStr(1, NewsRead, "LATEST WORLD NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/worldNews"
If InStr(1, NewsRead, "LATEST ENTERTAINMENT NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/entertainment"
If InStr(1, NewsRead, "LATEST SPORTS NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/sportsNews"
If InStr(1, NewsRead, "LATEST TECHNOLOGY NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/technologyNews"
If InStr(1, NewsRead, "LATEST POLITICAL NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/politicsNews"
If InStr(1, NewsRead, "LATEST SCIENCE NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/scienceNews"
If InStr(1, NewsRead, "LATEST HEALTH NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/healthNews"
If InStr(1, NewsRead, "LATEST ODD NEWS", 1) > 0 Then NewsTopic = "http://feeds.reuters.com/reuters/oddlyEnoughNews"
Return NewsTopic
End Function
Public Function WeatherReader(ByRef UserInput As String, ByRef SearchWeatherzip As String) As String
Dim NewsTopic As String = ""
Dim NewsRead As String = UserInput
If InStr(1, NewsRead, "CURRENT WEATHER", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=currtxt&zcode=z4641"
If InStr(1, NewsRead, "CURRENT WEATHER FORECAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "CURRENT FORECAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "LATEST WEATHER", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=currtxt&zcode=z4641"
If InStr(1, NewsRead, "LATEST WEATHER FORECAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "LATEST FORECAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "CURRENT WEATHER FORCAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "CURRENT FORCAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "LATEST WEATHER FORCAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
If InStr(1, NewsRead, "LATEST FORCAST", 1) > 0 Then NewsTopic = "http://feeds.weatherbug.com/rss.aspx?zipcode=" & SearchWeatherzip & "&feed=fcsttxt&zcode=z4641"
Return NewsTopic
End Function
Public Function AttemptFeed() As String
AttemptFeed = ""
Dim Choice As Integer
Select Case Choice
Case 1
AttemptFeed = "One moment, linking to news feed."
Case 2
AttemptFeed = "Buffering news stream."
Case 3
AttemptFeed = "Awaiting news stream."
Case 4
AttemptFeed = "Updating news feed."
Case 5
AttemptFeed = "Just a moment. Parsing news data."
Case 6
AttemptFeed = "Downloading news data."
End Select
Return AttemptFeed
End Function
Public Function RespondFeed(ByRef FeedData As String) As String
Dim Choice As Integer
RespondFeed = ""
Select Case Choice
Case 1
RespondFeed = "Just a moment." & vbCrLf & FeedData & "This concludes the news feed. Terminating connection."
Case 2
RespondFeed = "One moment." & vbCrLf & FeedData & "End of news feed. Closing data stream."
Case 3
RespondFeed = "Just a moment." & vbCrLf & FeedData & "That is all the news data at this time. News feed terminated."
Case 4
RespondFeed = "One moment." & vbCrLf & FeedData & "News feed complete. Closing uplink."
Case 5
RespondFeed = "Just a moment." & vbCrLf & FeedData & "That is all of the current data. Terminating feed."
Case 6
RespondFeed = "One moment." & vbCrLf & FeedData & "This concludes the news stream. Closing all stream connections."
End Select
End Function
Public Function RespondBadFeed() As String
RespondBadFeed = ""
Dim Choice As Integer
Select Case Choice
Case 1
RespondBadFeed = "That stream contains no data at the present time. I'm sorry. Please try again momentarily."
Case 2
RespondBadFeed = "I can't seem to find a valid source at that location. I'm sorry. The stream must be in the process of updating the data. Please try again in a moment."
Case 3
RespondBadFeed = "I'm sorry to have to tell you this, but that source is not operational. If the data is being updated then, it will be temporarily unavailable."
Case 4
RespondBadFeed = "There seems to be a problem. That stream is currently void of any usable data. The data must be updating. The stream should be available in a moment."
Case 5
RespondBadFeed = "There seems to be a fault in the uplink. Please confirm the source, and try again in a moment."
Case 6
RespondBadFeed = "There must be a fault in the data stream. Please check the uplink source, and try again."
End Select
End Function
End Module
End Namespace
Namespace AI_SDK_EXTENSIONS
Namespace Functions
Public Module iFileExtensions
Public Sub SaveTextFile(ByRef FileName As String, ByRef Text As String)
SaveTextFileAs(FileName, Text)
End Sub
Public Function GetDirSubDirectorys(ByVal directory As IO.DirectoryInfo, ByVal pattern As String) As List(Of String)
Dim Files As New List(Of String)
For Each file In directory.GetFiles(pattern)
Console.WriteLine(file.FullName)
Files.Add(file.FullName)
Next
For Each subDir In directory.GetDirectories
GetDirSubDirectorys(subDir, pattern)
Next
Return Files
End Function
''' <summary>
''' Loads Json file to new string
''' </summary>
''' <returns></returns>
Public Function LoadJson() As String
Dim Scriptfile As String = ""
Dim Ofile As New OpenFileDialog
With Ofile
.Filter = "Json files (*.Json)|*.Json"
If (.ShowDialog() = DialogResult.OK) Then
Scriptfile = .FileName
End If
End With
Dim txt As String = ""
If Scriptfile IsNot "" Then
txt = My.Computer.FileSystem.ReadAllText(Scriptfile)
Return txt
Else
Return txt
End If
End Function
''' <summary>
''' Writes the contents of an embedded file resource embedded as Bytes to disk.
''' EG: My.Resources.DefBrainConcepts.FileSave(Application.StartupPath and "\DefBrainConcepts.ACCDB")
''' </summary>
''' <param name="BytesToWrite">Embedded resource Name</param>
''' <param name="FileName">Save to file</param>
''' <remarks></remarks>
<System.Runtime.CompilerServices.Extension()>
Public Sub FileSave(ByVal BytesToWrite() As Byte, ByVal FileName As String)
If IO.File.Exists(FileName) Then
IO.File.Delete(FileName)
End If
Dim FileStream As New System.IO.FileStream(FileName, System.IO.FileMode.OpenOrCreate)
Dim BinaryWriter As New System.IO.BinaryWriter(FileStream)
BinaryWriter.Write(BytesToWrite)
BinaryWriter.Close()
FileStream.Close()
End Sub
<Runtime.CompilerServices.Extension()>
Public Sub AppendTextFile(ByRef Text As String, ByRef FileName As String)
UpdateTextFileAs(FileName, Text)
End Sub
''' <summary>
''' replaces text in file with supplied text
''' </summary>
''' <param name="PathName">Pathname of file to be updated</param>
''' <param name="_text">Text to be inserted</param>
<System.Runtime.CompilerServices.Extension()>
Public Sub UpdateTextFileAs(ByRef PathName As String, ByRef _text As String)
Try
If File.Exists(PathName) = True Then File.Create(PathName).Dispose()
Dim alltext As String = _text
File.AppendAllText(PathName, alltext)
Catch ex As Exception
MsgBox("Error: " & Err.Number & ". " & Err.Description, , NameOf(UpdateTextFileAs))
End Try
End Sub
''' <summary>
''' Creates saves text file as
''' </summary>
''' <param name="PathName">nfilename and path to file</param>
''' <param name="_text">text to be inserted</param>
<System.Runtime.CompilerServices.Extension()>
Public Sub SaveTextFileAs(ByRef PathName As String, ByRef _text As String)
Try
If File.Exists(PathName) = True Then File.Create(PathName).Dispose()
Dim alltext As String = _text
File.WriteAllText(PathName, alltext)
Catch ex As Exception
MsgBox("Error: " & Err.Number & ". " & Err.Description, , NameOf(SaveTextFileAs))
End Try
End Sub
''' <summary>
''' Opens text file and returns text
''' </summary>
''' <param name="PathName">URL of file</param>
''' <returns>text in file</returns>
<System.Runtime.CompilerServices.Extension()>
Public Function OpenTextFile(ByRef PathName As String) As String
Dim _text As String = ""
Try
If File.Exists(PathName) = True Then
_text = File.ReadAllText(PathName)
End If
Catch ex As Exception
MsgBox("Error: " & Err.Number & ". " & Err.Description, , NameOf(SaveTextFileAs))
End Try
Return _text
End Function
End Module
Public Class ObjectSerializer
#Region "Public Fields"
'<ComClass(SDK_Propositional.ClassId, SDK_Propositional.InterfaceId, SDK_Propositional.EventsId)>
Public Const ClassId As String = "2828E720-7705-401C-BAB3-38FBA7BC1AC9"
Public Const EventsId As String = "CDB77327-FA5E-401A-ACAD-3CF80B6BD6F1"
Public Const InterfaceId As String = "8B7A55F8-5D13-4059-82AB-B53131B14BB5"
#End Region
#Region "Public Methods"
''' <summary>
''' Used to extract Object from XML
''' </summary>
''' <param name="FileName">XML FILENAME</param>
''' <param name="myObj">OBJECT RETURNED</param>
''' <returns>True If Sucessfull</returns>
Public Shared Function ObjectDeserializer(ByRef FileName As String, ByRef myObj As Object) As Boolean
Try
Dim ObjItem As Object
Dim string_reader As New StringReader(FileName)
Dim xml_serializer As New XmlSerializer(myObj.GetType)
ObjItem = xml_serializer.Deserialize(string_reader)
ObjectDeserializer = True
Catch ex As Exception
ObjectDeserializer = False
End Try
End Function
''' <summary>
''' Serializes object to XML
''' </summary>
''' <param name="myObj">Presented Object</param>
''' <returns>True if Sucessfull</returns>
Public Shared Function ObjectSerializer(ByRef myObj As Object) As Boolean
Try
Dim string_writer As New StringWriter()
Dim xml_serializer As New Xml.Serialization.XmlSerializer(myObj.GetType)
xml_serializer.Serialize(string_writer, myObj)
ObjectSerializer = True
Catch ex As Exception
ObjectSerializer = False
End Try
End Function
''' <summary>
''' Serialize object
''' </summary>
''' <param name="Item"></param>
''' <returns></returns>
Public Shared Function ToJson(ByRef Item As Object) As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Item)
End Function
#End Region
End Class
''' <summary>
''' Colors Words in RichText Box
''' </summary>
Public Class SyntaxHighlighter
#Region "Public Fields"
Public Shared SyntaxTerms() As String = ({"SPYDAZ", "ABS", "ACCESS", "ADDITEM", "ADDNEW", "ALIAS", "AND", "ANY", "APP", "APPACTIVATE", "APPEND", "APPENDCHUNK", "ARRANGE", "AS", "ASC", "ATN", "BASE", "BEEP", "BEGINTRANS", "BINARY", "BYVAL", "CALL", "CASE", "CCUR", "CDBL", "CHDIR", "CHDRIVE", "CHR", "CHR$", "CINT", "CIRCLE", "CLEAR", "CLIPBOARD", "CLNG", "CLOSE", "CLS", "COMMAND", "
COMMAND$", "COMMITTRANS", "COMPARE", "CONST", "CONTROL", "CONTROLS", "COS", "CREATEDYNASET", "CSNG", "CSTR", "CURDIR$", "CURRENCY", "CVAR", "CVDATE", "DATA", "DATE", "DATE$", "DATESERIAL", "DATEVALUE", "DAY", "
DEBUG", "DECLARE", "DEFCUR", "CEFDBL", "DEFINT", "DEFLNG", "DEFSNG", "DEFSTR", "DEFVAR", "DELETE", "DIM", "DIR", "DIR$", "DO", "DOEVENTS", "DOUBLE", "DRAG", "DYNASET", "EDIT", "ELSE", "ELSEIF", "END", "ENDDOC", "ENDIF", "
ENVIRON$", "EOF", "EQV", "ERASE", "ERL", "ERR", "ERROR", "ERROR$", "EXECUTESQL", "EXIT", "EXP", "EXPLICIT", "FALSE", "FIELDSIZE", "FILEATTR", "FILECOPY", "FILEDATETIME", "FILELEN", "FIX", "FOR", "FORM", "FORMAT", "
FORMAT$", "FORMS", "FREEFILE", "FUNCTION", "GET", "GETATTR", "GETCHUNK", "GETDATA", "DETFORMAT", "GETTEXT", "GLOBAL", "GOSUB", "GOTO", "HEX", "HEX$", "HIDE", "HOUR", "IF", "IMP", "INPUT", "INPUT$", "INPUTBOX", "INPUTBOX$", "
INSTR", "INT", "INTEGER", "IS", "ISDATE", "ISEMPTY", "ISNULL", "ISNUMERIC", "KILL", "LBOUND", "LCASE", "LCASE$", "LEFT", "LEFT$", "LEN", "LET", "LIB", "LIKE", "LINE", "LINKEXECUTE", "LINKPOKE", "LINKREQUEST", "
LINKSEND", "LOAD", "LOADPICTURE", "LOC", "LOCAL", "LOCK", "LOF", "LOG", "LONG", "LOOP", "LSET", "LTRIM",
"LTRIM$", "ME", "MID", "MID$", "MINUTE", "MKDIR", "MOD", "MONTH", "MOVE", "MOVEFIRST", "MOVELAST", "MOVENEXT", "MOVEPREVIOUS",
"MOVERELATIVE", "MSGBOX", "NAME", "NEW", "NEWPAGE", "NEXT", "NEXTBLOCK", "NOT", "NOTHING",
"NOW", "NULL", "OCT", "OCT$", "ON", "OPEN", "OPENDATABASE", "OPTION", "OR", "OUTPUT", "POINT", "PRESERVE", "PRINT",
"PRINTER", "PRINTFORM", "PRIVATE", "PSET", "PUT", "PUBLIC", "QBCOLOR", "RANDOM", "RANDOMIZE", "READ", "REDIM", "REFRESH",
"REGISTERDATABASE", "REM", "REMOVEITEM", "RESET", "RESTORE", "RESUME", "RETURN", "RGB", "RIGHT", "RIGHT$", "RMDIR", "RND",
"ROLLBACK", "RSET", "RTRIM", "RTRIM$", "SAVEPICTURE", "SCALE", "SECOND", "SEEK", "SELECT", "SENDKEYS", "SET", "SETATTR",
"SETDATA", "SETFOCUS", "SETTEXT", "SGN", "SHARED",
"SHELL", "SHOW", "SIN", "SINGLE", "SPACE", "SPACE$", "SPC", "SQR",
"STATIC", "STEP", "STOP", "STR", "STR$", "STRCOMP", "STRING", "STRING$", "SUB",
"SYSTEM", "TAB", "TAN", "TEXT", "TEXTHEIGHT", "TEXTWIDTH", "THEN", "TIME", "TIME$",
"TIMER", "TIMESERIAL", "TIMEVALUE", "TO", "TRIM",
"TRIM$", "TRUE", "TYPE", "TYPEOF", "UBOUND", "UCASE", "UCASE$", "UNLOAD",
"UNLOCK", "UNTIL", "UPDATE", "USING", "VAL", "VARIANT", "VARTYPE", "WEEKDAY", "WEND", "WHILE", "WIDTH",
"WRITE", "XOR", "YEAR", "ZORDER", "ADDHANDLER", "ADDRESSOF", "ALIAS", "AND", "ANDALSO", "AS", "BYREF",
"BOOLEAN", "BYTE", "BYVAL", "CALL", "CASE", "CATCH", "CBOOL", "CBYTE", "CCHAR", "CDATE",
"CDEC", "CDBL", "CHAR", "CINT", "CLASS", "CLNG", "COBJ", "CONST", "CONTINUE", "CSBYTE",
"CSHORT", "CSNG", "CSTR", "CTYPE", "CUINT", "CULNG", "CUSHORT", "DATE", "DECIMAL", "DECLARE",
"DEFAULT", "DELEGATE", "DIM", "DIRECTCAST", "DOUBLE", "DO", "EACH", "ELSE", "ELSEIF", "END",
"ENDIF", "ENUM", "ERASE", "ERROR", "EVENT", "EXIT", "FALSE", "FINALLY", "FOR", "FRIEND",
"FUNCTION", "GET", "GETTYPE", "GLOBAL", "GOSUB", "GOTO", "HANDLES", "IF", "IMPLEMENTS",
"IMPORTS", "IN", "INHERITS", "INTEGER", "INTERFACE", "IS", "ISNOT", "LET", "LIB", "LIKE",
"LONG", "LOOP", "ME", "MOD", "MODULE", "MUSTINHERIT", "MUSTOVERRIDE", "MYBASE", "MYCLASS",
"NAMESPACE", "NARROWING", "NEW", "NEXT", "NOT", "NOTHING", "NOTINHERITABLE", "NOTOVERRIDABLE",
"OBJECT", "ON", "OF", "OPERATOR", "OPTION", "OPTIONAL", "OR", "ORELSE", "OVERLOADS",
"OVERRIDABLE", "OVERRIDES", "PARAMARRAY", "PARTIAL", "PRIVATE", "PROPERTY", "PROTECTED",
"PUBLIC", "RAISEEVENT", "READONLY", "REDIM", "REM", "REMOVEHANDLER", "RESUME", "RETURN",
"SBYTE", "SELECT", "SET", "SHADOWS", "SHARED", "SHORT", "SINGLE", "STATIC", "STEP", "STOP",
"STRING", "STRUCTURE", "SUB", "SYNCLOCK", "THEN", "THROW", "TO", "TRUE", "TRY", "TRYCAST",
"TYPEOF", "WEND", "VARIANT", "UINTEGER", "ULONG", "USHORT", "USING", "WHEN", "WHILE", "WIDENING",
"WITH", "WITHEVENTS", "WRITEONLY",
"XOR", "#CONST", "#ELSE", "#ELSEIF", "#END", "#IF"})
#End Region
#Region "Private Fields"
Private Shared indexOfSearchText As Integer = 0
Private Shared start As Integer = 0
Private mGrammar As New List(Of String)
#End Region
#Region "Public Methods"
Public Shared Sub ColorSearchTerm(ByRef SearchStr As String, Rtb As RichTextBox)
ColorSearchTerm(SearchStr, Rtb, Color.CadetBlue)
End Sub
Public Shared Sub ColorSearchTerm(ByRef SearchStr As String, Rtb As RichTextBox, ByRef MyColor As Color)
Dim startindex As Integer = 0
start = 0
indexOfSearchText = 0
If SearchStr <> "" Then
SearchStr = SearchStr & " "
If SearchStr.Length > 0 Then
startindex = FindText(Rtb, ProperCase(SearchStr), start, Rtb.Text.Length)
End If
If SearchStr.Length > 0 And startindex = 0 Then
startindex = FindText(Rtb, LCase(SearchStr), start, Rtb.Text.Length)
End If
If SearchStr.Length > 0 And startindex = 0 Then
startindex = FindText(Rtb, UCase(SearchStr), start, Rtb.Text.Length)
End If
If SearchStr.Length > 0 And startindex = 0 Then
startindex = FindText(Rtb, SearchStr, start, Rtb.Text.Length)
End If
' If string was found in the RichTextBox, highlight it
If startindex >= 0 Then
' Set the highlight color as red
Rtb.SelectionColor = MyColor
' Find the end index. End Index = number of characters in textbox
Dim endindex As Integer = SearchStr.Length
' Highlight the search string