Thursday, November 28, 2013

Changing Domain Name on your PrestaShop install

If you are moving PrestaShop to a different domain, or switching from server pathways to your domain name, then you must update PrestaShop with the new domain name. This article explains what changes need to carried out.

UPDATING YOUR DATABASE
Log into cPanel, then go to "PHPMyAdmin" and log into your PrestaShop database. Go to the table "ps_configuration" and locate the records for PS_SHOP_DOMAIN and PS_SHOP_DOMAIN_SSL. Change these to the new domain name. Check the configuration table for any other entries that contain the old domain name and change accordingly.

SELECT * FROM ps_configuration WHERE name LIKE '%domain%'

Go to Admin Page
Go to Admin page > Advanced Parameters > Multistore > Canada > Actions > Edit:

Domain: ca.webstore.local
Domain SSL: ca.webstore.local
Physical URL: /
Virtual URL: store/

Repeat the same steps with USA store.

UPDATING YOUR CONFIG SETTINGS
Via FTP or the file manager in cPanel, modify the PHP file /config/settings.inc.php. Look for the entry for PS_BASE_URI__ and modify as necessary. For a shop located in the root, it should read:

define('__PS_BASE_URI__', '/');

UPDATING SEO-FRIENDLY URLS
Delete (or rename) the .htaccess file on your site.

In our PrestaShop admin, you now need to re-generate the SEO URLs with the new domain name. Log into your PS admin, then go to "tools->generate->generate .htaccess".

ENABLING SSL
If your site has a full SSL Certificate, then you can also enable this via your PS admin under "Preferences page -> Enable SSL: Yes".

Please note that PrestaShop won't work with our Shared SSL as the SEO URLs rewrite rules don't work with the server paths. For PS shops, you either need to have a Dedicated IP & your own Full SSL Certificate or you need to disable SSL.

Reference:
https://support.terranetwork.net/web/knowledgebase/125/Changing-Domain-Name-on-your-PrestaShop-install.html

How to reset the PrestaShop admin password

GET YOUR _COOKIE_KEY_
Log into your site's cPanel and go to "File Manager"
Open /config/settings.php and copy the _COOKIE_KEY_ value
In the same file, check the database name in use for your PS install. The name will show as the value of "_DB_NAME_"

CHECK YOUR DATABASE
In your site's cPanel, go to PHPMyAdmin and open the database for your PrestaShop install
Look for a table called "employee" or if you are using prefixes, "ps_employee"
Check what email address is being used for your login in this table

RESET PASSWORD

1. Still in the database, go to "SQL" at the top and run the following query, where you replace the $VAR with the correct information

UPDATE employee SET passwd = md5(concat('$COOKIE_KEY', '$PASSWORD'))
WHERE email = "youremailaddress";

2. If your PrestaShop install uses table prefixes such as "ps_", amend the command to include the prefix:

UPDATE ps_employee SET passwd = md5(concat('$COOKIE_KEY', '$PASSWORD'))
WHERE email = "youremailaddress";

Wednesday, November 27, 2013

SERIAL PORT BUFFERING C#.NET

SERIAL PORT BUFFERING C#.NET
ШАБЛОНЫ САЙТОВ ОНЛАЙН-МАГАЗИНЫ
ФАЙЛОВЫЕ МЕНЕДЖЕРЫ JOOMLA
In this article Serial Port buffering is explained. How to receive the serial port data without any loss if incoming data stream flow into seperate triggers is realized using c#.

Serial data flow through RS-232/RS-485/RS-422 has nothing to do with ‘packets’. It’s just a stream of bytes in and out. There is no guarantee that data arrives together. Data may come seperate triggers

Communication using Serial Port often used on monitoring the incoming data coming from electronic device that is designed on the bench, Commercial Off The Shelf device that we purchase for the use of as a part of our project, or electronic test instrument communication interface.

