/// <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); } }
static Message() { Initialize(); _getMessagesParametersFactory = TweetinviContainer.Resolve <IFactory <IGetMessagesParameters> >(); _messagePublishParametersFactory = TweetinviContainer.Resolve <IFactory <IPublishMessageParameters> >(); }
private static void Initialize() { _messageFactory = TweetinviContainer.Resolve <IMessageFactory>(); _messageController = TweetinviContainer.Resolve <IMessageController>(); _messageGetLatestsReceivedRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsReceivedRequestParameters> >(); _messageGetLatestsSentRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsSentRequestParameters> >(); }
// 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; }
static TwitterList() { Initialize(); _twitterListIdentifierFactory = TweetinviContainer.Resolve <ITwitterListIdentifierFactory>(); _twitterListQueryParameterGenerator = TweetinviContainer.Resolve <ITwitterListQueryParameterGenerator>(); }
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> >(); }
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> >(); }
static Message() { Initialize(); _messageGetLatestsReceivedRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessagesReceivedParameters> >(); _messageGetLatestsSentRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessagesSentParameters> >(); _messagePublishParametersFactory = TweetinviContainer.Resolve <IFactory <IPublishMessageParameters> >(); }
static RateLimit() { Initialize(); _rateLimitAwaiter = TweetinviContainer.Resolve <IRateLimitAwaiter>(); _rateLimitCacheManager = TweetinviContainer.Resolve <IRateLimitCacheManager>(); _rateLimitCache = TweetinviContainer.Resolve <IRateLimitCache>(); }
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); }
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); }
// 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)); }
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); }; }
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 }
static Sync() { InitializeStaticThread(); _taskFactory = TweetinviContainer.Resolve <ITaskFactory>(); }
private static void Initialize() { _tweetController = TweetinviContainer.Resolve <ITweetController>(); _tweetFactory = TweetinviContainer.Resolve <ITweetFactory>(); }
private static void Initialize() { _geoFactory = TweetinviContainer.Resolve <IGeoFactory>(); _geoController = TweetinviContainer.Resolve <IGeoController>(); }
private static void Initialise() { _exceptionHandler = TweetinviContainer.Resolve <IExceptionHandler>(); }
static TweetList() { Initialize(); _listUpdateParametersUnityFactory = TweetinviContainer.Resolve <IUnityFactory <IListUpdateParameters> >(); }
static CredentialsCreator() { _credentialsCreator = TweetinviContainer.Resolve <ICredentialsCreator>(); _webTokenCreator = TweetinviContainer.Resolve <IWebTokenCreator>(); _credentialsStore = TweetinviContainer.Resolve <ICredentialsStore>(); }
private static void Initialize() { _savedSearchFactory = TweetinviContainer.Resolve <ISavedSearchFactory>(); _savedSearchController = TweetinviContainer.Resolve <ISavedSearchController>(); }
private static void Initialize() { _helpController = TweetinviContainer.Resolve <IHelpController>(); }
static TweetinviConfig() { _currentSettingsAccessor = TweetinviContainer.Resolve <ITweetinviSettingsAccessor>(); }
private static void Initialize() { _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>(); _credentialsCreatorForCurrentThread = TweetinviContainer.Resolve <ICredentialsCreator>(); }
private static void Initialize() { _twitterAccessor = TweetinviContainer.Resolve <ITwitterAccessor>(); }
private static void Initialize() { _searchController = TweetinviContainer.Resolve <ISearchController>(); _searchQueryGenerator = TweetinviContainer.Resolve <ISearchQueryGenerator>(); }
static TweetinviEvents() { _tweetinviEvents = TweetinviContainer.Resolve <ITweetinviEvents>(); }
private static void InitializeStaticThread() { _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>(); }
static Upload() { Initialize(); _uploadHelper = TweetinviContainer.Resolve <IUploadHelper>(); }
private static void Initialize() { _uploadQueryExecutor = TweetinviContainer.Resolve <IUploadQueryExecutor>(); }