Tuesday, July 1, 2014

Error 103 (net::ERR_CONNECTION_ABORTED): Unknown error

One fine day I got a report from user that one of my webpage is broken. I was taken by surprised when I know they are using IE but the error has chrome logo, I thought, "wow, now they are getting friendly helping one another".

Error 103 (net::ERR_CONNECTION_ABORTED): Unknown error.
I’ve done some research, most of it stated that google have issue with certain antivirus or having a network issue. After further investigation, deduction, reinstall chrome, head banging, jumping around the office, I finally get some epiphany.

In my webpage, I put chrome=1 in meta http-equiv=”X-UA-Compatible”. If your PC has Google Chrome Frame and you are using IE to browse, IE will run Chrome Frame.
Google Chrome Frame was an open source plug-in that seamlessly brought Google Chrome's open web technologies and speedy JavaScript engine to Internet Explorer.
https://developers.google.com/chrome/chrome-frame/

I notice sarcasm in that statement, speedy JavaScript engine to Internet Explorer, so you are saying IE doesn’t have those speedy java engine thingy, quite cheeky?

After I remove chrome=1, it worked, or you can also uninstall Chrome Frame which has been no longer supported and retired as of February 25, 2014

References: http://stackoverflow.com/questions/14637943/what-is-x-ua-compatible-when-it-references-ie-edge-chrome-1  https://developers.google.com/chrome/chrome-frame/

Sunday, June 8, 2014

Xml to Object

I have xml as datasource and need to be translated to an object. Sometimes the xml is not in desirable structure and we can’t compromise with it. Here are few example of xml and class definition for them. Example:
  1. <catalog>
  2. <item>
  3. <id>18338517</id>
  4. <note label="Name ">Gear xyz</note>
  5. <note label="Size ">10</note>
  6. <note label="Source">Store xyz</note>
  7. <relation weight="100">
  8. <type>External</type>
  9. <id>123</id>
  10. <name>Mcday</name>
  11. </relation>
  12. <relation weight="99">
  13. <type>Internal</type>
  14. <id>234</id>
  15. <name>Mcnight</name>
  16. </relation>
  17. </item>
  18. <item> ..... </item>
  19. </catalog>

Following are the class definition:
  1. [XmlRoot("catalog")]
  2. public class Catalog
  3. {
  4.     [XmlElement("item")]
  5.     public Item[] item{ get; set; }
  6. }
  7. [XmlType("item")]
  8. public class Item
  9. {
  10.     [XmlElement("id")]
  11.     public string id { get; set; }
  12.     [XmlElement("note", typeof(Note))]
  13.     public Note[] note { get; set; }
  14.     [XmlElement("relation", typeof(Relation))]
  15.     public Relation[] relation { get; set; }
  16. }
  17. [Serializable]
  18. public class Note
  19. {
  20.     [XmlAttribute("label")]
  21.     public string label { get; set; }
  22.     [XmlText]
  23.     public string Value { get; set; }
  24. }
  25. [Serializable]
  26. public class Relation
  27. {
  28.     [XmlAttribute("weight")]
  29.     public string weight { get; set; }
  30.     [XmlText]
  31.     public string Value { get; set; }
  32.     [XmlElement("id")]
  33.     public string id { get; set; }
  34.     [XmlElement("type")]
  35.     public string type { get; set; }
  36.     [XmlElement("name")]
  37.     public string name { get; set; }
  38. }

Finally deserializing xml:
  1. Catalog catalog = null;
  2. XmlSerializer mySerializer = new XmlSerializer(typeof(Catalog));
  3. using (TextReader reader = new StreamReader(@"C:\xml\catalog.xml"))
  4. {
  5. catalog = (Catalog)mySerializer.Deserialize(reader);
  6. }

Note:
  • For xml tag that don’t have any attribute and inner tag, but have value, we can just put it as below
    1. [XmlElement("id")]
    2. public string id { get; set; }
  • For xml tag that have attribute and value, we can refer to Note as example
