public override bool Equals(object o) { StringEmulator a = o as StringEmulator; if (a == null) { return(false); } else { if (this.s1.Equals(a.s1) == true) { return(true); } else { string pattern = ""; //Console.WriteLine("DEBUG: {0}", a.GetString()); if (a.GetString()[0] == '*') //In the beginning { if (a.GetSize() == 1) //all { return(true); } else { pattern += a.GetString().Substring(1) + "$"; Regex rx = new Regex(@pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matches = rx.Matches(s1); if (matches.Count > 0) { return(true); } } } if (a.GetString()[a.GetSize() - 1] == '*') //In the end { pattern += "^" + a.GetString().Substring(0, a.GetSize() - 2); Regex rx = new Regex(@pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matches = rx.Matches(s1); if (matches.Count > 0) { return(true); } } return(false); } } }
static void Main(string[] args) { int id; Uri uri; int min_delay; int max_delay; if (args.Length != 4) { Console.WriteLine("Insuficient arguments: SERVER_ID URL MIN_DELAY MAX_DELAY"); args = Console.ReadLine().Split(' '); } id = Int32.Parse(args[0].Substring(1)); //catch number from the 1 position try { uri = new Uri(args[1]); } catch (UriFormatException e) { Console.WriteLine("Invalid URL: {0}", args[1]); Console.ReadLine(); return; } min_delay = Int32.Parse(args[2]); max_delay = Int32.Parse(args[3]); Random rnd = new Random(); delay_messages = rnd.Next(min_delay, max_delay + 1); //open file with database of all Servers in the system AllServers = new List <EachServer>(); My_Identification = new EachServer(uri, id); string[] lines = File.ReadAllLines(path); foreach (string line in lines) { string[] words = line.Split(' '); int tmp_id = Int32.Parse(words[0]); Uri uri_tmp; try { uri_tmp = new Uri(words[1]); AllServers.Add(new EachServer(uri_tmp, tmp_id)); if (tmp_id == 1) { RootServer = new EachServer(uri_tmp, tmp_id); Console.WriteLine("ENTRANCE POINT/ROOT SERVER => " + RootServer.uid.ToString()); } } catch (UriFormatException e) { Console.WriteLine("Invalid URL: {0}", words[1]); //Console.ReadLine(); return; } } channel = new TcpChannel(uri.Port); ChannelServices.RegisterChannel(channel, false); new Thread(() => Server_thread()).Start(); new Thread(() => Client_thread(uri, id)).Start(); new Thread(() => ServerService.CheckCommandsInQueue_thread()).Start(); new Thread(() => ServerService.CheckCommandsInQueue_thread_Replica()).Start(); System.Console.WriteLine("I'm server: " + args[1]); //teste tuple space object[] tupleOBJ = new object[1]; tupleOBJ[0] = new StringEmulator("a"); ServerService.ts.Add(new MyTuple(tupleOBJ)); System.Console.ReadLine(); }