Cryptopro c# Get the list of all certificate containers


public class Win32
    {
        [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool CryptAcquireContext(
        ref IntPtr hProv,
        string pszContainer,
        string pszProvider,
        uint dwProvType,
        uint dwFlags);

        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool CryptGetProvParam(
        IntPtr hProv,
        uint dwParam,
        [In, Out] byte[] pbData,
        ref uint dwDataLen,
        uint dwFlags);

        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool CryptGetProvParam(
        IntPtr hProv,
        uint dwParam,
        [MarshalAs(UnmanagedType.LPStr)] StringBuilder pbData,
        ref uint dwDataLen,
        uint dwFlags);

        [DllImport("advapi32.dll")]
        public static extern bool CryptReleaseContext(
        IntPtr hProv,
        uint dwFlags);
    }
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Collections;
using System.Text;

namespace CryptoHelper
{
    public static class CryptoHelper
    {
        public static string[] GetContainerNames()
        {
            int BUFFSIZE = 512;
            ArrayList containernames = new ArrayList();
            uint pcbData = 0;
            //String provider = null; //can use null, for default provider
            String provider = "Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider";
            String container = null;   //required for crypt_verifycontext 
            uint type = PROV_RSA_FULL;
            uint cspflags = CRYPT_VERIFYCONTEXT | CSPKEYTYPE;  //no private key access required.
            uint enumflags = PP_ENUMCONTAINERS;  //specify container enumeration functdionality
            IntPtr hProv = IntPtr.Zero;
            uint dwFlags = CRYPT_FIRST;

            bool gotcsp = Win32.CryptAcquireContext(ref hProv, container, provider, type, cspflags);
            if (!gotcsp)
            {
                showWin32Error(Marshal.GetLastWin32Error());
                return null;
            }


            StringBuilder sb = null;
            Win32.CryptGetProvParam(hProv, enumflags, sb, ref pcbData, dwFlags);
            BUFFSIZE = (int)(2 * pcbData);
            sb = new StringBuilder(BUFFSIZE);

            /*  ----------  Get KeyContainer Names ------------- */
            dwFlags = CRYPT_FIRST;  //required initalization
            while (Win32.CryptGetProvParam(hProv, enumflags, sb, ref pcbData, dwFlags))
            {
                dwFlags = 0;      //required to continue entire enumeration
                containernames.Add(sb.ToString());
            }
            if (hProv != IntPtr.Zero)
                Win32.CryptReleaseContext(hProv, 0);

            if (containernames.Count == 0)
                return null;
            else
                return (string[])containernames.ToArray(Type.GetType("System.String"));
        }

        const uint PROV_RSA_FULL = 0x00000001;
        const uint CRYPT_VERIFYCONTEXT = 0xF0000000;
        static uint CSPKEYTYPE = 0;
        const uint PP_ENUMCONTAINERS = 0x00000002;
        const uint CRYPT_FIRST = 0x00000001;

        private static void showWin32Error(int errorcode)
        {
            Win32Exception myEx = new Win32Exception(errorcode);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error code:\t 0x{0:X}", myEx.ErrorCode);
            Console.WriteLine("Error message:\t {0}\n", myEx.Message);
            Console.ForegroundColor = ConsoleColor.White;
        }
    }
}

c# парсим строку текст


public List<string> ParseString(string _string4Parse,string _beginVal,string _endVal)
        {
            List<string> res = new List<string>();
            int _begin = 0;
            while ((_begin = _string4Parse.IndexOf(_beginVal, _begin)) > -1)
            {
                _begin += _beginVal.Length;
                int _length = _string4Parse.IndexOf(_endVal, _begin)-_begin;
                res.Add(_string4Parse.Substring(_begin, _length));
            }
            return res;
        }

c# Переводим с помощью Bing Api translator


using System;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.Web;
using System.ServiceModel.Channels;
using System.ServiceModel;

namespace BlogSubmitterFXApp
{
    public static class BingTranslate
    {
        public static string Translate(string clientId,string ClientSecret,string TextForTranslate)
        {
            AdmAccessToken admToken;
            string headerValue;
            //Get Client Id and Client Secret from https://datamarket.azure.com/developer/applications/
            //Refer obtaining AccessToken (http://msdn.microsoft.com/en-us/library/hh454950.aspx) 
            AdmAuthentication admAuth = new AdmAuthentication(clientId, ClientSecret);
            try
            {
                admToken = admAuth.GetAccessToken();
                DateTime tokenReceived = DateTime.Now;
                // Create a header with the access_token property of the returned token
                headerValue = "Bearer " + admToken.access_token;
                return BingTranslate.TranslateMethod(headerValue, TextForTranslate);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

        static string TranslateMethod(string authToken, string TextForTranslate)
        {
            // Add TranslatorService as a service reference, Address:http://api.microsofttranslator.com/V2/Soap.svc
            TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();
            //Set Authorization header before sending the request
            HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
            httpRequestProperty.Method = "POST";
            httpRequestProperty.Headers.Add("Authorization", authToken);

            // Creates a block within which an OperationContext object is in scope.
            using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
                //string sourceText = "<UL><LI>Use generic class names. <LI>Use pixels to express measurements for padding and margins. <LI>Use percentages to specify font size and line height. <LI>Use either percentages or pixels to specify table and container width.   <LI>When selecting font families, choose browser-independent alternatives.   </LI></UL>";
                string translationResult;
                //Keep appId parameter blank as we are sending access token in authorization header.
                translationResult = client.Translate("", TextForTranslate, "en", "ru", "text/html", "general");
                return translationResult;
            }
        }
    }

    [DataContract]
    public class AdmAccessToken
    {
        [DataMember]
        public string access_token { get; set; }
        [DataMember]
        public string token_type { get; set; }
        [DataMember]
        public string expires_in { get; set; }
        [DataMember]
        public string scope { get; set; }
    }

    public class AdmAuthentication
    {
        public static readonly string DatamarketAccessUri = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
        private string clientId;
        private string cientSecret;
        private string request;

        public AdmAuthentication(string clientId, string clientSecret)
        {
            this.clientId = clientId;
            this.cientSecret = clientSecret;
            //If clientid or client secret has special characters, encode before sending request
            this.request = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=http://api.microsofttranslator.com", HttpUtility.UrlEncode(clientId), HttpUtility.UrlEncode(clientSecret));
        }

        public AdmAccessToken GetAccessToken()
        {
            return HttpPost(DatamarketAccessUri, this.request);
        }

        private AdmAccessToken HttpPost(string DatamarketAccessUri, string requestDetails)
        {
            //Prepare OAuth request 
            WebRequest webRequest = WebRequest.Create(DatamarketAccessUri);
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.Method = "POST";
            byte[] bytes = Encoding.ASCII.GetBytes(requestDetails);
            webRequest.ContentLength = bytes.Length;
            using (Stream outputStream = webRequest.GetRequestStream())
            {
                outputStream.Write(bytes, 0, bytes.Length);
            }
            using (WebResponse webResponse = webRequest.GetResponse())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AdmAccessToken));
                //Get deserialized object from JSON stream
                AdmAccessToken token = (AdmAccessToken)serializer.ReadObject(webResponse.GetResponseStream());
                return token;
            }
        }
    }
}

