miércoles, 30 de septiembre de 2015

WPF Web browser does not display my website but others yes

Intended for: C# developers of all levels

Resultado de imagen de wpf logo
Last week it happened that after having desisted from fix a problem, I found myself with an remote possibility to fix it. More specifically what happened to me is that I made a WPF application that automated the process on the website of my company and should show the results in the browser; which did not do, was showing only a blank page on my website (if I was going to Google or other sites worked without problems).

First thing to dodge this problem is to use Awesomium, which works fine but of course: what website is created for Chromium? I guess that someone will bother to adapt their web to this fantastic brower, but this is not my case; It is for this reason that the web looked poorly and the "workaround" that I had invented just did´t work for me. Although it is true that I am not a user of Internet Explorer (I love Chrome), for a WPF applications which require a browser my choice is clear: the WebBrowser control. But of course, just if it works.

The first thing is to solve the million dollar question: Why it shows me a blank page? Because you are using an older version of Internet Explorer (possibly the oldest one you have installed in your PC, even if you do not have access to it, such as 8 or 9). Although it seems a foolishness, to me it has taken me long to find this.

And now comes the solution to the problem:

  1. We open the editor of the Windows registry by pressing the "Windows" + R keys, we will get the execution window:


  2. We write regedit.exe and give administrator permissions . If we are not the administrator of our we can not fix this problem. Run.
  3. If we have a normal PC of 64 or 32 bits seek the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
  4. If your PC emulates 64-bit on a 32 will look for the key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
  5. Once you have found it we will add a new value DWORD of 32 bits with the full name of our application as a key (including the .exe at the end) and as a value one  of the table detail below.

Valor
Sirve para…
11001 (0x2EDF) 
Intenet Explorer 11, even with the directive ¡DOCTYPE
11000 (0x2AF8) 
Intenet Explorer 11, those with the directive ¡DOCTYPE will be displayed in mode IE9
10001 (0x2AF7)
Internet Explorer 10, even with the directive ¡DOCTYPE
10000 (0x2710) 
Intenet Explorer 10, those with the directive ¡DOCTYPE will be displayed in mode IE9
9999 (0x270F) 
Internet Explorer 9, even with the directive ¡DOCTYPE
9000 (0x2328) 
Internet Explorer 9, even with the directive ¡DOCTYPE (this case is identical to the previous). Those of Microsoft they have done wrong, I'm afraid…
8888 (0x22B8) 
Intenet Explorer 8, even with the directive ¡DOCTYPE
8000 (0x1F40) 
Internet Explorer 8, even with the directive ¡DOCTYPE (this case is identical to the previous). Those of Microsoft they have done wrong, I'm afraid again…
7000 (0x1B58) 
Internet Explorer 7


One more note, that is also very important. If you are debugging with Visual Studio will have to add the famous extension .vshost.exe (instead of .exe only) to the name of our application specifically for this to work as intended.

With that I think I've explained everything. If you have any questions, you can comment.

miércoles, 23 de septiembre de 2015

Duplicate cookies or that do not delete

Intended for: C# developers of all levels

Today I have come across with one of those "weirdness" that I love, the kind that make you lose midmorning and give you a hard time... Well, like those we must endure, we programmers, on a daily basis.

It turns out that the "cookies" that are used in 99% or maybe 100% of current web pages (well, maybe this information is pull out of the sleeve, nevertheless very much used) they are a pain in the ass. And not because in itself involve a special difficulty, no. It is for a bug that appears to exist in the enumeration Request.Cookies yResponse.Cookies.

How to detect when we are making a mistake? Well, the first symptom is the sight of more than one cookie with the same name in the lists above, that means, if we analyze the content of Request.Cookies or deResponse.Cookies and we detect in AllKeys property two or more times the same name, means that we are literally "screwed up".

Search in your code something like the following: this.Request.Cookies ["nameofyourCookie"] == null  or this.Response.Cookies ["nameofyourCookie"] == null.

And now I tell you that this is not working. And why? - you wonder. By the time you call the indexer this.Response.Cookies ["nameofyourCookie"] and without warning you create a new blank cookie (no data) with the same name.

So how I can delete a cookie since this would happens? I will illustrate it below with a practical example:

Code who fails:

if (this.Response.Cookies.[cookieName] != null)
{
      this.Response.Cookies.Remove(cookieName);
}

Code that works:

if (this.Response.Cookies.AllKeys.Contains(cookieName))
{
       this.Response.Cookies.Remove(cookieName);
}

This knowledge can be applied to other areas of cookies, just be careful to use the property AllKeys to check the existence of the cookie and it is more than enough.

