/// <summary>
        /// サムネダウンロード
        /// </summary>
        /// <param name="ImgThumbnail"></param>
        /// <param name="empty"></param>
        /// <param name="thumbnailUrl"></param>
        /// <returns></returns>
        public IEnumerator UpdateThumbnail(RawImage ImgThumbnail, Texture empty, string thumbnailUrl)
        {
            //登録されていない場合は、ダウンロード

            using (WWW www = new WWW(ThumbnailUrl.CreateListThumbnailUrl(thumbnailUrl)))
            {
                // 画像ダウンロード完了を待機
                while (www.MoveNext())
                {// コルーチンの終了を待つ
                    yield return(null);
                }


                if (!string.IsNullOrEmpty(www.error))
                {
                    ImgThumbnail.texture = empty;
                }

                yield return(new WaitForSeconds(0.5f));

                try
                {
                    ImgThumbnail.texture = www.texture;
                }
                catch
                {
                    ImgThumbnail.texture = empty;
                }
            }

            Destroy(this.gameObject);
        }
Beispiel #2
0
        public void OverwriteDownloadUrl(ThumbnailUrl loadThumbnailUrl)
        {
            if (string.IsNullOrEmpty(loadThumbnailUrl.Url))
            {
                return;
            }

            if (imageTex != null && currentTexturePath == loadThumbnailUrl.Url)
            {
                return;
            }

            var downloadThumbnailService = new DownloadThumbnailService(
                loadThumbnailUrl,
                tex =>
            {
                loadingImage = false;
                imageTex     = tex;
            });

            downloadThumbnailService.Run();
            loadingImage       = true;
            imageTex           = Texture2D.whiteTexture;
            currentTexturePath = loadThumbnailUrl.Url;
        }
Beispiel #3
0
        /// <summary>
        /// Rewrites the Thumbnail path and the Tour URL of the tour for the community payload.
        /// </summary>
        /// <param name="serviceUrl">Community service URL</param>
        /// <param name="applicationPath">Application where the service is hosted.</param>
        /// <remarks>
        /// Service URL represents the URL of the Community service whereas application path represents the WebSite or Virtual directory
        /// where the service and all its files are deployed.
        /// </remarks>
        internal void RewriteLocalUrls(string serviceUrl, string applicationPath)
        {
            UrlRewritten = true;

            // Special characters in these properties needs to be escaped so that XML serialization will work fine.
            Title            = SecurityElement.Escape(Title);
            Description      = SecurityElement.Escape(Description);
            Author           = SecurityElement.Escape(Author);
            OrganizationUrl  = SecurityElement.Escape(OrganizationUrl);
            OrganizationName = SecurityElement.Escape(OrganizationName);
            TourUrl          = SecurityElement.Escape(TourUrl);
            AuthorImageUrl   = SecurityElement.Escape(AuthorImageUrl);
            ThumbnailUrl     = SecurityElement.Escape(ThumbnailUrl);

            if (string.IsNullOrWhiteSpace(ThumbnailUrl))
            {
                ThumbnailUrl = applicationPath + Constants.DefaultTourThumbnail;
            }
            else if (!ThumbnailUrl.IsValidUrl())
            {
                ThumbnailUrl = string.Format(CultureInfo.InvariantCulture, Constants.FileServicePath, serviceUrl, ThumbnailUrl);
            }

            if (!string.IsNullOrWhiteSpace(TourUrl) && !TourUrl.IsValidUrl())
            {
                TourUrl = string.Format(CultureInfo.InvariantCulture, Constants.FileServicePath, serviceUrl, TourUrl);
            }
        }
        public void ThumbnailUrlInitsWithNoArgs()
        {
            var thumbnailUrl = new ThumbnailUrl();

            Assert.NotNull(thumbnailUrl);
            Assert.IsType <ThumbnailUrl>(thumbnailUrl);
        }
Beispiel #5
0
    /// <summary>
    /// サムネイルを更新する
    /// </summary>
    /// <returns></returns>
    public IEnumerator UpdateThumbnail(RawImage ImgThumbnail, string thumbnailUrl)
    {
        //登録されていない場合は、ダウンロード

        using (WWW www = new WWW(ThumbnailUrl.CreateListThumbnailUrl(thumbnailUrl)))
        {
            // 画像ダウンロード完了を待機
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                CreateEmpty();

                ImgThumbnail.texture = empty;
            }

            yield return(new WaitForSeconds(0.5f));

            try
            {
                ImgThumbnail.texture = www.texture;
            }
            catch
            {
                CreateEmpty();

                ImgThumbnail.texture = empty;
            }
        }

        yield return(new WaitForSeconds(0.1f));
    }
 public DownloadThumbnailService(
     ThumbnailUrl thumbnailUrl,
     Action <Texture2D> onSuccess = null,
     Action <Exception> onError   = null
     )
 {
     this.thumbnailUrl = thumbnailUrl;
     this.onSuccess    = onSuccess;
     this.onError      = onError;
 }
        public void ThumbnailUrlInits()
        {
            var url = "http://example.com";
            var alt = "example url";

            var thumbnailUrl = new ThumbnailUrl(url, alt);

            Assert.NotNull(thumbnailUrl);
            Assert.IsType <ThumbnailUrl>(thumbnailUrl);
            Assert.Equal(url, thumbnailUrl.Url);
            Assert.Equal(alt, thumbnailUrl.Alt);
        }
        public void AudioCardInit()
        {
            var title    = "title";
            var subtitle = "subtitle";
            var text     = "text";
            var image    = new ThumbnailUrl("https://example.com", "example image");
            var media    = new List <MediaUrl>()
            {
                new MediaUrl("http://exampleMedia.com", "profile")
            };
            var buttons = new List <CardAction>()
            {
                new CardAction("type", "title", "image", "text", "displayText", new { }, new { })
            };
            var shareable = true;
            var autoloop  = true;
            var autostart = true;
            var aspect    = "aspect";
            var value     = new { };
            var duration  = "duration";

            var audioCard = new AudioCard(
                title,
                subtitle,
                text,
                image,
                media,
                buttons,
                shareable,
                autoloop,
                autostart,
                aspect,
                value,
                duration);

            Assert.NotNull(audioCard);
            Assert.IsType <AudioCard>(audioCard);
            Assert.Equal(title, audioCard.Title);
            Assert.Equal(subtitle, audioCard.Subtitle);
            Assert.Equal(text, audioCard.Text);
            Assert.Equal(image, audioCard.Image);
            Assert.Equal(media, audioCard.Media);
            Assert.Equal(buttons, audioCard.Buttons);
            Assert.Equal(shareable, audioCard.Shareable);
            Assert.Equal(autoloop, audioCard.Autoloop);
            Assert.Equal(autostart, audioCard.Autostart);
            Assert.Equal(aspect, audioCard.Aspect);
            Assert.Equal(value, audioCard.Value);
            Assert.Equal(duration, audioCard.Duration);
        }
        public void SetImageUrl(ThumbnailUrl url)
        {
            if (string.IsNullOrEmpty(url.Url))
            {
                SetError();
                return;
            }

            var downloadThumbnailService = new DownloadThumbnailService(
                url, SetSuccess, exc => SetError());

            downloadThumbnailService.Run();
            reactiveOverlay.Val = "…";
        }
