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);
            }
        }
Example #2
0
        public async Task AddUserInfo(int userId, UserInfoDTO userInfo)
        {
            IMediaService media = new MediaService();

            var currentUrl = MediaPath.GetFolderPath(_unitOfWork.Users.Get(userId).Info.PhotoUrl);

            if (userInfo.Photo != null)
            {
                var url = await media.SavePersonImage(userInfo.Photo, userId, currentUrl);

                _unitOfWork.Users.Get(userId).Info.PhotoUrl = url;
            }
            else
            {
                //if (currentUrl != null)
                //{
                //    File.Delete(currentUrl);
                //}
            }
            //_unitOfWork.Users.Get(userId).Info.PhotoUrl = url;
            _unitOfWork.Users.Get(userId).Info.Address = userInfo.Address;
            _unitOfWork.Users.Get(userId).Info.About   = userInfo.About;
            _unitOfWork.Users.Get(userId).Info.SexId   = userInfo.Sex;
            _unitOfWork.Complete();
        }
        public async Task AddMessage(int senderId, MessageInputDTO messageInput)
        {
            if (string.IsNullOrWhiteSpace(messageInput.Message) && messageInput.Media == null)
            {
                throw new MessageAndMediaEmptyException("epty message data");
            }
            _unitOfWork.Messages.Add(new Message
            {
                SenderId   = senderId,
                ReceiverId = messageInput.ReceiverId,
                Text       = messageInput.Message,
                DateTime   = System.DateTime.Now,
                IsRead     = false,
            });
            _unitOfWork.Complete();
            if (messageInput.Media != null)
            {
                var message = _unitOfWork.Messages.Find(m => m.SenderId == senderId && m.ReceiverId == messageInput.ReceiverId)
                              .Last();
                Console.WriteLine("===================================================");
                Console.WriteLine(messageInput.Media.FileName);
                message.MediaName     = MediaPath.GetFileName(messageInput.Media.FileName);
                message.AttachmentUrl = await AddMedia(messageInput.Media, message.MessageId);


                _unitOfWork.Messages.Update(message);
                _unitOfWork.Complete();
            }
        }
        private void OnInspectorGUI_Subtitles()
        {
            // TODO: add support for multiple targets?
            MediaPlayer media = (this.target) as MediaPlayer;

            //EditorGUILayout.BeginVertical();
            EditorGUILayout.PropertyField(_propSubtitles, new GUIContent("Sideload Subtitles"));

            EditorGUI.BeginDisabledGroup(!_propSubtitles.boolValue);

            EditorGUILayout.BeginVertical(GUI.skin.box);

            EditorGUILayout.PropertyField(_propSubtitlePath);

            //if (!Application.isPlaying)
            {
                GUI.color = Color.white;
                GUILayout.BeginHorizontal();

                if (Application.isPlaying)
                {
                    if (GUILayout.Button("Load"))
                    {
                        MediaPath mediaPath = new MediaPath(_propSubtitlePath.FindPropertyRelative("_path").stringValue, (MediaPathType)_propSubtitlePath.FindPropertyRelative("_pathType").enumValueIndex);
                        media.EnableSubtitles(mediaPath);
                    }
                    if (GUILayout.Button("Clear"))
                    {
                        media.DisableSubtitles();
                    }
                }
                else
                {
                    GUILayout.FlexibleSpace();
                }

                MediaPathDrawer.ShowBrowseSubtitlesButtonIcon(_propSubtitlePath);

                GUILayout.EndHorizontal();
                if (_propSubtitles.boolValue)
                {
                    ///MediaPath mediaPath = new MediaPath(_propSubtitlePath.FindPropertyRelative("_path").stringValue, (MediaPathType)_propSubtitlePath.FindPropertyRelative("_pathType").enumValueIndex);
                    //ShowFileWarningMessages(mediaPath, media.AutoOpen, Platform.Unknown);
                    //GUI.color = Color.white;
                }
            }

            //EditorGUILayout.EndVertical();

            EditorGUILayout.EndVertical();
            EditorGUI.EndDisabledGroup();
        }
        internal static bool OpenMediaFileDialog(string startPath, ref MediaPath mediaPath, ref string fullPath, string extensions)
        {
            bool result = false;

            string path = UnityEditor.EditorUtility.OpenFilePanel("Browse Media File", startPath, extensions);

            if (!string.IsNullOrEmpty(path) && !path.EndsWith(".meta"))
            {
                mediaPath = GetMediaPathFromFullPath(path);
                result    = true;
            }

            return(result);
        }
