public Result(TypeOfDepth depth, String attributeName, String value)
        {
            InitializeComponent();
            if (depth != TypeOfDepth.Post)
            {
                dataGrid1.Visibility = System.Windows.Visibility.Hidden;
                label1.Visibility = System.Windows.Visibility.Hidden;
                textBlock1.Visibility = System.Windows.Visibility.Hidden;
            }
            dataGrid1.AutoGenerateColumns = true;
            /*
            DataGridTextColumn dgtc = new DataGridTextColumn();
            dgtc.Header = "Attribute";
            dataGrid1.Columns.Add(dgtc);
            DataGridTextColumn dgtc2 = new DataGridTextColumn();
            dgtc2.Header = "Value";
            dataGrid1.Columns.Add(dgtc2);
            */
            this.depth = depth;
            this.attributeName = attributeName;
            this.value = value;
            this.searcher=new Searcher();
            this.resultList = new List<dynamic>();

            s = searcher;
            list = resultList;
            tree = treeView1;
       }
        internal static Result run(TypeOfDepth depth, String attributeName, String value)
        {
            Result result = new Result(depth, attributeName, value);
            list = s.search(depth, value, tree);

            //System.Threading.Thread.Sleep(5000);

            //list = s.searchFromAnotherNodes(depth, value, tree);

            return result;
        }
        public List<dynamic> SendMessage(TypeOfDepth depth, string value)
        {
            List<dynamic> srchresult =  this.communicate.SendMessageToServer(depth, value);
            Console.WriteLine("Sent");
            List<dynamic> result = new List<dynamic>();

            if (depth == TypeOfDepth.Post)
                foreach (List<dynamic> l in srchresult)
                    result.Add(new Post(l[0], l[1], l[2], l[3], l[4]));
            else if (depth == TypeOfDepth.Thread)
                foreach (List<dynamic> l in srchresult)
                    result.Add(new ForumThread(l[0], l[1]));
            else if (depth == TypeOfDepth.Section)
                foreach (List<dynamic> l in srchresult)
                    result.Add(new Section(l[0]));

            result.AddRange(srch.ReceiveMessage(depth, value));

            return result;
        }
        public List<dynamic> ReceiveMessage(TypeOfDepth depth, string value)
        {
            List<dynamic> result = new List<dynamic>();

            if (depth == TypeOfDepth.Section)
            {
                result.Add(new Section("section1"));
                result.Add(new Section("section2"));
            }
            else if (depth == TypeOfDepth.Thread)
            {
                result.Add(new ForumThread("section1", "thread1"));
                result.Add(new ForumThread("section2", "thread2"));
            }
            else if (depth == TypeOfDepth.Post)
            {
                result.Add(new Post("thread1", "section1", "author1", "content1", DateTime.Now));
                result.Add(new Post("thread2", "section2", "author2", "content2", DateTime.Now));
            }

            return result;
        }
        public List<dynamic> SendMessageToClient(TypeOfDepth depth, string value)
        {
            List<dynamic> result = new List<dynamic>();
            List<dynamic> srchresult = null;

            Console.WriteLine("Message from server: " + depth + " " + value);
            ISearcher srch = ClientServer.getSearcher();
            srchresult = srch.ReceiveMessage(depth, value);

            if (depth == TypeOfDepth.Post)
                foreach (Post p in srchresult)
                    result.Add(new List<dynamic>() { p.ThreadName, p.SectionName, p.Author, p.Content, p.dateTime});
            else if (depth == TypeOfDepth.Thread)
                foreach (ForumThread f in srchresult)
                    result.Add(new List<dynamic>() { f.ThreadName, f.SectionName });
            else if (depth == TypeOfDepth.Section)
                foreach (Section s in srchresult)
                    result.Add(new List<dynamic>() {s.SectionName});

            return result;
            
        }
        public List<dynamic> SendMessageToServer(TypeOfDepth depth, string value)
        {
            List<dynamic> result = new List<dynamic>();
            List<Client> toRemove = new List<Client>();
 
            IServerCalback callback = OperationContext.Current.GetCallbackChannel<IServerCalback>();
            foreach (Client c in clients)
            {
                if (c.callback != callback)
                {
                    if (((ICommunicationObject)c.callback).State == CommunicationState.Opened)
                        result.AddRange(c.callback.SendMessageToClient(depth, value));
                    else toRemove.Add(c);
                }
            }

            foreach (Client c in toRemove)
            {
                clients.Remove(c);
            }
            return result;
        }
 public List<dynamic> ReceiveResults(TypeOfDepth type, String value)
 {
     if (type == TypeOfDepth.ForumThread)
     {
         var _value = value;
         var query = Query.EQ("name", value);
         Producer temp = producerList.FindOne(query);
         if (temp == null)
         {
             return null;
         }
         else
         {
             if (temp.GetThreads() == null)
             {
                 return null;
             }
             else
             {
                 return temp.GetThreads().ToList<dynamic>();
             }
         }
     }
     else if (type == TypeOfDepth.Post)
     {
         var _value = value;
         var query = Query.EQ("name", _value);
         Producer temp = producerList.FindOne(query);
         if (temp == null)
         {
             return null;
         }
         else
         {
             if (temp.GetPosts() == null)
             {
                 return null;
             }
             else
             {
                 return temp.GetPosts().ToList<dynamic>();
             }
         }
     }
     else if (type == TypeOfDepth.Section)
     {
         var _value = value;
         var query = Query.EQ("name", value);
         Producer temp = producerList.FindOne(query);
         if (temp == null)
         {
             return null;
         }
         else
         {
             if (temp.GetSections() == null)
             {
                 return null;
             }
             else
             {
                 return temp.GetSections().ToList<dynamic>();
             }
         }
     }
     else return null;
 }