Topic
  • 1 reply
  • Latest Post - ‏2013-12-05T19:55:43Z by thartric
thartric
thartric
10 Posts

Pinned topic Dec 5th Forums Test II

‏2013-12-05T19:55:04Z |

trying some code formatting


using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using DOORSCOMLib; using System.Runtime.InteropServices; using System.ComponentModel; using System.Security.Permissions; namespace ConnectDoorsServers 
{ 
/// To use the class in DOORS you need to generate a type library from this dll and put it next to the door.exe, probably some other way of doing it via GAC 
/// I have a post build event that runs the following line, this also registers the dll and gives it a GUID 
/// regasm "D:\Visual Studio 2008\Projects\ConnectDoorsServers\ConnectDoorsServers\bin\Release\ConnectDoorsServers.dll" /tlb:"C:\Program Files\IBM\Rational\DOORS\9.2\bin\ConnectDoorsServers.tlb" 
///  
///You can use the following DXL to test its working 
/////initiate my dll - note that type library has to be registered and installed next to doors.exe 
/////might want to use this as an executable if possible to get around the issue 
///OleAutoObj conDoorsServerTool = oleCreateAutoObject("ConnectDoorsServers.ControlDoors") 
///string testStr  
///oleGet(conDoorsServerTool, "test", testStr) 
///print testStr 
///oleCloseAutoObject(conDoorsServerTool) 
/// </summary>     
/// <summary> 
/// This needs to have an interface and a delegate we can subscribe to in dxl ideally we want to raise and recieve events from the  
/// .net system we are building - doubt this will work, worth a little experiment though  
/// may have to poll the results in dxl using oleSetResult command and poll it here by looking at the DoorClass.Result property or standardout of process 
/// </summary> 
//[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] 
//public interface IFinishedProcessing  
//{ 
// void OnFinishing(string finishMessage) 
//} 
/// <summary> 
/// Methods exposed to doors here 
/// </summary> 

public 

interface IControlDoors 
{ string test 
{ get; 
} 

void firstConnect(); 
}       
//public delegate void FinishingDelegate(string finishMessage);     
/// <summary> 
/// Need to be able to establish one or more connections and sendxl between them, we also need to be able to connect to already running instances 
/// Need to be able to wait for dxls to be ran and accept back statuses, standard outs, data structures etc 
/// not sure dll referenced by doors is best way forward 
/// </summary> [ClassInterface(ClassInterfaceType.None)]
//,ComSourceInterfaces("IFinishedProcessing")] 

public 

class ControlDoors : IControlDoors 
{ 
/// <summary> 
/// Constructor need to do something 
/// </summary> 

private Process firstDatabase; 

public ControlDoors() 
{ System.Windows.Forms.MessageBox.Show(
"I am Working"); 
//firstConnect(); 
} 

public string test 
{ get 
{ 

return 
"just a test"; 
} 
}   

public 

void firstConnect() 
{     
// Get all instances of doors running on the local computer. this works when debugged from another project but not when 
//compiled into a dll and not from DOORS! Why? Process[] doorsProcArray = Process.GetProcessesByName(
"doors"); 

if (doorsProcArray.Length.Equals(0)) 
{ System.Windows.Forms.MessageBox.Show(
"This dll should only be loaded from doors"); 
} 

else 

if (doorsProcArray.Length.Equals(1)) 
{ firstDatabase = doorsProcArray[0]; System.Windows.Forms.MessageBox.Show(
"Working correctly in debug mode"); 
} 

else 
{ System.Windows.Forms.MessageBox.Show(
"More than one doors process running, don't know how to get right one"); 
}   
//get the correct doors process 
//Fire the event out 
//push the dxl to the process 
//wait for the event to occur 
//trouble is we are firing the event from here the way I have done it, need to fire the event from DOORS and handle it here 
//try again with brain inserted.     
//need to cast the process into doors com lib class or get it off the process somehow 
//dlls can't be static, not what they do can only poll the other DOORS processes, this is not a dll task I guess. 
//DOORSClass d = (DOORSCOMLib.DOORSClass); 
//d.runStr("print \"Have we found the parent process\""); 
}     
} 
/// <summary> 
/// Pinched from internet should be in seperate class, could consider using ntdll from inside DOORS 
/// </summary> [StructLayout(LayoutKind.Sequential)] 

public struct ParentProcessUtilities 
{ 
// These members must match PROCESS_BASIC_INFORMATION internal IntPtr Reserved1; internal IntPtr PebBaseAddress; internal IntPtr Reserved2_0; internal IntPtr Reserved2_1; internal IntPtr UniqueProcessId; internal IntPtr InheritedFromUniqueProcessId;   [DllImport(
"ntdll.dll")] 

private 

static extern 

int NtQueryInformationProcess(IntPtr processHandle, 

int processInformationClass, ref ParentProcessUtilities processInformation, 

int processInformationLength, out 

int returnLength);   
/// <summary> 
/// Gets the parent process of the current process. 
/// </summary> 
/// <returns>An instance of the Process class.</returns> 

public 

static Process GetParentProcess() 
{ 

return GetParentProcess(Process.GetCurrentProcess().Handle); 
}   
/// <summary> 
/// Gets the parent process of specified process. 
/// </summary> 
/// <param name="id">The process id.</param> 
/// <returns>An instance of the Process class.</returns> 

public 

static Process GetParentProcess(

int id) 
{ Process process = Process.GetProcessById(id); 

return GetParentProcess(process.Handle); 
}   
/// <summary> 
/// Gets the parent process of a specified process. 
/// </summary> 
/// <param name="handle">The process handle.</param> 
/// <returns>An instance of the Process class.</returns> 

public 

static Process GetParentProcess(IntPtr handle) 
{ ParentProcessUtilities pbi = 

new ParentProcessUtilities(); 

int returnLength; 

int status = NtQueryInformationProcess(handle, 0, ref pbi, Marshal.SizeOf(pbi), out returnLength); 

if (status != 0) 

throw 

new Win32Exception(status);   

try 
{ 

return Process.GetProcessById(pbi.InheritedFromUniqueProcessId.ToInt32()); 
} 

catch (ArgumentException) 
{ 
// not found 

return 

null; 
} 
} 
} 
}
  • thartric
    thartric
    10 Posts

    Re: Dec 5th Forums Test II

    ‏2013-12-05T19:55:43Z  

    Seems to work