References http://msdn.microsoft.com/en-us/library/2baksw0z(v=vs.110).aspx http://stackoverflow.com/questions/22781813/missing-child-nodes-when-deserializing-xml-to-object

Thursday, September 16, 2010

Adding Alfresco web service from VS 2005

Alfresco is an open source Content Management System that allow user to store data inside the server. To make it simple it's just like a database where you can store data/file/image and add your desired property along with the data. Since most of alfresco client use java; actually alfresco is written in java so there are some challenge that .Net will face, including the scarcity of resource on the web. If you are a java user, you can include alfresco classes in your code, but for .Net user you should rewrite the code from .Net to Java which gonna waste your time, or you convert .class to .dll, I use IKVM to do the job, I'll cover that in the next post.

Coding environment
  1. Alfresco 3.3 Community edition
  2. Visual Studio .Net 2005
  3. Windows XP Pro version 2002 SP3

List of the web service in alfresco










Service NamePurposeURL
AccessControlServiceManage permissionshttp://host:port/alfresco/api/AccessControlService?WSDL
ActionServiceExecute custom actions and ruleshttp://host:port/alfresco/api/ActionService?WSDL
AdministrationServiceManage users and groupshttp://host:port/alfresco/api/AdministrationService?WSDL
AuthenticationServiceLogin and access session ticketshttp://host:port/alfresco/api/AuthenticationService?WSDL
AuthoringServiceAllows collaboration between usershttp://host:port/alfresco/api/AuthoringService?WSDL
ContentServiceRead and write contenthttp://host:port/alfresco/api/ContentService?WSDL
ClassificationServiceManage categorieshttp://host:port/alfresco/api/ClassificationService?WSDL
DictionaryServiceManage content modelshttp://host:port/alfresco/api/DictionaryService?WSDL
RepositoryServiceNavigate, search, and manipulate nodes.http://host:port/alfresco/api/RepositoryService?WSDL

I manage to add all the wsdl, but AccessControlService can not be call, I fail to update web reference also, maybe there are something wrong with it's schema.

Okay from here on, you need additional class to help you to communicate with the web service
  1. WebServiceFactory.cs
  2. AuthenticationUtils.cs
  3. Constants.cs
Thanks to this generous person who share his experience in communicating with alfresco, you can get this file http://forge.alfresco.com/frs/download.php/80/alfresco-dotNet-0.2Beta.zip.

You would likely encounter this error when you call WebServiceFactory.addSecurityHeader
"cannot convert from 'Alfresco.RepositoryWebService.RepositoryService' to 'Microsoft.Web.Services3.WebServicesClientProtocol'"

To fix this you must change file Reference.cs for every WSDL that you add in your code, example
  • public partial class ContentService : System.Web.Services.Protocols.SoapHttpClientProtocol
change into
  • public partial class ContentService : Microsoft.Web.Services3.WebServicesClientProtocol

It goes without saying you should add references Microsoft.Web.Services3

Still in WebServiceFactory don't forget to change this value and point it to your alfresco server
  • private const string DEFAULT_ENDPOINT_ADDRESS = "http://localhost:8080/alfresco"
That should do the job, in the next post I will cover insert document to alfresco.

Generate table from server side

I've been absent long enough :p, but few days ago, I found my post can be reference for myself so I decide to update again hohoho. For some reason I want to generate table(actually I don't know what reason, why didn't I used DataGrid or GridView instead of table)