Beispiel #10
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Symbol != null ? Symbol.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ThumbnailUrl != null ? ThumbnailUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Archetype;
         hashCode = (hashCode * 397) ^ (int)Commitment;
         hashCode = (hashCode * 397) ^ (Language != null ? Language.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IsRecruiting.GetHashCode();
         hashCode = (hashCode * 397) ^ IsRolePlay.GetHashCode();
         hashCode = (hashCode * 397) ^ MemberCount.GetHashCode();
         return(hashCode);
     }
 }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (int)Type;
         hashCode = (hashCode * 397) ^ (Title != null ? Title.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ThumbnailUrl != null ? ThumbnailUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ThumbnailWidth;
         hashCode = (hashCode * 397) ^ ThumbnailHeight;
         hashCode = (hashCode * 397) ^ (Html != null ? Html.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Width;
         hashCode = (hashCode * 397) ^ Height;
         return(hashCode);
     }
 }
Beispiel #12
0
 public override int GetHashCode()
 {
     if (OriginalUrl != null)
     {
         return(OriginalUrl.GetHashCode());
     }
     if (LargeUrl != null)
     {
         return(LargeUrl.GetHashCode());
     }
     if (ThumbnailUrl != null)
     {
         return(ThumbnailUrl.GetHashCode());
     }
     return(base.GetHashCode());
 }
Beispiel #13
0
        /// <summary>
        /// 対象のニュースリストを回し
        /// </summary>
        /// <param name="NewsList"></param>
        /// <param name="NotExistsUrlList"></param>
        private void SetNotExistsUrlList(List <MsgBaseNewsData> NewsList, ref List <string> NotExistsUrlList)
        {
            List <MsgBaseNewsData> rvList = new List <MsgBaseNewsData>(NewsList);

            //rvList.Reverse();

            foreach (var news in rvList)
            {
                string thumbUrl = ThumbnailUrl.CreateListThumbnailUrl(news.THUMBNAIL_URL);

                if (!DicImage.ContainsKey(thumbUrl))
                {
                    NotExistsUrlList.Add(thumbUrl);
                }
            }
        }
Beispiel #14
0
        public void SetImageUrl(ThumbnailUrl url)
        {
            IsEmpty = string.IsNullOrEmpty(url.Url);
            if (IsEmpty)
            {
                reactiveImageTex.Val = Resources.Load <Texture2D>("require_image");
                reactiveOverlay.Val  = "";
                return;
            }

            var downloadThumbnailService = new DownloadThumbnailService(
                url, SetSuccess, exc => SetError());

            downloadThumbnailService.Run();

            reactiveOverlay.Val = "…";
        }
        public void SetImageUrl(ThumbnailUrl url)
        {
            IsEmpty = string.IsNullOrEmpty(url.Url);
            if (IsEmpty)
            {
                reactiveImageTex.Val = AssetDatabase.LoadAssetAtPath <Texture2D>("Packages/mu.cluster.cluster-creator-kit/Editor/Texture/require_image.png");
                reactiveOverlay.Val  = "";
                return;
            }

            var downloadThumbnailService = new DownloadThumbnailService(
                url, SetSuccess, exc => SetError());

            downloadThumbnailService.Run();

            reactiveOverlay.Val = "…";
        }
Beispiel #16
0
    /// <summary>
    /// サムネイルを更新する
    /// </summary>
    /// <returns></returns>
    public IEnumerator UpdateThumbnail()
    {
        if (panelList == null)
        {
            yield break;
        }

        foreach (TopicPanel panel in panelList)
        {
            //パネルロード要求フラグがONなら更新
            if (panel.FlgThumbnailLoadRequest)
            {
                //登録されていない場合は、ダウンロード

                using (WWW www = new WWW(ThumbnailUrl.CreateListThumbnailUrl(panel.news.THUMBNAIL_URL)))
                {
                    // 画像ダウンロード完了を待機
                    yield return(www);

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        //次回走査対象外とするため、空のスプライトを設定する。
                        panel.SetThumbnail(empty);

                        Debug.Log(www.error);
                    }

                    try
                    {
                        //スプライト設定
                        panel.SetThumbnail(Sprite.Create(www.texture, new Rect(0, 0, (int)www.texture.width, (int)www.texture.height), Vector2.zero));
                    }
                    catch (Exception ex)
                    {
                        //次回走査対象外とするため、空のスプライトを設定する。
                        panel.SetThumbnail(empty);

                        Debug.Log(ex);
                    }

                    yield return(new WaitForSeconds(0.1f));
                }
            }
        }
    }
        public void MediaCardInits()
        {
            var title    = "title";
            var subtitle = "subtitle";
            var text     = "I am a media card";
            var image    = new ThumbnailUrl("http://example.com", "media card image");
            var media    = new List <MediaUrl>()
            {
                new MediaUrl("http://anotherExample.com", "profile")
            };
            var buttons = new List <CardAction>()
            {
                new CardAction("action1"), new CardAction("action2")
            };
            var shareable = true;
            var autoloop  = true;
            var autostart = true;
            var aspect    = "4:3";
            var value     = new { };
            var duration  = "1000";

            var mediaCard = new MediaCard(title, subtitle, text, image, media, buttons, shareable, autoloop, autostart, aspect, value, duration);

            Assert.NotNull(mediaCard);
            Assert.IsType <MediaCard>(mediaCard);
            Assert.Equal(title, mediaCard.Title);
            Assert.Equal(subtitle, mediaCard.Subtitle);
            Assert.Equal(text, mediaCard.Text);
            Assert.Equal(image, mediaCard.Image);
            Assert.Equal(media, mediaCard.Media);
            Assert.Equal(buttons, mediaCard.Buttons);
            Assert.Equal(shareable, mediaCard.Shareable);
            Assert.Equal(autoloop, mediaCard.Autoloop);
            Assert.Equal(autostart, mediaCard.Autostart);
            Assert.Equal(aspect, mediaCard.Aspect);
            Assert.Equal(value, mediaCard.Value);
            Assert.Equal(duration, mediaCard.Duration);
        }
        public void VideoCardInits()
        {
            var title    = "title";
            var subtitle = "subtitle";
            var text     = "text";
            var image    = new ThumbnailUrl("http://example.com", "example image");
            var media    = new List <MediaUrl>()
            {
                new MediaUrl("http://example-media-url.com", "profile")
            };
            var buttons = new List <CardAction>()
            {
                new CardAction()
            };
            var shareable = true;
            var autoloop  = true;
            var autostart = true;
            var aspect    = "4:3";
            var value     = new { };
            var duration  = "1000";

            var videoCard = new VideoCard(title, subtitle, text, image, media, buttons, shareable, autoloop, autostart, aspect, value, duration);

            Assert.NotNull(videoCard);
            Assert.IsType <VideoCard>(videoCard);
            Assert.Equal(title, videoCard.Title);
            Assert.Equal(subtitle, videoCard.Subtitle);
            Assert.Equal(text, videoCard.Text);
            Assert.Equal(image, videoCard.Image);
            Assert.Equal(media, videoCard.Media);
            Assert.Equal(buttons, videoCard.Buttons);
            Assert.Equal(shareable, videoCard.Shareable);
            Assert.Equal(autoloop, videoCard.Autoloop);
            Assert.Equal(autostart, videoCard.Autostart);
            Assert.Equal(aspect, videoCard.Aspect);
            Assert.Equal(value, videoCard.Value);
            Assert.Equal(duration, videoCard.Duration);
        }
 /// <summary>
 /// URLを生成する
 /// </summary>
 /// <param name="ThumbnailData"></param>
 /// <returns></returns>
 private string CreateUrl(MsgThumbnailData ThumbnailData)
 {
     if (LiplisSetting.Instance.Setting.GraphicLevel == GRAPHIC_LEVEL.GraphicLevel_Low)
     {
         //ローレベル リストURL
         return(ThumbnailUrl.CreateListThumbnailUrl(ThumbnailData.thumbnailUrl));
     }
     else if (LiplisSetting.Instance.Setting.GraphicLevel == GRAPHIC_LEVEL.GraphicLevel_Middle)
     {
         //普通 スモールURL
         return(ThumbnailUrl.CreateThumbnailSmallUrl(ThumbnailData.thumbnailUrl));
     }
     else if (LiplisSetting.Instance.Setting.GraphicLevel == GRAPHIC_LEVEL.GraphicLevel_Heigh)
     {
         //高い 生データURL
         return(ThumbnailUrl.CreateThumbnailUrl(ThumbnailData.thumbnailUrl));
     }
     else
     {
         //それ以外はスモールURLリストURL
         return(ThumbnailUrl.CreateThumbnailSmallUrl(ThumbnailData.thumbnailUrl));
     }
 }