Since the bytes may come to computers Serial Port Communication Hardware(Serial Port of the Computer) in at any time, buffering the incoming data is important for not loosing any byte. For example, you may send a command out to your device, and the response back to the PC could trigger a single DataReceived event with all the 15 bytes of response data in the receive buffer. Or more likely, it could be any number of separate triggers of the DataReceived (up to the number of bytes received), like 4 triggers, first with 2 bytes, then 15 bytes, then 1 byte, then 12 bytes.

In the above case, someone do not know when will the complete response is completed. At this point buffering the data plays an important role on not loosing the incoming data. This is known as Serial Port Buffering.
Istead of looking a complete response in a single DataReceived Event to be finished by the sender one may follow the following rule to catch the data

1. buffer the incoming data
2. then scan your buffer to find complete data
3. remove the used data from the buffer

public void serialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Use either the binary OR the string technique (but not both)
// Buffer and process binary data
while (com.BytesToRead > 0)
bBuffer.Add((byte)com.ReadByte());
ProcessBuffer(bBuffer);

// Buffer string data
sBuffer += com.ReadExisting();
ProcessBuffer(sBuffer);
}

private void ProcessBuffer(string sBuffer)
{
// Look in the string for useful information
// then remove the useful data from the buffer
}

private void ProcessBuffer(List<byte> bBuffer)

{
// Look in the byte array for useful information
// then remove the useful data from the buffer
}
The above code samples catches all the data coming out of the device.

To make clear the buffering, follow the example case below:

Let us assume that we have connected the serial port of the PC to the external harware to communicate.We send a command byte [] cmd = new byte[]{command CRC} and expect a response as byte[]{messageLength b1 b2 b3 b4 b5 b6 b7 b8 b9 CRC}(here a messageLength is 11). And assume also that the response arrives to the PCs serial port into 5 seperate triggers as ;

fisrt trigger:messageLength b1 b2
second trigger:b3 b4
third trigger:b5 b6
fourth trigger:b7 b8
fifth trigger:b9 CRC

Here are the stpes to be followed to communicate the serial port device
1.Send the command message to the serial port device, serialport.send(cmd)
2.wait for the response using following code

public void seriport_DataAvailable(object sender, EventArgs e)
{
while (((SerialPort)sender).BytesToRead > 0)
{
serialPortReceivedData = new byte[((SerialPort)sender).BytesToRead];
((SerialPort)sender).Read(serialPortReceivedData, 0, serialPortReceivedData.Length);
bBuffer.AddRange(serialPortReceivedData);
if (bBuffer[0] == bBuffer.Count)
{
//send the response to the listeners
bBuffer.Clear();
break;
}
}
}

http://www.miltest.com/articles/application-notes/59-serial-port-buffering-csharp.html

Saturday, November 23, 2013

send string key to a textbox in WPF

TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, mybox, "Hello World"));

send keystroke in WPF

lb.Focus();

InputManager.Current.ProcessInput(
  new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Down)
  {
    RoutedEvent = Keyboard.KeyDownEvent
  }
);

Friday, November 22, 2013

To get or set the position of a textbox or a button in WPF

To get the position of a textbox or a button

Point p2 = mybox.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0))

Debug.WriteLine("here: " + p2.X + ", " + p2.Y);

To set the position of a canvas:
Canvas c = new Canvas();
c.Margin = new Thickness(X, Y, 0, 0);

To set the position of a button within a canvas:
Button b = new Button();
b.Content = "asdf";
b.Width = 50;
b.Height = 22;
b.Click += new RoutedEventHandler(b_Click);
c.Children.Add(b);

Canvas.SetLeft(b, 20);
Canvas.SetTop(b, 40);

private void b_Click(object sender, RoutedEventArgs e) {
Debug.WriteLine("good");
}

Thursday, November 21, 2013

Get Absolute Position of element within the window in wpf

You have to specify window you clicked in Mouse.GetPosition(IInputElement relativeTo) Following code works well for me
protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        base.OnMouseDown(e);
        Point p = e.GetPosition(this);
        MessageBox.Show(p.ToString());
    }
