Exemplo n.º 1
0
        private static void CheckAuthentication()
        {
            string apiKey;
            string secret;

            using (FileStream fs = new FileStream("apikey.apikey", FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    apiKey = sr.ReadLine();
                    sr.Close();
                    fs.Close();
                }
            }

            using (FileStream fs = new FileStream("secret.secret", FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    secret = sr.ReadLine();
                    sr.Close();
                    fs.Close();
                }
            }

            RtmConnectionHelper.InitializeRtmConnection(apiKey, secret);

            if (File.Exists("authtoken.authtoken"))
            {
                string authtoken;
                using (FileStream fs = new FileStream("authtoken.authtoken", FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        authtoken = sr.ReadLine();
                        sr.Close();
                        fs.Close();
                    }
                }
                RtmConnectionHelper.SetApiAuthToken(authtoken);
            }
            else
            {
                RefreshToken();
            }

            RtmApiResponse tokenResponse = RtmConnectionHelper.CheckApiAuthToken();

            if (tokenResponse.ErrorResponse.Code == 98)
            {
                RefreshToken();
            }

            /*tokenResponse =*/
            RtmConnectionHelper.CheckApiAuthToken();
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            CheckAuthentication();

            RtmApiResponse listResponse = RtmMethodHelper.GetListsList();
            RtmApiResponse taskResponse = RtmMethodHelper.GetTasksList();

            string         timeline        = RtmConnectionHelper.CreateTimeline().TimeLine;
            RtmApiResponse newTaskResponse = RtmMethodHelper.AddTask(timeline, "try something new at 5 pm", parse: "1");

            //string transactionId = newTaskResponse.Transaction.Id;
            //RtmApiResponse undoResponse = RtmMethodHelper.UndoTransaction(timeline, transactionId);

            //IList<string> tssListIds = listResponse.ListCollection.Lists.Where(list => string.Equals(list.Name, "3ss tasks", StringComparison.OrdinalIgnoreCase)).Select(list => list.Id).ToList();
            //IList<RtmApiTaskSeries> tssTasks = taskResponse.TaskSeriesCollection.TaskSeriesList
            //    .Where(taskSeriesList => taskSeriesList.TaskSeries.Any() && tssListIds.Contains(taskSeriesList.Id))
            //    .SelectMany(taskSeriesList => taskSeriesList.TaskSeries)
            //    .ToList();
        }
Exemplo n.º 3
0
        private static void RefreshToken()
        {
            string url = RtmConnectionHelper.GetAuthenticationUrl(RtmConnectionHelper.Permissions.Delete);

            Console.WriteLine("Press any key after auth is complete.");
            Process.Start(url);
            Console.ReadKey();

            RtmApiResponse authResponse = RtmConnectionHelper.GetApiAuthToken();

            using (FileStream fs = new FileStream("authtoken.authtoken", FileMode.Create, FileAccess.ReadWrite))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(authResponse.Auth.Token);
                    sw.Close();
                    fs.Close();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create Auth File and set RTM token
        /// </summary>
        /// <param name="name">File name</param>
        /// <param name="token">Token from RTM</param>
        public void CreateAuthFile(string name, string token)
        {
            FileStream fs = null;

            try
            {
                using (fs = new FileStream(name, FileMode.Create, FileAccess.ReadWrite))
                {
                    using (var sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        sw.Write(token);
                        sw.Close();
                    }
                }
            }
            finally
            {
                fs?.Close();
            }

            RtmConnectionHelper.SetApiAuthToken(token);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Take Auth keys and initiate basic RTM connection by creating or reading authtoken file
        /// </summary>
        /// <param name="authKeys">Passing <c>AuthKeys</c> keys</param>
        public void InitiateConnection(AuthKeys authKeys)
        {
            if (!string.IsNullOrEmpty(authKeys.MyRTMkey) || !string.IsNullOrEmpty(authKeys.MyRTMsecret))
            {
                RtmConnectionHelper.InitializeRtmConnection(authKeys.MyRTMkey, authKeys.MyRTMsecret);
            }
            else
            {
                System.Windows.Application.Current.Shutdown();
            }
            MainWindow.SetLoggingMessage_Other("RTM: Initiate Connection using: " + authKeys.MyRTMkey + " and " + authKeys.MyRTMsecret);

            string rtmUriWithWritePerms = RtmConnectionHelper.GetAuthenticationUrl(RtmConnectionHelper.Permissions.Write);

            MainWindow.SetLoggingMessage_Other("RTM: we are inside of InitiateConnection() method: " + rtmUriWithWritePerms);

            Process.Start(rtmUriWithWritePerms);
            System.Threading.Thread.Sleep(2000);

            RtmApiResponse authResponseToken = RtmConnectionHelper.GetApiAuthToken();

            logger.Info("RTM: authResponseToken: -> " + authResponseToken.Auth.Token);
            MainWindow.SetLoggingMessage_Other("RTM: " + authResponseToken.Auth.User.FullName +
                                               " token: -> " + authResponseToken.Auth.Token);

            if (!File.Exists("authtoken.authtoken"))
            {
                // if file does not exist, then create it by writing into it
                CreateAuthFile("authtoken.authtoken", authResponseToken.Auth.Token);
            }
            else
            {
                // if file does exist, then check for its creation time
                DateTime file_created = File.GetLastWriteTime("authtoken.authtoken");
                long     file_len     = new FileInfo("authtoken.authtoken").Length;

                // if that time is older than 1 day, check for token's validity
                if ((DateTime.Now - file_created).TotalHours >= 25 || file_len < 10)
                {
                    try
                    {
                        RtmConnectionHelper.CheckApiAuthToken();
                    }
                    catch (Exception e)
                    {
                        string mes = "RTM: checking for the RTM token has failed. Creating new one";
                        MainWindow.SetLoggingMessage_Other(mes);
                        logger.Error(mes);
                        MainWindow.SetLoggingMessage_Other(e.Message);
                    }

                    CreateAuthFile("authtoken.authtoken", authResponseToken.Auth.Token);
                }
                else
                {
                    string file_text = File.ReadAllText(@"authtoken.authtoken");
                    string msg       = "RTM: Our file_text to read from: ";
                    logger.Info(msg + file_text);
                    MainWindow.SetLoggingMessage_Other(msg + file_text);
                    RtmConnectionHelper.SetApiAuthToken(file_text);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns a newly created RTM timeline
 /// </summary>
 /// <returns>a new timeline</returns>
 private string GetRTMTimeline()
 {
     timeline = RtmConnectionHelper.CreateTimeline().TimeLine;
     return(timeline);
 }