Пример #1
0
        static Message()
        {
            Initialize();

            _getMessagesParametersFactory    = TweetinviContainer.Resolve <IFactory <IGetMessagesParameters> >();
            _messagePublishParametersFactory = TweetinviContainer.Resolve <IFactory <IPublishMessageParameters> >();
        }
Пример #2
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;
        }
Пример #3
0
 private static void Initialize()
 {
     _messageFactory    = TweetinviContainer.Resolve <IMessageFactory>();
     _messageController = TweetinviContainer.Resolve <IMessageController>();
     _messageGetLatestsReceivedRequestParametersFactory = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsReceivedRequestParameters> >();
     _messageGetLatestsSentRequestParametersFactory     = TweetinviContainer.Resolve <IFactory <IMessageGetLatestsSentRequestParameters> >();
 }
Пример #4
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);
            }
        }
Пример #5
0
        static TwitterList()
        {
            Initialize();

            _twitterListIdentifierFactory       = TweetinviContainer.Resolve <ITwitterListIdentifierFactory>();
            _twitterListQueryParameterGenerator = TweetinviContainer.Resolve <ITwitterListQueryParameterGenerator>();
        }
Пример #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> >();
 }
Пример #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> >();
 }
Пример #8
0
        static Message()
        {
            Initialize();

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

            _rateLimitAwaiter      = TweetinviContainer.Resolve <IRateLimitAwaiter>();
            _rateLimitCacheManager = TweetinviContainer.Resolve <IRateLimitCacheManager>();
            _rateLimitCache        = TweetinviContainer.Resolve <IRateLimitCache>();
        }
Пример #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);
        }
Пример #11
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);
            };
        }
Пример #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));
        }
Пример #13
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
        }
Пример #14
0
        static TweetList()
        {
            Initialize();

            _listUpdateParametersUnityFactory = TweetinviContainer.Resolve <IUnityFactory <IListUpdateParameters> >();
        }
Пример #15
0
 private static void Initialize()
 {
     _tweetController = TweetinviContainer.Resolve <ITweetController>();
     _tweetFactory    = TweetinviContainer.Resolve <ITweetFactory>();
 }
Пример #16
0
 private static void Initialize()
 {
     _savedSearchFactory    = TweetinviContainer.Resolve <ISavedSearchFactory>();
     _savedSearchController = TweetinviContainer.Resolve <ISavedSearchController>();
 }
Пример #17
0
 private static void Initialise()
 {
     _exceptionHandler = TweetinviContainer.Resolve <IExceptionHandler>();
 }
Пример #18
0
 static TweetinviConfig()
 {
     _currentSettingsAccessor = TweetinviContainer.Resolve <ITweetinviSettingsAccessor>();
 }
Пример #19
0
 static CredentialsCreator()
 {
     _credentialsCreator = TweetinviContainer.Resolve <ICredentialsCreator>();
     _webTokenCreator    = TweetinviContainer.Resolve <IWebTokenCreator>();
     _credentialsStore   = TweetinviContainer.Resolve <ICredentialsStore>();
 }
Пример #20
0
 private static void Initialize()
 {
     _twitterAccessor = TweetinviContainer.Resolve <ITwitterAccessor>();
 }
Пример #21
0
 private static void Initialize()
 {
     _uploadQueryExecutor = TweetinviContainer.Resolve <IUploadQueryExecutor>();
 }
Пример #22
0
 private static void Initialize()
 {
     _searchController     = TweetinviContainer.Resolve <ISearchController>();
     _searchQueryGenerator = TweetinviContainer.Resolve <ISearchQueryGenerator>();
 }
Пример #23
0
 private static void Initialize()
 {
     _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();
     _credentialsCreatorForCurrentThread = TweetinviContainer.Resolve <ICredentialsCreator>();
 }
Пример #24
0
 static TweetinviEvents()
 {
     _tweetinviEvents = TweetinviContainer.Resolve <ITweetinviEvents>();
 }
Пример #25
0
 private static void InitializeStaticThread()
 {
     _credentialsAccessor = TweetinviContainer.Resolve <ICredentialsAccessor>();
 }
Пример #26
0
 private static void Initialize()
 {
     _userController       = TweetinviContainer.Resolve <IUserController>();
     _userFactory          = TweetinviContainer.Resolve <IUserFactory>();
     _friendshipController = TweetinviContainer.Resolve <IFriendshipController>();
 }
Пример #27
0
 private static void Initialize()
 {
     _geoFactory    = TweetinviContainer.Resolve <IGeoFactory>();
     _geoController = TweetinviContainer.Resolve <IGeoController>();
 }
Пример #28
0
 private static void Initialize()
 {
     _helpController = TweetinviContainer.Resolve <IHelpController>();
 }
Пример #29
0
        static Sync()
        {
            InitializeStaticThread();

            _taskFactory = TweetinviContainer.Resolve <ITaskFactory>();
        }
Пример #30
0
        static Upload()
        {
            Initialize();

            _uploadHelper = TweetinviContainer.Resolve <IUploadHelper>();
        }