I suspect that you need to refer to the window not from it own class but from other point of the application. In this case Application.Current.MainWindow will help you.

Reference:
http://stackoverflow.com/questions/386731/get-absolute-position-of-element-within-the-window-in-wpf

Wednesday, November 20, 2013

Dynamically Loading XAML in WPF

Dynamically Loading XAML in WPF

Loading XAML at run time is really simple. I wrote a small sample to load the XAML at run time and than attach the event handler with the XAML object. I created following XAML page and copied it to the debug folder.
<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1">
    <Grid>
        <Button Margin="0,0,9,38" Name="button1" Height="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="132">Button</Button>
    </Grid>
</Page>
and here is the C# code
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            LoadXAMLMethod(); 
        }

        Button ButtoninXAML;
        public void LoadXAMLMethod()
        {
            try
            {
                StreamReader mysr = new StreamReader("Page1.xaml");
                DependencyObject rootObject = XamlReader.Load(mysr.BaseStream) as DependencyObject;
                ButtoninXAML = LogicalTreeHelper.FindLogicalNode(rootObject, "button1") as Button ; 
                ButtoninXAML.Click += new RoutedEventHandler(Button_Click); 
                this.Content = rootObject;
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show(ex.Message.ToString());    
            }
        }
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Hi WPF");  
        }
    }
}
do not forget to add following namespaces.

using System.IO;
using System.Windows.Markup;

Reference:
http://blogs.msdn.com/b/ashish/archive/2007/08/14/dynamically-loading-xaml.aspx

Tuesday, November 5, 2013

C# cannot locate resource imagesource

C# cannot locate resource imagesource

pack://siteoforigin:,,,/Subfolder/test.png

pack://siteoforigin:,,,/SomeAssembly;component/ResourceFile.xaml

http://msdn.microsoft.com/en-us/library/aa970069.aspx
http://stackoverflow.com/questions/12982889/cannot-locate-resource

Determine the mime type of a file based on the file header signatures not the extension

Most image file formats have unique bytes at the start. The unix file command looks at the start of the file to see what type of data it contains.

http://en.wikipedia.org/wiki/List_of_file_signatures
http://magicdb.org/

A comprehensive site of file formats is available at:
http://www.wotsit.org

If you're using .NET Framework 4.5 or above, there is a now a MimeMapping.GetMimeMapping(filename) method that will return a string with the correct Mime mapping for the passed filename.

Documentation is at http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping

Windows DLL Urlmon.dll is capable of determining the MIME type of a given data stored in memory, considering the first 256 bytes of the byte array, where such data is stored.

http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature?rq=1
http://stackoverflow.com/questions/15300567/alternative-to-findmimefromdata-method-in-urlmon-dll-one-which-has-more-mime-typ/15595571#15595571
http://stackoverflow.com/questions/52739/is-there-a-way-to-infer-what-image-format-a-file-is-without-reading-the-entire

Monday, November 4, 2013

two-tier

Refers to client/server architectures in which the user interface runs on the client and the database is stored on the server. The actual application logic can run on either the client or the server. A newer client/server architecture, called a three-tier architecture introduces a middle tier for the application logic.

http://www.webopedia.com/TERM/T/two_tier.html

three-tier

A special type of client/server architecture consisting of three well-defined and separate processes, each running on a different platform:

1. The user interface, which runs on the user's computer (the client).
2. The functional modules that actually process data. This middle tier runs on a server and is often called the application server.
3. A database management system (DBMS) that stores the data required by the middle tier. This tier runs on a second server called the database server.

The three-tier design has many advantages over traditional two-tier or single-tier designs, the chief ones being:

  • The added modularity makes it easier to modify or replace one tier without affecting the other tiers.
  • Separating the application functions from the database functions makes it easier to implement load balancing.
  • Refers to client/server architectures in which the user interface runs on the client and the database is stored on the server. The actual application logic can run on either the client or the server. A newer client/server architecture, called a three-tier architecture introduces a middle tier for the application logic.


http://www.webopedia.com/TERM/T/three_tier.html