I've make a generic function PopulateTable(Table tblObj, DataTable dtObject, TableRow trHeader), if needed you can edit according to your needs, because some data may need certain formatting in table. The code itself easy to understand

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. //Assuming we have data in this tbl
  4. DataTable tbl = new DataTable();
  5. PopulateTable(tblContent, tbl, GetDocumentTableHeader());
  6. }
  7. private TableHeaderRow GetDocumentTableHeader()
  8. {
  9. TableHeaderRow thr = new TableHeaderRow();
  10. TableHeaderCell thc = new TableHeaderCell();
  11. thc.Text = "Title"; thc.CssClass = "title"; thr.Cells.Add(thc);
  12. thc = new TableHeaderCell();
  13. thc.Text = "Author"; thc.CssClass = "author"; thr.Cells.Add(thc);
  14. thc = new TableHeaderCell();
  15. thc.Text = "Description"; thc.CssClass = "categories"; thr.Cells.Add(thc);
  16. return thr;
  17. }
  18. private void PopulateTable(Table tblObj, DataTable dtObject, TableRow trHeader)
  19. {
  20. tblObj.Rows.Clear();
  21. tblObj.Rows.Add(trHeader);
  22. if (dtObject == null || dtObject.Rows.Count == 0)
  23. {
  24. //If no records found in DataTable then show No Result Found
  25. TableRow row = new TableRow();
  26. TableCell cell = new TableCell();
  27. cell.Text = "No Result Found!";
  28. cell.HorizontalAlign = HorizontalAlign.Center;
  29. cell.Font.Bold = true;
  30. cell.ForeColor = System.Drawing.Color.Red;
  31. cell.ColumnSpan = trHeader.Cells.Count;
  32. row.Cells.Add(cell);
  33. tblObj.Rows.Add(row);
  34. }
  35. else
  36. {
  37. for (int i = 0; i < dtObject.Rows.Count; i++)
  38. {
  39. TableRow row = new TableRow();
  40. for (int j = 0; j < trHeader.Cells.Count; i++)
  41. {
  42. TableCell cell = new TableCell();
  43. cell.Text = dtObject.Rows[i][j].ToString();
  44. row.Cells.Add(cell);
  45. }
  46. tblObj.Rows.Add(row);
  47. }
  48. }
  49. }

Wednesday, July 30, 2008

Adding Rows to DataGrid

One day my colleague want me to add some rows to existing DataGrid, the rest of the record is populate with query from the database meanwhile the records that will be add should be filled manually and not from database, for few minutes I feel foolish enough to find out that we can't add rows using the DataGrid object directly like we add rows in DataTable (Creating DataTable Manually), but we should manipulate the DataGrid.DataSource that I fill in with DataView object. So we should manipulate the DataTable and not the DataGrid, the code is quite same like my previous post (Creating DataTable Manually) with some lines added.

  • DataSet ds = new DataSet();
  • //Assuming that ds already contains record populated from database
  • DataRow rs1 = ds.Tables[0].NewRow();
  • DataRow rs2 = ds.Tables[0].NewRow();
  • rs1["COL1"] = "Testing row1col1"; rs1["COL2"] = "Testing row1col2";
  • rs2["COL1"] = "Testing row2col1"; rs2["COL2"] = "Testing row2col2";
  • ds.Tables[0].Rows.Add(r1);
  • ds.Tables[0].Rows.Add(r2);
  • DataView dv = ds.Tables[0].DefaultView;
  • DataGrid dg = new DataGrid();
  • dg.DataSource = dv;

Friday, July 11, 2008

How to remove duplicate primary keys rows from DataTable

Let's say that I have a table in database, for some reason the one who created it didn't set any primary keys, but giving assumption that some columns will be use as primary keys. Because of that condition, somehow the columns that assume to be primary keys can have duplicate value and also can have null value. I want to remove records that have null and duplicate values in primary keys. There are two ways to do it, one is using query another one is loop DataRow and check it programmatically.

This is the first way
  • This is the first way
  • SELECT t.*
  • FROM
  • ( SELECT u.PK1 ,u.PK2 FROM MyTable u
  • WHERE u.PK1 is not null and u.PK2 is not null
  • GROUP BY u.PK1 ,u.PK2
  • HAVING COUNT(*) = 1 ) s
  • LEFT JOIN MyTable t
  • ON t.PK1=s.PK1 and t.PK1=s.PK2
  • WHERE t.PK1 is not null and t.PK2 is not null

