private void onOpenClick(object sender, RoutedEventArgs e)
        {
            TabEvent currentTab = tab_List.SelectedItem as TabEvent;

            if (currentTab == null)
            {
                onNewTabClick(null, null);
                currentTab = tab_List.SelectedItem as TabEvent;
            }
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Title      = "Open";
            openDialog.DefaultExt = "txt";
            if (openDialog.ShowDialog().Value)
            {
                using (StreamReader reader = new StreamReader(openDialog.FileName))
                {
                    string jsonStr = reader.ReadToEnd();
                    IDictionary <string, object> state = JsonSerializer.DeserializeObject(jsonStr) as IDictionary <string, object>;
                    currentTab.SetState(state["event_type"] as string,
                                        state["date_from"] as string,
                                        state["date_to"] as string,
                                        state["content"] as string);

                    currentTab.DisplayState();
                    reader.Close();
                }
            }
        }
 private void addRefreshButtons(object sender, RoutedEventArgs e)
 {
     foreach (MyObject obj in m_TabList)
     {
         TabEvent tab = obj.Value as TabEvent;
         tab.btn_Refresh.Visibility = System.Windows.Visibility.Visible;
     }
 }
        private void onNewTabClick(object sender, RoutedEventArgs e)
        {
            TabEvent tab = new TabEvent(m_EventList);

            m_TabList.Add(
                new MyObject {
                Header = tab.EventType, Value = tab
            });
            tab.HeaderUpdated     += headerUpdated;
            tab.EventListUpdated  += eventListUpdated;
            tab_List.ItemsSource   = null;
            tab_List.ItemsSource   = m_TabList;
            tab_List.SelectedIndex = m_TabList.Count - 1;
        }
        private void createEventList(bool isNew)
        {
            int expireTime = Utilities.ConvertToTimestamp(DateTime.Now.AddMinutes(1));
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("type", "general");
            parameters.Add("expire", expireTime.ToString());
            IsLoading = true;

            string uri = MixPanel.Default.GetUri(parameters, URI_EVENTLIST);

            MixPanel.Default.HttpGet(uri, (object sender, DownloadStringCompletedEventArgs e) =>
            {
                IsLoading = false;
                if (e.Error != null)
                {
                    MessageBox.Show(e.Error.Message);
                }
                else
                {
                    m_EventList = Utilities.GetEventsName(e.Result);
                    if (isNew)
                    {
                        /*First time run*/
                        onNewTabClick(null, null);
                    }
                    else
                    {
                        /*Update all tabs' event list*/
                        foreach (MyObject obj in m_TabList)
                        {
                            TabEvent tab = obj.Value as TabEvent;
                            tab.box_Event.ItemsSource  = m_EventList;
                            tab.btn_Refresh.Visibility = System.Windows.Visibility.Collapsed;
                        }
                    }
                }
            });
        }
        private void onSaveClick(object sender, RoutedEventArgs e)
        {
            TabEvent currentTab = tab_List.SelectedItem as TabEvent;

            if (string.IsNullOrEmpty(currentTab.GetState().Content))
            {
                MessageBox.Show("No data to save.");
            }
            else
            {
                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.DefaultExt       = "txt";
                saveDialog.AddExtension     = true;
                saveDialog.FileName         = currentTab.EventType + DateTime.Today.ToString("ddMMyyyy");
                saveDialog.InitialDirectory = @"C:\";
                saveDialog.OverwritePrompt  = true;
                saveDialog.Title            = "Save";

                if (saveDialog.ShowDialog().Value)
                {
                    Dictionary <string, object> saveState = new Dictionary <string, object>();
                    State state = currentTab.GetState();
                    saveState["event_type"] = state.EventType;
                    saveState["date_from"]  = state.DateFrom;
                    saveState["date_to"]    = state.DateTo;
                    saveState["content"]    = state.Content as string;
                    string jsonStr = JsonSerializer.SerializeObject(saveState);

                    using (StreamWriter writer = new StreamWriter(saveDialog.FileName))
                    {
                        writer.Write(jsonStr);
                        writer.Close();
                    }
                }
            }
        }