Example #6
0
        internal static void ShowFileWarningMessages(string filePath, MediaPathType fileLocation, MediaReference mediaReference, MediaSource mediaSource, bool isAutoOpen, Platform platform)
        {
            MediaPath mediaPath = null;

            if (mediaSource == MediaSource.Path)
            {
                mediaPath = new MediaPath(filePath, fileLocation);
            }
            else if (mediaSource == MediaSource.Reference)
            {
                if (mediaReference != null)
                {
                    mediaPath = mediaReference.GetCurrentPlatformMediaReference().MediaPath;
                }
            }

            ShowFileWarningMessages(mediaPath, isAutoOpen, platform);
        }
Example #7
0
        internal static void ShowFileWarningMessages(MediaSource mediaSource, MediaPath mediaPath, MediaReference mediaReference, bool isAutoOpen, Platform platform)
        {
            MediaPath result = null;

            if (mediaSource == MediaSource.Path)
            {
                if (mediaPath != null)
                {
                    result = mediaPath;
                }
            }
            else if (mediaSource == MediaSource.Reference)
            {
                if (mediaReference != null)
                {
                    result = mediaReference.GetCurrentPlatformMediaReference().MediaPath;
                }
            }

            ShowFileWarningMessages(result, isAutoOpen, platform);
        }
Example #8
0
        private void Callback_Browse(object obj)
        {
            BrowseData         data             = (BrowseData)obj;
            SerializedProperty propFilePath     = data.propPath.FindPropertyRelative("_path");
            SerializedProperty propFilePathType = data.propPath.FindPropertyRelative("_pathType");
            string             startFolder      = EditorHelper.GetBrowsableFolder(propFilePath.stringValue, (MediaPathType)propFilePathType.enumValueIndex);
            string             videoPath        = propFilePath.stringValue;
            string             fullPath         = string.Empty;
            MediaPath          mediaPath        = new MediaPath();

            if (EditorHelper.OpenMediaFileDialog(startFolder, ref mediaPath, ref fullPath, data.extensions))
            {
                // Assign to properties
                propFilePath.stringValue        = mediaPath.Path.Replace("\\", "/");
                propFilePathType.enumValueIndex = (int)mediaPath.PathType;
                if (data.propMediaSource != null)
                {
                    data.propMediaSource.enumValueIndex = (int)MediaSource.Path;
                }

                // Mark as modified
                data.propPath.serializedObject.ApplyModifiedProperties();
                foreach (Object o in data.propPath.serializedObject.targetObjects)
                {
                    EditorUtility.SetDirty(o);
                }

                if (data.autoLoadMedia)
                {
                    MediaPlayer mediaPlayer = (MediaPlayer)data.propPath.serializedObject.targetObject;
                    if (mediaPlayer != null)
                    {
                        mediaPlayer.OpenMedia(mediaPlayer.MediaPath, autoPlay: true);
                    }
                }

                RecentItems.Add(fullPath);
            }
        }
        internal static MediaPath GetMediaPathFromFullPath(string fullPath)
        {
            MediaPath result      = null;
            string    projectRoot = System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, ".."));

            projectRoot = projectRoot.Replace('\\', '/');

            if (fullPath.StartsWith(projectRoot))
            {
                if (fullPath.StartsWith(Application.streamingAssetsPath))
                {
                    // Must be StreamingAssets relative path
                    result = new MediaPath(GetPathRelativeTo(Application.streamingAssetsPath, fullPath), MediaPathType.RelativeToStreamingAssetsFolder);
                }
                else if (fullPath.StartsWith(Application.dataPath))
                {
                    // Must be Assets relative path
                    result = new MediaPath(GetPathRelativeTo(Application.dataPath, fullPath), MediaPathType.RelativeToDataFolder);
                }
                else
                {
                    // Must be project relative path
                    result = new MediaPath(GetPathRelativeTo(projectRoot, fullPath), MediaPathType.RelativeToProjectFolder);
                }
            }
            else
            {
                // Must be persistant data
                if (fullPath.StartsWith(Application.persistentDataPath))
                {
                    result = new MediaPath(GetPathRelativeTo(Application.persistentDataPath, fullPath), MediaPathType.RelativeToPersistentDataFolder);
                }

                // Must be absolute path
                result = new MediaPath(fullPath, MediaPathType.AbsolutePathOrURL);
            }
            return(result);
        }