C# Post/Add BlogPost to wordpress


using CookComputing.XmlRpc;

namespace BlogSubmitterFXApp.WorkWithAPI
{
    public struct blogInfo
    {
        public string title;
        public string description;
    }

    public interface IgetCatList
    {
        [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
        string NewPage(int blogId, string strUserName, string strPassword, blogInfo content, int publish);
    }

    public static class WordPress
    {
        public static bool NewPost(string strUserName, string strPassword, string blogurl ,blogInfo bi)
        {


            blogInfo newBlogPost = default(blogInfo);

            newBlogPost.title = bi.title;
            newBlogPost.description = bi.description;

            IgetCatList categories = (IgetCatList)XmlRpcProxyGen.Create(typeof(IgetCatList));
            XmlRpcClientProtocol clientProtocol = (XmlRpcClientProtocol)categories;

            //For example clientProtocol.Url = "http://msnetdeveloper.wordpress.com/xmlrpc.php";
            clientProtocol.Url = blogurl;

            string result = null;
            result = "";

            try
            {
                result = categories.NewPage(1, strUserName, strPassword, newBlogPost, 1);
                return false;
            }
            catch 
            {
                return true;
            }
        }
    }
}

c# read rss


using System;
using System.Collections.Generic;
using System.Xml;
using System.ServiceModel.Syndication;

namespace LJUpper
{
    public static class RSS
    {
        public struct RssItem
        {
            public string Title { get; set; }
            public string Text { get; set; }
        }

