Beispiel #1
0
        private FileUploadReturnInfo UploadFile(ImageInformation ii, ServerInfo si)
        {
            FileUploadInfo fui = new FileUploadInfo();

            fui.overwrite = true;
            fui.name      = ii.filename;
            fui.type      = Mimetypes.MimeType(ii.filename);

            BinaryReader br = new BinaryReader(File.Open(ii.fullpath, FileMode.Open));

            byte[] bytes = new byte[br.BaseStream.Length];
            br.Read(bytes, 0, (int)br.BaseStream.Length);
            br.Close();
            fui.bits = bytes;

            try
            {
                FileUploadReturnInfo retval = si.conn.UploadFile(0, si.username, si.password, fui);
                return(retval);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(null);
            }
        }
Beispiel #2
0
        private void btn_PublishPost_Click(object sender, EventArgs e)
        {
            string content = txt_Content.Text;

            // Add title
            string title = "<title>" + titleElem.InnerHtml + "</title>";

            // Upload images
            ProgressForm p = new ProgressForm();

            p.Text = "Uploading files...";
            Thread t = new Thread(new ThreadStart(delegate()
            {
                while (!p.Visible)
                {
                }
                p.Progress    = 0;
                double count  = 0;
                int itemcount = list_images.Items.Count;

                for (int i = 0; i < itemcount; i++)
                {
                    ImageInformation ii = null;
                    Invoke(new Invoker(delegate()
                    {
                        ListViewItem lvi = list_images.Items[i];
                        ii = lvi.Tag as ImageInformation;
                    }));

                    if (ii.uploadedToDevServer)
                    {
                        FileUploadReturnInfo retval = UploadFile(ii, targetserver);
                        if (retval == null)
                        {
                            MessageBox.Show("Unable to upload a file");
                            return;
                        }

                        string localfullurl = Uri.EscapeUriString(ii.fullurl);
                        string localmedurl  = Uri.EscapeUriString(ii.medurl);

                        ii.fullurl = retval.url;
                        GetMedWidth(ii);

                        content = content.Replace(localfullurl, ii.fullurl);
                        content = content.Replace(localmedurl, ii.medurl);
                    }
                    count++;
                    Invoke(new Invoker(delegate()
                    {
                        p.Progress    = count / (double)list_images.Items.Count;
                        p.DisplayText = ii.filename;
                    }));
                }

                Invoke(new Invoker(delegate()
                {
                    p.Close();
                }));
            }));

            t.Start();
            p.ShowDialog();

            // Make the content string and send it off
            content = title + content;
            int postid = targetserver.conn.NewPost(0, 0, targetserver.username, targetserver.password, content, true);

            // Set the category
            List <CategoryFullInfo> cfis = new List <CategoryFullInfo>();

            foreach (Control ctl in flow_Categories.Controls)
            {
                CheckBox cb = ctl as CheckBox;
                if (cb.Checked)
                {
                    cfis.Add(cb.Tag as CategoryFullInfo);
                }
            }
            targetserver.conn.SetPostCategories(postid, targetserver.username, targetserver.password, cfis.ToArray());

            // Set the tags
            MWPost post = targetserver.conn.MWGetPost(postid, targetserver.username, targetserver.password);

            tags.ForEach(x => post.mt_keywords += (post.mt_keywords.Length == 0 ? "" : ",") + x);

            targetserver.conn.MWEditPost(postid, targetserver.username, targetserver.password, post);
        }