You can use inner join too, but in this scenario it is faster to use left join because it doesn't have to check every records for each row. Thanks to Anita for helping me with this query, being inspired too by this article written by Pinal Dave. By the way this query is not the only way, u can use another trick or even use store procedure.

This is the second way, the important thing is YOU MUST SORT the content in dtSource and dtDup base on the primary keys respectively. I noticed that there are different behaviors of DataTable if u create it manually and if u use DataSet then populate the records from database. If u use DataTable that u create manually when u delete the row, then the row will be deleted permanently and the index will changed, but if u use DataSet then it will be marked as deleted it will be deleted if u use DataTable.AcceptChanges. If u use DataSet then look at my code with comment "//THIS LINE SHOULD BE REMOVED", statement "i--;" in that line should be removed, but if you use DataTable that u create manually u need that statement, it took a while for me to test and realize there are something odd with the result before, now it fix :) .
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. //DataTable that contain all records
  6. DataTable dtSource = new DataTable();
  7. dtSource.Columns.Add("PK1");
  8. dtSource.Columns.Add("PK2");
  9. dtSource.Columns.Add("Column1");
  10. dtSource.Columns.Add("Column2");
  11. Random rnd = new Random();
  12. int j = 0;
  13. ArrayList arr = new ArrayList();
  14. for (int i = 0; i < 10 ; i ++ )
  15. {
  16. j = rnd.Next(1, 3);
  17. if (j == 2) arr.Add(i);
  18. for (int k = 0; k < j ; k ++ )
  19. {
  20. DataRow dr = dtSource.NewRow();
  21. dr["PK1"] = "PK1" + i;
  22. dr["PK2"] = "PK2" + i;
  23. dr["Column1"] = "C1" + i;
  24. dr["Column2"] = "C2" + i;
  25. dtSource.Rows.Add(dr);
  26. }
  27. }
  28. //DataTable that only contains rows with the duplicate primary keys
  29. DataTable dtDup = new DataTable();
  30. dtDup.Columns.Add("PK1");
  31. dtDup.Columns.Add("PK2");
  32. for (int i = 0; i < arr.Count ; i ++ )
  33. {
  34. DataRow dr = dtDup.NewRow();
  35. dr["PK1"] = "PK1" + arr[i].ToString();
  36. dr["PK2"] = "PK2" + arr[i].ToString();
  37. dtDup.Rows.Add(dr);
  38. }
  39. PrintRows(dtSource);
  40. Console.WriteLine();
  41. Program obj = new Program();
  42. string [] dupPrimary = new string[2]{"PK1", "PK2"};
  43. obj.RemoveDuplicatePrimaryKey( ref dtSource, dtDup, dupPrimary );
  44. PrintRows(dtSource);
  45. Console.ReadLine();
  46. }
  47. private static void PrintRows(DataTable dt)
  48. {
  49. for (int i = 0; i < dt.Rows.Count; i++)
  50. Console.WriteLine("PK1: {0}, PK2: {1}, Column1: {2}, Column2: {3}",
  51. dt.Rows[i]["PK1"], dt.Rows[i]["PK2"],
  52. dt.Rows[i]["Column1"], dt.Rows[i]["Column2"]);
  53. }
  54. public void RemoveDuplicatePrimaryKey
  55. (ref DataTable Source, DataTable Target, string[] PrimaryKeys)
  56. {
  57. DataColumn[] keyColumns = new DataColumn[PrimaryKeys.Length];
  58. for (int i = 0; i < PrimaryKeys.Length; i++)
  59. {
  60. keyColumns[i] = Source.Columns[ PrimaryKeys[i] ];
  61. }
  62. bool bStart = false, bEnd = false;
  63. int j = 0;
  64. bool bDuplicate;
  65. for (int i = 0; i < Source.Rows.Count; i++)
  66. {
  67. DataRow drSource = Source.Rows[i];
  68. bDuplicate = IsDuplicate(drSource, Target.Rows[j], keyColumns);
  69. if (!bDuplicate)
  70. {
  71. if (bEnd) break;
  72. else if (bStart)
  73. {
  74. bStart = false;
  75. j++;
  76. i--;
  77. }
  78. else if (j == 0) continue;
  79. }
  80. else
  81. {
  82. Source.Rows[i].Delete();
  83. bStart = true;
  84. if (j == Target.Rows.Count - 1) bEnd = true;
  85. i--; //THIS LINE SHOULD BE REMOVED
  86. }
  87. }
  88. Source.AcceptChanges();
  89. }
  90. private bool IsDuplicate
  91. (DataRow drSource, DataRow drTarget, DataColumn[] dcPrimaryKeys)
  92. {
  93. bool retVal = true;
  94. foreach (DataColumn column in dcPrimaryKeys)
  95. {
  96. retVal = retVal &&
  97. (drSource[column.ColumnName].ToString() ==
  98. drTarget[column.ColumnName].ToString());
  99. if (!retVal) break;
  100. }
  101. return retVal;
  102. }
  103. }