        public static List<RssItem> GetRSS(string _feedUri)
        {
            SyndicationFeed syndicationFeed;
            List<RssItem> resList = new List<RssItem>();
            try
            {
                using (XmlReader reader = XmlReader.Create(new Uri(_feedUri).AbsoluteUri))
                    syndicationFeed = SyndicationFeed.Load(reader);

                string _title = "";
                string _text = "";


                foreach (SyndicationItem t in syndicationFeed.Items)
                {
                    if (t.Title == null)
                        _title += t.Title.Text;
                    if (t.Content == null)
                        _text += t.Summary.Text;
                    else
                        _text += (t.Content as TextSyndicationContent).Text;
                    resList.Add(new RssItem() { Title = t.Title.Text, Text = _text });
                }
            }
            catch
            {
                return null;
            }
            return resList;
        }
    }
}

C# Post/Add BlogPost Blogger.com

Download GData.Client https://code.google.com/p/google-gdata/downloads/list



using System;
using Google.GData.Client;

namespace BloggerAPI
{
    public static class Blogger
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="UserblogTitle">If null,then will select first user blog</param>
        public static bool SubmitNewPost(string username, string password, string UserblogTitle)
        {
            Service service = new Service("blogger", "blogger-example");
            service.Credentials = new GDataCredentials(username, password);
            try
            {
                Uri blogPostUri = SelectUserBlog(service, UserblogTitle);
                AtomEntry createdEntry = PostNewEntry(service, blogPostUri);
                return true;
            }
            catch
            {
                return false;
            }
        }

        static AtomEntry PostNewEntry(Service service, Uri blogPostUri)
        {
            AtomEntry createdEntry = null;
            if (blogPostUri != null)
            {
                AtomEntry newPost = new AtomEntry();
                newPost.Title.Text = "Marriage!";
                newPost.Content = new AtomContent();
                newPost.Content.Content = "<div xmlns=\"http://www.w3.org/1999/xhtml\">" +
                    "<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" +
                    "<p>He is the last man on earth I would ever desire to marry.</p>" +
                    "<p>Whatever shall I do?</p>" +
                    "</div>";
                newPost.Content.Type = "xhtml";
                createdEntry = service.Insert(blogPostUri, newPost);
            }
            return createdEntry;
        }

        static Uri SelectUserBlog(Service service, string UserblogTitle)
        {
            FeedQuery query = new FeedQuery();
            query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs");
            AtomFeed feed = service.Query(query);
            Uri blogPostUri = null;
            if (feed != null)
                foreach (AtomEntry entry in feed.Entries)
                    if (UserblogTitle == entry.Title.Text || UserblogTitle == null)
                    {
                        for (int i = 0; i < entry.Links.Count; i++)
                            if (entry.Links[i].Rel.Equals("http://schemas.google.com/g/2005#post"))
                                blogPostUri = new Uri(entry.Links[i].HRef.ToString());
                        return blogPostUri;
                    }
            return blogPostUri;
        }
    }
}