Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Saturday, 21 May 2011

ModuleSettings and TabModuleSettings Difference in DotNetNuke

If you do not like to read preambula and want to know what is the difference between ModuleSettings and TabModuleSettings, then you can read it here.

Have been worked with it for a long time. Also asked a lot of DotNetNuke gurus, but they did not provide concrete answer about difference between ModuleSettings and TabModuleSettings. In generally it looks the same. For example, we have Settings.ascx. Inside we save some settings, for example Template. So our code should be like this:

Sunday, 8 May 2011

Create User Programmatically in DotNetNuke

One colleague asked about example on how to create user in DotNetNuke programmatically. Here is simple example on C# how to do this:

Saturday, 7 May 2011

Custom Event In The Custom Control

It is good rule to add Custom Events in the Custom Controls you build. It allows easy to use your control from the external code without any problems.

How to add Custom Event? Very easy, just add this code to your class:


// delegate declaration

public delegate void ChangingHandler(object sender);

// event declaration

public event ChangingHandler OnDoFilter;

// this one is to call event

private
void FireOnDoFilter(object sender)
{
  if (OnDoFilter != null)
  {
    OnDoFilter(sender);
  }
}


Custom Events are easy to create and easy to use. Lets use it!

Hope this helps!

Friday, 6 May 2011

DotNetNuke Telerik Editor ToolBars

Each DotNetNuke developer can easy add RichEditor to the project. All what you need is to add control to your .ascx file, like this:


<%@ Register TagPrefix="dnn" TagName="TextEditor" Src="~/controls/TextEditor.ascx" %>

<dnn:TextEditor runat="server" id="tbFirst" DefaultMode="BASIC"></dnn:TextEditor>
<dnn:TextEditor runat="server" id="tbSecond" DefaultMode="RICH"></dnn:TextEditor>


This code adds two  RichEditors. One like simple textbox (DefaultMode="BASIC") and another fully WYSIWYG . RichEditor with WYSIWYG looks like this:

This is great! Users like it to use. It has a lot of ToolBars. Control provides very good functionality. But sometimes it needs to remove some ToolBars. So how to do this in the DotNetNuke module?

Tuesday, 3 May 2011

JavaScript Object: Properties and Methods

Sometimes it needs to get list of Properties and Methods of the JavaScript Object. Its very easy to do with code like this::

var keysValues = "";
for(var keyName in myObject)
{
    keysValues += keyName + " = " + myObject[keyName] + ", ";
}
alert(keysValues);

This code shows list of all Properties and Methods of myObject.

Hope this helps!

Friday, 22 April 2011

Create new page for DotNetNuke in background

Prehistory:
Some customers need to create a lot of pages at one time. This is why "Bulk Pages Creation" has been added to the Pages Admin - Tabs Manager. But few days ago one customer submitted bug. He tried to create about 500 pages in bulk. Less then 100 have been created, but other have been failed. Problem is httpRuntime executionTimeout in the web.config has small time and after 90 seconds (default value) it fails.

History:

Tuesday, 19 April 2011

How to add break to the ModuleActions for DotNetNuke module

Sometimes in the module for DotNetNuke there are a lot of Actions, like this:


It is not good for usability. Would be better to group items somehow with small breaks between Actions in the list, like this:
As you see breaks between items in the menu makes it more user friendly and grouped. it is very easy to add breaks like this, just need to pass special character "~" for Title for ModuleAction object. Here is example of code (C#):


Actions.Add(GetNextActionID(),
"Suppliers",
DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent,
"", "", EditUrl("Currency"), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);


Actions.Add(new DotNetNuke.Entities.Modules.Actions.ModuleAction(GetNextActionID(), "~", ""));


Hope this helps!

Sunday, 27 March 2011

How to upgrade DotNetNuke module or SQL scripts for new versions

DotNetNuke (DNN) is very good CMS. It allows easy and fast build new modules without any problems. Furthermore it allows to do an upgrade of old modules with beautiful and perfect process. For example, we have Module with version 01.00.00. During installation all SQL scripts locate in the 01.00.00.SqlDataProvider. This file contains all required SQL for correct Module functionality.

In case you need to upgrade your module, then all what you do is add to your module new file, like 01.00.01.SqlDataProvider. During installation DNN framework checks current version and runs all scripts above current version. It allows to do cumulative upgrade without any problems.

But some clients do an upgrade manually and it can be a lot of headache. So here is a way how to protect your SQL script:

IF(
NOT EXISTS(
SELECT sc.name 
FROM syscolumns sc
WHERE (sc.id IN 
(SELECT so.id
FROM sysobjects so
WHERE so.name='{objectQualifier}Survey'))
AND
(sc.name='CategoryID')
)
)
BEGIN
ALTER TABLE {databaseOwner}{objectQualifier}Survey ADD CategoryID int NOT NULL DEFAULT(0)
END

As you see, this script checks for field before creation. So, do not need to worry customer runs it twice or more times.

PS: My old teacher said: Good code allows to remove half of lines and continues to work :)

Saturday, 26 March 2011

Recursive references in the projects