Example #10
0
        private void Callback_Select(object obj)
        {
            RecentMenuItemData data = (RecentMenuItemData)obj;

            // Move it to the top of the list
            RecentItems.Add(data.path);

            // Resolve to relative path
            MediaPath mediaPath = EditorHelper.GetMediaPathFromFullPath(data.path);

            SerializedProperty propMediaPath     = data.propPath.FindPropertyRelative("_path");
            SerializedProperty propMediaPathType = data.propPath.FindPropertyRelative("_pathType");

            // Assign to properties
            propMediaPath.stringValue        = mediaPath.Path.Replace("\\", "/");
            propMediaPathType.enumValueIndex = (int)mediaPath.PathType;
            if (data.propMediaSource != null)
            {
                data.propMediaSource.enumValueIndex = (int)MediaSource.Path;
            }

            // Mark as modified
            data.propPath.serializedObject.ApplyModifiedProperties();
            foreach (Object o in data.propPath.serializedObject.targetObjects)
            {
                EditorUtility.SetDirty(o);
            }

            if (data.autoLoadMedia)
            {
                MediaPlayer mediaPlayer = (MediaPlayer)data.propPath.serializedObject.targetObject;
                if (mediaPlayer != null)
                {
                    mediaPlayer.OpenMedia(mediaPlayer.MediaPath, autoPlay: true);
                }
            }
        }
Example #11
0
 public void Insert <T>(T obj, MediaPath hest)
 {
 }
