-
Notifications
You must be signed in to change notification settings - Fork 0
/
tribe4.cs
7539 lines (6245 loc) · 263 KB
/
tribe4.cs
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
// "I'm really pleased with the way mine came out..." - John, [email protected], Vermfont Technical College (get full name from PayPal)
// "I think it's a fabulous and interesting idea!" - Joelle Tjahjadi ([email protected])
// "I love your mind map so much!!!" Jess Brisch ([email protected])
// "I'm amazed by the fact you managed to place my boyfriend closest to me (even though he doesn't update his journal and I never told who he is), my other journal (which I kind of keep a secret), my best friend (both screen names), the girl I'm moving in with next week, my other good friend, the girl who knows one of my deepest darkest secrets...all of them in big letters and close to me. that's amazing." - Tiffany
// "this thing is really neat." - [email protected]
// "I think you are very groovy for doing this for everyone. I appreciate it. :)" - Tammy
// "I threw some money your way. I think the social ramifications of your linked project are interesting. People who come up with projects like this think outside the box. The way the mindmaps work is defining a whole online "culture" and then to turn it into graphics that I think are beautiful is amazing. Thanks for sharing your project with so many people on here." - feline
// "I just thought the mindmap was just one of the coolest things I've ever seen, you did a great job!" - Kimberly Burton - [email protected] (spacefem, but that's secret)
// using System.Data.SqlClient ;
using System.Xml.Serialization ;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D ;
//using System.Runtime.Serialization.Formatters.Soap ;
using System ;
using System.Net ;
using System.IO ; // for FileStream
using System.Text.RegularExpressions;
using System.Collections ;
using System.Web.Services ;
using System.Threading ;
using System.Diagnostics;
using System.Collections.Generic ;
using System.Net.Mail;
using Npgsql;
using System.Web ;
using System.Text ;
using Microsoft.Win32;
using System.Linq;
// using System.Data;
/*
[WebService (Description="Request Tribe Maps", Namespace="http://tribeserver.gal2k.com:81/")]
public class TribeServer : WebService
{
public System.Threading.Thread m_workerThread ;
[WebMethod(Description="Given tribe seed, returns useage information.")]
public string Nudge( )
{
if (m_workerThread == null)
{
m_workerThread = new System.Threading.Thread(new System.Threading.ThreadStart(myStartingMethod));
m_workerThread.Start();
}
return "<center>This feature is not implemented yet. Sure, it'll be cool when it is. But it's not. So ask mcfnord and he'll make you a MindMap.</center>" ;
}
void myStartingMethod()
{
*/
// load the dataset first time in.
// Report( "slave thread started." ) ;
// GrabClass.LoadMasterUserList() ;
// Read the queue.txt, and find any entries that aren't currently tribal seeds.
/*
for(int iCount = 0 ; iCount < 10 ; iCount++)
{
string UseMe = "c:\\temp\\websquirty.txt" ;
FileInfo fi = new FileInfo(UseMe);
if (!fi.Exists)
{
using (StreamWriter sw = fi.CreateText())
{
sw.Write(DateTime.Now.ToString()) ;
sw.Write(" ") ;
sw.WriteLine(iCount.ToString()) ;
}
}
using (StreamWriter sw = fi.AppendText())
{
sw.Write(DateTime.Now.ToString()) ;
sw.Write(" ") ;
sw.WriteLine(iCount.ToString() ) ;
}
Thread.Sleep(10000) ;
}
*/
// Report("Master User List loaded") ;
// we just loop
/*
for(;;)
{
// Look at the server for seed requests that are not currently calculated tribes.
}
for(int iCount = 0 ; iCount < 10 ; iCount++)
{
string UseMe = // HttpContext.Current.Server.MapPath(
"c:\\temp\\websquirt.txt" ;
// ) ;
FileInfo fi = new FileInfo(UseMe);
if (!fi.Exists)
{
using (StreamWriter sw = fi.CreateText())
{
sw.Write(DateTime.Now.ToString()) ;
sw.Write(" ") ;
sw.WriteLine(iCount.ToString()) ;
}
}
using (StreamWriter sw = fi.AppendText())
{
sw.Write(DateTime.Now.ToString()) ;
sw.Write(" ") ;
sw.WriteLine(iCount.ToString() ) ;
}
Thread.Sleep(10000) ;
}
*/
// }
//}
[Serializable]
public class LJUser2 // : IComparable
{
public LJUser2() { }
// public LJUser2 ( LJUser lju ) { Name = lju.Name; Location = lju.Location; Readers = lju.Readers ; BDate = lju.BDate ; whoIRead = lju.whoIRead ; }
private string m_name ;
private bool fIDCurrent = false ;
private Int32 m_id;
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
fIDCurrent = false;
}
}
public Int32 ID
{
get
{
if (fIDCurrent)
return m_id;
m_id = IDMap.NameToID(m_name);
fIDCurrent = true;
return m_id;
}
}
public string Location ; // Now actually a Cooltip.. Could be location, could be anything.
public string Url ; // a Url to their posted map, if any.
public int Readers ;
public DateTime BDate ; // could be null ya know
// public ArrayList whoIRead ; // (could include self!)
// public string fd ; // the actual fd text.
public HashSet<Int32> ifd
{
get
{
return internalifd;
}
set
{
internalifd = value;
numericIsValid = false;
}
}
private HashSet<Int32> internalifd;
private bool numericIsValid = false ;
private HashSet<Int32> whoIReadNumericInternal;
public HashSet<Int32> whoIReadNumeric
{
get
{
if (numericIsValid)
return whoIReadNumericInternal;
else
{
whoIReadNumericInternal = new HashSet<int>();
var justwhoiread = from dude in ifd where dude > 0 select dude;
foreach (var dude in justwhoiread)
whoIReadNumericInternal.Add(dude);
numericIsValid = true;
return whoIReadNumericInternal;
}
}
}
/*
public HashSet<string> whoIRead
{
get
{
var justwhoiread = from dude in ifd where dude > 0 select IDMap.IDToName( dude);
return (HashSet<string>)justwhoiread.ToList<string>();
}
}
* */
public ArrayList tribe ;
// these members are used by alternative LJUser lists (but not the master list)
public int Tier ; // not even used within user's Tribe, because the tribe list
// CONTAINS NO LJUser objects!
public Rectangle rect ; // also for sublist display and sorting. not saved in master list.
public int color ; // for sublist use only. not saved. internal stuff.
// public ArrayList whoIReadNumeric ; // used by CalcSingleUser to refer to user by slot in CUserList, not name. Faster.
public int distanceAway ; // used by coloring to order the consideration of items
public LJUser2( string strName, int tier ) { Name = strName; Tier = tier ; }
// why does this freakish ffunction exist?
public void Clone( LJUser2 ljuToClone )
{
this.Name = ljuToClone.Name ;
this.Tier = ljuToClone.Tier ;
// this.whoIRead = ljuToClone.whoIRead ;
this.Url = ljuToClone.Url ;
this.Location = ljuToClone.Location ;
this.ifd = ljuToClone.ifd ;
// This clone is incomplete and is amended as needed.
}
/*
public bool ReadsByID(Int32 id)
{
return ifd.Contains(id);
}
* */
public bool Reads(LJUser2 lju)
{
return ifd.Contains(lju.ID);
}
public bool Reads( string strName )
{
return ifd.Contains( IDMap.NameToID(strName) );
}
// if (-1 != this.fd.IndexOf("> " + strName + "\n"))
// return true ;
// return false ;
/*
// if (this.Name == "" || strName == "")
// return true ; // we read everyone! We are lattice buildwerks.
if (whoIRead == null)
whoIRead = new ArrayList() ;
foreach( string strIRead in whoIRead)
{
if (strIRead.ToUpper() == strName.ToUpper())
return true ;
}
return false ;*/
// IComparable sorts by # of NUMERIC readers, which is not always valid, and is a subset of readership.
// see .Sort useage for clues why.
/*
public int CompareTo(object obj)
{
if (obj is LJUser2)
{
LJUser2 ljuThem = (LJUser2) obj ;
if (GrabClass.SB_DISTANCE == GrabClass.m_iSortBy)
return ljuThem.distanceAway.CompareTo( this.distanceAway ) ;
// return this.distanceAway.CompareTo( ljuThem.distanceAway ) ;
if (GrabClass.SB_READERS == GrabClass.m_iSortBy)
return ljuThem.whoIReadNumeric.Count.CompareTo( this.whoIReadNumeric.Count ) ;
// return fl.m_iShips.CompareTo(this.m_iShips) ;
}
throw new ArgumentException("Object is not a CFleet.") ;
}
* */
}
// this SHOULD be inherited from terse.cs somehow, so the online version is guaranteed match.
public class TerseLJUser
{
public string Name ;
public ArrayList TribesBySeedSlot ; // integers of which seed user slots in the TerseLJUser array I appear in. ought to be at least one, dontcha think.
public TerseLJUser() { }
public TerseLJUser( string name ) { Name = name ; }
}
[Serializable]
public class CUserList : HashSet<LJUser2> // positions cannot be valid : List<LJUser2>
{
public LJUser2 GetUser( string strName )
{
foreach( LJUser2 lju in this)
if (lju.Name.ToUpper() == strName.ToUpper())
return lju ;
return null ;
}
public LJUser2 GetUserByID(int id)
{
// return from lju in this where lju.Name.ToUpper() == IDMap.IDToName(id) select lju;
foreach (LJUser2 lju in this)
if( lju.Name.ToUpper() == IDMap.IDToName( id ).ToUpper())
return lju;
return null;
}
/*
public int? GetUserNumber( string strName )
{
LJUser2 lju = this.GetUser( strName ) ;
if (lju == null)
{
return null; // we're letting this ride 2010!
// throw new Exception() ; // I want to freaking stop the bus.
// return -1 ;
}
return this.IndexOf( lju ) ;
}
* */
}
class TribeList : IComparable
{
public ArrayList m_tribeMembers ;
public string m_seedUserName ;
public TribeList( ArrayList alTribeMembers, string seedUserName )
{
m_tribeMembers = alTribeMembers ;
m_seedUserName = seedUserName ;
}
public int CompareTo(object obj)
{
if (obj is TribeList)
{
TribeList tl = (TribeList) obj ;
// THIS IS IMPLEMENTED BASS-ACKWARDS BECAUSE I WANT
// HIGH-TO-LOW SORTING!
return tl.m_tribeMembers.Count.CompareTo(this.m_tribeMembers.Count) ;
}
throw new ArgumentException("Object is not a TribeList.") ;
}
}
public class MasterDB
{
static NpgsqlConnection userDBConnection = null ;
static CUserList localUserListCache = new CUserList() ;
public static bool m_fNoDBMode = false ;
public static int m_fdDayOffset = 0 ; // I can tell fdata archive to pretend it's x days into the past!
public static void ClobberInternalCache()
{
localUserListCache = new CUserList() ; Console.WriteLine("Clobbered internal cache!") ;
}
// For cases where you want to party all over the database, as with seedmap's needs,
// you can grab the underlying db.
static public NpgsqlConnection GetDBConnection()
{
if ( userDBConnection == null)
Init() ;
return userDBConnection ;
}
static public void Init()
{
// userDBConnection = new NpgsqlConnection( "Database=mindmap;Server=bonkers;Port=5432;User Id=postgres;Password=postgres;") ; // pgsql
userDBConnection = new NpgsqlConnection(Registry.GetValue("HKEY_CURRENT_USER\\Software\\MindMap", "PostgreInitString", null).ToString());
// userDBConnection = new SqlConnection( "initial catalog=mindmap;data source=perky;Integrated Security=SSPI" ) ;
userDBConnection.Open() ;
}
static public void Close()
{
userDBConnection.Close() ;
}
/* this is the GetUser from tribe4
static public LJUser2 GetUser( string requestedUser )
{
// i've repeated this trick throughout my code, but i do it again here:
// i maintain a local userlist. if i can't find the user you want there,
// then i load it. it's a typical optimization.
LJUser2 ljuGot = localUserListCache.GetUser( requestedUser ) ;
if (null != ljuGot)
return ljuGot ;
// I'm going to create a table entry for every user.
// Load the dataset as usual.
// first populate the LJUsers table.
string strCmd = string.Format("select Name, Location from LJUsers where Name='{0}'", requestedUser) ;
SqlCommand cmd = new SqlCommand(strCmd, userDBConnection) ;
SqlDataReader myReader = cmd.ExecuteReader() ;
myReader.Read ( ) ;
LJUser2 lju = new LJUser2() ;
try
{
lju.Name = myReader.GetString(0).Trim() ;
lju.Location = myReader.GetString(1).Trim() ;
}
catch( Exception )
{
myReader.Close() ;
return null ;
}
myReader.Close() ;
// we have to poplate this user's reader list.
strCmd = string.Format("select UserIRead from WhoIRead where Name='{0}'", requestedUser) ;
cmd = new SqlCommand(strCmd, userDBConnection) ;
myReader = cmd.ExecuteReader() ;
lju.whoIRead = null ;
while( myReader.Read ( ) )
{
if (lju.whoIRead == null)
lju.whoIRead = new ArrayList() ;
// in the database, we have all kinds of messes, including duplicate entries.
string strReader = myReader.GetString( 0 ).Trim() ;
bool fAlready = false ;
foreach( string strAlready in lju.whoIRead )
{
if (strAlready.ToUpper() == strReader.ToUpper())
{
fAlready = true ;
break ;
}
}
if (false == fAlready)
lju.whoIRead.Add( strReader ) ;
}
myReader.Close() ;
// and if there's a tribe, we add that. This is where the data will differ from the original.
// but we'll do our best. tiers... tears.
int iTier = 0 ;
bool fMoreTiers = true ;
lju.tribe = null ;
while( fMoreTiers )
{
ArrayList alThisTier = new ArrayList() ;
strCmd = string.Format("select Member from Tribes where Name='{0}' and Tier='{1}'", requestedUser, iTier) ;
cmd = new SqlCommand(strCmd, userDBConnection) ;
myReader = cmd.ExecuteReader() ;
while( myReader.Read() )
{
if (lju.tribe == null)
lju.tribe = new ArrayList() ;
alThisTier.Add( myReader.GetString( 0 ).Trim()) ;
}
if (alThisTier.Count == 0)
{
myReader.Close() ;
localUserListCache.Add( lju ) ;
return lju ;
}
// FOR HISTORICAL REASONS, we add a layer of indirection:
ArrayList alNewLayer = new ArrayList() ;
alNewLayer.Add( alThisTier ) ;
lju.tribe.Add( alNewLayer ) ;
iTier++ ;
myReader.Close() ;
}
localUserListCache.Add( lju ) ;
return lju ;
}
*/
/*
static public void AddUrl( string name, string strUrl )
{
GrabClass.ChokeOnBlankUrl( strUrl ) ;
string str = string.Format("UPDATE LJUSEREXTRAS SET URL='{1}' where Name='{0}'", name, strUrl) ;
SqlCommand cmd = new SqlCommand(str, userDBConnection) ;
cmd.ExecuteNonQuery() ;
} */
/*
static public void AddCooltip( string name, string strCooltip )
{
// Do it right. Query. If it exists, update.
string strCmd = string.Format("select count(*) from LJUserExtras where Name='{0}'", name) ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand( strCmd, userDBConnection ) ;
NpgsqlDataReader myReader = cmd.ExecuteReader() ;
myReader.Read ( ) ;
if (null != strCooltip)
strCooltip = strCooltip.Replace("'", "''") ;
strCooltip = HttpUtility.UrlEncodeUnicode( strCooltip ) ;
if (0 == myReader.GetInt64(0))
{
myReader.Close() ;
strCmd = string.Format("INSERT INTO LJUserExtras (Name, Cooltip) Values('{0}', '{1}')", name, strCooltip) ;
cmd = new MyNpgsqlCommand(strCmd, userDBConnection) ;
cmd.ExecuteNonQuery() ;
}
else
{
myReader.Close() ;
strCmd = string.Format("UPDATE LJUserExtras SET Cooltip='{1}' WHERE Name='{0}'", name, strCooltip) ;
cmd = new MyNpgsqlCommand(strCmd, userDBConnection) ;
cmd.ExecuteNonQuery() ; // died once here as deadlock victim.
}
}
* */
static public void ClobberUrl( string seed )
{
string str = string.Format("UPDATE LJUSEREXTRAS SET URL=null where Name='{0}'", seed) ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand(str, userDBConnection) ;
cmd.ExecuteNonQuery() ;
}
/*
static public void NukeUser( string seed )
{
// this is for the phantom bug. not sure how far this will need to go.
int iNuke = (int) localUserListCache.GetUserNumber( seed ) ;
localUserListCache.RemoveAt( iNuke ) ;
string str = string.Format("DELETE FROM TRIBES where Name='{0}'", seed) ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand(str, userDBConnection) ;
cmd.ExecuteNonQuery() ;
}
* */
/*
static public bool IsMoneyBit( string seed)
{
string strCmd = "select Money from LJUserExtras WHERE NAME='" + seed + "'" ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand(strCmd, userDBConnection) ;
NpgsqlDataReader myReader = cmd.ExecuteReader() ;
myReader.Read ( ) ;
try
{
try
{
if (myReader.IsDBNull(0))
return false ;
}
catch(InvalidOperationException)
{
return false ;
}
if (true == myReader.GetBoolean(0))
return true ;
return false ;
}
finally
{
myReader.Close() ;
}
}
* */
static public LJUser2 GetSlimUser( string user)
{
return GetSlimUser( user, false ) ;
}
static public LJUser2 GetSlimUser(string user, bool fCooltip)
{
// we have to poplate this user's reader list.
// using a property, we short-circuit the parameter stack
// and provide the day offset if needed
string fd = FData.GetFData(user, m_fdDayOffset); // is this the ONLY entrance into fdata.cs in the calc process?
if (null == fd)
return null;
HashSet<Int32> ifd = FData.IDsInIReadFData(fd);
var oppoSet = from dude in FData.IDsInTheyReadMeFData(fd) select -dude;
ifd.UnionWith(oppoSet);
fd = null;
LJUser2 lju = new LJUser2();
lju.Name = user;
lju.ifd = ifd;
/*
lju.whoIRead = null;
Regex rIRead = new Regex(@"> \w+\n");
Match m = rIRead.Match(fd);
if (lju.whoIRead == null)
lju.whoIRead = new ArrayList();
while (m.Success)
{
string who = m.ToString().Trim().Substring(2);
lju.whoIRead.Add(who);
m = m.NextMatch();
}
if (fCooltip)
{
string strCmd = string.Format("select count(*) from LJUserExtras where Name='{0}'", user);
MyNpgsqlCommand cmd = new MyNpgsqlCommand(strCmd, userDBConnection);
NpgsqlDataReader myReader = cmd.ExecuteReader();
myReader.Read(); // deadlock victim. did not cause cascading failure.
if (0 < myReader.GetInt64(0))
{
myReader.Close();
strCmd = string.Format("select Cooltip from LJUserExtras where Name='{0}'", user);
cmd = new MyNpgsqlCommand(strCmd, userDBConnection);
myReader = cmd.ExecuteReader();
myReader.Read();
if (false == myReader.IsDBNull(0))
// lju.Location = myReader.GetString(0).Trim() ;
lju.Location = HttpUtility.UrlDecode(myReader.GetString(0).Trim());
}
myReader.Close();
}
* */
return lju;
}
/*
// THIS IS tribe5's GetUser.
static public LJUser2 GetUser( string requestedUser )
{
// i've repeated this trick throughout my code, but i do it again here:
// i maintain a local userlist. if i can't find the user you want there,
// then i load it. it's a typical optimization.
LJUser2 ljuGot = localUserListCache.GetUser( requestedUser ) ;
if (null != ljuGot)
return ljuGot ;
// first populate the LJUsers table.
string strCmd = string.Format("select A.Name, B.Cooltip, B.Url, A.Readers from LJUsers A LEFT OUTER JOIN LJUserExtras B ON A.Name=B.Name where A.Name='{0}'", requestedUser) ; // CRASH!
SqlCommand cmd = new SqlCommand(strCmd, userDBConnection) ;
SqlDataReader myReader = cmd.ExecuteReader() ;
myReader.Read ( ) ; //
LJUser2 lju = new LJUser2() ;
try
{
lju.Name = myReader.GetString(0).Trim() ;
if (false == myReader.IsDBNull(1))
{
lju.Location = myReader.GetString(1).Trim() ;
}
if(false == myReader.IsDBNull(2))
{
lju.Url = myReader.GetString(2).Trim() ;
}
lju.Readers = myReader.GetInt32(3) ;
}
catch( Exception )
{
return null ;
}
finally
{
myReader.Close() ;
}
// we have to poplate this user's reader list.
string fd = FData.GetFData( requestedUser ) ;
lju.whoIRead = null ;
Regex rIRead = new Regex(@"> \w+\n") ;
Match m = rIRead.Match( fd );
while (m.Success)
{
if (lju.whoIRead == null )
lju.whoIRead = new ArrayList() ;
string who = m.ToString().Trim().Substring(2) ;
lju.whoIRead.Add( who ) ;
m = m.NextMatch();
}
// and if there's a tribe, we add that. This is where the data will differ from the original.
// but we'll do our best. tiers... tears.
// FIRST we need to know the FULL RANGE OF TIERS.
strCmd = string.Format("select Tier from Tribes where Name='{0}'", requestedUser) ;
cmd = new SqlCommand(strCmd, userDBConnection) ;
myReader = cmd.ExecuteReader() ;
int iTops = 0 ;
bool fSomething = false ;
while( myReader.Read() )
{
fSomething = true ;
int iThisOne =myReader.GetInt32( 0 ) ;
if (iThisOne > iTops)
iTops = iThisOne ;
}
myReader.Close() ;
// int iTier = 0 ;
// bool fMoreTiers = true ;
lju.tribe = null ;
if (fSomething)
{
// lju.tribe = new ArrayList() ; // null ;
for(int iTier = 0 ; iTier <= iTops; iTier++)
{
ArrayList alThisTier = new ArrayList() ;
strCmd = string.Format("select Member from Tribes where Name='{0}' and Tier='{1}'", requestedUser, iTier) ;
cmd = new SqlCommand(strCmd, userDBConnection) ;
myReader = cmd.ExecuteReader() ;
while( myReader.Read() )
{
if (lju.tribe == null)
lju.tribe = new ArrayList() ;
alThisTier.Add( myReader.GetString( 0 ).Trim()) ;
// Console.WriteLine("I'm adding: " + myReader.GetString( 0 ).Trim()) ;
}
// FOR HISTORICAL REASONS, we add a layer of indirection:
ArrayList alNewLayer = new ArrayList() ;
alNewLayer.Add( alThisTier ) ;
lju.tribe.Add( alNewLayer ) ;
myReader.Close() ;
}
// if (lju.tribe.Count == 0)
// lju.tribe = null ;
}
localUserListCache.Add( lju ) ;
// seems like we returned a null. why? tell me why.
if (null == lju)
throw new Exception() ;
return lju ;
}
*/
static public void AddUser( LJUser2 lju, bool fJustAddTribe, CUserList ulForNumericAdd )
{
if(m_fNoDBMode)
{
localUserListCache.Add( lju ) ;
return ;
}
string str = "" ;
MyNpgsqlCommand cmd ;
if (false == fJustAddTribe)
{
str = string.Format("INSERT INTO LJUsers (Name, Location, Readers, BDate, Refreshed) Values('{0}', '{1}', {2}, null, GETDATE())", lju.Name, lju.Location, lju.Readers, lju.BDate) ;
cmd = new MyNpgsqlCommand(str, userDBConnection) ;
// try
// {
cmd.ExecuteNonQuery() ;
// }
// catch( Exception e )
// {
// we are bad people. we do bad things.
// Console.WriteLine("FAILED LJUser: " + str) ;
// Console.WriteLine ( e.ToString()) ;
// }
// communities don't have readers (in my dumb world) and probably should be added but here we are.
/*
if (lju.whoIRead != null)
{
foreach( string strIRead in lju.whoIRead)
{
str = string.Format("INSERT INTO WhoIRead (Name, UserIRead) Values('{0}', '{1}')", lju.Name, strIRead) ;
cmd = new MyNpgsqlCommand(str, userDBConnection) ;
// try
{
cmd.ExecuteNonQuery() ;
}
// crash me out
// catch( Exception e )
// {
// Console.WriteLine("FAILED WhoIRead: " + str) ;
// Console.WriteLine( e.ToString()) ;
// }
}
}
* */
}
// i must duplicate the dataset perfectly. But I don't. I jumble sets.
// and so with version five, i stop duplicating saves. This will make my dataset smaller as we proceed.
if (lju.tribe != null)
{
for( int iLevel = 0; iLevel < lju.tribe.Count; iLevel++)
{
ArrayList alWrittenAtThisLevel = new ArrayList() ;
ArrayList alThisLevel = (ArrayList) lju.tribe[iLevel] ;
foreach( ArrayList thisSet in alThisLevel )
foreach( int strUser in thisSet )
{
// we're gonna lose the sets. BOo hoo.
/* bool fAlreadyDone = false ;
foreach( int strAlready in alWrittenAtThisLevel)
{
if (strUser == strAlready)
{
fAlreadyDone = true ;
break ;
}
}
if (false == fAlreadyDone)
{
alWrittenAtThisLevel.Add( strUser ) ;
LJUser2 user = (LJUser2) ulForNumericAdd.GetUserByID( strUser ) ;
str = string.Format("INSERT INTO Tribes (Name, Member, Tier) Values('{0}', '{1}', {2})", lju.Name, user.Name, iLevel) ;
cmd = new MyNpgsqlCommand(str, userDBConnection) ;
try
{
}
catch( Exception )
{
}
}
* */
}
}
}
}
static public bool WasSeedAborted( string strSeed )
{
string strCmd = string.Format("select Name from Abortions where Name='{0}'", strSeed) ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand(strCmd, userDBConnection) ;
NpgsqlDataReader myReader = cmd.ExecuteReader() ;
bool fRet = myReader.Read ( ) ;
myReader.Close() ;
return fRet ;
}
/*
static public void AbortSeed( string strSeed )
{
string str = string.Format("INSERT INTO Abortions (Name) Values('{0}')", strSeed) ;
MyNpgsqlCommand cmd = new MyNpgsqlCommand(str, userDBConnection) ;
cmd.ExecuteNonQuery() ;
}
*/
}
class GrabClass
{
public const string SYSTEM_PASSWORD = "bipSy8!"; // this line makes this source code top secret.
static public bool m_fYesToTimeouts = false;
static public bool m_fALWAYSYesToTimeouts = false;
static public bool m_fAbortNow = false;
static public bool m_fDudeImDone = false;
static public bool m_fLiberalCalcTime = false;
static public bool m_fJustUploadRawSeed = false;
static public bool m_fRetryAfterDelay = false;
// static public bool m_fOkBruteForceIt = false;
static public int m_iNextStepCount = -1;
static public bool m_fTryTribeAgain = false;
static public bool m_fDBDown = false;
// static public int m_iSortBy;
// public const int SB_READERS = 1;
// public const int SB_DISTANCE = 2;
static public int m_iLastHourPlucked = -1;
// static public string m_topTier = "";
// static public string m_bottomTier = "";
// static public bool? fEmailCycle = null ;
// public const int SB_
// static public CUserList olMasterUserList = new CUserList() ;
static public CUserList olCustomUserList = new CUserList(); // ONLY used in CalculateSingleSeed and growSet.
static DateTime m_timeCheckUploadsAt = DateTime.Now;
// static public string MASTER_USER_LIST = "LJUserDataset.xml" ; // c:\\temp\\ was removed cuz it wrecked my manual useage.
/*
public static void LoadMasterUserList()
{
try
{
Stream sr = File.OpenRead(MASTER_USER_LIST) ;
SoapFormatter x = new SoapFormatter() ; // XmlSerializer(typeof(ArrayList), new Type[] { typeof(LJUser) }) ;
olMasterUserList = (CUserList)x.Deserialize(sr) ;
sr.Close() ;
}
catch( Exception e)
{
Console.WriteLine(e.ToString()) ;
}
}
static void SaveMasterUserList()
{
try
{
Stream sw = File.Create(MASTER_USER_LIST) ;
SoapFormatter x = new SoapFormatter() ; // XmlSerializer x = new XmlSerializer(typeof(ArrayList), new Type[] { typeof(LJUser) }) ;
x.Serialize(sw, olMasterUserList) ;
sw.Close() ;
}
catch( Exception e )
{
Console.WriteLine( e.ToString() ) ;
}
}
*/
/*
static CUserList ConvertToLJ2( CUserList olSource )
{
CUserList newList = new CUserList () ;
foreach( LJUser lju in olSource)
{
newList.Add ( new LJUser2( lju ) ) ;
}