Esempio n. 1
0
        public MetaWeblog.UrlInfo metaweblog_newMediaObject(object blogid, string username, string password, MetaWeblog.MediaType enc)
        {
            if (!_dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = _siteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }

            // Get the binary data
            string strPath = Path.Combine(_dasBlogSettings.RelativeToRoot(_dasBlogSettings.SiteConfiguration.BinariesDir), enc.name);

            // check if the name of the media type includes a subdirectory we need to create
            FileInfo fileInfo = new FileInfo(strPath);

            if (fileInfo.Directory.Exists == false && fileInfo.Directory.FullName != _dasBlogSettings.RelativeToRoot(_dasBlogSettings.SiteConfiguration.BinariesDir))
            {
                fileInfo.Directory.Create();
            }

            try
            {
                using (FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(enc.bits);
                    }
                }
            }
            catch (Exception e)
            {
                throw new XmlRpcException(e.ToString());
            }

            string path = Path.Combine(_dasBlogSettings.SiteConfiguration.BinariesDirRelative, enc.name);

            MetaWeblog.UrlInfo urlInfo = new MetaWeblog.UrlInfo();
            urlInfo.url = _dasBlogSettings.RelativeToRoot(path);
            return(urlInfo);
        }
Esempio n. 2
0
        public MetaWeblog.UrlInfo metaweblog_newMediaObject(object blogid, string username, string password, MetaWeblog.MediaType enc)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }

            if (!VerifyLogin(username, password))
            {
                throw new SecurityException();
            }

            Stream stream = new MemoryStream(enc.bits);

            var filePath = binaryManager.SaveFile(stream, enc.name);

            var urlInfo = new MetaWeblog.UrlInfo
            {
                url = Path.Combine(dasBlogSettings.RelativeToRoot(dasBlogSettings.SiteConfiguration.BinariesDir.TrimStart('~')), enc.name)
            };

            return(urlInfo);
        }