Example #1
0
        /// <summary>
        /// Execute a task asynchronously with Tweetinvi
        /// </summary>
        public static async Task <T> ExecuteTaskAsync <T>(Func <T> resultFunc)
        {
            // We store the credentials at the time of the call within the local memory
            var credentialsAtInvokeTime = CredentialsAccessor.CurrentThreadCredentials;

            // We are cloning to avoid changes to the settings before the async operation starts
            var sourceThreadSettingsClone = TweetinviConfig.CurrentThreadSettings.Clone();

            // The lambda expression will store 'credentialsAtInvokeTime' within a generated class
            // In order to keep the reference to the credentials at the time of invocation
            var operationRunWithSpecificCredentials = new Func <T>(() =>
            {
                TweetinviConfig.CurrentThreadSettings.InitialiseFrom(sourceThreadSettingsClone);

                // We get the newly created credentialsAccessor for the async thread (CredentialsAccessor are Thread specific)
                var credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();

                // We now use credentials of the lambda expression local variables to perform our operation
                //return AsyncContext.Run(() => credentialsAccessor.ExecuteOperationWithCredentials(credentialsAtInvokeTime, resultFunc));
                return(credentialsAccessor.ExecuteOperationWithCredentials(credentialsAtInvokeTime, resultFunc));
            });

            using (var thread = new AsyncContextThread())
            {
                var result = await thread.Factory.Run(() => { return(operationRunWithSpecificCredentials()); });

                return(result);
            }
        }
Example #2
0
        static Message()
        {
            Initialize();

            _getMessagesParametersFactory    = TweetinviContainer.Resolve <IFactory <IGetMessagesParameters> >();
            _messagePublishParametersFactory = TweetinviContainer.Resolve <IFactory <IPublishMessageParameters> >();
        }
Example #3
0
 private static void Initialize()
 {
     _messageFactory    = TweetinviContainer.Resolve <IMessageFactory>();
     _messageController = TweetinviContainer.Resolve <IMessageController>();
     _messageGetLatestsReceivedRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsReceivedRequestParameters> >();
     _messageGetLatestsSentRequestParametersFactory     = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsSentRequestParameters> >();
 }
Example #4
0
        // ALERT : THIS CODE IS AWESOME :D

        /// <summary>
        /// Execute a task asynchronously with Tweetinvi
        /// </summary>
        public static async Task ExecuteTaskAsync(Action action)
        {
            // We store the credentials at the time of the call within the local memory
            var credentialsAtInvokeTime = CredentialsAccessor.CurrentThreadCredentials;

            // We are cloning to avoid changes to the settings before the async operation starts
            var sourceThreadSettingsClone = TweetinviConfig.CurrentThreadSettings.Clone();

            // The lambda expression will store 'credentialsAtInvokeTime' within a generated class
            // In order to keep the reference to the credentials at the time of invocation
            var operationRunWithSpecificCredentials = new Action(() =>
            {
                TweetinviConfig.CurrentThreadSettings.InitialiseFrom(sourceThreadSettingsClone);

                // We get the newly created credentialsAccessor for the async thread (CredentialsAccessor are Thread specific)
                var credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();

                // We now use credentials of the lambda expression local variables to perform our operation
                credentialsAccessor.ExecuteOperationWithCredentials(credentialsAtInvokeTime, action);
            });

            AsyncContext.Run(async() =>
            {
                await _taskFactory.ExecuteTaskAsync(operationRunWithSpecificCredentials);
            });

            await Task.CompletedTask;
        }
Example #5
0
        static TwitterList()
        {
            Initialize();

            _twitterListIdentifierFactory       = TweetinviContainer.Resolve <ITwitterListIdentifierFactory>();
            _twitterListQueryParameterGenerator = TweetinviContainer.Resolve <ITwitterListQueryParameterGenerator>();
        }
Example #6
0
 static Stream()
 {
     _userStreamFactory          = TweetinviContainer.Resolve <IFactory <IUserStream> >();
     _tweetStreamUnityFactory    = TweetinviContainer.Resolve <IFactory <ITweetStream> >();
     _sampleStreamUnityFactory   = TweetinviContainer.Resolve <IFactory <ISampleStream> >();
     _trackedStreamUnityFactory  = TweetinviContainer.Resolve <IFactory <ITrackedStream> >();
     _filteredStreamUnityFactory = TweetinviContainer.Resolve <IFactory <IFilteredStream> >();
 }
