AgentManager.cs :  » SQL-Clients » Database-Commander » YariSoft » Utils » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » SQL Clients » Database Commander 
Database Commander » YariSoft » Utils » AgentManager.cs
using System;
using System.Windows.Forms;

namespace YariSoft.Utils{
  public class AgentManager
  {  
    #region Local variables
    private System.Drawing.Point        _defaultPosition= new System.Drawing.Point (Screen.PrimaryScreen.Bounds.Width - 150, Screen.PrimaryScreen.Bounds.Height - 180 );
    private AgentInfo              _info      = null;
    private AgentServerObjects.IAgentCharacter  _agent      = null;
    private AgentServerObjects.IAgentEx      _server      = null;
    private int                  characterID    = 0;
    #endregion
    
    #region Properties
    public AgentServerObjects.IAgentCharacter Character
    {
      get{ return this._agent; }
    }
    #endregion

    #region Constructor/Destructor
    public AgentManager()
    {
    }
    #endregion

    #region Public functions
    public bool Init( AgentInfo  Info, bool ActivateOperations )
    {
      this._info = Info;
      try{
        if( Info.AgentActive ){
          this._server = ( AgentServerObjects.IAgentEx )new AgentServerObjects.AgentServerClass();
          int pdwReqID;
          this._server.Load( null, out this.characterID, out pdwReqID);
          
          object ptrAgent;
          this._server.GetCharacter ( this.characterID, out ptrAgent );
          this._agent = (( AgentServerObjects.IAgentCharacterEx )ptrAgent);
          if( ActivateOperations ){
            this.Show();
          }
        } else {
          if( ActivateOperations ){
            this.Hide();
          }
        }
      }catch{
        return false;
      }
      return true;
    }

    public bool Init( AgentInfo  Info )
    {
      return this.Init( Info, false );
    }

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
     static extern IntPtr FindWindow( int ClassName, string WinCaption ); 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    static extern bool SetForegroundWindow( IntPtr WinHandle ); 

    public void ShowProperties ()
    {
      if( this._server != null ){
        this._agent.StopAll( 0xFFFFFFF );
        this._server.ShowDefaultCharacterProperties ( (short)( Screen.PrimaryScreen.Bounds.Width / 2 ), 
                                (short)( Screen.PrimaryScreen.Bounds.Height / 2 ), 
                                 0 );

        IntPtr ptr = FindWindow ( 0, "Character Properties" );
        if( ptr.ToInt32() != 0 ){
          SetForegroundWindow ( ptr );
        }
      }
    }

    public void Show ()
    {
      if( this._agent != null ){
        int pdwReqID;
        this._agent.SetPosition( _defaultPosition.X, _defaultPosition.Y );
        this._agent.Show( 0, out pdwReqID );
        this.Play( Utils.AgentPlayer.MovieTypeEnum.Start );
      }
    }

    public void Hide()
    {
      if( this._agent != null ){
        int pdwReqID;
        this.Play( Utils.AgentPlayer.MovieTypeEnum.Stop );
        this._agent.Hide  ( 0, out pdwReqID );
        this._agent = null;
        this._server.Unload ( this.characterID );
        this._server = null;
      }
    }

    public void Play( Utils.AgentPlayer.MovieTypeEnum MovieType )
    {
      if( this._agent != null && this._info.ConfigFileName != "" ){
        if( MovieType == Utils.AgentPlayer.MovieTypeEnum.DefPosition ){
          int LeftPos;
          int TopPos;
          this._agent.GetPosition ( out LeftPos, out TopPos );
          if( LeftPos != _defaultPosition.X || TopPos != _defaultPosition.Y ){
            AgentMovie movie = new AgentMovie( "Untitled" );
            movie.AddOperation( new AgentOperation ( AgentOperation.OperationTypeEnum.MoveTo, _defaultPosition ));
            AgentPlayer agentPlayer = Utils.AgentPlayer.LoadFromFile( this._info.ConfigFileName );
            agentPlayer.Play( movie, this.Character );
          }
        }else{
          AgentPlayer agentPlayer = Utils.AgentPlayer.LoadFromFile( this._info.ConfigFileName );
          agentPlayer.Play( MovieType, this.Character );
        }
      }
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.