Example #12
0
        internal static void ShowFileWarningMessages(MediaPath mediaPath, bool isAutoOpen, Platform platform)
        {
            string fullPath = string.Empty;

            if (mediaPath != null)
            {
                fullPath = mediaPath.GetResolvedFullPath();
            }
            if (string.IsNullOrEmpty(fullPath))
            {
                if (isAutoOpen)
                {
                    EditorHelper.IMGUI.NoticeBox(MessageType.Error, "No media specified");
                }
                else
                {
                    EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "No media specified");
                }
            }
            else
            {
                bool isPlatformAndroid = (platform == Platform.Android) || (platform == Platform.Unknown && BuildTargetGroup.Android == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);
                bool isPlatformIOS     = (platform == Platform.iOS);
                isPlatformIOS |= (platform == Platform.Unknown && BuildTargetGroup.iOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);
                bool isPlatformTVOS = (platform == Platform.tvOS);

                isPlatformTVOS |= (platform == Platform.Unknown && BuildTargetGroup.tvOS == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup);

                // Test file extensions
                {
                    bool isExtensionAVI = fullPath.ToLower().EndsWith(".avi");
                    bool isExtensionMOV = fullPath.ToLower().EndsWith(".mov");
                    bool isExtensionMKV = fullPath.ToLower().EndsWith(".mkv");

                    if (isPlatformAndroid && isExtensionMOV)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "MOV file detected. Android doesn't support MOV files, you should change the container file.");
                    }
                    if (isPlatformAndroid && isExtensionAVI)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "AVI file detected. Android doesn't support AVI files, you should change the container file.");
                    }
                    if (isPlatformAndroid && isExtensionMKV)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "MKV file detected. Android doesn't support MKV files until Android 5.0.");
                    }
                    if (isPlatformIOS && isExtensionAVI)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "AVI file detected. iOS doesn't support AVI files, you should change the container file.");
                    }
                }

                if (fullPath.Contains("://"))
                {
                    if (fullPath.ToLower().Contains("rtmp://"))
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "RTMP protocol is not supported by AVPro Video, except when Windows DirectShow is used with an external codec library (eg LAV Filters)");
                    }
                    if (fullPath.ToLower().Contains("youtube.com/watch"))
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "YouTube URL detected. YouTube website URL contains no media, a direct media file URL (eg MP4 or M3U8) is required.  See the documentation FAQ for YouTube support.");
                    }
                    if (mediaPath.PathType != MediaPathType.AbsolutePathOrURL)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "URL detected, change location type to URL?");
                    }
                    else
                    {
                        // Display warning to iOS users if they're trying to use HTTP url without setting the permission
                        if (isPlatformIOS || isPlatformTVOS)
                        {
                            if (!PlayerSettings.iOS.allowHTTPDownload && fullPath.StartsWith("http://"))
                            {
                                EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Starting with iOS 9 'allow HTTP downloads' must be enabled for HTTP connections (see Player Settings)");
                            }
                        }
#if UNITY_ANDROID
                        if (fullPath.StartsWith("http://"))
                        {
                            EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Starting with Android 8 unsecure HTTP is not allowed by default and HTTPS must be used, unless a custom cleartext security policy is assigned");
                        }
#endif
                        // Display warning for Android users if they're trying to use a URL without setting permission
                        if (isPlatformAndroid && !PlayerSettings.Android.forceInternetPermission)
                        {
                            EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You need to set 'Internet Access' to 'require' in your Player Settings for Android builds when using URLs");
                        }

                        // Display warning for UWP users if they're trying to use a URL without setting permission
                        if (platform == Platform.WindowsUWP || (platform == Platform.Unknown && (
                                                                    BuildTargetGroup.WSA == UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup
                                                                    )))
                        {
                            if (!PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.InternetClient))
                            {
                                EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You need to set 'InternetClient' capability in your Player Settings when using URLs");
                            }
                        }
                    }
                }
                else
                {
                    // [MOZ] All paths on (i|mac|tv)OS are absolute so this check just results in an incorrect warning being shown
                                        #if !UNITY_EDITOR_OSX
                    if (mediaPath.PathType != MediaPathType.AbsolutePathOrURL && fullPath.StartsWith("/"))
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Absolute path detected, change location to Absolute path?");
                    }
                                        #endif

                    // Display warning for Android users if they're trying to use absolute file path without permission
                    if (isPlatformAndroid && !PlayerSettings.Android.forceSDCardPermission)
                    {
                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "You may need to access the local file system you may need to set 'Write Access' to 'External(SDCard)' in your Player Settings for Android");
                    }

                    if (platform == Platform.Unknown || platform == MediaPlayer.GetPlatform())
                    {
                        if (!System.IO.File.Exists(fullPath))
                        {
                            EditorHelper.IMGUI.NoticeBox(MessageType.Error, "File not found");
                        }
                        else
                        {
                            // Check the case
                            // This approach is very slow, so we only run it when the app isn't playing
                            if (!Application.isPlaying)
                            {
                                string comparePath = fullPath.Replace('\\', '/');
                                string folderPath  = System.IO.Path.GetDirectoryName(comparePath);
                                if (!string.IsNullOrEmpty(folderPath))
                                {
                                    string[] files     = System.IO.Directory.GetFiles(folderPath, "*", System.IO.SearchOption.TopDirectoryOnly);
                                    bool     caseMatch = false;
                                    if (files != null && files.Length > 0)
                                    {
                                        for (int i = 0; i < files.Length; i++)
                                        {
                                            if (files[i].Replace('\\', '/') == comparePath)
                                            {
                                                caseMatch = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!caseMatch)
                                    {
                                        EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "File found but case doesn't match");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (mediaPath != null && mediaPath.PathType == MediaPathType.RelativeToStreamingAssetsFolder)
            {
                if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
                {
                    GUILayout.BeginHorizontal();
                    GUI.color = Color.yellow;
                    GUILayout.TextArea("Warning: No StreamingAssets folder found");

                    if (GUILayout.Button("Create Folder"))
                    {
                        System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
                        AssetDatabase.Refresh();
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    bool checkAndroidFileSize = false;
#if UNITY_ANDROID
                    if (platform == Platform.Unknown)
                    {
                        checkAndroidFileSize = true;
                    }
#endif
                    if (platform == Platform.Android)
                    {
                        checkAndroidFileSize = true;
                    }

                    if (checkAndroidFileSize)
                    {
                        try
                        {
                            System.IO.FileInfo info = new System.IO.FileInfo(fullPath);
                            if (info != null && info.Length > (1024 * 1024 * 512))
                            {
                                EditorHelper.IMGUI.NoticeBox(MessageType.Warning, "Using this very large file inside StreamingAssets folder on Android isn't recommended.  Deployments will be slow and mapping the file from the StreamingAssets JAR may cause storage and memory issues.  We recommend loading from another folder on the device.");
                            }
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                }
            }

            GUI.color = Color.white;
        }
Example #13
0
 /// <summary> 打开视频 </summary>
 public bool OpenMedia(MediaPath path, bool autoPlay = true)
 {
     return(_mediaPlayer.OpenMedia(path.PathType, path.Path, autoPlay));
 }