public string constructMsgToLog(Tup tup)
        {
            string message = "tuple " + _operator.myAddress + ", ";
            string tuple   = constructTuple(tup);

            return(message + tuple);
        }
        private int getHashValue(Tup tuple, int limit, int fieldNumber)
        {
            string strToHash = tuple.fields[fieldNumber - 1];
            int    hashValue = strToHash.GetHashCode() % limit;

            return(Math.Abs(hashValue));
        }
        public string constructTuple(Tup tup)
        {
            string tuple = "";

            foreach (string s in tup.fields)
            {
                tuple += s + ", ";
            }
            tuple = tuple.Substring(0, tuple.Length - 2);
            return(tuple);
        }
 public void exchangeTuples(Tup tuple)
 {
     Console.WriteLine("Received the following tuple -> " + constructTuple(tuple));
     lock (_operator.inputTuples){
         _operator.inputTuples.Add(tuple);
     }
     Console.WriteLine("Before IF Freezing Condition");
     if (_operator.freeze)
     {
         _operator.eventPreventReturn.WaitOne();
     }
     Console.WriteLine("I'm going to return a value bitchees");
 }
        private static void readFileToInputBuffer(string file)
        {
            string[] lines = File.ReadAllLines(file);
            int      cont  = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                string[] line = lines[i].Split(new[] { ", " }, StringSplitOptions.None);
                if (!String.IsNullOrEmpty(line[0]))
                {
                    if (!line[0].StartsWith("%%"))
                    {
                        string[] fields = new string[line.Length];
                        for (int j = 0; j < line.Length; j++)
                        {
                            fields[j] = line[j];
                        }
                        cont++;
                        Tup tup = new Tup(cont, fields);
                        _operator.inputTuples.Add(tup);
                    }
                }
            }
        }
        public override void execute()
        {
            Console.WriteLine("Execute Custom with the following arguments:");
            Console.WriteLine("DLL = " + _operator.dllCustom + ", Class = " + _operator.classCustom + ", Method = " + _operator.methodCustom);
            Console.WriteLine("Dll custom this = " + this.dllCustom);
            byte[]   code     = File.ReadAllBytes(this.dllCustom); // carregamento da dll
            Assembly assembly = Assembly.Load(code);

            // Walk through each type in the assembly looking for our class
            try
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (type.IsClass == true)
                    {
                        if (type.FullName.EndsWith("." + this.classCustom))
                        {
                            // create an instance of the object
                            object ClassObj = Activator.CreateInstance(type);

                            // Dynamically Invoke the method
                            while (true)
                            {
                                base.execute();

                                if (this.inputTuples.Count != 0)
                                {
                                    checkSleeping();
                                    Tup inputTuple;
                                    lock (this.inputTuples)
                                    {
                                        inputTuple = (Tup)this.inputTuples[0].Clone();
                                    }
                                    object[] args         = new object[] { inputTuple };
                                    object   resultObject = type.InvokeMember(this.methodCustom,
                                                                              BindingFlags.Default | BindingFlags.InvokeMethod,
                                                                              null,
                                                                              ClassObj,
                                                                              args);
                                    IList <IList <string> > result = (IList <IList <string> >)resultObject;
                                    Console.WriteLine("Result of executing Custom Operator: ");
                                    if (result.Count == 0)
                                    {
                                        destroyTupleInAllReplicas(inputTuple.id);
                                    }
                                    foreach (IList <string> tuple in result)
                                    {
                                        string[] outputFields = new string[tuple.Count];
                                        tuple.CopyTo(outputFields, 0);
                                        int oldID       = inputTuple.id;
                                        Tup outputTuple = new Tup(oldID, outputFields);
                                        Console.Write("tuple: ");
                                        Console.WriteLine(constructTuple(outputTuple));
                                        addProcessingNumberToAllReplicas();
                                        lock (this.outputTuples)
                                        {
                                            outputTuples.Add(outputTuple);
                                            _operator.outputTuples.Sort((s1, s2) => s1.id.CompareTo(s2.id));
                                        }
                                    }
                                    lock (this.inputTuples)
                                    {
                                        inputTuples.RemoveAt(0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                Console.WriteLine(errorMessage);
            }

            //throw (new System.Exception("could not invoke method"));
        }