Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Snapshot using WebBrowser
  1. class Program
  2. {
  3.     [STAThread]
  4.     public static void Main(string[] args)
  5.     {
  6.         var image = Capture("http://www.yahoo.com", 1024, 768);
  7.         image.Save("aa.png", System.Drawing.Imaging.ImageFormat.Png);
  8.     }
  9.  
  10.      
  11.     static Image Capture(string url, int width, int height)
  12.     {
  13.         using (WebBrowser wb = new WebBrowser())
  14.         {
  15.             // skip script error
  16.             wb.ScriptErrorsSuppressed = true;
  17.             wb.ScrollBarsEnabled = false;
  18.             wb.AllowNavigation = true;
  19.             // Set the size of the WebBrowser control
  20.             wb.Width = width;
  21.             wb.Height = height;
  22.             ServicePointManager.ServerCertificateValidationCallback
  23.                 = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) =>
  24.                 {
  25.                     return true;
  26.                 });
  27.  
  28.  
  29.             if (width == -1)
  30.             {
  31.                 // Take Screenshot of the web pages full width
  32.                 wb.Width = wb.Document.Body.ScrollRectangle.Width;
  33.             }
  34.  
  35.             if (height == -1)
  36.             {
  37.                 // Take Screenshot of the web pages full height
  38.                 wb.Height = wb.Document.Body.ScrollRectangle.Height;
  39.             }
  40.  
  41.             wb.Navigate(url);
  42.             while (wb.ReadyState != WebBrowserReadyState.Complete)
  43.             {
  44.                 Application.DoEvents();
  45.             }
  46.             System.Threading.Thread.Sleep(5000);
  47.             wb.Update();
  48.  
  49.             // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
  50.             Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
  51.             wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
  52.             return bitmap;
  53.         }
  54.     }
  55. }
ADOMD.NET, Query data from cube
Add assembly: Microsoft.AnalysisServices.AdomdClient.dll
  1. string ReturnCommandUsingCellSet()
  2. {
  3.     //Create a new string builder to store the results
  4.     System.Text.StringBuilder result = new System.Text.StringBuilder();
  5.  
  6.     //Connect to the local server
  7.     using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;"))
  8.     {
  9.         conn.Open();
  10.  
  11.         //Create a command, using this connection
  12.         AdomdCommand cmd = conn.CreateCommand();
  13.         cmd.CommandText = @"
  14.                       WITH MEMBER [Measures].[FreightCostPerOrder] AS 
  15.                             [Measures].[Reseller Freight Cost]/[Measures].[Reseller Order Quantity],  
  16.                             FORMAT_STRING = 'Currency'
  17.                       SELECT 
  18.                             [Geography].[Geography].[Country].&[United States].Children ON ROWS, 
  19.                             [Date].[Calendar].[Calendar Year] ON COLUMNS
  20.                       FROM [Adventure Works]
  21.                       WHERE [Measures].[FreightCostPerOrder]";
  22.  
  23.         //Execute the query, returning a cellset
  24.         CellSet cs = cmd.ExecuteCellSet();
  25.  
  26.         //Output the column captions from the first axis
  27.         //Note that this procedure assumes a single member exists per column.
  28.         result.Append("\t");
  29.         TupleCollection tuplesOnColumns = cs.Axes[0].Set.Tuples;
  30.         foreach (Tuple column in tuplesOnColumns)
  31.         {
  32.             result.Append(column.Members[0].Caption + "\t");
  33.         }
  34.         result.AppendLine();
  35.  
  36.         //Output the row captions from the second axis and cell data
  37.         //Note that this procedure assumes a two-dimensional cellset
  38.         TupleCollection tuplesOnRows = cs.Axes[1].Set.Tuples;
  39.         for (int row = 0; row < tuplesOnRows.Count; row++)
  40.         {
  41.             result.Append(tuplesOnRows[row].Members[0].Caption + "\t");
  42.             for (int col = 0; col < tuplesOnColumns.Count; col++)
  43.             {
  44.                 result.Append(cs.Cells[col, row].FormattedValue + "\t");
  45.             }
  46.             result.AppendLine();
  47.         }
  48.         conn.Close();
  49.  
  50.         return result.ToString();
  51.     } // using connection
  52. }