sample code to find unsupported character conversions

/*
    http://en.wikipedia.org/wiki/Code_page_1252
    http://en.wikipedia.org/wiki/EBCDIC_037
  
    http://stackoverflow.com/questions/13389182/in-net-how-do-i-determine-what-characters-existing-in-the-windows-1252-codepag
 
 
    Notes:
    (1) There is a problem in the code.  The .Net conversion from Windows 1252 to IBM 37 has problem.  It converted the of Ÿ (159 in windows 12562) to "Y" (232 IBM 37) instead of "Ÿ" (255 IBM 37).
    (2) The Console cannot display all the characters on the terminal.
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace test_code_page
{
    class find_unsupported_conversions
    {
        static void Main(string[] args)
        {
            FileStream stream = null;
            StreamWriter streamwriter = null;
            TextWriter console_streamwriter = Console.Out;
            string path;

            if (args.Length == 1)
                path = args[0];
            else
            {
                Console.Write("Enter path: ");
                path = Console.ReadLine();
            }

            try
            {
                stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
                streamwriter = new StreamWriter(stream);
                Console.SetOut(streamwriter);
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot open '" + path + "' for writing");
                Console.WriteLine(e.Message);
            }

            test_code_pages();

            Console.SetOut(console_streamwriter);
            if (streamwriter != null)
                streamwriter.Close();
            if (stream != null)
                stream.Close();
        }

        private static void test_code_pages()
        {
            Encoding source_encoding = Encoding.GetEncoding("Windows-1252");
            Encoding target_encoding = Encoding.GetEncoding("IBM037");
            
            byte source_question_mark = source_encoding.GetBytes("?")[0];
            byte target_question_mark = target_encoding.GetBytes("?")[0];

            int count = 0;
            byte[] b = new byte[1];
            for (int i = 0; i < 256; i++)
            {
                b[0] = (byte)i;
                if (b[0] != source_question_mark && Encoding.Convert(source_encoding, target_encoding, b)[0] == target_question_mark)
                {
                    count++;
                    Console.WriteLine(source_encoding.GetString(b) + " " + i.ToString());
                }
            }

            Console.WriteLine(count.ToString() + " unsupported.");
        }
    }
}

C# InputBox

using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace input
{
    public class InputBox : Form
    {
        private Container components = null;

        private Label label;
        private TextBox textbox;
        private Button button;

        private string input_value = "";

        public InputBox(string prompt) : this(prompt, "", ""){}

        public InputBox(string prompt, string title) : this(prompt, title, "") {}

        public InputBox(string prompt, string title, string default_value)
        {
            Init();
            set(prompt, title, default_value);
        }

        private void set(string prompt, string title, string default_value)
        {
            this.label.Text = prompt;
            this.Text = title;
            this.textbox.Text = default_value;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
                if (components != null)
                    components.Dispose();
            base.Dispose(disposing);
        }

        private void Init()
        {
            this.label = new Label();
            this.textbox = new TextBox();
            this.button = new Button();

            this.SuspendLayout();

            this.label.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            this.label.Location = new Point(10, 10);
            this.label.Size = new Size(190, 20);

            this.textbox.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            this.textbox.Location = new Point(10, 35);
            this.textbox.Size = new Size(150, 25);
            this.textbox.KeyPress += new KeyPressEventHandler(textbox_KeyPress);

            this.button.Anchor = AnchorStyles.Right;
            this.button.Location = new Point(170, 33);                        
            this.button.Text = "OK";            
            this.button.Click += new System.EventHandler(this.button_Click);

            Controls.Add(this.label);
            Controls.Add(this.textbox);
            Controls.Add(this.button);

            // enable the escape key
            this.CancelButton = null;
            this.KeyPreview = true;
            this.KeyPress += new KeyPressEventHandler(InputBox_KeyPress);

            this.Size = new Size(260, 100);
            this.MinimizeBox = false;
            this.MaximizeBox = false;
            this.Name = "InputBox";

            this.ResumeLayout(false);
        }

        void InputBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                this.Value = null;
                this.Close();
            }
        }

        void textbox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
                this.button.PerformClick();
        }


        private void button_Click(object sender, EventArgs e)
        {
            this.Value = this.textbox.Text;
            this.Close();
        }

        public string Value
        {
            get { return this.input_value; }
            set { this.input_value = value; }
        }

        public string Show()
        {
            this.ShowDialog();
            return this.Value;
        }

        public string Show(string prompt)
        {
            return Show(prompt, "", "");
        }

        public string Show(string prompt, string title)
        {
            return Show(prompt, title, "");
        }

        public string Show(string prompt, string title, string default_value)
        {
            set(prompt, title, default_value);
            return Show();
        }
    }
}

Retrieving Data from Active Directory

Retrieving Information from Active Directory with SSIS

This one show how to use the ADO.NET connection manager to retrieve data from Active Directory. The problem is the SSIS don’t support all ADO properties. There is no way to set the number of returning objects, LDAP_OPT_SIZELIMIT . In most case, the AD will return 1000.

Return All My User Accounts

This one show how to use the VBscript and ADO to retrieve the data from Active Directory. It use the Page Size property to get around the problem. It work well.

Active Directory Users

This one show how to use the C#.Net script and the System.DirectoryServices to retrieve data from Active Directory. It works.

More samples for System.DirectoryServices

MSXML 6.0 vs. System.Xml

http://blogs.msdn.com/stan_kitsis/archive/2005/09/20/472185.aspx

 

Feature MSXML 6 system.xml

Using XML attributes without explicit schema declaration not supported supported
element of type xs:ID supported* not supported
Conflicting values of facets minInclusive, maxInclusive in base and derived types not allowed* allowed
maxOccurs=0 with no minOccurs error* no error
Multiple redefines of the same schema document error warning (only first redefine is processed)
parsing of targetNamespace attribute as anyURI supported* not supported
Regex support for Unicode Character blocks Unicode 3.1 Unicode 4.0.1
Regex patterns involving combinating a negative group with another using ‘|’ not supported supported*
XSD Errata for Regex E2-52 not supported supported*
Regex character class subtraction not supported supported*
Matching newlines/linebreaks from a xsd:pattern facet not supported supported*
minOccurs/maxOccurs value limits upto 2^32 CLR decimal
limit of totalDigits facet values upto 2^32 CLR decimal
datatypes used to store length, minLength, maxLength facet values upto 2^32 CLR decimal
a prohibited attribute in a complex type no error, attribute stripped* warning, attribute stripped*
unreferenced groups in the schema always compiled compiled on reference
default element values availability not supported supported*
expose post schema validation infoset not supported supported*
ENTITY in DTD resolvable by attribute/elements of type xs:ENTITY DOM=Yes, SAX=no Yes
adding a default qualified attribute to an element in a document that has attribute’s namespace as default DOM: apply qualified default attribute with namespace value as the prefix. SAX=does not generate prefix for default qualified attributes error
identity constraints (key/unique) evaluation for skip/lax blocks node is null not able to find node
element with mixed content, and a fixed schema value, containing child elements instance accepted instance not accepted*
whitespace facet on anySimpleType preserve* collapsed
XSD Errata on xs:base64Binary parsing supported* not supported
xs:dateTime: number of year digits supported 10 4
xs:dateTIme: number of fraction digits supported in seconds 9 7
xs:dateTime: Range of hours in time zone “-14:00 to +14:00” * 99:00 to -99:00
xs:dateTime: negative years supported* not supported
“z” (as opposed to “Z”) in xs:dateTime to represent UTC time not allowed* allowed
xs:time: range of hour value 00:00:00 to 24:00:00* 00:00:00 to 23:59:59
xs:gMonth: XSD Errata revised the lexical representation of gMonth only –MM is allowed* both –MM and –MM– are allowed
maximum digits allowed for the xs:decimal data type 128 29
xs:duration: duration with second part specified, but has no digits error no error, infer a 0 for the second part