Beispiel #20
0
 => await(await User.GetOrCreateDMChannelAsync()).SendEmbedAsync(Description, Title, Footer, ImageUrl, ThumbnailUrl, Url);
Beispiel #21
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("Contact(");
        bool __first = true;

        if (Mid != null && __isset.mid)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Mid: ");
            Mid.ToString(sb);
        }
        if (__isset.createdTime)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CreatedTime: ");
            CreatedTime.ToString(sb);
        }
        if (__isset.type)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Type: ");
            Type.ToString(sb);
        }
        if (__isset.status)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Status: ");
            Status.ToString(sb);
        }
        if (__isset.relation)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Relation: ");
            Relation.ToString(sb);
        }
        if (DisplayName != null && __isset.displayName)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("DisplayName: ");
            DisplayName.ToString(sb);
        }
        if (PhoneticName != null && __isset.phoneticName)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PhoneticName: ");
            PhoneticName.ToString(sb);
        }
        if (PictureStatus != null && __isset.pictureStatus)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PictureStatus: ");
            PictureStatus.ToString(sb);
        }
        if (ThumbnailUrl != null && __isset.thumbnailUrl)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("ThumbnailUrl: ");
            ThumbnailUrl.ToString(sb);
        }
        if (StatusMessage != null && __isset.statusMessage)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("StatusMessage: ");
            StatusMessage.ToString(sb);
        }
        if (DisplayNameOverridden != null && __isset.displayNameOverridden)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("DisplayNameOverridden: ");
            DisplayNameOverridden.ToString(sb);
        }
        if (__isset.favoriteTime)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("FavoriteTime: ");
            FavoriteTime.ToString(sb);
        }
        if (__isset.capableVoiceCall)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CapableVoiceCall: ");
            CapableVoiceCall.ToString(sb);
        }
        if (__isset.capableVideoCall)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CapableVideoCall: ");
            CapableVideoCall.ToString(sb);
        }
        if (__isset.capableMyhome)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CapableMyhome: ");
            CapableMyhome.ToString(sb);
        }
        if (__isset.capableBuddy)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CapableBuddy: ");
            CapableBuddy.ToString(sb);
        }
        if (__isset.attributes)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Attributes: ");
            Attributes.ToString(sb);
        }
        if (__isset.settings)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Settings: ");
            Settings.ToString(sb);
        }
        if (PicturePath != null && __isset.picturePath)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PicturePath: ");
            PicturePath.ToString(sb);
        }
        if (RecommendParams != null && __isset.recommendParams)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("RecommendParams: ");
            RecommendParams.ToString(sb);
        }
        if (__isset.friendRequestStatus)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("FriendRequestStatus: ");
            FriendRequestStatus.ToString(sb);
        }
        if (MusicProfile != null && __isset.musicProfile)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("MusicProfile: ");
            MusicProfile.ToString(sb);
        }
        if (VideoProfile != null && __isset.videoProfile)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("VideoProfile: ");
            VideoProfile.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