Example #7
0
 private static void Initialize()
 {
     _timelineController                   = TweetinviContainer.Resolve <ITimelineController>();
     _homeTimelineParameterFactory         = TweetinviContainer.Resolve <IFactory <IHomeTimelineParameters> >();
     _userTimelineParameterFactory         = TweetinviContainer.Resolve <IFactory <IUserTimelineParameters> >();
     _mentionsTimelineParameterFactory     = TweetinviContainer.Resolve <IFactory <IMentionsTimelineParameters> >();
     _retweetsOfMeTimelineParameterFactory = TweetinviContainer.Resolve <IFactory <IRetweetsOfMeTimelineParameters> >();
 }
Example #8
0
        static Message()
        {
            Initialize();

            _messageGetLatestsReceivedRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessagesReceivedParameters> >();
            _messageGetLatestsSentRequestParametersFactory     = TweetinviContainer.Resolve <IFactory <IMessagesSentParameters> >();
            _messagePublishParametersFactory = TweetinviContainer.Resolve <IFactory <IPublishMessageParameters> >();
        }
Example #9
0
        static RateLimit()
        {
            Initialize();

            _rateLimitAwaiter      = TweetinviContainer.Resolve <IRateLimitAwaiter>();
            _rateLimitCacheManager = TweetinviContainer.Resolve <IRateLimitCacheManager>();
            _rateLimitCache        = TweetinviContainer.Resolve <IRateLimitCache>();
        }
Example #10
0
        private static IResultsWithCursor <IMessage> generateResultsWithCursor(IEnumerable <IMessage> messages,
                                                                               string cursor)
        {
            if (messages == null)
            {
                return(null);
            }

            IResultsWithCursor <IMessage> resultsWithCursor = TweetinviContainer.Resolve <IResultsWithCursor <IMessage> >();

            resultsWithCursor.Results = messages;
            resultsWithCursor.Cursor  = cursor;
            return(resultsWithCursor);
        }
Example #11
0
        public static void Add <T>() where T : ITweetinviModule
        {
            var type = typeof(T);

            var ctor = type.GetConstructor(new Type[0]);

            if (ctor == null)
            {
                throw new InvalidOperationException("This class is not a plugin that can be added as no valid ctor could be identified");
            }

            var instance = ctor.Invoke(null);
            var module   = (T)instance;

            TweetinviContainer.AddModule(module);
        }
Example #12
0
        // ALERT : THIS CODE IS AWESOME :D
        public static async Task <T> ExecuteTaskAsync <T>(Func <T> resultFunc)
        {
            // We store the credentials at the time of the call within the local memory
            var credentialsAtInvokeTime = CredentialsAccessor.CurrentThreadCredentials;

            // The lambda expression will store 'credentialsAtInvokeTime' within a generated class
            // In order to keep the reference to the credentials at the time of invocation
            var operationRunWithSpecificCredentials = new Func <T>(() =>
            {
                // We get the newly created credentialsAccessor for the async thread (CredentialsAccessor are Thread specific)
                var credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();

                // We now use credentials of the lambda expression local variables to perform our operation
                return(credentialsAccessor.ExecuteOperationWithCredentials(credentialsAtInvokeTime, resultFunc));
            });

            return(await _taskFactory.ExecuteTaskAsync(operationRunWithSpecificCredentials));
        }
Example #13
0
        static TweetinviEvents()
        {
            _tweetinviEvents = TweetinviContainer.Resolve <ITweetinviEvents>();
            _tweetinviEvents.QueryBeforeExecute += (sender, args) =>
            {
                _currentThreadEvents.RaiseQueryBeforeExecute(sender, args);
            };

            _tweetinviEvents.QueryBeforeExecuteAfterRateLimitAwait += (sender, args) =>
            {
                _currentThreadEvents.RaiseQueryBeforeExecuteAfterRateLimitAwait(sender, args);
            };

            _tweetinviEvents.QueryAfterExecute += (sender, args) =>
            {
                _currentThreadEvents.RaiseQueryAfterExecute(sender, args);
            };
        }
