protected override void Execute(CodeActivityContext context)
        {
            service = new TwitterService(ConsumerKey.Get(context),
                                         ConsumerSecret.Get(context),
                                         AccessToken.Get(context),
                                         AccessSecret.Get(context));
            service.TraceEnabled = true;

            using (var stream = new FileStream(MediaPath.Get(context), FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                TwitterChunkedMedia uploadedMedia = InitialiseMediaUpload(service, stream);

                UploadMediaChunks(service, stream, uploadedMedia);

                FinializeMediaAndWaitForProcessing(service, uploadedMedia);

                // Now send a tweet with the media attached
                var twitterStatus = service.SendTweet(new SendTweetOptions()
                {
                    Status   = Message.Get(context),
                    MediaIds = new string[] { uploadedMedia.MediaId.ToString() }
                });

                //AssertResultWas(service, HttpStatusCode.OK);
                //Assert.IsNotNull(twitterStatus);

                // Capture Posted Tweet Id
                TweetId.Set(context, twitterStatus.Id);
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            service = new TwitterService(ConsumerKey.Get(context),
                                         ConsumerSecret.Get(context),
                                         AccessToken.Get(context),
                                         AccessSecret.Get(context))
            {
                TraceEnabled = true
            };

            var tweetsSearch = service.Search(new SearchOptions
            {
                Q          = SearchKey.Get(context),
                Resulttype = TwitterSearchResultType.Recent,
                Count      = Count.Get(context)
            });

            List <TwitterStatus> resultList = new List <TwitterStatus>(tweetsSearch.Statuses);


            dtTweet.Columns.Add("Tweet Id");
            dtTweet.Columns.Add("User Name");
            dtTweet.Columns.Add("User Screen Name");
            dtTweet.Columns.Add("Text");
            dtTweet.Columns.Add("Created Date");
            dtTweet.Columns.Add("Retweet Count");
            dtTweet.Columns.Add("Favorite Count");
            dtTweet.Columns.Add("Profile Image URL");

            foreach (var tweet in tweetsSearch.Statuses)
            {
                //tweet.Id; //Id of the tweet
                //tweet.User.ScreenName;  //Screen Name of the user
                //tweet.User.Name;   //Name of the User
                //tweet.Text; // Trimmed Text of the tweet
                //tweet.FullText; // Full Text of the tweet
                //tweet.RetweetCount; //No of retweet on twitter
                //tweet.User.FavouritesCount; //No of Fav mark on twitter
                //tweet.User.ProfileImageUrl; //Profile Image of Tweet
                //tweet.CreatedDate; //For Tweet posted time
                //"https://twitter.com/intent/retweet?tweet_id=" + tweet.Id;  //For Retweet
                //"https://twitter.com/intent/tweet?in_reply_to=" + tweet.Id; //For Reply
                //"https://twitter.com/intent/favorite?tweet_id=" + tweet.Id; //For Favorite

                //Above are the things we can also get using TweetSharp.
                dtTweet.Rows.Add(
                    FetchUserDetails.Get(context) ? tweet.Id : 0L,
                    FetchUserDetails.Get(context) ? tweet.User.Name : "",
                    FetchUserDetails.Get(context) ? tweet.User.ScreenName : "",
                    FetchFullText.Get(context) ? tweet.FullText : tweet.Text,
                    tweet.CreatedDate,
                    tweet.RetweetCount,
                    tweet.FavoriteCount,
                    FetchUserDetails.Get(context) ? tweet.User.ProfileImageUrl : ""
                    );
            }
            OutputResult.Set(context, dtTweet);
        }
        protected override void Execute(CodeActivityContext context)
        {
            service = new TwitterService(ConsumerKey.Get(context),
                                         ConsumerSecret.Get(context),
                                         AccessToken.Get(context),
                                         AccessSecret.Get(context));

            service.Retweet(new RetweetOptions {
                Id = TweetID.Get(context)
            });
        }
        //private TraceSource traceSource = new TraceSource("Workflow");
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            //   traceSource.TraceEvent(TraceEventType.Information, 0, "0");

            /* String sfdcConsumerkey = "3MVG9CxwbdV68qJIIz27ukIaKmSfOCVO8I6JbMGHkEt4s5KwlreFqQqE.5UIpNcOds3xKVoib9cEZpUk3f5os";
             * String sfdcConsumerSecret = "8782286442880574610";
             * String sfdcUserName = "******";
             * String sfdcPassword = "******";
             * String sfdcSecurityToken = "dg912XkpjYZjhtj2kOMqjh4qU";*/

            String sfdcConsumerkey    = ConsumerKey.Get(context);
            String sfdcConsumerSecret = ConsumerSecret.Get(context);
            String sfdcUserName       = UserName.Get(context);
            String sfdcPassword       = Password.Get(context);
            String sfdcSecurityToken  = SecurityToken.Get(context);

            String  SfdcloginPassword = sfdcPassword + sfdcSecurityToken;
            Boolean TestServer        = (ServerType == Type_of_Server.Test) ? true : false;

            var dictionaryForUrl = new Dictionary <String, String>
            {
                { "grant_type", "password" },
                { "client_id", sfdcConsumerkey },
                { "client_secret", sfdcConsumerSecret },
                { "username", sfdcUserName },
                { "password", SfdcloginPassword }
            };

            var task = (new CmdRestAPI(dictionaryForUrl, TestServer)).ExecuteAsync();
            var tcs  = new TaskCompletionSource <CmdRestAPI>(state);

            task.ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    tcs.TrySetException(t.Exception.InnerExceptions);
                }
                else if (t.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(t.Result);
                }
                if (callback != null)
                {
                    callback(tcs.Task);
                }
            });

            return(tcs.Task);
        }
