When my DatePickerDialog shows the year is set to '1900'. I Only know how to limit the past dates but I don't know how to limit the past years. What I want to happen is as follows.
ex. The user wants to input the Cheque/Check Date, I will only allow the past dates to the current year.
public void ChequeDate(View view) {
DatePickerDialog dpd = new DatePickerDialog(PaymentHeader.this,
new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
if (year < mYear)
view.updateDate(mYear, mMonth, mDay);
if (monthOfYear < mMonth && year == mYear)
view.updateDate(mYear, mMonth, mDay);
if (dayOfMonth < mDay && year == mYear && monthOfYear == mMonth)
view.updateDate(mYear, mMonth, mDay);
if (monthOfYear < 9) {
if (dayOfMonth < 10) {
ChequeDateET.setText(year + "-0"
+ (monthOfYear + 1) + "-0" + dayOfMonth);
} else {
ChequeDateET.setText(year + "-0"
+ (monthOfYear + 1) + "-" + dayOfMonth);
}
} else {
if (dayOfMonth < 10) {
ChequeDateET.setText(year + "-"
+ (monthOfYear + 1) + "-0" + dayOfMonth);
} else {
ChequeDateET.setText(year + "-"
+ (monthOfYear + 1) + "-" + dayOfMonth);
}
}
}
}, mYear, mMonth, mDay);
//dpd.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
dpd.show();
}
You have to get current calendar instance and from this you have to get year, month and dateobjects to pass as an arguments in the DatePickerDialog method and enable setMinDate method.
Check the following code now
public void ChequeDate(View view) {
Calendar calendar = Calendar.getInstance();
int date = calendar.get(Calendar.DATE);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
DatePickerDialog dpd = new DatePickerDialog(PaymentHeader.this,
new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
if (year < mYear)
view.updateDate(mYear, mMonth, mDay);
if (monthOfYear < mMonth && year == mYear)
view.updateDate(mYear, mMonth, mDay);
if (dayOfMonth < mDay && year == mYear && monthOfYear == mMonth)
view.updateDate(mYear, mMonth, mDay);
if (monthOfYear < 9) {
if (dayOfMonth < 10) {
ChequeDateET.setText(year + "-0"
+ (monthOfYear + 1) + "-0" + dayOfMonth);
} else {
ChequeDateET.setText(year + "-0"
+ (monthOfYear + 1) + "-" + dayOfMonth);
}
} else {
if (dayOfMonth < 10) {
ChequeDateET.setText(year + "-"
+ (monthOfYear + 1) + "-0" + dayOfMonth);
} else {
ChequeDateET.setText(year + "-"
+ (monthOfYear + 1) + "-" + dayOfMonth);
}
}
}
}, year, month, date);
dpd.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
dpd.show();
}
Related
How can I concatenate my String and the int in the lines:
print('Computer is moving to ' + (i + 1));
and print("Computer is moving to " + (i + 1));
I cant figure it out because the error keeps saying "The argument type 'int' can't be assigned to the parameter type 'String'
void getComputerMove() {
int move;
// First see if there's a move O can make to win
for (int i = 0; i < boardSize; i++) {
if (_mBoard[i] != humanPlayer && _mBoard[i] != computerPlayer) {
String curr = _mBoard[i];
_mBoard[i] = computerPlayer;
if (checkWinner() == 3) {
print('Computer is moving to ' + (i + 1));
return;
} else
_mBoard[i] = curr;
}
}
// See if there's a move O can make to block X from winning
for (int i = 0; i < boardSize; i++) {
if (_mBoard[i] != humanPlayer && _mBoard[i] != computerPlayer) {
String curr = _mBoard[i]; // Save the current number
_mBoard[i] = humanPlayer;
if (checkWinner() == 2) {
_mBoard[i] = computerPlayer;
print("Computer is moving to " + (i + 1));
return;
} else
_mBoard[i] = curr;
}
}
}
With string interpolation:
print("Computer is moving to ${i + 1}");
Or just call toString():
print("Computer is moving to " + (i + 1).toString());
You can simply use .toString which will convert your integer to String :
void main(){
String str1 = 'Welcome to Matrix number ';
int n = 24;
//concatenate str1 and n
String result = str1 + n.toString();
print(result);
}
And in your case it's gonna be like this :
print("Computer is moving to " + (i + 1).toString());
First time posting a question. Maybe I'm just being an idiot that's not seeing the problem, but can anyone identify what's wrong with my code below? Everything else works fine. But when the code is done compiling, it says "Error: no suitable method found for length(int)" for if (l.length(0)) and if (f.length(0)).
import java.util.Scanner;
public class Project2 {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int salary;
double savingsRate;
double interestRate;
int employmentYears;
double retirementSavings;
System.out.println("Enter input salary savings_rate interest_rate years_employed lastname firstname");
salary = scnr.nextInt();
savingsRate = scnr.nextDouble();
interestRate = scnr.nextDouble();
employmentYears = scnr.nextInt();
String l = scnr.nextLine(); // Last Name
String f = scnr.nextLine(); // First Name
retirementSavings = employmentYears * savingsRate * salary * (1 + interestRate);
if (salary < 0) {
System.out.println("Salary is negative");
}
else if (salary > 1000000) {
System.out.println("Error: Salary " + salary + "exceeds maximum 1000000.0");
}
else {
System.out.println("Salary: " + salary);
}
if (savingsRate < 0) {
System.out.println("Savings rate is negative");
}
else if (savingsRate > 0.5) {
System.out.println("Error: Savings rate " + savingsRate + "exceeds maximum 0.5");
}
else {
System.out.println("Savings Rate:" + savingsRate);
}
if (interestRate < 0) {
System.out.println("Interest Rate is negative");
}
else if (interestRate > 0.25) {
System.out.println("Error: Interest Rate " + interestRate + "exceeds maximum 0.25");
}
else {
System.out.println("Interest Rate: " + interestRate);
}
if (employmentYears < 0) {
System.out.println("Years employed is negative!");
}
else if (employmentYears > 50) {
System.out.println("Error: Years employed " + employmentYears + "exceeds maximum 50");
}
else {
System.out.println("Years of Employment: " + employmentYears);
}
if (l.length(0)) {
System.out.println("Error: Name too short");
}
else if (l == f) {
System.out.println("Error: Last Name and First Name are the same");
}
else {
System.out.println("Last Name: " + l);
}
if (f.length(0)) {
System.out.println("Error: Name too short");
}
else {
System.out.println("First Name: " + f);
}
System.out.println("Retirement Savings: " + retirementSavings);
}
}
I think you are trying to check if the name is empty, Am I right?
you have:
1) string.length() : length() method is a final variable which is applicable for string objects. length() method returns the number of characters presents in the string.
2) array.length : length is a final variable applicable for arrays. With the help of length variable, we can obtain the size of the array.
(visit geeksforgeeks to see more).
But you don't have a String.length(int) method.
My app uses a countdown timer in the background in a class that extends Services. The background running service is designed to access the Sharedpreferences data of the app. During the countdown, a particular integer in the Sharedpreferences changes value and the updated value is expected to be accessed in the onFinish() call of the countdown timer. The problem now is that the Service don't read the updated valued from the Sharedpreferences but rather returns the initial value at the point the background service started.
I saw somewhere that the solution to the problem is to use
PreferenceManager.getDefaultSharedPreferences()
instead of getSharedPrefences to be able access the current SharedPreferences value. I implemented this recommendation but the problem persist.
Please somebody should help me out because trying to figure out this is taking too much of my time.
My code is here:
public class BroadcastService extends Service {
DatabaseHelperClass myDatabase = new DatabaseHelperClass(this);
private SharedPreferences defaultSharedPreferences, sharedPreferences, staffSignedIn;
private SharedPreferences.Editor staffEditor, defaultSharedPreferencesEditor;
int countSignIn;
private SimpleDateFormat simpleDateFormatII;
Long timeLeftInMiliseconds;
private final static String TAG = "BroadcastService";
public static final String COUNTDOWN_BR = "com.cenitscitech.www.etimebook.countdown_br";
Intent bi = new Intent(COUNTDOWN_BR);
CountDownTimer cdt = null;
#Override
public void onCreate() {
super.onCreate();
defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
defaultSharedPreferencesEditor = defaultSharedPreferences.edit();
sharedPreferences = getSharedPreferences("setTime", MODE_PRIVATE);
//staffSignedIn = getSharedPreferences("present", MODE_PRIVATE);
//countSignIn = staffSignedIn.getInt("max", 0);
//staffEditor = staffSignedIn.edit();
simpleDateFormatII = new SimpleDateFormat("MMM EEE dd, yyyy HH:mm");
Log.i(TAG, "Starting timer in broadcast receiver...");
Log.i(TAG, "max Count Obtained onBroadcastCreate: "+defaultSharedPreferences.getInt("max", 0));
}
#Override
public void onDestroy() {
//cdt.cancel();
Log.i(TAG, "Timer in broadcast receiver cancelled");
super.onDestroy();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
timeLeftInMiliseconds = intent.getLongExtra("timeLeft", 0L);
cdt = new CountDownTimer(timeLeftInMiliseconds, 1000) {
#Override
public void onTick(long millisUntilFinished) {
SharedPreferences defaultShared = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.i(TAG, "Countdown seconds remaining: " + millisUntilFinished / 1000);
/*bi.putExtra("countdown", millisUntilFinished);
sendBroadcast(bi);*/
}
#Override
public void onFinish() {
SharedPreferences defaultSharedPreferences2 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
countSignIn = defaultSharedPreferences2.getInt("max", 0);
Log.i(TAG, "Timer finished");
bi.putExtra("countdown", "Timer finished");
sendBroadcast(bi);
StringBuilder phoneBuilder = new StringBuilder();
Calendar cStart = Calendar.getInstance();
cStart.set(Calendar.HOUR_OF_DAY, 0);
cStart.set(Calendar.MINUTE, 0);
cStart.set(Calendar.SECOND, 0);
Long cStartLong = cStart.getTimeInMillis();
Calendar cEnd = Calendar.getInstance();
cEnd.set(Calendar.HOUR_OF_DAY, 23);
cEnd.set(Calendar.MINUTE, 59);
cEnd.set(Calendar.SECOND, 59);
Long cEndLong = cEnd.getTimeInMillis();
String[] conditionsElements;
Log.i(TAG + " onFinish", "MAXIMUM COUNT OBTAINED: " + defaultSharedPreferences2.getInt("max", 0));
Log.i(TAG + " onFinish", "MAXIMUM COUNT OBTAINED: " + countSignIn);
if (defaultSharedPreferences2.getInt("max", 0) > 0) {
Log.i(TAG + " onFinish", "CURRENT countSignIn Value: "+countSignIn+"\n"+" max Value: "+defaultSharedPreferences2.getInt("max", 0));
conditionsElements = new String[defaultSharedPreferences2.getInt("max", 0)];
for (int i = 1; i <= defaultSharedPreferences2.getInt("max", 0); i++) {
conditionsElements[i - 1] = defaultSharedPreferences2.getString(Integer.toString(i), "NoElement");
Log.i(TAG + " onFinish", "conditionsElement[" + (i - 1) + "] = " + defaultSharedPreferences2.getString(Integer.toString(i), "NoElement"));
if (i < defaultSharedPreferences2.getInt("max", 0)) {
phoneBuilder.append("MOBILE_NUMBER = ? OR ");
Log.i(TAG + " onFinish", "phoneBuilder[" + (i - 1) + "]: " + phoneBuilder);
//phoneBuilder.append(staffSignedIn.getString(Integer.toString(i), "NoStaff")+"_");
} else if (i == defaultSharedPreferences2.getInt("max", 0)) {
//phoneBuilder.append(staffSignedIn.getString(Integer.toString(i), "NoStaff"));
phoneBuilder.append("MOBILE_NUMBER = ?");
Log.i(TAG + " onFinish", "phoneBuilder[final]: " + phoneBuilder);
}
}
} else {
Log.i(TAG + " onFinishInsideElse", "CURRENT countSignIn Value: "+countSignIn+"\n"+" max Value: "+defaultSharedPreferences2.getInt("max", 0));
conditionsElements = new String[1];
conditionsElements[0] = "NoElement";
phoneBuilder.append("MOBILE_NUMBER = ?");
}
Cursor cursor = myDatabase.queryAbsentStaff(SURNAME_COLUMN + ", " + FIRST_NAME_COLUMN + ", " + MIDDLE_NAME_COLUMN + ", " + MOBILE_NUMBER_COLUMN + ", " + DATE_COLUMN,
SURNAME_COLUMN + ", " + FIRST_NAME_COLUMN + ", " + MIDDLE_NAME_COLUMN + ", " + MOBILE_NUMBER_COLUMN + ", " + DATE_COLUMN,
phoneBuilder.toString(),
conditionsElements);
Log.i(TAG + " onFinish", "\n" + "SET TIMES:" + "\n" + cStartLong + "\n" + cEndLong + "\n" + "RETURNED ROWS:" + "\n" + cursor.getCount());
/*staffEditor.putInt("max", 0);
staffEditor.apply();
for(int i=0; i<staffSignedIn.getInt("totalStaff", 100); i++){
staffEditor.putString(Integer.toString((i+1)), "empty").apply();
}*/
if(cursor.moveToFirst()){
for (int i = 0; i < cursor.getCount(); i++) {
if(myDatabase.insertTimeBookRecord(cursor.getString(cursor.getColumnIndex(SURNAME_COLUMN)), cursor.getString(cursor.getColumnIndex(FIRST_NAME_COLUMN)),
cursor.getString(cursor.getColumnIndex(MIDDLE_NAME_COLUMN)), cursor.getString(cursor.getColumnIndex(MOBILE_NUMBER_COLUMN)),
"ABSENT", Long.toString(System.currentTimeMillis()), 1000000L, "NO", "0000", System.currentTimeMillis(), "notSynced", "notSynced")){
cursor.moveToNext();
if(cursor.isAfterLast()){
cursor.close();
}
}else{
cursor.moveToNext();
if(cursor.isAfterLast()){
cursor.close();
}
}
}
}
Log.i(TAG +" onFinish: ", "max val reset: "+defaultSharedPreferences2.getInt("max", 0));
I need optimized solution to increment and decrement alphanumeric string value as we do in excel. When I specify alphanumeric string with range then it should give me both decremented n incremented list of values. For e.g I need range of +-10 of alphanumeric string as.
PN - Alpha character may come in start / middle /end
1. A2000018 -> A2000008 to A2000028
2. A39999 -> A39989 to A40009
3. A00005 -> A00001 to A00015
4. AZ00005 -> AZ00001 to AZ00015
5. A342S0004 -> A342S0001 to A342S0014
6. A342S9999 -> A342S9989 to A342S10009
7. 1234A -> 1224A to 1244A
8. 0003A -> 0001A to 0013A
public static List<String> getRangeList(String docNumber, int range) {
List<String> rangeList = new ArrayList<>();
System.out.println("Document Number Received " + docNumber);
/**
* REGEX checks for String value starting with 1 character as alpha and rest numeric
*/
boolean trailingAlphabet = false;
boolean leadingNtrailingAlphabet = false;
boolean leadingNtrailingNumber = false;
String patternStr = "";
if (docNumber.trim().matches("[a-zA-Z]{1,5}[0-9]{1,20}[a-zA-Z]{1,5}$")) { //String docNumber = "AD234SD1234 ";
patternStr = "(.*?)(\\d+)(.*?)$";
leadingNtrailingAlphabet = true;
} else if (docNumber.trim().matches("[0-9]{1,20}[a-zA-Z]{1,5}[0-9]{1,20}+$")) { //String docNumber = "1234AD1234 ";
patternStr = "(\\d+)(.*?)(\\d+)$";
leadingNtrailingNumber = true;
} else if (docNumber.trim().matches("[0-9]{1,20}[a-zA-Z]{1,4}+$")) { //String docNumber = "1234A ";
patternStr = "(\\d+)(.*?)$";
trailingAlphabet = true;
} else if (docNumber.trim().matches("[a-zA-Z]{1,5}[0-9]+$")
|| docNumber.trim().matches("[a-zA-Z]{1,5}[0-9]{1,20}[a-zA-Z]{1,4}[0-9]+$")) {
patternStr = "(.*?)(\\d+)$";
}
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(docNumber.trim());
if (matcher.find()) {
String firstAlpha = "";
String origNumber = "";
String lastAlpha = "";
if (trailingAlphabet) {
firstAlpha = matcher.group(2);
origNumber = matcher.group(1);
} else if (leadingNtrailingAlphabet) {
firstAlpha = matcher.group(1);
origNumber = matcher.group(2);
lastAlpha = matcher.group(3);
} else if (leadingNtrailingNumber) {
firstAlpha = matcher.group(1);
lastAlpha = matcher.group(2);
origNumber = matcher.group(3);
} else {
firstAlpha = matcher.group(1);
origNumber = matcher.group(2);
}
//System.out.println("1 Alpha : " + firstAlpha + " origNNum : " + origNumber + " lastAlpha : " + lastAlpha);
String incrNumStr = origNumber;
String dcrNumStr = origNumber;
for (int i = 0; i < range; i++) {
if (Integer.parseInt(dcrNumStr) - 1 <= 0) {
break;
}
dcrNumStr = String.format("%0" + dcrNumStr.length() + "d", Integer.parseInt(dcrNumStr) - 1);
if (leadingNtrailingNumber) {
rangeList.add(firstAlpha + lastAlpha + dcrNumStr);
} else if (leadingNtrailingAlphabet) {
rangeList.add(firstAlpha + dcrNumStr + lastAlpha);
} else if (trailingAlphabet) {
rangeList.add(dcrNumStr + firstAlpha);
} else {
rangeList.add(firstAlpha + dcrNumStr);
}
}
for (int i = 0; i < range; i++) {
incrNumStr = String.format("%0" + incrNumStr.length() + "d", Integer.parseInt(incrNumStr) + 1);
if (leadingNtrailingNumber) {
rangeList.add(firstAlpha + lastAlpha + incrNumStr);
} else if (leadingNtrailingAlphabet) {
rangeList.add(firstAlpha + incrNumStr + lastAlpha);
} else if (trailingAlphabet) {
rangeList.add(incrNumStr + firstAlpha);
} else {
rangeList.add(firstAlpha + incrNumStr);
}
}
Collections.sort(rangeList);
System.out.println(rangeList);
}
return rangeList;
}
When I execute the code I developed to call an Async method of the linq2Twitter, I am getting a System.Aggregate Exception, the code is below:
static async Task<List<myTwitterStatus>> getRetweets(ulong tweetID, TwitterContext twitterCtx)
{
List<myTwitterStatus> reTweets = new List<myTwitterStatus>();
var publicTweets =
await
(from tweet in twitterCtx.Status
where tweet.Type == StatusType.Retweets &&
tweet.ID == tweetID
select tweet)
.ToListAsync();
if (publicTweets != null)
publicTweets.ForEach(tweet =>
{
if (tweet != null && tweet.User != null)
{
myTwitterStatus tempStatus = new myTwitterStatus();
tempStatus.Country = tweet.Place.Country;
tempStatus.createdAt = tweet.CreatedAt;
tempStatus.FavoriteCount = long.Parse(tweet.FavoriteCount.ToString());
tempStatus.ID = tweet.ID;
tempStatus.isTruncated = tweet.Truncated;
tempStatus.Lang = tweet.Lang;
tempStatus.MaxID = tweet.MaxID;
tempStatus.PlaceFullname = tweet.Place.FullName;
tempStatus.RetweetCount = tweet.RetweetCount;
tempStatus.ScreenName = tweet.ScreenName;
tempStatus.Text = tweet.Text;
tempStatus.UserFriends = tweet.User.FriendsCount;
tempStatus.UserCreated = tweet.User.CreatedAt;
tempStatus.UserFollowers = tweet.User.FollowersCount;
tempStatus.UserFavorities = tweet.User.FavoritesCount;
tempStatus.UserFriends = tweet.User.FriendsCount;
tempStatus.UserLocation = tweet.User.Location;
tempStatus.UserName = tweet.User.Name;
tempStatus.UserTweetCount = tweet.User.StatusesCount;
reTweets.Add(tempStatus);
}
});
return reTweets;
}
The issue is when I called the method
var authorizer = new SingleUserAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = SM.Default.Consumer_key2.ToString(),
ConsumerSecret = SM.Default.Consumer_secret2.ToString(),
OAuthToken = SM.Default.Access_token2.ToString(),
OAuthTokenSecret = SM.Default.Access_secret2.ToString()
}
};
TwitterContext twitterCtx = new TwitterContext(authorizer);
Task<List<myTwitterStatus>> task = Task<List<myTwitterStatus>>.Factory.StartNew(() => getRetweets(ulong.Parse(tweet.StringId), twitterCtx).Result);
task.Wait();
List<myTwitterStatus> tempList = task.Result.ToList<myTwitterStatus>();
foreach (var ret in tempList)
{
un = file.RemoveSpecialCharacters(ret.UserName);
sn = file.RemoveSpecialCharacters(ret.ScreenName);
tweets.AppendLine(account + "," + getWE(ret.createdAt) + "," + Text + "," + un + "," + sn + "," + ret.createdAt + "," +
file.RemoveSpecialCharacters(ret.UserLocation) + ",,,1,," + ret.UserTweetCount + "," +
ret.RetweetCount + "," + ret.FavoriteCount + "," + ret.UserFollowers);
I would appreciate any kind of assistance about it, I have no idea how to solve it.
Can you add a try/catch so see what the inner exception is.
try
{
//Perform your operation here
}
catch (AggregateException aex)
{
//Dive into inner exception
}
Thanks to all for the help, I activate the breakpoints for the specific exception and an additional validation was added, the issue was not in the async process, it was because it was trying to handle a null as an string, to hendle this error this line was modified sn = file.RemoveSpecialCharacters(ret.ScreenName ?? string.Empty);
The full code is below:
private void getRetweets(TwitterStatus tweet)
{
Text = file.RemoveSpecialCharacters(tweet.Text);
tweetID = tweet.StringId;
#region Get retweets
RetweetsOptions retOpt = new RetweetsOptions();
if (int.Parse(tweet.RetweetCountString.ToString()) > 1)
retOpt.Count = int.Parse(tweet.RetweetCountString.ToString()) + 1;
else
retOpt.Count = 1;
String errorText = "";
DateTime fromDate, toDate;
if (radDate.Checked == true)
{
fromDate = dtpFrom.Value;
toDate = dtpTo.Value;
}
else
{
fromDate = tweet.CreatedDate;
toDate = DateTime.Now;
}
TwitterResponse<TwitterStatusCollection> retweet = null;
if (int.Parse(tweet.RetweetCountString.ToString()) > 100)
{
var authorizer = new SingleUserAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = SM.Default.Consumer_key2.ToString(),
ConsumerSecret = SM.Default.Consumer_secret2.ToString(),
OAuthToken = SM.Default.Access_token2.ToString(),
OAuthTokenSecret = SM.Default.Access_secret2.ToString()
}
};
TwitterContext twitterCtx = new TwitterContext(authorizer);
//HELPER: https://www.youtube.com/watch?v=IONqMWGn9-w
try
{
Task<List<myTwitterStatus>> task = null;
Parallel.Invoke(
() =>
{
task = getRetweets(ulong.Parse(tweet.StringId), twitterCtx);
while (!task.IsCompleted)
{
Thread.Sleep(250);
}
});
List<myTwitterStatus> tempList = task.Result.ToList<myTwitterStatus>();
foreach (var ret in tempList)
{
un = file.RemoveSpecialCharacters(ret.UserName);
sn = file.RemoveSpecialCharacters(ret.ScreenName ?? string.Empty);
tweets.AppendLine(account + "," + getWE(ret.createdAt) + "," + Text + "," + un + "," + sn + "," + ret.createdAt + "," +
file.RemoveSpecialCharacters(ret.UserLocation) + ",,,1,," + ret.UserTweetCount + "," +
ret.RetweetCount + "," + ret.FavoriteCount + "," + ret.UserFollowers);
}
}catch(Exception ex){
Console.WriteLine("Error: " + ex.Message+ Environment.NewLine + ex.StackTrace);
}
return;
}
else
retweet= TwitterStatus.Retweets(tokensRet, Decimal.Parse(tweet.Id.ToString()), retOpt);
if (retweet.Result.ToString() == "Success" && retweet.ResponseObject.Count > 0 && retweet!=null)
{
int retPages = int.Parse(tweet.RetweetCountString.ToString()) + 1 / 20;
for (int page = 0; page <= retPages; page++)
{
try
{
//List<TwitterStatus> retList = new List<TwitterStatus>(retweet.ResponseObject.Page = page);
retweet.ResponseObject.Page = page;
List<TwitterStatus> retList = retweet.ResponseObject.ToList<TwitterStatus>();
foreach (var ret in retList)
{
try
{
if (ret.CreatedDate.CompareTo(fromDate) >= 0 && ret.CreatedDate.CompareTo(toDate) <= 0)
{
#region Get UN Sync
getUN(ret, ref un, ref sn);
#endregion
tweets.AppendLine(account + "," + getWE(ret.CreatedDate) + "," + Text + "," + un + "," + sn + "," + ret.CreatedDate + "," +
file.RemoveSpecialCharacters(ret.User.Location.ToString()) + ",,,1,," + ret.User.NumberOfStatuses.ToString() + "," +
ret.RetweetCount + "," + ret.User.NumberOfFavorites.ToString() + "," + ret.User.NumberOfFollowers.ToString());
}
else if (tweet.CreatedDate.CompareTo(toDate) <= 0)//if the tweet's created date is lower than the from's date, exits the loop
break;
}
catch (NullReferenceException ex)
{
errorText = ex.Source + Environment.NewLine + ex.StackTrace;
continue;
}
}
}
catch (Exception ex)
{
errorText = ex.Source + Environment.NewLine + ex.StackTrace;
//MessageBox.Show(ex.Message + Environment.NewLine + "Rate Limit was reached!" + Environment.NewLine +
// "Wait an hour or try a shorter date range", "Rate Limit Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else if (error == false && retweet.Result.ToString() != "Success")
{
errorText = retweet.Result.ToString();
MessageBox.Show("Retweets: Something went wrong!" + Environment.NewLine + errorText, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
error = true;
}
#endregion
}