Example #14
0
        static JsonSerializer()
        {
            _jsonConvert = typeof(JsonConvert)
                           .GetMethods()
                           .Where(m => m.Name == "DeserializeObject")
                           .Select(m => new
            {
                Method = m,
                Params = m.GetParameters(),
                Args   = m.GetGenericArguments()
            })
                           .Where(x => x.Args.Length == 1 &&
                                  x.Params.Length == 2)
                           .Select(x => x.Method)
                           .First();

            var tweetFactory           = TweetinviContainer.Resolve <ITweetFactory>();
            var userFactory            = TweetinviContainer.Resolve <IUserFactory>();
            var messageFactory         = TweetinviContainer.Resolve <IMessageFactory>();
            var twitterListFactory     = TweetinviContainer.Resolve <ITwitterListFactory>();
            var savedSearchFactory     = TweetinviContainer.Resolve <ISavedSearchFactory>();
            var accountSettingsFactory = TweetinviContainer.Resolve <IAccountController>();
            var friendshipFactory      = TweetinviContainer.Resolve <IFriendshipFactory>();

            _getSerializableObject = new Dictionary <Type, IJsonSerializer>();

            // ReSharper disable RedundantTypeArgumentsOfMethod
            Map <ITweet, ITweetDTO>(u => u.TweetDTO, tweetFactory.GenerateTweetFromJson);
            Map <IUser, IUserDTO>(u => u.UserDTO, userFactory.GenerateUserFromJson);
            Map <IMessage, IEventWithAppDTO>(m =>
            {
                var eventWithApp   = TweetinviContainer.Resolve <IEventWithAppDTO>();
                eventWithApp.Event = m.EventDTO;
                eventWithApp.App   = m.App;
                return(eventWithApp);
            }, messageFactory.GenerateMessageFromJson);
            Map <ITwitterList, ITwitterListDTO>(l => l.TwitterListDTO, twitterListFactory.GenerateListFromJson);
            Map <ISavedSearch, ISavedSearchDTO>(s => s.SavedSearchDTO, savedSearchFactory.GenerateSavedSearchFromJson);
            Map <IAccountSettings, IAccountSettingsDTO>(s => s.AccountSettingsDTO, accountSettingsFactory.GenerateAccountSettingsFromJson);
            Map <IOEmbedTweet, IOEmbedTweetDTO>(t => t.OembedTweetDTO, tweetFactory.GenerateOEmbedTweetFromJson);
            Map <IRelationshipDetails, IRelationshipDetailsDTO>(r => r.RelationshipDetailsDTO, friendshipFactory.GenerateFriendshipDetailsFromJson);
            Map <IRelationshipState, IRelationshipStateDTO>(r => r.RelationshipStateDTO, friendshipFactory.GenerateFriendshipStateFromJson);
            // ReSharper restore RedundantTypeArgumentsOfMethod
        }
Example #15
0
        static Sync()
        {
            InitializeStaticThread();

            _taskFactory = TweetinviContainer.Resolve <ITaskFactory>();
        }
Example #16
0
 private static void Initialize()
 {
     _tweetController = TweetinviContainer.Resolve <ITweetController>();
     _tweetFactory    = TweetinviContainer.Resolve <ITweetFactory>();
 }
Example #17
0
 private static void Initialize()
 {
     _geoFactory    = TweetinviContainer.Resolve <IGeoFactory>();
     _geoController = TweetinviContainer.Resolve <IGeoController>();
 }
Example #18
0
 private static void Initialise()
 {
     _exceptionHandler = TweetinviContainer.Resolve <IExceptionHandler>();
 }
Example #19
0
        static TweetList()
        {
            Initialize();

            _listUpdateParametersUnityFactory = TweetinviContainer.Resolve <IUnityFactory <IListUpdateParameters> >();
        }
Example #20
0
 static CredentialsCreator()
 {
     _credentialsCreator = TweetinviContainer.Resolve <ICredentialsCreator>();
     _webTokenCreator    = TweetinviContainer.Resolve <IWebTokenCreator>();
     _credentialsStore   = TweetinviContainer.Resolve <ICredentialsStore>();
 }
Example #21
0
 private static void Initialize()
 {
     _savedSearchFactory    = TweetinviContainer.Resolve <ISavedSearchFactory>();
     _savedSearchController = TweetinviContainer.Resolve <ISavedSearchController>();
 }
Example #22
0
 private static void Initialize()
 {
     _helpController = TweetinviContainer.Resolve <IHelpController>();
 }
Example #23
0
 static TweetinviConfig()
 {
     _currentSettingsAccessor = TweetinviContainer.Resolve <ITweetinviSettingsAccessor>();
 }
Example #24
0
 private static void Initialize()
 {
     _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();
     _credentialsCreatorForCurrentThread = TweetinviContainer.Resolve <ICredentialsCreator>();
 }
Example #25
0
 private static void Initialize()
 {
     _twitterAccessor = TweetinviContainer.Resolve <ITwitterAccessor>();
 }
Example #26
0
 private static void Initialize()
 {
     _searchController     = TweetinviContainer.Resolve <ISearchController>();
     _searchQueryGenerator = TweetinviContainer.Resolve <ISearchQueryGenerator>();
 }
Example #27
0
 static TweetinviEvents()
 {
     _tweetinviEvents = TweetinviContainer.Resolve <ITweetinviEvents>();
 }
Example #28
0
 private static void InitializeStaticThread()
 {
     _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();
 }
Example #29
0
        static Upload()
        {
            Initialize();

            _uploadHelper = TweetinviContainer.Resolve <IUploadHelper>();
        }
Example #30
0
 private static void Initialize()
 {
     _uploadQueryExecutor = TweetinviContainer.Resolve <IUploadQueryExecutor>();
 }