예제 #5
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                service = new TwitterService(ConsumerKey.Get(context),
                                             ConsumerSecret.Get(context),
                                             AccessToken.Get(context),
                                             AccessSecret.Get(context));

                TwitterStatus status;
                if (ImagePath.Get(context) == null)
                {
                    // Send Tweet without Image
                    status = service.SendTweet(new SendTweetOptions {
                        Status = Message.Get(context)
                    });
                }
                else
                {
                    // Send Tweet with Image
                    MediaFile mf     = new MediaFile();
                    Stream    stream = new FileStream(ImagePath.Get(context), FileMode.Open);
                    mf.Content = stream;

                    var media = service.UploadMedia(new UploadMediaOptions {
                        Media = mf
                    });
                    var id = media.Media_Id;

                    List <string> ls = new List <string>();
                    ls.Add(id.ToString());

                    status = service.SendTweet(new SendTweetOptions
                    {
                        Status   = Message.Get(context),
                        MediaIds = ls,
                    });
                }

                // Capture Posted Tweet Id
                TweetId.Set(context, status.Id);
            }
            catch (Exception e)
            {
                TweetId.Set(context, e.Message);
            }
        }
        protected override void Execute(NativeActivityContext context)
        {
            RestSharp.RestClient client     = new RestSharp.RestClient();
            MCser.SoapClient     soapClient = null;

            String ExistAuthToken  = "" + ExistingAuth.Get(context);
            String ExistServiceURL = "" + ExistingServ.Get(context);

            if (ExistAuthToken.Trim().Length > 1)
            {
                RespAuthToken  = ExistAuthToken.Trim();
                RespServiceURL = ExistServiceURL.Trim();
            }
            else
            {
                String  sfdcConsumerkey    = "";
                String  sfdcConsumerSecret = "";
                String  sfdcServiceURL     = "";
                String  sfdcUserName       = "";
                String  sfdcPassword       = "";
                Boolean EnvType            = (EnvironmentType == Type_of_Environment.Design_and_Test) ? true : false;
                if (EnvType)
                {
                    sfdcConsumerkey    = ConsumerKey.Get(context);
                    sfdcConsumerSecret = ConsumerSecret.Get(context);
                    sfdcServiceURL     = ServiceURL.Get(context);
                    sfdcUserName       = UserName.Get(context);
                    sfdcPassword       = Password.Get(context);
                }
                else
                {
                    sfdcConsumerkey    = ConsumerKeyProd.Get(context);
                    sfdcConsumerSecret = SecureStringToString(ConsumerSecretProd.Get(context));
                    sfdcServiceURL     = "" + SecureStringToString(ServiceURLProd.Get(context));
                    sfdcUserName       = UserNameProd.Get(context);
                    sfdcPassword       = SecureStringToString(PasswordProd.Get(context));
                }

                try
                {
                    client.BaseUrl = new Uri("https://auth.exacttargetapis.com/v1/requestToken");

                    var request2 = new RestRequest(Method.POST);
                    request2.RequestFormat = DataFormat.Json;
                    request2.AddParameter("clientId", sfdcConsumerkey);
                    request2.AddParameter("clientSecret", sfdcConsumerSecret);

                    JObject jsonObj = JObject.Parse(client.Post(request2).Content);
                    RespAuthToken = (String)jsonObj["accessToken"];
                    String ErrorType = "";
                    ErrorType = (String)jsonObj["error"];
                    String ErrorMsg = "";
                    ErrorMsg = (String)jsonObj["error_description"];


                    if ((RespAuthToken != null && RespAuthToken != "") && ErrorMsg == null)
                    {
                        BasicHttpsBinding binding = new BasicHttpsBinding();
                        binding.Name                   = "MyServicesSoap";
                        binding.CloseTimeout           = TimeSpan.FromMinutes(1);
                        binding.OpenTimeout            = TimeSpan.FromMinutes(1);
                        binding.ReceiveTimeout         = TimeSpan.FromMinutes(60);
                        binding.SendTimeout            = TimeSpan.FromMinutes(1);
                        binding.AllowCookies           = false;
                        binding.BypassProxyOnLocal     = false;
                        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                        binding.MaxBufferSize          = 20000000;
                        binding.MaxBufferPoolSize      = 20000000;
                        binding.MaxReceivedMessageSize = 20000000;
                        binding.MessageEncoding        = WSMessageEncoding.Text;
                        binding.TextEncoding           = System.Text.Encoding.UTF8;
                        binding.TransferMode           = TransferMode.Buffered;
                        binding.UseDefaultWebProxy     = true;

                        binding.ReaderQuotas.MaxDepth = 32;
                        binding.ReaderQuotas.MaxStringContentLength = 8192;
                        binding.ReaderQuotas.MaxArrayLength         = 16384;
                        binding.ReaderQuotas.MaxBytesPerRead        = 4096;
                        binding.ReaderQuotas.MaxNameTableCharCount  = 16384;

                        binding.Security.Mode = BasicHttpsSecurityMode.Transport;
                        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                        binding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
                        binding.Security.Transport.Realm = "";
                        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                        binding.Security.Message.AlgorithmSuite       = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;


                        String          endpointStr = "https://webservice.s10.exacttarget.com/Service.asmx";
                        EndpointAddress endpoint    = new EndpointAddress(endpointStr);
                        soapClient = new MCser.SoapClient(binding, endpoint);
                        soapClient.ClientCredentials.UserName.UserName = sfdcUserName;
                        soapClient.ClientCredentials.UserName.Password = sfdcPassword;
                        soapClient.Endpoint.EndpointBehaviors.Add(new FuelOAuthHeaderBehavior(RespAuthToken));
                        RespServiceURL = sfdcServiceURL;
                    }
                    else if (RespAuthToken == null && (ErrorMsg != "" && ErrorMsg != null))
                    {
                        RespAuthToken  = "Error Type: " + ErrorType;
                        RespServiceURL = "Error: " + ErrorMsg;
                    }
                }
                catch (Exception ex)
                {
                    RespAuthToken  = "Error Type: " + ex.ToString();
                    RespServiceURL = "Error: " + ex.ToString();
                }
            }

            var salesForceProperty = new SalesForceProperty(soapClient, true, RespAuthToken, RespServiceURL);

            if (Body != null)
            {
                context.ScheduleAction <SalesForceProperty>(Body, salesForceProperty, OnCompleted, OnFaulted);
            }
        }