In the real case, I use query to populate data into dtSource and dtDup, here they are:
  • SELECT PK1, PK2, Column1, Column2
  • FROM MyTable
  • WHERE PK1 is not null and PK2 is not null
  • ORDER BY PK1, PK2
  • SELECT PK1, PK2
  • FROM MyTable
  • WHERE PK1 is not null and PK2 is not null
  • GROUP BY PK1, PK2
  • HAVING COUNT(*) = 1
  • ORDER BY PK1, PK2

Braviax Virus

At the first time, I didn't install any antivirus or spyware, one day when I was surfing the internet, my laptop suddenly restart. I think maybe the operating system was crash or something, after the computer reboot, I open windows task manager and found something strange, there is process name braviax and almost all the process have blank user name. I check msconfig and I found another braviax and start up. geezz after that I realized I've got infected, paniiiiccccccccc.

Calm down mann, soon I installed PC tools spyware doctor, it can detect braviax but can't clean it perfectly, because it keep show up. sighh this virus is something, after that I try to installed Symantec Antivirus, guess what, I can't installed it, it say that I don't have sufficient priviledge, but heyy I'm the only admin in this laptop. Later I found out it is because the virus, I'm getting moreeeee paniccccccc

ok ok, calm downn, google it first, found one article that suggest me to kill the process and delete the braviax.exe, hey dude I've done it few timess it's not that simple. Finally i've found one article How To Remove Braviax. I download the SDFix and combofix and follow the step, and voila it workss thx Godd, whoever wrote it, thx a lot dude. Here is the step taken from the the url above :

Download SDFix and save the file to your desktop. Double click SDFix.exe and it will extract the files to %systemdrive% (Drive that contains the Windows Directory, typically C:\SDFix)
Download combofix.

Reboot your PC in Safe mode.

  1. Restart your computer
  2. After hearing your computer beep once during startup, but before the Windows icon appears, press F8.
  3. Instead of Windows loading as normal, a menu should appear
  4. Select the first option, to run Windows in Safe Mode.

Open the SDFix folder and double-click RunThis.bat.

  • Type Y to begin the cleanup process.
  • It will remove any Trojan Services and Registry Entries that it finds then prompt you to press any key to Reboot.
  • Press any Key and it will restart the PC.
  • When the PC restarts the Fixtool will run again and complete the removal process then display Finished, press any key to end the script and load your desktop icons.
  • Close any open browsers.
  • Double click on combofix.exe and follow the prompts.
Note 1: Can`t run anti spyware programs ? rename them and try again.

Note 2: Some variants of braviax very difficult for removing from PC.
If in a combofix log you have found Win32.Agent.zb header with list of infected files, then you should remove and install these apps again.

If you are still having problems with spyware after completing these instructions, it`s possible, then please follow the steps: How to use Spyware Removal Forum - MUST READ