This is the most stupid thing i have ever seen in development. Few years ago there was a project from the client. Project was live already and required some major changes for it. Customer sent me a source and once i started to work, i found about 5 recursive references like: project1 references to the project2 and project2 references to the project1. This is very big problem with development, it means something wrong with architecture. I have moved required methods to the separate project and it fixed 4 recursive references. But 1 recursive reference still exists. This issue did not allow to compile project. Fix was easy: need to set in the properties of the reference "Copy Local" = false.

Hope this helps!

Friday, 25 March 2011

No processes to attach in Visual Studio

Usually to debug projects for DotNetNuke i attach to the aspnet_wp.exe process. Its very good way on how to debug modules for DotNetNuke. But sometimes there was big confuse. Once i opened list of processes to connect i got it empty. It confused me, how it can be?

After deep debugging problem has been found.Source of problem is frozen processes IEXPLORE. Once i killed them in Task Manager and restarted IIS, everything goes back and i can attach to process for Debugging.

Hope this helps!

Thursday, 24 March 2011

How to send POST in background

Sometimes it needs to send POST in the background and get some info. In our case we had to send POST to the Protx (UK payment gateway - now its SagePay). Here is quick C# script how to do this:


private string ChargeProtx(CreditCardInfo objCardInfo)
{
    System.Net.HttpWebRequest request = 
(System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create("https://ukvpstest.protx.com/VSPSimulator/VSPDirectGateway.asp");


    request.Method = "POST";
    
string postData = "VPSProtocol=2.22&" +
"TxType=PAYMENT&" +
"Vendor=vendorname&" +
"VendorTxCode=" + objCardInfo.OrderID + "&" +
"Amount=" + objCardInfo.Amount.ToString().Replace(",",".")+"&"+
"Currency=GBP&" +
"Description=Direct_payment&" +
"CardHolder=" + objCardInfo.FirstName + " " + objCardInfo.LastName + "&" +
"CardNumber=" + objCardInfo.Number + "&";


    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
    request.ContentLength = byteArray.Length;
    System.IO.Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();


    System.Net.HttpWebResponse responseX = (System.Net.HttpWebResponse) request.GetResponse();
    dataStream = responseX.GetResponseStream();
    System.IO.StreamReader reader = new System.IO.StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();


    reader.Close();
    dataStream.Close();
    responseX.Close();


return responseFromServer;
}

Hope this helps!

Wednesday, 23 March 2011

How to insert one DNN module into another

This is not common task between different modules. But it is good to use controls inside of single project and this is very popular. So, to add one module to another you just need to know name of the primary control. Then your form will be like this:
<%@ Register TagPrefix="dnn" TagName="MultiEdit" Src="~/DesktopModules/dnn.MultiEdit/MultiEdit.ascx" %>
<dnn:multiedit id="objMultiEdit" runat="server"></dnn:multiedit>

Hope this helps!

How to rotate SQL Table

There was very good customer from Australia. He always had interesting projects. One of this project was to show report on products sales. At start it looks like simple project, but there were two issues:
1) Customer had very big amounts of data in MS SQL.
2) He would like to show data grouped in columns, not rows.

First version of project does grouping in the columns at the C# code, but with such big amount of data it was crazy slow and takes a lot of memory. This is why grouping has been moved to the MS SQL side. Here is a beautiful script (sorry, but can't remember original source):

Strip non word or sanitizing text in DotNetNuke

Sometimes in DotNetNuke we would like to prepare some text to the sanitized form. This is very common task for preparing FriendlyUrls. I would like to recommend to use core DNN method:

public static string StripNonWord(string HTML, bool RetainSpace)
Member of DotNetNuke.Common.Utilities.HtmlUtils

It allows to remove not only spaces, but also all non-URL characters.

BTW: This function used in Core DNN on Tabs updating.

Hope this helps!

Tuesday, 22 March 2011

Blocked references in Visual Studio

Sometimes, when you try to compile project for DotNetNuke in Visual Studio it can not to do this. Error says: can't rebuild, because .dll of the project is locked. Sometimes it was real headache for me, because was really unexpected and unusual. First time i thought its problem with IIS, but later i found its problem with Visual Studio references. So, there are 4 steps to fix this issue:

1) Remove all references from your project (or whole solution). Try to rebuild - it shows errors, because can't find references.
2) Close Visual Studio.
3) Open solution and add all references.
4) Rebuild solution. It works now.

Hope this helps.

Let me introduce myself

My name is Sergey. I am developer from the prehistoric times. It starts a lot of years ago, when computers were big and slow and continues until today. For this long period i have got great experience: machine codes, Assembler, Basic, Fortran, C, Pascal, Prolog, later Delphi, VB, C++, C#, Java, PHP, Perl and sure databases DBase, Paradox, FoxPro, MSSQL, MySQL, PostGre...Really it should take a lot of time to describe everything.

Since 2002 i develop for Web. More then 75% of my projects are DotNetNuke oriented. DotNetNuke (DNN) is great Content Management System and this is good to work with this product and community. But DNN is not my single priority. Also a lot of requests from customers on synchronizing data between different products. There were some projects for NopCommerce, Magento, OpenErp, OpenBravo Pos.

This work is good. It allows me to work remotely with different customers from around the world. Thats great opportunity and very good experience!