Beispiel #22
0
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.mid)
            {
                hashcode = (hashcode * 397) + Mid.GetHashCode();
            }
            if (__isset.createdTime)
            {
                hashcode = (hashcode * 397) + CreatedTime.GetHashCode();
            }
            if (__isset.type)
            {
                hashcode = (hashcode * 397) + Type.GetHashCode();
            }
            if (__isset.status)
            {
                hashcode = (hashcode * 397) + Status.GetHashCode();
            }
            if (__isset.relation)
            {
                hashcode = (hashcode * 397) + Relation.GetHashCode();
            }
            if (__isset.displayName)
            {
                hashcode = (hashcode * 397) + DisplayName.GetHashCode();
            }
            if (__isset.phoneticName)
            {
                hashcode = (hashcode * 397) + PhoneticName.GetHashCode();
            }
            if (__isset.pictureStatus)
            {
                hashcode = (hashcode * 397) + PictureStatus.GetHashCode();
            }
            if (__isset.thumbnailUrl)
            {
                hashcode = (hashcode * 397) + ThumbnailUrl.GetHashCode();
            }
            if (__isset.statusMessage)
            {
                hashcode = (hashcode * 397) + StatusMessage.GetHashCode();
            }
            if (__isset.displayNameOverridden)
            {
                hashcode = (hashcode * 397) + DisplayNameOverridden.GetHashCode();
            }
            if (__isset.favoriteTime)
            {
                hashcode = (hashcode * 397) + FavoriteTime.GetHashCode();
            }
            if (__isset.capableVoiceCall)
            {
                hashcode = (hashcode * 397) + CapableVoiceCall.GetHashCode();
            }
            if (__isset.capableVideoCall)
            {
                hashcode = (hashcode * 397) + CapableVideoCall.GetHashCode();
            }
            if (__isset.capableMyhome)
            {
                hashcode = (hashcode * 397) + CapableMyhome.GetHashCode();
            }
            if (__isset.capableBuddy)
            {
                hashcode = (hashcode * 397) + CapableBuddy.GetHashCode();
            }
            if (__isset.attributes)
            {
                hashcode = (hashcode * 397) + Attributes.GetHashCode();
            }
            if (__isset.settings)
            {
                hashcode = (hashcode * 397) + Settings.GetHashCode();
            }
            if (__isset.picturePath)
            {
                hashcode = (hashcode * 397) + PicturePath.GetHashCode();
            }
            if (__isset.recommendParams)
            {
                hashcode = (hashcode * 397) + RecommendParams.GetHashCode();
            }
            if (__isset.friendRequestStatus)
            {
                hashcode = (hashcode * 397) + FriendRequestStatus.GetHashCode();
            }
            if (__isset.musicProfile)
            {
                hashcode = (hashcode * 397) + MusicProfile.GetHashCode();
            }
            if (__isset.videoProfile)
            {
                hashcode = (hashcode * 397) + VideoProfile.GetHashCode();
            }
        }
        return(hashcode);
    }
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as Activity;

            var rand = new Random();

            string[] defaultMessages = { "Estes são alguns resultados que encontrei:",
                                         "Aqui estão alguns dos principais resultados sobre isso:",
                                         "Eu gosto disso, fique à vontade para saber mais:" };
            var      reply = activity.CreateReply(defaultMessages[rand.Next(defaultMessages.Count())]);

            reply.Type             = ActivityTypes.Message;
            reply.TextFormat       = TextFormatTypes.Plain;
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments      = new List <Attachment>();

            var item = loginUser;

            if (item != null)
            {
                var client = new FacebookClient();
                client.AccessToken = item.AccessTokenFacebook.AccessToken;
                client.Version     = "v2.10";
                client.AppId       = ConfigurationManager.AppSettings["appIdFacebook"];
                client.AppSecret   = ConfigurationManager.AppSettings["appSecretFacebook"];

                dynamic retorno = null;

                //Verifica se foi solicitado algum interesse via pergunta
                if (activity.Text != null)
                {
                    //Envia dados para Application Insights Analytics
                    TelemetryClient telemetry  = new TelemetryClient();
                    var             properties = new Dictionary <string, string> {
                        { "Question", activity.Text }, { "Dialog", "Interesses" }
                    };
                    if (activity.From != null)
                    {
                        properties.Add("Name", activity.From.Name);
                        properties.Add("Channel", activity.ChannelId);
                        properties.Add("IdChatbot", activity.From.Id);
                    }
                    telemetry.TrackEvent("BotQuestion", properties);
                    //

                    string[] words = activity.Text.Split(' ');
                    if (words.Length > 1)
                    {
                        //Call API LUIS (Language Understanding Intelligent Service)
                        var responseLUIS = await Luis.GetResponse(activity);

                        //Trata resposta (DEVE SER CRIADO EM UM OUTRO MÉTODO)
                        if (responseLUIS != null)
                        {
                            var intent = responseLUIS.topScoringIntent;

                            if (!string.IsNullOrEmpty(intent.intent) && intent.intent.ToUpper() != "NONE" && intent.score >= 0.30) //30%
                            {
                                activity.Text = intent.intent;
                            }
                        }
                    }

                    switch (activity.Text.ToUpper())
                    {
                    /*case "Amigos":
                     *  reply.AttachmentLayout = AttachmentLayoutTypes.List;
                     *
                     *  retorno = client.Get("me/friends?fields=name");
                     *
                     *  List<CardElement> cardElements = new List<CardElement>();
                     *
                     *  foreach (var friend in retorno.data)
                     *  {
                     *      cardElements.Add(new TextBlock { Text = friend.name, Size = TextSize.Small });
                     *  }
                     *
                     *  AdaptiveCard adaptiveCard = new AdaptiveCard()
                     *  {
                     *      Body = cardElements
                     *  };
                     *
                     *  reply.Attachments.Add(new Attachment { ContentType = "application/vnd.microsoft.card.adaptive", Content = adaptiveCard });
                     *
                     *  break;*/
                    case "ATLETAS":
                    case "ATHLETES":
                        reply.AttachmentLayout = AttachmentLayoutTypes.List;

                        retorno = client.Get("me?fields=favorite_athletes");

                        if (retorno.Count > 1)
                        {
                            foreach (var athlete in retorno.favorite_athletes)
                            {
                                HeroCard plCard = new HeroCard()
                                {
                                    Title = athlete.name
                                };

                                Attachment attachment = plCard.ToAttachment();
                                reply.Attachments.Add(attachment);
                            }
                        }

                        break;

                    case "ESPORTES":
                    case "SPORTS":
                        reply.AttachmentLayout = AttachmentLayoutTypes.List;

                        retorno = client.Get("me?fields=sports");

                        if (retorno.Count > 1)
                        {
                            foreach (var sport in retorno.sports)
                            {
                                HeroCard plCard = new HeroCard()
                                {
                                    Title = sport.name
                                };

                                Attachment attachment = plCard.ToAttachment();
                                reply.Attachments.Add(attachment);
                            }
                        }

                        break;

                    case "EVENTOS":
                    case "EVENTS":
                        retorno = client.Get("me/events?fields=name,cover,id");

                        foreach (var evento in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                cardImages.Add(new CardImage(url: evento.cover.source));
                            }
                            catch (Exception ex) { }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = "https://www.facebook.com/events/" + evento.id,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            HeroCard plCard = new HeroCard()
                            {
                                Title   = evento.name,
                                Images  = cardImages,
                                Buttons = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "FILMES":
                    case "MOVIES":
                        //FILMES JÁ ASSISTIDOS:
                        //retorno = client.Get("me/video.watches?fields=data");
                        retorno = client.Get("me/movies?fields=name,genre,about,description,link,cover");

                        foreach (var movie in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                cardImages.Add(new CardImage(url: movie.cover.source));
                            }
                            catch (Exception ex) { }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = movie.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            HeroCard plCard = new HeroCard()
                            {
                                Title    = movie.name,
                                Subtitle = movie.genre,
                                Text     = !string.IsNullOrEmpty(movie.description) ? movie.description : movie.about,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "FOTOS":
                    case "PHOTOS":
                        retorno = client.Get("me/photos?fields=name,link,images");

                        foreach (var photo in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            cardImages.Add(new CardImage(url: photo.images[0].source));

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = photo.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            HeroCard plCard = new HeroCard()
                            {
                                Subtitle = photo.name,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);

                            //ADAPTIVECARD : http://adaptivecards.io/explorer/#ActionOpenUrl

                            /*List<CardElement> cardElements = new List<CardElement>();
                             * cardElements.Add(new Image { Url = photo.picture.data.url, Size = ImageSize.Large, HorizontalAlignment = HorizontalAlignment.Center });
                             * cardElements.Add(new TextBlock { Text = photo.name, Size = TextSize.Small });
                             *
                             * List<ActionBase> cardActions = new List<ActionBase>();
                             * cardActions.Add(new OpenUrlAction { Url = photo.link, Title = "Mais Informações" });
                             *
                             * AdaptiveCard adaptiveCard = new AdaptiveCard()
                             * {
                             *  Body = cardElements,
                             *  Actions = cardActions
                             * };
                             *
                             * Attachment attachment = new Attachment();
                             * attachment.ContentType = "application/vnd.microsoft.card.adaptive";
                             * attachment.Content = adaptiveCard;*/
                        }

                        break;

                    case "GOSTOS":
                    case "LIKES":
                        reply.AttachmentLayout = AttachmentLayoutTypes.List;

                        retorno = client.Get("me/likes?fields=name,about,picture");

                        foreach (var like in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                cardImages.Add(new CardImage(url: like.picture.data.url));
                            }
                            catch (Exception ex) { }

                            ThumbnailCard plCard = new ThumbnailCard()
                            {
                                Title    = like.name,
                                Subtitle = like.about,
                                Images   = cardImages
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "JOGOS":
                    case "GAMES":
                        retorno = client.Get("me/games?fields=name,link,picture,description,category");

                        foreach (var game in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                cardImages.Add(new CardImage(url: game.picture.data.url));
                            }
                            catch (Exception ex) { }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = game.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            ThumbnailCard plCard = new ThumbnailCard()
                            {
                                Title    = game.name,
                                Subtitle = game.category,
                                Text     = game.description,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "LIVROS":
                    case "BOOKS":
                        //LIVROS JÁ LIDOS:
                        //retorno = client.Get("me/books.reads?fields=data");
                        retorno = client.Get("me/books?fields=name,description,link,picture,about");

                        foreach (var book in retorno.data)
                        {
                            /*List<CardImage> cardImages = new List<CardImage>();
                             * cardImages.Add(new CardImage(url: book.picture.data.url));*/

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = book.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            HeroCard plCard = new HeroCard()
                            {
                                Title = book.name,
                                Text  = !string.IsNullOrEmpty(book.description) ? book.description : book.about,
                                //Images = cardImages,
                                Buttons = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "LUGARES":
                    case "PLACES":
                        retorno = client.Get("me/tagged_places?fields=name,place");

                        var apiKey = ConfigurationManager.AppSettings["BingMapsApiKey"];

                        List <Models.Location> locations = new List <Models.Location>();
                        foreach (var place in retorno.data)
                        {
                            if (place.place.location != null)
                            {
                                Models.Location location = new Models.Location();

                                Models.GeocodePoint geocodePoint = new Models.GeocodePoint();
                                geocodePoint.Coordinates = new List <double>();
                                geocodePoint.Coordinates.Add(place.place.location.latitude);     //latitude
                                geocodePoint.Coordinates.Add(place.place.location.longitude);    //longitude

                                location.Point = geocodePoint;
                                location.Name  = place.place.name;

                                try
                                {
                                    string endereco = "";
                                    if (!string.IsNullOrEmpty(place.place.location.street))
                                    {
                                        endereco = place.place.location.street;
                                    }

                                    if (!string.IsNullOrEmpty(place.place.location.city) && !string.IsNullOrEmpty(place.place.location.state))
                                    {
                                        if (string.IsNullOrEmpty(endereco))
                                        {
                                            endereco += place.place.location.city + "/" + place.place.location.state;
                                        }
                                        else
                                        {
                                            endereco += " - " + place.place.location.city + "/" + place.place.location.state;
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(place.place.location.country))
                                    {
                                        if (string.IsNullOrEmpty(endereco))
                                        {
                                            endereco += place.place.location.country;
                                        }
                                        else
                                        {
                                            endereco += " - " + place.place.location.country;
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(endereco))
                                    {
                                        location.Name += " (" + endereco + ")";
                                    }
                                }
                                catch (Exception ex) { }

                                locations.Add(location);
                            }
                        }

                        var cards = new List <HeroCard>();
                        int i     = 1;
                        foreach (var location in locations)
                        {
                            var heroCard = new HeroCard
                            {
                                Subtitle = location.Name
                            };

                            if (location.Point != null)
                            {
                                var image = new CardImage(
                                    url: new BingGeoSpatialService(apiKey).GetLocationMapImageUrl(location, i)
                                    );

                                heroCard.Images = new[] { image };

                                NumberFormatInfo nfi = new NumberFormatInfo();
                                nfi.NumberDecimalSeparator = ".";

                                var button = new CardAction(
                                    type: "openUrl",
                                    title: "Abrir no Google Maps",
                                    value: "https://maps.google.com/maps?ll=" + location.Point.Coordinates[0].ToString(nfi) + "," + location.Point.Coordinates[1].ToString(nfi)
                                    );

                                heroCard.Buttons = new[] { button };
                            }

                            cards.Add(heroCard);

                            i++;
                        }

                        foreach (var card in cards)
                        {
                            reply.Attachments.Add(card.ToAttachment());
                        }

                        break;

                    case "MÚSICAS":
                    case "MUSICAS":
                    case "MUSIC":
                        //MÚSICAS JÁ ESCUTADAS:
                        //retorno = client.Get("me/music.listens?fields=data");
                        retorno = client.Get("me/music?fields=name,about,link,picture,genre");

                        foreach (var music in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                cardImages.Add(new CardImage(url: music.picture.data.url));
                            }
                            catch (Exception ex) { }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = music.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            ThumbnailCard plCard = new ThumbnailCard()
                            {
                                Title    = music.name,
                                Subtitle = music.genre,
                                Text     = music.about,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "TELEVISÃO":
                    case "TELEVISAO":
                    case "TELEVISION":
                        //PROGRAMAS DE TV JÁ ASSISTIDOS:
                        //retorno = client.Get("me/video.watches?fields=data");
                        retorno = client.Get("me/television?fields=name,genre,description,link,cover,about");

                        foreach (var tv in retorno.data)
                        {
                            List <CardImage> cardImages = new List <CardImage>();
                            try
                            {
                                if (tv.cover.Count > 0)
                                {
                                    cardImages.Add(new CardImage(url: tv.cover.source));
                                }
                            }
                            catch (Exception ex) { }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = tv.link,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            HeroCard plCard = new HeroCard()
                            {
                                Title    = tv.name,
                                Subtitle = tv.genre,
                                Text     = !string.IsNullOrEmpty(tv.description) ? tv.description : tv.about,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;

                    case "TIMES":
                    case "TEAMS":
                        reply.AttachmentLayout = AttachmentLayoutTypes.List;

                        retorno = client.Get("me?fields=favorite_teams");

                        if (retorno.Count > 1)
                        {
                            foreach (var team in retorno.favorite_teams)
                            {
                                HeroCard plCard = new HeroCard()
                                {
                                    Title = team.name
                                };

                                Attachment attachment = plCard.ToAttachment();
                                reply.Attachments.Add(attachment);
                            }
                        }

                        break;

                    case "VÍDEOS":
                    case "VIDEOS":
                        retorno = client.Get("me/videos?fields=description,source,permalink_url,thumbnails");

                        foreach (var video in retorno.data)
                        {
                            ThumbnailUrl image = new ThumbnailUrl();
                            image.Url = video.thumbnails.data[0].uri;
                            foreach (var thumbnail in video.thumbnails.data)
                            {
                                if (thumbnail.is_preferred)
                                {
                                    image.Url = thumbnail.uri;
                                    break;
                                }
                            }

                            List <CardAction> cardButtons = new List <CardAction>();
                            cardButtons.Add(new CardAction()
                            {
                                Value = "https://www.facebook.com" + video.permalink_url,
                                Type  = "openUrl",
                                Title = "Mais Informações"
                            });

                            List <MediaUrl> mediaUrl = new List <MediaUrl>();
                            mediaUrl.Add(new MediaUrl(url: video.source));

                            VideoCard plCard = new VideoCard()
                            {
                                Title   = video.description,
                                Media   = mediaUrl,
                                Image   = image,
                                Buttons = cardButtons
                            };

                            Attachment attachment = plCard.ToAttachment();
                            reply.Attachments.Add(attachment);
                        }

                        break;
                    }
                }
            }

            if (reply.Attachments.Count == 0)
            {
                reply.Text = "Desculpe! Eu não encontrei nada sobre isso ou não estou capacitado para entender esse tipo de solicitação \U0001F61E";
            }

            await context.PostAsync(reply);

            context.Wait(this.MessageReceivedAsync);
        }
        //====================================================================
        //
        //                           イベントハンドラ
        //
        //====================================================================
        #region イベントハンドラ

        /// <summary>
        /// アイテム更新
        /// </summary>
        /// <returns></returns>
        private IEnumerator updateItem()
        {
            //インデックスチェック
            if (this.dataIndex == -1)
            {
                yield break;
            }

            //ニュースデータNULLチェック
            if (ScrollViewController.sc.NewsDataList == null)
            {
                yield break;
            }

            //ニュースデータカウントチェック
            if (ScrollViewController.sc.NewsDataList.Count - 1 < this.dataIndex)
            {
                yield break;
            }

            //ニュースデータ取得
            MsgBaseNewsData data = ScrollViewController.sc.NewsDataList[this.dataIndex];

            //コンペアチェック
            if (CompareData(data))
            {
                yield break;
            }

            //一個前のURL設定
            prvData = data;

            //タイトル表示
            this.title.text = data.TITLE;

            //サムネイルURL取得
            string thumbUrl = ThumbnailUrl.CreateListThumbnailUrl(data.THUMBNAIL_URL);

            //ファイルからサムネイル取得を試みる
            Texture2D texture = LiplisCache.Instance.ImagePath.GetWebTexutreFromFile(thumbUrl);

            //NULLならノーイメージ適用
            if (texture == null)
            {
                //優先要求リストに入れる
                LiplisCache.Instance.ImagePath.SetRequestUrlQPrioritize(thumbUrl);

                //ノーイメージテクスチャを返す
                texture = LiplisCache.Instance.ImagePath.GetNoImageTex();
            }

            //ボタンのテキスト変更
            if (texture != null)
            {
                try
                {
                    icon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                }
                catch
                {
                }
            }
            else
            {
                Debug.Log("テクスチャ未更新");
            }
        }
Beispiel #25
0
        //====================================================================
        //
        //                           更新処理
        //
        //====================================================================
        #region 更新処理

        /// <summary>
        /// アイテム更新
        /// </summary>
        /// <returns></returns>
        private IEnumerator updateItem()
        {
            if (this.dataIndex == -1)
            {
                yield break;
            }

            //ニュースデータNULLチェック
            if (ScrollViewControllerLog.sc.NewsDataList == null)
            {
                yield break;
            }

            //ニュースデータカウントチェック
            if (ScrollViewControllerLog.sc.NewsDataList.Count - 1 < this.dataIndex)
            {
                yield break;
            }

            //ニュースデータ取得
            MsgBaseNewsData data = ScrollViewControllerLog.sc.NewsDataList[this.dataIndex];

            //コンペアチェック
            if (CompareData(data))
            {
                yield break;
            }

            //一個前のURL設定
            prvData = data;

            //タイトル表示
            this.txtNews.text = data.TITLE;

            //サムネイルURL取得
            string thumbUrl = ThumbnailUrl.CreateListThumbnailUrl(data.THUMBNAIL_URL);

            //時刻表示
            this.txtTime.text = LpsDatetimeUtil.dec(data.CREATE_TIME).ToString("yyyy/MM/dd HH:mm:ss");

            //タイプ表示
            this.txtType.text = ContentCategolyText.GetContentText(data.DATA_TYPE);

            //ファイルからサムネイル取得を試みる
            Texture2D texture = LiplisCache.Instance.ImagePath.GetWebTexutreFromFile(thumbUrl);

            //NULLならノーイメージ適用
            if (texture == null)
            {
                texture = LiplisCache.Instance.ImagePath.GetNoImageTex();
            }

            //NULLならWebからダウンロードする
            if (texture == null)
            {
                //からテクスチャ取得
                texture = LiplisCache.Instance.ImagePath.GetNoImageTex();

                //設定
                icon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);

                //最新ニュースデータ取得
                var Async = LiplisCache.Instance.ImagePath.GetWebTexutre(thumbUrl);

                //非同期実行
                yield return(CoroutineHandler.StartStaticCoroutine(Async));

                //再度データを取り直す
                data = ScrollViewControllerLog.sc.NewsDataList[this.dataIndex];

                //データ取得
                texture = (Texture2D)Async.Current;
            }


            //ボタンのテキスト変更
            if (texture != null)
            {
                try
                {
                    icon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                }
                catch
                {
                }
            }
            else
            {
            }
        }
        public static Attachment GetAnimationCard(string title = null, string subtitle = null, string text = null, ThumbnailUrl animationUrl = null, List <MediaUrl> mediaUrl = null, bool autoLoop = false, bool autoStart = true)
        {
            var animationCard = new AnimationCard
            {
                Title     = title,
                Subtitle  = subtitle,
                Media     = mediaUrl,
                Autoloop  = autoLoop,
                Autostart = autoStart,
            };

            return(animationCard.ToAttachment());
        }
Beispiel #27
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("Profile(");
        bool __first = true;

        if (Mid != null && __isset.mid)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Mid: ");
            Mid.ToString(sb);
        }
        if (Userid != null && __isset.userid)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Userid: ");
            Userid.ToString(sb);
        }
        if (Phone != null && __isset.phone)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Phone: ");
            Phone.ToString(sb);
        }
        if (Email != null && __isset.email)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Email: ");
            Email.ToString(sb);
        }
        if (RegionCode != null && __isset.regionCode)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("RegionCode: ");
            RegionCode.ToString(sb);
        }
        if (DisplayName != null && __isset.displayName)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("DisplayName: ");
            DisplayName.ToString(sb);
        }
        if (PhoneticName != null && __isset.phoneticName)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PhoneticName: ");
            PhoneticName.ToString(sb);
        }
        if (PictureStatus != null && __isset.pictureStatus)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PictureStatus: ");
            PictureStatus.ToString(sb);
        }
        if (ThumbnailUrl != null && __isset.thumbnailUrl)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("ThumbnailUrl: ");
            ThumbnailUrl.ToString(sb);
        }
        if (StatusMessage != null && __isset.statusMessage)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("StatusMessage: ");
            StatusMessage.ToString(sb);
        }
        if (__isset.allowSearchByUserid)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("AllowSearchByUserid: ");
            AllowSearchByUserid.ToString(sb);
        }
        if (__isset.allowSearchByEmail)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("AllowSearchByEmail: ");
            AllowSearchByEmail.ToString(sb);
        }
        if (PicturePath != null && __isset.picturePath)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("PicturePath: ");
            PicturePath.ToString(sb);
        }
        if (MusicProfile != null && __isset.musicProfile)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("MusicProfile: ");
            MusicProfile.ToString(sb);
        }
        if (VideoProfile != null && __isset.videoProfile)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("VideoProfile: ");
            VideoProfile.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        ///
        //ThreadTest test = new ThreadTest();
        //delegate void del_thread(string str);

        //public static void new_thread(string name)
        //{
        //    Thread cur_thread = Thread.CurrentThread;
        //    Debug.WriteLine("Current {0} Thread = {1}", name, cur_thread.ManagedThreadId);
        //}

        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            //Thread workerThread = Thread.CurrentThread;
            //Worker workerObject = new Worker();
            //Thread workerThread = new Thread(workerObject.DoWork);

            // welcome message 출력
            if (activity.Type == ActivityTypes.ConversationUpdate && activity.MembersAdded.Any(m => m.Id == activity.Recipient.Id))
            {
                WeatherInfo weatherInfo = await GetWeatherInfo();

                //weatherInfo.list[0].weather[0].description
                Debug.WriteLine("weatherInfo :  " + weatherInfo.list[0].weather[0].description);
                Debug.WriteLine("weatherInfo : " + string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.min, 1)));
                Debug.WriteLine("weatherInfo : " + string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.max, 1)));

                DateTime startTime = DateTime.Now;
                //ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                //Activity reply = activity.CreateReply("");

                //reply.Recipient = activity.From;
                //reply.Type = "message";
                //reply.Attachments = new List<Attachment>();
                //reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                // Db
                DbConnect     db  = new DbConnect();
                List <Dialog> dlg = db.SelectDialog(3);
                Debug.WriteLine("!!!!!!!!!!! : " + dlg[0].dlgId);



                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));


                Activity reply2 = activity.CreateReply();
                reply2.Recipient        = activity.From;
                reply2.Type             = "message";
                reply2.Attachments      = new List <Attachment>();
                reply2.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                //reply.Recipient = activity.From;
                //reply.Type = "message";
                //reply.Attachments = new List<Attachment>();
                //reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;


                List <Card> card = db.SelectDialogCard(dlg[0].dlgId);

                VideoCard[]   plVideoCard   = new VideoCard[card.Count];
                HeroCard[]    plHeroCard    = new HeroCard[card.Count];
                ReceiptCard[] plReceiptCard = new ReceiptCard[card.Count];

                Attachment[] plAttachment = new Attachment[card.Count];


                for (int i = 0; i < card.Count; i++)
                {
                    List <Button> btn   = db.SelectBtn(card[i].dlgId, card[i].cardId);
                    List <Image>  img   = db.SelectImage(card[i].dlgId, card[i].cardId);
                    List <Media>  media = db.SelectMedia(card[i].dlgId, card[i].cardId);

                    List <CardAction> cardButtons = new List <CardAction>();
                    CardAction[]      plButton    = new CardAction[btn.Count];

                    ThumbnailUrl plThumnail = new ThumbnailUrl();

                    List <MediaUrl> mediaURL   = new List <MediaUrl>();
                    MediaUrl[]      plMediaUrl = new MediaUrl[media.Count];

                    for (int n = 0; n < img.Count; n++)
                    {
                        if (img[n].imgUrl != null)
                        {
                            plThumnail.Url = img[n].imgUrl;
                        }
                    }

                    for (int l = 0; l < media.Count; l++)
                    {
                        if (media[l].mediaUrl != null)
                        {
                            plMediaUrl[l] = new MediaUrl()
                            {
                                Url = media[l].mediaUrl
                            };
                        }
                    }
                    mediaURL = new List <MediaUrl>(plMediaUrl);

                    for (int m = 0; m < btn.Count; m++)
                    {
                        if (btn[m].btnTitle != null)
                        {
                            plButton[m] = new CardAction()
                            {
                                Value = btn[m].btnContext,
                                Type  = btn[m].btnType,
                                Title = btn[m].btnTitle
                            };
                        }
                    }
                    cardButtons = new List <CardAction>(plButton);

                    if (card[i].cardType == "videocard")
                    {
                        plVideoCard[i] = new VideoCard()
                        {
                            Title     = "**" + card[i].cardTitle + "**",
                            Text      = card[i].cardText,
                            Subtitle  = card[i].cardSubTitle,
                            Media     = mediaURL,
                            Image     = plThumnail,
                            Buttons   = cardButtons,
                            Autostart = true
                        };

                        plAttachment[i] = plVideoCard[i].ToAttachment();
                        reply2.Attachments.Add(plAttachment[i]);
                    }
                }
                var reply1 = await connector.Conversations.SendToConversationAsync(reply2);

                Debug.WriteLine("activity : " + activity.Id);
                Debug.WriteLine("activity : " + activity.ChannelId);
                Debug.WriteLine("activity : " + activity.Conversation.Id);
                Debug.WriteLine("activity : " + activity.Properties);
                Debug.WriteLine("activity : " + activity.Recipient);
                Debug.WriteLine("activity : " + activity.From.Id);
                Debug.WriteLine("activity : " + activity.Recipient.Id);
                Debug.WriteLine("end activity.Timestamp : " + activity.Timestamp);

                DateTime endTime = DateTime.Now;
                Debug.WriteLine("프로그램 수행시간 : {0}/ms", ((endTime - startTime).Milliseconds));
                //GetWeatherInfo();

                Activity reply = activity.CreateReply();
                for (int n = 0; n < dlg[0].dlgMent.Split(new string[] { "@@" }, StringSplitOptions.None).Length; n++)//new string[] {"@@"},StringSplitOptions.None
                {
                    reply = activity.CreateReply(dlg[0].dlgMent.Split(new string[] { "@@" }, StringSplitOptions.None)[n]);
                    await connector.Conversations.SendToConversationAsync(reply);
                }
                Activity testReply = activity.CreateReply("**가나다라마바사**  `jumped`");
                await connector.Conversations.SendToConversationAsync(testReply);



                Activity replyToConversation = activity.CreateReply("Should go to conversation, in carousel format");
                replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                //replyToConversation.AttachmentLayout = "test";
                replyToConversation.Attachments = new List <Attachment>();

                Dictionary <string, string> cardContentList = new Dictionary <string, string>();
                cardContentList.Add("PigLatin", "http://webbot02.azurewebsites.net/hyundai/images/price/Grandeur_24spec.PNG");
                cardContentList.Add("Pork Shoulder", "http://webbot02.azurewebsites.net/hyundai/images/price/Grandeur_24spec.PNG");
                cardContentList.Add("Bacon", "http://webbot02.azurewebsites.net/hyundai/images/price/Grandeur_24spec.PNG");

                foreach (KeyValuePair <string, string> cardContent in cardContentList)
                {
                    List <CardImage> cardImages = new List <CardImage>();
                    cardImages.Add(new CardImage(url: cardContent.Value));

                    List <CardAction> cardButtons = new List <CardAction>();

                    CardAction plButton = new CardAction()
                    {
                        Value = $"https://en.wikipedia.org/wiki/{cardContent.Key}",
                        Type  = "openUrl",
                        Title = "WikiPedia Page"
                    };

                    cardButtons.Add(plButton);

                    NewHeroCard plCard = new NewHeroCard()
                    {
                        Title    = $"I'm a hero card about {cardContent.Key}",
                        Subtitle = $"{cardContent.Key} Wikipedia Page",
                        Images   = cardImages,
                        Buttons  = cardButtons,
                        Kind     = "test"
                    };

                    Attachment attachment = plCard.ToAttachment();
                    replyToConversation.Attachments.Add(attachment);
                }

                await connector.Conversations.SendToConversationAsync(replyToConversation);
            }
            else if (activity.Type == ActivityTypes.Message)
            {
                //test.resume();

                //Thread.Sleep(3000);
                //test.pause();

                //Thread.Sleep(3000);


                //if (workerThread.IsAlive)
                //{

                //    workerObject.RequestStop();
                //    workerThread.Join();
                //    Debug.WriteLine("main thread: Worker thread has terminated.");
                //}

                DateTime startTime = DateTime.Now;

                long unixTime = ((DateTimeOffset)startTime).ToUnixTimeSeconds();
                Debug.WriteLine("startTime : " + startTime);
                Debug.WriteLine("startTime Millisecond : " + unixTime);

                Debug.WriteLine("Debuging : " + activity.Text);
                LUIS Luis = await GetIntentFromLUIS(activity.Text);

                Debug.WriteLine("Debuging :  " + Luis.intents[0].intent);
                Debug.WriteLine("Debuging : " + Luis.entities[0].entity);
                Debug.WriteLine("Debuging : " + Luis.entities[0].type);
                String entitiesStr = "";

                for (int i = 0; i < Luis.entities.Count(); i++)
                {
                    Debug.WriteLine("Split : " + Regex.Split(Luis.entities[i].type, "::")[1]);
                    entitiesStr += Regex.Split(Luis.entities[i].type, "::")[1] + ",";
                }

                entitiesStr = entitiesStr.Substring(0, entitiesStr.Length - 1);

                Debug.WriteLine("entitiesStr : " + entitiesStr);

                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                // Db
                DbConnect   db           = new DbConnect();
                List <Luis> LuisDialogID = db.SelectLuis(Luis.intents[0].intent, entitiesStr);

                List <Dialog> dlg = db.SelectDialog(LuisDialogID[0].dlgId);

                if (dlg.Count > 0)
                {
                    if (dlg[0].dlgMent != null)
                    {
                        // return our reply to the user
                        Activity reply = activity.CreateReply(dlg[0].dlgMent);
                        await connector.Conversations.ReplyToActivityAsync(reply);
                    }
                }

                List <Card> card = db.SelectDialogCard(LuisDialogID[0].dlgId);

                if (card.Count > 0)
                {
                    // HeroCard
                    Activity replyToConversation = activity.CreateReply("");

                    Debug.WriteLine("activity : " + activity.Id);
                    Debug.WriteLine("activity : " + activity.Properties);
                    Debug.WriteLine("activity : " + activity.Recipient);
                    Debug.WriteLine("activity : " + activity.Summary);
                    Debug.WriteLine("activity : " + activity.ReplyToId);
                    Debug.WriteLine("activity : " + activity.Recipient.Id);
                    Debug.WriteLine("activity : " + activity.Conversation.Id);

                    replyToConversation.Recipient        = activity.From;
                    replyToConversation.Type             = "message";
                    replyToConversation.Attachments      = new List <Attachment>();
                    replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                    for (int i = 0; i < card.Count; i++)
                    {
                        List <Button> btn   = db.SelectBtn(card[i].dlgId, card[i].cardId);
                        List <Image>  img   = db.SelectImage(card[i].dlgId, card[i].cardId);
                        List <Media>  media = db.SelectMedia(card[i].dlgId, card[i].cardId);

                        List <CardImage> cardImages = new List <CardImage>();
                        CardImage[]      plImage    = new CardImage[img.Count];

                        ThumbnailUrl plThumnail = new ThumbnailUrl();

                        List <CardAction> cardButtons = new List <CardAction>();
                        CardAction[]      plButton    = new CardAction[btn.Count];

                        List <MediaUrl> mediaURL   = new List <MediaUrl>();
                        MediaUrl[]      plMediaUrl = new MediaUrl[media.Count];

                        ReceiptCard[] plReceiptCard = new ReceiptCard[card.Count];
                        HeroCard[]    plHeroCard    = new HeroCard[card.Count];
                        VideoCard[]   plVideoCard   = new VideoCard[card.Count];
                        Attachment[]  plAttachment  = new Attachment[card.Count];



                        for (int l = 0; l < img.Count; l++)
                        {
                            if (card[i].cardType == "herocard")
                            {
                                if (img[l].imgUrl != null)
                                {
                                    plImage[l] = new CardImage()
                                    {
                                        Url = img[l].imgUrl
                                    };
                                }
                            }
                            else if (card[i].cardType == "videocard")
                            {
                                if (img[l].imgUrl != null)
                                {
                                    plThumnail.Url = img[l].imgUrl;
                                }
                            }
                        }
                        cardImages = new List <CardImage>(plImage);

                        for (int l = 0; l < media.Count; l++)
                        {
                            if (media[l].mediaUrl != null)
                            {
                                plMediaUrl[l] = new MediaUrl()
                                {
                                    Url = media[l].mediaUrl
                                };
                            }
                        }
                        mediaURL = new List <MediaUrl>(plMediaUrl);

                        for (int m = 0; m < btn.Count; m++)
                        {
                            if (btn[m].btnTitle != null)
                            {
                                plButton[m] = new CardAction()
                                {
                                    Value = btn[m].btnContext,
                                    Type  = btn[m].btnType,
                                    Title = btn[m].btnTitle
                                };
                            }
                        }
                        cardButtons = new List <CardAction>(plButton);


                        if (card[i].cardType == "herocard")
                        {
                            plHeroCard[i] = new HeroCard()
                            {
                                Title    = card[i].cardTitle,
                                Text     = card[i].cardText,
                                Subtitle = card[i].cardSubTitle,
                                Images   = cardImages,
                                Buttons  = cardButtons
                            };

                            plAttachment[i] = plHeroCard[i].ToAttachment();
                            replyToConversation.Attachments.Add(plAttachment[i]);
                        }
                        else if (card[i].cardType == "videocard")
                        {
                            plVideoCard[i] = new VideoCard()
                            {
                                Title     = card[i].cardTitle,
                                Text      = card[i].cardText,
                                Subtitle  = card[i].cardSubTitle,
                                Image     = plThumnail,
                                Media     = mediaURL,
                                Buttons   = cardButtons,
                                Autostart = true
                            };

                            plAttachment[i] = plVideoCard[i].ToAttachment();
                            replyToConversation.Attachments.Add(plAttachment[i]);
                        }
                    }
                    var reply1 = await connector.Conversations.SendToConversationAsync(replyToConversation);
                }

                DateTime endTime = DateTime.Now;
                Debug.WriteLine("프로그램 수행시간 : {0}/ms", ((endTime - startTime).Milliseconds));

                //Debug.WriteLine("current main thread = {0}",workerThread.ManagedThreadId);

                //del_thread new_th = new del_thread(new_thread);

                //new_th.BeginInvoke("TEST", null, null);
                //Thread.Sleep(3000);

                //// Start the worker thread.
                //workerThread.Start();
                //Debug.WriteLine("ID : "+ workerThread.ManagedThreadId);
                //Debug.WriteLine("main thread: Starting worker thread...");

                //// Loop until worker thread activates.
                //while (!workerThread.IsAlive) ;

                //Thread.Sleep(5);
                //test.resume();

                //Thread.Sleep(30000);
            }
            else
            {
                HandleSystemMessage(activity);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Beispiel #29
0
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.mid)
            {
                hashcode = (hashcode * 397) + Mid.GetHashCode();
            }
            if (__isset.userid)
            {
                hashcode = (hashcode * 397) + Userid.GetHashCode();
            }
            if (__isset.phone)
            {
                hashcode = (hashcode * 397) + Phone.GetHashCode();
            }
            if (__isset.email)
            {
                hashcode = (hashcode * 397) + Email.GetHashCode();
            }
            if (__isset.regionCode)
            {
                hashcode = (hashcode * 397) + RegionCode.GetHashCode();
            }
            if (__isset.displayName)
            {
                hashcode = (hashcode * 397) + DisplayName.GetHashCode();
            }
            if (__isset.phoneticName)
            {
                hashcode = (hashcode * 397) + PhoneticName.GetHashCode();
            }
            if (__isset.pictureStatus)
            {
                hashcode = (hashcode * 397) + PictureStatus.GetHashCode();
            }
            if (__isset.thumbnailUrl)
            {
                hashcode = (hashcode * 397) + ThumbnailUrl.GetHashCode();
            }
            if (__isset.statusMessage)
            {
                hashcode = (hashcode * 397) + StatusMessage.GetHashCode();
            }
            if (__isset.allowSearchByUserid)
            {
                hashcode = (hashcode * 397) + AllowSearchByUserid.GetHashCode();
            }
            if (__isset.allowSearchByEmail)
            {
                hashcode = (hashcode * 397) + AllowSearchByEmail.GetHashCode();
            }
            if (__isset.picturePath)
            {
                hashcode = (hashcode * 397) + PicturePath.GetHashCode();
            }
            if (__isset.musicProfile)
            {
                hashcode = (hashcode * 397) + MusicProfile.GetHashCode();
            }
            if (__isset.videoProfile)
            {
                hashcode = (hashcode * 397) + VideoProfile.GetHashCode();
            }
        }
        return(hashcode);
    }