Exemple #1
0
        public static string GetFilePath(this StoreMediaOptions self, string rootPath)
        {
            var isPhoto = !(self is StoreVideoOptions);

            var name = self?.Name;

            if (string.IsNullOrWhiteSpace(name))
            {
                var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture);
                if (isPhoto)
                {
                    name = "IMG_" + timestamp + ".jpg";
                }
                else
                {
                    name = "VID_" + timestamp + ".mp4";
                }
            }

            var ext = Path.GetExtension(name);

            if (string.IsNullOrEmpty(ext))
            {
                ext = isPhoto ? ".jpg" : ".mp4";
            }

            name = Path.GetFileNameWithoutExtension(name);

            var folder = Path.Combine(rootPath ?? string.Empty, self?.Directory ?? string.Empty);

            return(Path.Combine(folder, name + ext));
        }
Exemple #2
0
        public static void VerifyOptions(this StoreMediaOptions self)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (Path.IsPathRooted(self.Directory))
            {
                throw new ArgumentException("options.Directory must be a relative path", nameof(self));
            }
        }