2012-07-20 03:47:54 +04:00
//
// Copyright (c) 2012 Virtual Cable S.L.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Virtual Cable S.L. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// author: Adolfo Gómez, dkmaster at dkmon dot com
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Windows.Forms ;
namespace UdsAdmin.forms
{
public partial class AuthenticatorForm : Form
{
string _id ;
xmlrpc . GuiField [ ] _flds ;
xmlrpc . GuiFieldValue [ ] _fldValues ;
string _authenticatorName ;
string _authenticatorType ;
2013-02-27 16:16:08 +04:00
System . Text . RegularExpressions . Regex smallNameRe ;
2012-07-20 03:47:54 +04:00
public AuthenticatorForm ( string providerName , string providerType , Icon icon )
{
InitializeComponent ( ) ;
_fldValues = null ;
_id = null ;
_flds = null ;
_authenticatorName = providerName ;
_authenticatorType = providerType ;
Icon = icon ;
Text = Strings . titleAuthenticator ;
2013-02-27 16:16:08 +04:00
smallNameRe = new System . Text . RegularExpressions . Regex ( "^[A-Za-z0-9_:.-]+$" ) ;
2012-07-20 03:47:54 +04:00
}
2013-02-27 16:16:08 +04:00
public void setData ( string name , string comments , string id , string smallName , xmlrpc . GuiFieldValue [ ] data )
2012-07-20 03:47:54 +04:00
{
this . name . Text = name ;
this . comments . Text = comments ;
2013-02-27 16:16:08 +04:00
this . smallName . Text = smallName ;
2012-07-20 03:47:54 +04:00
this . _id = id ;
this . priority . Value = Convert . ToInt32 ( xmlrpc . GuiFieldValue . getData ( data , "priority" ) ) ;
_fldValues = data ;
}
private void Authenticator_Load ( object sender , EventArgs e )
{
_flds = xmlrpc . UdsAdminService . GetAuthenticatorGui ( _authenticatorType ) ;
Size sz = gui . DinamycFieldsManager . PutFields ( dataPanel , _flds , _fldValues ) ;
2013-02-27 16:16:08 +04:00
if ( sz . Width < groupData . Size . Width )
sz . Width = groupData . Size . Width ;
2012-08-20 08:55:14 +04:00
groupData . Size = new Size ( sz . Width , 32 + sz . Height ) ;
2012-07-20 03:47:54 +04:00
Size wSize = new Size ( ) ;
wSize . Width = Size . Width ;
2012-08-20 08:55:14 +04:00
int w = groupData . Location . X + groupData . Size . Width + 48 ;
if ( wSize . Width < w )
wSize . Width = w ;
2012-07-20 03:47:54 +04:00
wSize . Height = groupData . Location . Y + tableLayoutPanel1 . Size . Height + groupData . Size . Height + 48 ;
Size = MinimumSize = MaximumSize = wSize ;
if ( _flds . Length = = 0 )
groupData . Visible = false ;
Text = _authenticatorName ;
2012-08-20 08:55:14 +04:00
this . Location = MainForm . centerLocation ( this ) ;
2012-07-20 03:47:54 +04:00
//this.Location = System.Windows.Forms.Cursor.Position;
}
private void accept_Click ( object sender , EventArgs e )
{
if ( name . Text . Trim ( ) . Length = = 0 )
{
gui . UserNotifier . notifyError ( Strings . nameRequired ) ;
return ;
}
2013-02-27 16:16:08 +04:00
2013-04-03 03:11:49 +04:00
/ * if ( smallName . Text . Trim ( ) . Length = = 0 )
2013-02-27 16:16:08 +04:00
{
Random rnd = new Random ( ) ;
string str = "" ;
for ( int i = 0 ; i < 8 ; i + + )
str + = ( char ) ( 'A' + rnd . Next ( 0 , 26 ) ) ;
smallName . Text = str ;
2013-04-03 03:11:49 +04:00
} * /
2013-02-27 16:16:08 +04:00
if ( smallNameRe . IsMatch ( smallName . Text ) = = false )
{
gui . UserNotifier . notifyError ( Strings . smallNameRequired ) ;
return ;
}
2012-07-20 03:47:54 +04:00
xmlrpc . GuiFieldValue [ ] data ;
try {
data = gui . DinamycFieldsManager . ReadFields ( dataPanel , _flds ) ;
}
catch ( gui . DinamycFieldsManager . ValidationError err )
{
gui . UserNotifier . notifyValidationException ( err ) ;
return ;
}
try {
if ( _id = = null )
2013-02-27 16:16:08 +04:00
xmlrpc . UdsAdminService . CreateAuthenticator ( name . Text , comments . Text , _authenticatorType , Convert . ToInt32 ( priority . Value ) , smallName . Text , data ) ;
2012-07-20 03:47:54 +04:00
else
{
2013-02-27 16:16:08 +04:00
xmlrpc . UdsAdminService . ModifyAuthenticator ( name . Text , comments . Text , Convert . ToInt32 ( priority . Value ) , _id , smallName . Text , data ) ;
2012-07-20 03:47:54 +04:00
}
DialogResult = System . Windows . Forms . DialogResult . OK ;
}
catch ( CookComputing . XmlRpc . XmlRpcFaultException ex )
{
gui . UserNotifier . notifyRpcException ( ex ) ;
}
}
private void test_Click ( object sender , EventArgs e )
{
try
{
xmlrpc . GuiFieldValue [ ] data = gui . DinamycFieldsManager . ReadFields ( dataPanel , _flds ) ;
xmlrpc . ResultTest res = xmlrpc . UdsAdminService . TestAuthenticator ( _authenticatorType , data ) ;
gui . UserNotifier . notifyTestResult ( res ) ;
}
catch ( CookComputing . XmlRpc . XmlRpcFaultException ex )
{
gui . UserNotifier . notifyRpcException ( ex ) ;
}
catch ( gui . DinamycFieldsManager . ValidationError ex )
{
gui . UserNotifier . notifyValidationException ( ex ) ;
}
}
}
}