I hope I've been helpful!

What are the Windows Services?



Article for: All types of users

At this point in life there are still people who don't know what a Windows Service is. In the Linux operating system are commonly called Daemons. A Windows Service is an application (like the one you already know, such as Word), but with the difference that their goal is to provide services (pun intended) to a specific target and which directly you will not have visibility (working in background).

Unlike conventional applications, Windows services have no graphical interface. If it's necessary an additional graphical interface for control or configuration we would be facilitated, but usually will be handled from the graphical interfaces that Windows provides us.

There was a time in which Windows services were created everywhere... any worthless application were installed further for Windows service to stay updated (how useful! Much better to be updated on startup, where it will stop! That is why I recommend the following article to optimize your Windows startup I wrote some time ago ... Is your windows running abnormally slow?

These applications have different functions: from spying on your keystrokes (keyloggers, which are illegal) to keep the inbox of the line printers. It is very useful to review what they are and to clean them when they are expendable. Your computer could gain significantly speed and will not take long.

My recommendation is to inspect these, disabling those who we suspect. If it is something necessary, we can always turn them back on again.

If you have any question, I accept comments and I will try to help you ...

lunes, 21 de septiembre de 2015

Ashley Madison map and list of hacked accounts

 Article for: Anyone who wishes to read




The truth is that what has happened is something that can happen to any company: a group of hackers whose interests are not entirely clear and they decide to attack a known web server and when they obtain the data, made it public.

It is for this reason that I advocate for not trust certain Internet services or like we call it  these today "the cloud," but some people have no fear and these things happen ...

For those who do not know (which at this point, I doubt it), Ashley Madison is an online service dating for unfaithful peoples, which comes to be (always in my opinion) as a scam, because more than 90% registered users are men (I say this with the data that is on the map above), therefore the dating, if they occur (which I honestly do not think it would happen, but I speak from ignorance because I have not tried it) will be more likely between two men (and I think it's not the purpose) ...

It is true that internet dating services usually work, because the purpose is not sex (or at least not so shameless).Keep in mind that men are usually more nasty, but in general women do not seek casual sex on the first date (basically because they can have it whenever they want, even if is not exactly with the man they desire).

So here's my advice: careful with what we post in certain places about us.

Honestly, I'm so sorry for Ashley Madison, because those are jobs and people in the street; I hope they can fix it somehow although see it fucked up ...

Upgrading:
I found a website where they tell you if your account has been hacked. It seems true, although as I always mistrust and have used email accounts that are not important ...

So if you want to know if they have released your account is as simple as going to the web http://www.allaboutashley.cr/ and consult via email, username or telephone (the data are not fully public, you have to know at least something of the person).

It is very important to emphasize that this page may be other fraud to get information, but it true that on many sites they recommend it, so I suggest you to not trust it excessively...

There is another issue that concerns me and as I can see even on the web that gives you the information, it could happen. This type of site have hundreds of fake profiles and perfectly can be an email from someone that does not really have anything to do with that mess ... So do not fully believe if the result is positive and do not think that your partner have an affair.

Whatsapp in your PC

Article for: All types of users

I've been wondering for long how to have Whatsapp on my PC, just like I have LINE. Not long ago I discovered that there is a simple way to have it centralized on your computer thanks to modern browsers and their extensions.




Let's see how easy it is to have it in Chrome:


  • First let's go to Chrome Store where we can find the extension.
  • Click on the blue button "Add to Chrome"
  • it will ask for confirmation, click "Add"
  • If all goes well, it will display the following window:


  • Now click on the following link chrome://apps/ and look for your new application or seeks the next button and click it

  • Now we need to scan with our mobile through Whatsapp the code that will be displayed..


  • To do so, we will open Whatsapp and in the first window (where all the conversations) will click on the "Pop-up menu" of the mobile, the three stripes button (usually the left bottom).

  • We follow the instructions that Whatsapp give us to capture the Bidi code

  • Finally, if all goes well we will have the following screen
  • It is important to know that our mobile should be connected by WiFi before you start using the application, because the synchronization between all our phone messages and the desktop application could consume part of the data rate.

That's all, I hope you enjoyed my article. For Mozilla-Firefox the process is exactly the same. If you have any doubts, you can comment.

jueves, 30 de abril de 2015

Model View View Model, a simple explanation Part 1

Intended for: C# developers of all levels

I have been working about four years in WPF and every day I can see more bad examples on how people develop in this marvellous Microsoft's technology, that brings us to an upper level in graphical user interfaces.

In this way Microsoft have a CLEAR WAY OF WORK on how to operate and how to make developments for this technology, but people that comes from Windows Forms don't want to be adapted to it. Due to this I write this article, with the idea to help people that wants to adapt and trying to reach middle points in the desktop developments of applications. Besides the Silverlight future is dark, I hope it helps too to people that stills develop in this platform.

This article will be divided in five parts, because of the MVVM complexity and requieres a short time to adapt to it correctly. If you come from Windows Forms and you think that you can do same than always (work using events) you're correct, but you're making a big mistake. If you made a WPF application using events with more than two views, you are showing your ignorance about this: please, take your time to understand and update your mind.

The principle for all of this is: EVENTS ARE THE ENEMY, don't use them as you did all the time. This technology is not made to the classic click over a button or the Text_Changed in a Textbox. Change your mind and think further.

And now the answer to the question: How this work? Windows Presentation Foundation technology have a fanstatic way to operate, that allows us to use to the maximum our modern graphical cards and PCs. Not beign videogames applications (you can do it, but is not the final intentions of WPF), WPF applications could be beautiful and well designed that people fells using them as childs playing with them; as developers that must be our final goal, a user feeling like home VERY confortable using our developing tools.

The pattern MVVM consists in a serie of good practices that me as an experienced developer of it define like this (this could be of course discussed):
  • Sepparate the view from the functionallity that supports itself (this is that we call View)
  • Create a layer that connects business layer and view (which will be called View Model)
  • Finally, create a business layer that HAS NOTHING TO DEAL with the View (as you can think, this is the Model).

MVVM conceptualmente
Forbidden links: from Model is TOTALLY FORBIDDEN connect with the View.

Then, how we can communicate entities from this model? It's very simple:
  • User ONLY communicates with the View.
  • The View communicates ONLY with View Model.
  • The View Model interconnects the View and the Model.
For that, from Visual Studio we must create a Blank Solution and make the following:

We will create a Blank Solution in Visual Studio:

  • Then we must create a new WPF project, the one that will be the View.



  • At this point, we must create a Class Library projec the one that will be the new View Model.



  • Now we must create one or more projects (commonly several), of Class Library type, which will create the Model.



After all, we must have the following project tree:


How to relate them?

  • The View project must reference to the View Model project. Never will have references to the Model.
  • The View Model project will reference to one or several Model projects. It won't have references to View project (or we will have circular references).
  • The Model projects NEVER will reference to the View, and never will reference to the View Model.
With the defined relationships, the communication is only in one direction:
Communication direction due to project references
This communication is good but is not enought because we need mechanisms to inform to the rest of components in the other way. In a newer article I will explain to you a way to personalize events and a simple event manager for Weak Events.

But before doing complex things, in the next article I will explain XAML files and Bindings mechanism, vital for our goals.

I hope you enjoy this small intro and I sincerely want your comments, that will be welcome and from which I will apply as much corrections as I consider.
C# and Developing

domingo, 19 de abril de 2015

How important is not invent the wheel again... Programming Challenge #2

Intended for: C# programmers of all levels


A few days ago I've found a similar code than the above one... I guess that was due to I was very very tired, o because I wasn't expecting a creation like this but, is a fact that I need some seconds (lots of them) in undertand what the hell this code does.

After a conscious analisys finally I understand that it's creator only wants one thing: make a DateTime object that retrieves the current date using the useful DateTime.Now be converted in a string object, to be painted in the screen.

I don't want to blame this guy or it's proffessional capabilities, I don't want to freely complain because I know that EVERYBODY (I'm the first one) make mistakes sometimes at this job. What I want to say is that if we take 3 seconds to surf in Internet, we realize that this is not so far the best way to do this simple thing.

My reasons for this, but there will be million more, are the following:
  1. Each call to DateTime.Now have a useless and stupid additional cost, from the first call to the last one, besides beign small, there will be milliseconds difference between them (in the image you can realize that there are several calls to the functions, you only need to know the Now property).
  2. Concat operator ("+") is the slowest one for strings and is not good to use it for so extense concatenation. For it there is StringBuilder class (one of the tricks that I've learned in the official Microsoft course).
  3. This code is so far away of beign clear. I insist, my more that nine year's experience not allow me to understand it untial a difficult analisys so, a rookie trying to understand it fighting a dragon like this... Our code must be as clear as possible (there's sometimes where the code couldn't be more clear for several reasons.
No doubts about the best way to do this is the following one (people that knows about this realize at first for sure):


Both functions make EXACTLY THE SAME, but the second one is infinitely faster and clear than the first one. This means that in an application than needs a good performance, if we don't care about simple things like this it's possible that the response time will be penalized.

Because of all explained in this article I insist: don't invent the wheel again. The rule of lazy developer that will be explained in a future article must be the one that is with us every day. If we make "science" or "sorcery" like this, is normal that people cames with a crane and deletes our code.

I want feedback from you with similar experiences...

C# and Developing

Support to our dead Windows XP

Intended for: all kind of users


Windows XP maybe will be the best accepted and extended Microsoft's operating system. It's simplicity, easyness and good work if you look to its parents (we all remember the disgusting Millenium Edition...) make XP OS for several guvernamental institutions and for home users a reference for others.




A recent issue that made bleed its home users is that Microsoft announce officially the past 8 if April of 2014 that they won't bring no longer support for it, that means  that from that moment, all XP users are "totally abandoned". The decision is understandable: it's first release was in 25 October of 2001, 13 years ago... and Microsoft brings it's best to support this: it's time to update.

Companies still receiving support (of course, paid), and there's a version of Windows XP that stills having support. That updates are meant to be compatible with the rest of Windows XP versions so... There are people that discovered how to still having support. The source of this is a webpage that I'm a good fan of it NeoTeo (article for trick in Spanish).

Based on my knowledge of it, here you can download a .reg file that is intended to update this value of the Windows Registry and still receiving support for your old Windows XP without advanced knoledges: Windows XP support period extender.

As always, be aware of:
  • The fix is totally for free and you can't pay or be paid for it
  • You can put it on any web site always if you don't forget to put the source of the information (this blog and post) and you don't change the content inside the .reg file inside my web.
  • You're using this under YOUR OWN RESPONSIBILITY
  • I am free of all responsibility for any problem that you would have using it: no viruses, no errors of it's application, no human errors, NOTHING!
  • It's possible that Microsoft changes this in some way, or any of that updates hurts your PC: I'm not responsible of this too.
If you're not agree with the previous, please don't download it and don't use it. To be clear: is not my problem. I bring you this like a gift, my work and my effort and I bring it to you "AS IS". Of course, I will do my best to make my applications free of fails, but we all know that computing science have lots of historical failures that make loose millions of dollars to big companies: obviously a free app can have fails too. If you see error and want to report them, please comment right here.

To use it is enough that you download it to your PC and make double click over the file. It will ask you if you want to add to registry the new entries, click over Yes and restart your PC. With that must be enough to receive again automatic updates.

I hope it will be helpfull for you too!
Windows

lunes, 13 de abril de 2015

How important are comments in source code

Intended for: C# Developers

Comments


Comments are vital in our daily job, because as far as we can see create code for yourself is easy; read code from other developer and understand it is often a hell. Moreover, the added value of the XML comments that Visual Studio provides us: are shown in IntelliSense and help other developers to understand what certain methods do, why you crate some properties, ...

Please, take comments in count before start coding. Often we make confusing things (because of a lack of analisys, or because it's the only way out) which is mandatory to comment it intended for other one, even yourself in a few time, will understand it.

For it we have one line comments...
public void CorkBreadMethod(bool entry)
{
     if (entry)
     {
          //Code if entry is true
     }
}

…useful to bring a fast description of what we want to do.

We can use multiple line comments…
public void CorkBreadMethod(bool entry)
{
     if (entry)
     {
     /* Code if entry is true and loren ipsum when the sun goes
     * down and the moon is dark */

     }
}
… they are usefull when the line is too large and is totally neccesary all the text that we introduced. It is very important take this in account, text must be really neccesary; if not we're making dirty code for the next code reader. Watch section about line lenght.

XML Comments

XML comments are very important because they'll be the best help for the user to undestand better our classes and methods. For use them, Visual Studio provides us an automation: before the class, property or method (over the previous line) declaration we will write three times the slash character /// and automatically will be created the neccesary headers for the XML comment:
/// <summary>
/// Class in charge of beign an example
/// </summary>

class CorkBreadClass
{

}


Previously is an example on how to identificate one class using an XML comment. After do it, outside that class you will see as follows:


/// <summary>
/// Method inside CorkBreadClass
/// </summary>
/// <param name="entry">A boolean that represents the entry</param>
/// <returns>5 if entry is true, 0 elsewhere...</returns>

public int CorkBreadMethod(bool entry)
{
     return entry ? 5 : 0;
}

With previous XML comments we have the following results:



As we can see in previous capture, we get back all the previous information inside XML comments, so we gain that people that don't know too much our code or not have access to the source can understand what happend inside.
C# and Developing

 

Friendly Websites:

  • Manuel Enrique Díaz Rodríguez
  • CuRadio
  • Copyright © DotNet Pathways 2015
    Distributed By My Blogger Themes | Designed By Templateism