예제 #1
0
        private void m_addTableToWatch_Click(object sender, RoutedEventArgs e)
        {
            if (m_table != null)
            {
                /* Make sure the table we are adding is not in the table */
                if (!dbsets.isInAllSet((string)m_table.Id))
                {
                    /* Start configuration/setup dialog */
                    WatcherSetupDialog wsd = new WatcherSetupDialog((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + m_table.Name + "-db.txt"), (string)m_table.Id, m_table, false);
                    bool?result            = wsd.ShowDialog();

                    /* Make sure the addition wasn't canceled */
                    if (result.Value == true)
                    {
                        /* Add to working database */
                        dbsets.addToWatchedSets((string)m_table.Id, m_table.Name, (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + m_table.Name + "-db.txt"));

                        /* Save database to file */
                        dbsets.saveToDbFile((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath));
                    }

                    /* Refresh working configuration (in case user wants to update the same table again without closing the window) */
                    dbsets = new WatchedSets(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath);
                }
                else
                {
                    MessageBox.Show("Table is already being watched.");
                }

                /* MessageBox.Show((string)m_table.Id);
                 * using (FileStream fs = File.Open(Properties.Settings.Default.dbfilepath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                 * {
                 *  StreamReader sr = new StreamReader(fs);
                 *  StreamWriter sw = new StreamWriter(fs);
                 *  MessageBox.Show("Worked!");
                 *  bool inTable = false;
                 *  while(!sr.EndOfStream)
                 *  {
                 *      var parts = sr.ReadLine().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                 *      if (parts[0] == (string)m_table.Id)
                 *      {
                 *          inTable = true;
                 *          break;
                 *      }
                 *  }
                 *  if (inTable == false)
                 *  {
                 *      MessageBox.Show("HERE!");
                 *      sw.WriteLine((string)m_table.Id + DELIM + m_table.Name); //Insert configuration file for ImportContent here
                 *      sw.Flush();
                 *  }
                 *  fs.Close();
                 * }*/
            }
        }
예제 #2
0
 public void OnLoad()
 {
     dbsets           = new WatchedSets(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath);
     m_serverUrl.Text = Properties.Settings.Default.defaultserverip;
 }
예제 #3
0
        public static int Main(string[] args)
        {
            int ret = 0;
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
                e.Cancel = true;
                Program.interrupted = true;
            };
            int res;
            string ncHostname = "10.50.149.13";
            int ncPort = 80;

            IServerSession session = CSAPI.Create().CreateServerSession(ncHostname, ncPort);
            //Authenticate(session);
            bool authenticated;
            do
            {
                authenticated = Authenticate(session);
            }
            while (!authenticated);
            while (!Program.interrupted)
            {
                Console.WriteLine("Updating internal database...");
                Console.WriteLine((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath));
                WatchedSets sets = new WatchedSets((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath));
                foreach (w_set toLoad in sets.all_set)
                {
                    workingConf = new SetConfig(toLoad.TABLE_DB_PATH);
                    res = importItem(session, workingConf);
                    Console.WriteLine("Updating table: " + toLoad.TABLE_NAME);
                    if (res == 2) //Server Timeout
                    {
                        Console.WriteLine("Server timeout, disconnecting . . .");
                        bool reauthen = false;
                        do
                        {
                            Thread.Sleep(5000);
                            session = CSAPI.Create().CreateServerSession(ncHostname, ncPort);
                            reauthen = Authenticate(session);
                        }
                        while (!reauthen);
                        break;
                    }
                    else if (res == -1)
                    {
                        Console.WriteLine("Authentication error, retrying . . .");
                        bool reauthen = false;
                        do
                        {
                            Thread.Sleep(5000);
                            session = CSAPI.Create().CreateServerSession(ncHostname, ncPort);
                            reauthen = Authenticate(session);
                        }
                        while (!reauthen);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Updated: " + toLoad.TABLE_NAME);
                    }
                }
                Console.WriteLine("Finished... Sleeping...");
                Thread.Sleep(900000);
            }
            return ret;
        }