public static WeiboSender CreateSender(string token) { WeiboSender sender = new WeiboSender(); try { sender.mToken = token; sender.mSinaClient = new SinaWeiboClient(token); /* * string userJson = WeiboApi2.GetUserInfo(sender.mSinaClient, 3); * SimpleJSON.JSONNode jsonNode = SimpleJSON.JSON.Parse(userJson); * sender.mUserId = jsonNode["id"]; * sender.mUserName = jsonNode["screen_name"]; * sender.mHeaderUrl = jsonNode["profile_image_url"]; */ }catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } return(sender); }
public void readConfig() { Win32Api ini = Win32Api.getInstance().setPath(".\\config.ini"); string cookiePath = ini.ReadValue("robot", "cookie"); string windowText = ini.ReadValue("robot", "windows"); string tokenText = ini.ReadValue("robot", "weibo_sender_tokens"); interval = ini.ReadValue("robot", "interval"); uid = ini.ReadValue("robot", "uid"); topCount = ini.ReadValue("robot", "top"); try { ifLog = bool.Parse(ini.ReadValue("robot", "iflog")); } catch (Exception) { } try { ifHeader = bool.Parse(ini.ReadValue("robot", "show_user_info", "true")); } catch (Exception) { } try { ifFooter = bool.Parse(ini.ReadValue("robot", "show_source", "true")); } catch (Exception) { } windows = string.IsNullOrEmpty(windowText)? new string[0] : windowText.Split(','); weiboTokens = string.IsNullOrEmpty(tokenText) ? new string[0] : tokenText.Split(','); if (File.Exists(cookiePath)) { try { cookie = File.ReadAllText(cookiePath); }catch (Exception e) { cookie = ""; } } proxy = ini.ReadValue("robot", "proxy"); takerKind = ini.ReadValue("robot", "taker", "weibo"); autoStartServer = bool.Parse(ini.ReadValue("robot", "auto_start", "false")); textBox1.Text = cookie; listBox1.Items.Clear(); textBox3.Text = uid; textBox4.Text = interval; textBox5.Text = topCount; textBox7.Text = takerKind; textBox8.Text = proxy; checkBox1.Checked = ifHeader; checkBox2.Checked = ifFooter; for (int i = 0; i < windows.Length; i++) { listBox1.Items.Add(windows[i]); } for (int i = 0; i < weiboTokens.Length; i++) { listBox1.Items.Add(weiboTokens[i]); } handle.senders.Clear(); handle.ifLog = ifLog; handle.showHeader = ifHeader; handle.showFooter = ifFooter; listBox2.Items.Clear(); bool qqWindowReady = windows.Length <= 0 ? true : false; foreach (string win in windows) { QQSender sender = QQSender.CreateSender(win, this); if (sender != null) { handle.senders.AddLast(sender); listBox2.Items.Add(sender.getName()); qqWindowReady = true; } } foreach (string token in weiboTokens) { WeiboSender sender = WeiboSender.CreateSender(token); if (sender != null) { handle.senders.AddLast(sender); listBox2.Items.Add(sender.getName()); } } if (autoStartServer && handle.senders.Count > 0) { if (qqWindowReady) { SynchronizationContext.Current.Post(new SendOrPostCallback(t => { button2_Click(null, null); }), null); //this.Invoke((Action) delegate{ button2_Click(null, null); }); } else { Thread.Sleep(15000); readConfig(); } } }