initial oogynize check in _ this actually used to work!

This commit is contained in:
2016-02-14 21:16:31 -08:00
parent b183af5d55
commit 532ea133bc
337 changed files with 30692 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Platform.Win32;
namespace Foo.WorkspaceMgr.Closers
{
internal class Closer_Generic : IClose
{
#region IClose Members
/// <summary>
/// Sends a WM_QUERYENDSESSION to the Window that the Artifact Belongs To
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryClose(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
// To Do: Must get hWnd From RAT
IntPtr hWnd = IntPtr.Zero;
if (Win32Functions.SendMessage(hWnd, (int)WindowMessage.WM_QUERYENDSESSION, IntPtr.Zero, IntPtr.Zero) != 0)
{
return FuncDepBoolType.Success;
}
else
{
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Sends a WM_Close to the Window that the Artifact Belongs To
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IClose(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
// To Do: Must get hWnd From RAT
IntPtr hWnd = IntPtr.Zero;
if (Win32Functions.SendMessage(hWnd, (int)WindowMessage.WM_CLOSE, IntPtr.Zero, IntPtr.Zero) == 0)
{
return FuncDepBoolType.Success;
}
else
{
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Platform.Win32;
namespace Foo.WorkspaceMgr.Closers
{
internal class Closer_IE : IClose
{
#region IClose Members
/// <summary>
///
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryClose(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
// To Do: Must get hWnd From RAT
//IntPtr hWnd = IntPtr.Zero;
//if (Win32Functions.SendMessage(hWnd, (int)WindowMessage.WM_QUERYENDSESSION, IntPtr.Zero, IntPtr.Zero) != 0)
//{
// return FuncDepBoolType.Success;
//}
//else
//{
// return FuncDepBoolType.Failed;
//}
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Sends a WM_Close to the Window that the Artifact Belongs To
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IClose(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
// To Do: Must get hWnd From RAT
//IntPtr hWnd = IntPtr.Zero;
//if (Win32Functions.SendMessage(hWnd, (int)WindowMessage.WM_CLOSE, IntPtr.Zero, IntPtr.Zero) == 0)
//{
// return FuncDepBoolType.Success;
//}
//else
//{
// return FuncDepBoolType.Failed;
//}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,625 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Foo.Platform;
using Foo.Platform.Win32;
using System.Diagnostics;
using System.Runtime.InteropServices;
////
// Ignore 'Ambiguity' warning message, seems like no way around those
////
#pragma warning disable 0467
namespace Foo.WorkspaceMgr.Closers
{
class Closer_Office : IClose
{
#region IClose Members
/// <summary>
/// Dispatches the QueryClose Request to the Proper Office Closer
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType IQueryClose(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return QueryClose_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return QueryClose_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return QueryClose_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return QueryClose_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return QueryClose_MSVisio(strArtifactLocation);
case "MSACCESS.EXE":
return QueryClose_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
/// <summary>
/// Dispatches the Close Request to the Proper Office Closer
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType IClose(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return Close_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return Close_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return Close_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return Close_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return Close_MSVisio(strArtifactLocation);
case "MSACCESS.EXE":
return Close_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
#endregion
#region Microsoft Word IClose Members
public const string Word_ProgId = "Word.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSWord(string strArtifactLocation)
{
try
{
// Microsoft.Office.Interop.Word.Application app = null;
// app = Win32Functions.GetCOMObject(Word_ProgId) as Microsoft.Office.Interop.Word.Application;
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
if (doc.Saved)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
//**** Another Way Stored here for Later ****
// may be this is helpful..
//using ComTypes = System.Runtime.InteropServices.ComTypes;
//ComTypes.IPersistFile persistFile = (ComTypes.IPersistFile)document;
//Checks an object for changes since it was last saved to its current file.
//if (persistFile.IsDirty)
//{
//do your stuff
//}
return FuncDepBoolType.Failed;
}
/// <summary>
/// *** Technically ** Here we want to close the Word Document (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSWord(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Found the document to close * Close it Without Prompting *
object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
object originalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;
var app = doc.Application;
// Let's get the Window that belongs to this document
Microsoft.Office.Interop.Word.Window docWindow = null;
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
if (window.Document.FullName.ToLower() == strArtifactLocation.ToLower())
{
docWindow = window;
}
}
//Object missing = Missing.Value;
doc.Close(ref saveOption, ref originalFormat, ref routeDocument);
Marshal.FinalReleaseComObject(doc); // force clean-up
// Close the Window
if (docWindow != null)
docWindow.Close(ref saveOption, ref routeDocument);
// Close Word if this is the Last Document Instance
if (app.Documents.Count == 0)
{
app.Quit(ref saveOption, ref originalFormat, ref routeDocument);
Marshal.FinalReleaseComObject(app); // force clean-up, closes Process for sure
}
return FuncDepBoolType.Success;
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft Excel IClose Members
public const string Excel_ProgId = "Excel.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
if(book.Saved)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// *** Technically ** Here we want to close the Excel Workbook (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
// In case there is a running rogue excel process left open,
// we can always force it to close by closing the process
// int hWnd = app.Hwnd;
// Process process = Win32Functions.GetProcessFromHandle((IntPtr) hWnd);
var app = book.Application;
// Close the Workbook
book.Close(true, strArtifactLocation, false);
Marshal.FinalReleaseComObject(book); // force clean-up
// Close Excel if this is the last Workbook
if (app.Workbooks.Count == 0)
{
app.Quit();
Marshal.FinalReleaseComObject(app); // force clean-up, should clean up excel process
//process.Close();
}
return FuncDepBoolType.Success;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft PowerPoint IClose Members
public const string PowerPoint_ProgId = "PowerPoint.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
//Microsoft.Office.Interop.PowerPoint.Application app = null;
//app = Win32Functions.GetCOMObject(PowerPoint_ProgId) as Microsoft.Office.Interop.PowerPoint.Application;
//foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in app.Presentations)
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
switch (presentation.Saved)
{
case Microsoft.Office.Core.MsoTriState.msoTrue:
return FuncDepBoolType.Success;
case Microsoft.Office.Core.MsoTriState.msoFalse:
return FuncDepBoolType.Failed;
}
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// *** Technically ** Here we want to close the Word Document (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
//Microsoft.Office.Interop.PowerPoint.Application app = null;
//app = Win32Functions.GetCOMObject(PowerPoint_ProgId) as Microsoft.Office.Interop.PowerPoint.Application;
//foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in app.Presentations)
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
var app = presentation.Application;
// Save this Presentation
presentation.Save();
// Close this Presentation
presentation.Close();
Marshal.FinalReleaseComObject(presentation); // force clean-up
// Close PowerPoint if there are no more Presentations
if (app.Presentations.Count == 0)
{
app.Quit();
Marshal.FinalReleaseComObject(app); // force clean-up, kill application for sure
}
return FuncDepBoolType.Success;
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft Publisher IClose Members
public const string Publisher_ProgId = "Publisher.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSPublisher(string strArtifactLocation)
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
if (pubDoc.Saved)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
}
return FuncDepBoolType.Success;
}
/// <summary>
/// *** Technically ** Here we want to close the Word Document (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSPublisher(string strArtifactLocation)
{
IntPtr hWnd = IntPtr.Zero;
try
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Save the Document
pubDoc.Save();
// Get the Handle
hWnd = (IntPtr)pubDoc.ActiveWindow.Hwnd;
goto FOUND_DOCUMENT_HWND;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
FOUND_DOCUMENT_HWND:
// Get the Process
Process process = Win32Functions.GetProcessFromHandle(hWnd);
// Send Close Message
if (Win32Functions.SendMessage((IntPtr)hWnd, (int)WindowMessage.WM_CLOSE, IntPtr.Zero, IntPtr.Zero) == 0)
{
process.Kill();
return FuncDepBoolType.Success;
}
else
{
return FuncDepBoolType.Failed;
}
}
#endregion
#region Microsoft Visio IClose Members
public const string Visio_ProgId = "Visio.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
if (doc.Saved)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
return FuncDepBoolType.Success;
}
/// <summary>
/// *** Technically ** Here we want to close the Word Document (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
doc.Save();
var app = doc.Application;
doc.Close();
Marshal.FinalReleaseComObject(doc); // Force Clean-up
if (app.Documents.Count == 0)
{
app.Quit();
Marshal.FinalReleaseComObject(app); // force clean-up
}
return FuncDepBoolType.Success;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
}
}
return FuncDepBoolType.Success;
}
#endregion
#region Microsoft Access IClose Members
public const string Access_ProgId = "Access.Application";
/// <summary>
/// To Do : Test This - Let's us know if the user has unsaved data
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType QueryClose_MSAccess(string strArtifactLocation)
{
var RunningAccessApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Access.Application>();
foreach (Microsoft.Office.Interop.Access.Application app in RunningAccessApps)
{
if (app.CurrentProject.FullName.ToLower() == strArtifactLocation.ToLower())
{
return FuncDepBoolType.Success;
}
}
return FuncDepBoolType.Failed;
}
/// <summary>
/// *** Technically ** Here we want to close the Word Document (Not Prompt the user at all)
/// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
/// DOM, however more testing to be done here
/// </summary>
/// <param name="strArtifactLocation"></param>
/// <returns></returns>
public FuncDepBoolType Close_MSAccess(string strArtifactLocation)
{
var RunningAccessApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Access.Application>();
foreach (Microsoft.Office.Interop.Access.Application app in RunningAccessApps)
{
if (app.CurrentProject.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Get Handle and Process
IntPtr hWnd = (IntPtr) app.hWndAccessApp();
Process process = Win32Functions.GetProcessFromHandle((IntPtr)hWnd);
// Close the database
//app.CloseCurrentDatabase();
app.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveAll);
Marshal.FinalReleaseComObject(app); // force clean-up
// Kill the process
process.Kill();
return FuncDepBoolType.Success;
}
}
return FuncDepBoolType.Failed;
}
#endregion
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Foo.WorkspaceMgr.Closers
{
internal interface IClose
{
FuncDepBoolType IQueryClose(string strArtifactLocation);
FuncDepBoolType IClose(string strArtifactLocation);
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Platform.Utilities;
namespace Foo.WorkspaceMgr
{
public static class Configurations
{
#region Excel 2007 Configuration
private static string EXCEL_OPTIONS_REGISTRY_LOCATION = "Microsoft\\Office\\12.0\\Excel\\Options";
static public void Configure_Excel2007()
{
RegM reg = new RegM(HKEYRoot.CurrentUser, KeySub.Software, EXCEL_OPTIONS_REGISTRY_LOCATION, true);
reg.SetVal_Int("ShowWindowsInTaskbar", 1);
}
#endregion
static Configurations()
{
}
}
}

147
WorkspaceMgr/HelperFunc.cs Normal file
View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.DataAccessLayer.DataTypes;
namespace Foo.WorkspaceMgr
{
internal static class HelperFunc
{
internal const int DEFAULT_SHOWNHIDE_SLEEP_TIME = 250;
internal const int DEFAULT_CLOSE_SLEEP_TIME = 500;
internal const int DEFAULT_LAUNCH_SLEEP_TIME = 1000;
/// <summary>
/// Depending on the Quality of the Index Optimizations,
/// Return what the best type of action is afterward
/// </summary>
internal enum IndexOptimizationQuality
{
Good,
Average,
Poor
}
// Helper Class for OptimalLaunchIndexesForFileArtifacts
internal class OptimalIndexes
{
public int Index;
public string FileName;
internal OptimalIndexes(int Index, string FileName)
{
this.Index = Index;
this.FileName = FileName;
}
}
/// <summary>
///
/// </summary>
/// <param name="quality"></param>
/// <returns></returns>
internal static int GetSleepTimeForQuality(IndexOptimizationQuality quality)
{
int nSleepTime = 1350;
switch (quality)
{
case HelperFunc.IndexOptimizationQuality.Good:
nSleepTime = 1350;
break;
case HelperFunc.IndexOptimizationQuality.Average:
nSleepTime = 1675;
break;
case HelperFunc.IndexOptimizationQuality.Poor:
nSleepTime = 2000;
break;
}
return nSleepTime;
}
/// <summary>
/// For Launching of File Artifacts we must make sure that artifacts are in an order that allows us
/// to properly resolve them dynamically. When files with the same name get launched too close together,
/// window resolution will become increasingly difficult.
/// </summary>
/// <param name="artifactItems">a group of artifacts (Only file Artifacts will be processed)</param>
/// <returns>an array of indexes that specifies the launch order of all the files in this group</returns>
internal static IndexOptimizationQuality OptimalLaunchIndexesForFileArtifacts(ArtifactItem[] artifactItems, out int[] optimalIndexes)
{
// Step One - If it is a file type, then we get the file name and it's index to put into a list
List<OptimalIndexes> optIndex = new List<OptimalIndexes>();
for (int i = 0; i < artifactItems.Length; ++i)
{
if(artifactItems[i].IsFile)
optIndex.Add(new OptimalIndexes(i, artifactItems[i].FileName));
}
// Step Two - Sort the List by FileName
optIndex.Sort(delegate(OptimalIndexes o1, OptimalIndexes o2) { return o1.FileName.CompareTo(o2.FileName); });
// Step Three - Go thru sorted list and get out all the Singles
List<int> singlesList = new List<int>();
for (int i = 0; i < optIndex.Count; ++i)
{
bool bIsSingle = true;
bool bCompareUp = ((i > 0) && (i < optIndex.Count));
bool bCompareDown = (i < (optIndex.Count - 1));
if (bIsSingle && bCompareUp)
bIsSingle = (String.Compare(optIndex[i].FileName, optIndex[i - 1].FileName, true) != 0);
if (bIsSingle && bCompareDown)
bIsSingle = (String.Compare(optIndex[i].FileName, optIndex[i + 1].FileName, true) != 0);
// If Single - Add To Singles List
if (bIsSingle)
singlesList.Add(i);
}
// If all items in the List were singles then we are really good to go
// and can exit out of here
if (singlesList.Count == optIndex.Count)
{
// Pass out the Indexes of the Array To The Caller
optimalIndexes = new int[optIndex.Count];
for (int i = 0; i < optIndex.Count; ++i)
optimalIndexes[i] = optIndex[i].Index;
// Since there are no doubles - this is a low risk / high quality optimization
return IndexOptimizationQuality.Good;
}
// Step Four - There are doubles and/or no singles
// ~remove all singles from optIndex
foreach (int index in singlesList)
{
}
// 2) we make a list of all filenames in sorted order (with an index to which artifact it belongs)
// 3) we then generate the most optimal list of indexes that we pass out for the caller to use
foreach (ArtifactItem artifact in artifactItems)
{
}
optimalIndexes = new int[1];
return IndexOptimizationQuality.Average;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.DataAccessLayer;
using Foo.DataAccessLayer.DataTypes;
namespace Foo.WorkspaceMgr
{
public interface IWorkspaceMgr
{
// Artifact Related
bool LaunchArtifact(ArtifactItem artifactItem);
bool CloseArtifact(ArtifactItem artifactItem);
bool HideShowArtifact(ArtifactItem artifactItem, bool bShow);
// Workspace Related
bool LaunchWorkspace(string WorkspaceName);
bool CloseWorkspace(string WorkspaceName);
bool HideShowWorkspace(string WorkspaceName, bool bShow);
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Foo.WorkspaceMgr.Launchers
{
internal interface ILaunch
{
FuncDepBoolType IQueryLaunch(string strArtifactLocation);
FuncDepBoolType ILaunch(string strArtifactLocation);
}
}

View File

@@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Foo.Platform.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
namespace Foo.WorkspaceMgr.Launchers
{
internal class Launcher_Excel : ILaunch
{
#region ILaunch Members
/// <summary>
/// Checks to see if the file exists in the system i.e. can be reached over
/// the network. if FileExists fails, we shouldn't be able to launch it.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryLaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
if (File.Exists(strArtifactLocation))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.ArtifactLocationUnavailable;
}
else
{
return FuncDepBoolType.ParametersInvalid;
}
}
public const string Excel_ProgId = "Excel.Application";
/// <summary>
/// Generic Launcher should be able to handle any file type. Launched the .Net Way.
/// ~this is the same as if the User clicks on the file.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType ILaunch(string strArtifactLocation)
{
Microsoft.Office.Interop.Excel.Application app = null;
app = new Microsoft.Office.Interop.Excel.Application();
// Mark the Application as visible
app.Visible = true;
app.Workbooks.Open(strArtifactLocation, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value );
// Keep Track of all our Excel Instances
///WorkspaceState.Launched_ExcelInstances.Add(app);
return FuncDepBoolType.Success;
//if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
//{
// Process.Start(strArtifactLocation);
//}
//return FuncDepBoolType.ParametersInvalid;
}
#endregion
///// <summary>
///// To Do : Test This - Let's us know if the user has unsaved data
///// </summary>
///// <param name="strArtifactLocation"></param>
///// <returns></returns>
//public FuncDepBoolType QueryClose_MSExcel(string strArtifactLocation)
//{
// try
// {
// foreach (Microsoft.Office.Interop.Excel.Workbook book in app.Workbooks)
// {
// if (book.FullName.ToLower() == strArtifactLocation.ToLower())
// {
// if (book.Saved)
// return FuncDepBoolType.Success;
// else
// return FuncDepBoolType.Failed;
// }
// }
// }
// catch (Exception e)
// {
// string message = e.Message;
// message = message + "";
// // TODO: Log Something here
// return FuncDepBoolType.ErrorThrown;
// }
// return FuncDepBoolType.Failed;
//}
///// <summary>
///// *** Technically ** Here we want to close the Excel Workbook (Not Prompt the user at all)
///// **** we could close it with a WM_CLOSE or WM_SCLOSE or with the DOM. ~for now it's the
///// DOM, however more testing to be done here
///// </summary>
///// <param name="strArtifactLocation"></param>
///// <returns></returns>
//public FuncDepBoolType Close_MSExcel(string strArtifactLocation)
//{
// try
// {
// Microsoft.Office.Interop.Excel.Application app = null;
// app = Win32Functions.GetCOMObject(Excel_ProgId) as Microsoft.Office.Interop.Excel.Application;
// // For Debugging
// //int nCount = app.Workbooks.Count;
// foreach (Microsoft.Office.Interop.Excel.Workbook book in app.Workbooks)
// {
// if (book.FullName.ToLower() == strArtifactLocation.ToLower())
// {
// book.Close(true, strArtifactLocation, false);
// // Close Excel if this is the last Workbook
// if (app.Workbooks.Count == 0)
// app.Quit();
// return FuncDepBoolType.Success;
// }
// }
// }
// catch (Exception e)
// {
// string message = e.Message;
// message = message + "";
// // TODO: Log Something here
// return FuncDepBoolType.ErrorThrown;
// }
// return FuncDepBoolType.Failed;
//}
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Foo.Platform.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Foo.WorkspaceMgr.Launchers
{
internal class Launcher_Generic : ILaunch
{
#region ILaunch Members
/// <summary>
/// Checks to see if the file exists in the system i.e. can be reached over
/// the network. if FileExists fails, we shouldn't be able to launch it.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryLaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
if (File.Exists(strArtifactLocation))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.ArtifactLocationUnavailable;
}
else
{
return FuncDepBoolType.ParametersInvalid;
}
}
/// <summary>
/// Generic Launcher should be able to handle any file type. Launched the .Net Way.
/// ~this is the same as if the User clicks on the file.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType ILaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
Process.Start(strArtifactLocation);
return FuncDepBoolType.Success;
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Foo.Platform.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Foo.WorkspaceMgr.Launchers
{
internal class Launcher_Shell : ILaunch
{
#region ILaunch Members
/// <summary>
/// Checks to see if the file exists in the system i.e. can be reached over
/// the network. if FileExists fails, we shouldn't be able to launch it.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryLaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
if (File.Exists(strArtifactLocation))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.ArtifactLocationUnavailable;
}
else
{
return FuncDepBoolType.ParametersInvalid;
}
}
/// <summary>
/// Generic Launcher should be able to handle any file type using Shell Execute
/// ~This is NOT the same as Process.start(). When using ShellExecute, Excel workbooks
/// launch in a different window (and for some reason Don't SHOW UP in the Excel DOM)
/// ~this is why this is broken out (more testing is needed)
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType ILaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
// Shellexecute works almost just like process.start except for the limitation
// mentioned:
// We could do process start but doing so means all excel docs open in the same
// excel window (just like powerpoint does) ~this may or may not be desirable
// ~excel docs won't show in the DOM, after being launched this way ~ - very odd
bool bIsValidExe = false;
string strExeOrDllPath = string.Empty;
bool bFound = Win32_WrapperFunc.FindExeOrDll(strArtifactLocation, out strExeOrDllPath, out bIsValidExe);
const int SEE_MASK_NOCLOSEPROCESS = 0x40;
ShellExecuteInfo sei = new ShellExecuteInfo();
sei.cbSize = Marshal.SizeOf(sei);
sei.lpVerb = "open";
sei.lpParameters = '\"' + strArtifactLocation + '\"';
sei.nShow = (int)WindowAction.SW_SHOWNORMAL;
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
// Use Shell32 or Explorer to launch the artifact
if (bFound && bIsValidExe)
sei.lpFile = strExeOrDllPath;
else
sei.lpFile = '\"' + Win32_WrapperFunc.GetWindowsPath() + "\\explorer.exe" + '\"';
if (Win32Functions.ShellExecuteEx(ref sei))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Foo.Platform.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
namespace Foo.WorkspaceMgr.Launchers
{
internal class Launcher_Visio : ILaunch
{
#region ILaunch Members
/// <summary>
/// Checks to see if the file exists in the system i.e. can be reached over
/// the network. if FileExists fails, we shouldn't be able to launch it.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryLaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
if (File.Exists(strArtifactLocation))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.ArtifactLocationUnavailable;
}
else
{
return FuncDepBoolType.ParametersInvalid;
}
}
public const string Excel_ProgId = "Visio.Application";
/// <summary>
/// Generic Launcher should be able to handle any file type. Launched the .Net Way.
/// ~this is the same as if the User clicks on the file.
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType ILaunch(string strArtifactLocation)
{
Microsoft.Office.Interop.Visio.Application app = null;
app = new Microsoft.Office.Interop.Visio.Application();
// Mark the Application as visible
app.Visible = true;
app.Documents.Open(strArtifactLocation);
// Keep Track of all our Excel Instances
///WorkspaceState.Launched_ExcelInstances.Add(app);
return FuncDepBoolType.Success;
//if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
//{
// Process.Start(strArtifactLocation);
//}
//return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Foo.WorkspaceMgr.Launchers
{
class Launcher_Web : ILaunch
{
#region ILaunch Members
/// <summary>
/// Checks to see if the url is valid
/// ~~( We could even check if the webpage is available here!!!) ~to do later?
/// </summary>
/// <param name="strArtifactLocation">url to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryLaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
if (Uri.IsWellFormedUriString(strArtifactLocation, UriKind.Absolute))
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Generic Launcher should be able to handle any url type
/// </summary>
/// <param name="strArtifactLocation">url to launch</param>
public FuncDepBoolType ILaunch(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation) && (strArtifactLocation.Length > 3))
{
Process.Start(strArtifactLocation);
return FuncDepBoolType.Success;
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

BIN
WorkspaceMgr/MyKeyFile.SNK Normal file

Binary file not shown.

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WorkspaceMgr")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WorkspaceMgr")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5f6d39ae-f75e-447b-b3c0-e1abb34b4fc8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Foo.WorkspaceMgr.Hiders
{
internal interface IShowNHide
{
FuncDepBoolType IQueryShow(string strArtifactLocation);
FuncDepBoolType IShow(string strArtifactLocation);
FuncDepBoolType IQueryHide(string strArtifactLocation);
FuncDepBoolType IHide(string strArtifactLocation);
}
}

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Platform.Win32;
namespace Foo.WorkspaceMgr.Hiders
{
internal class ShowNHide_Generic : IShowNHide
{
#region IShowNHide Members
/// <summary>
/// Default behavior is to just return success ** Should Check if Window is hidden?/shown???
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryShow(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
return FuncDepBoolType.Success;
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Calls ShowWindow to Show the Window
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IShow(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
IntPtr hWnd = IntPtr.Zero; // ToDo : Implement RAT
Win32Functions.ShowWindow(hWnd, (int)WindowAction.SW_SHOW);
return FuncDepBoolType.Success;
}
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Default behavior is to just return success ** Should Check if Window is hidden?/shown???
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IQueryHide(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
return FuncDepBoolType.Success;
return FuncDepBoolType.ParametersInvalid;
}
/// <summary>
/// Calls ShowWindow to Hide the Window
/// </summary>
/// <param name="strArtifactLocation">location of the path + file to launch</param>
/// <returns></returns>
public FuncDepBoolType IHide(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
IntPtr hWnd = IntPtr.Zero; // ToDo : Implement RAT
Win32Functions.ShowWindow(hWnd, (int)WindowAction.SW_HIDE);
return FuncDepBoolType.Success;
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,847 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Platform.Win32;
using System.Runtime.InteropServices;
namespace Foo.WorkspaceMgr.Hiders
{
internal class ShowNHide_Office : IShowNHide
{
#region IShowNHide Members
public FuncDepBoolType IQueryShow(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return QueryShow_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return QueryShow_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return QueryShow_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return QueryShow_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return QueryShow_MSVisio(strArtifactLocation);
//case "ACCESS.EXE":
// return QueryClose_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
public FuncDepBoolType IShow(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return Show_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return Show_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return Show_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return Show_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return Show_MSVisio(strArtifactLocation);
//case "ACCESS.EXE":
// return QueryClose_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
public FuncDepBoolType IQueryHide(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return QueryHide_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return QueryHide_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return QueryHide_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return QueryHide_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return QueryHide_MSVisio(strArtifactLocation);
//case "ACCESS.EXE":
// return QueryClose_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
public FuncDepBoolType IHide(string strArtifactLocation)
{
switch (Win32_WrapperFunc.GetRegisteredExeForFile(strArtifactLocation))
{
case "WINWORD.EXE":
return Hide_MSWord(strArtifactLocation);
case "EXCEL.EXE":
return Hide_MSExcel(strArtifactLocation);
case "POWERPNT.EXE":
return Hide_MSPowerPoint(strArtifactLocation);
case "MSPUB.EXE":
return Hide_MSPublisher(strArtifactLocation);
case "VISIO.EXE":
return Hide_MSVisio(strArtifactLocation);
//case "ACCESS.EXE":
// return QueryClose_MSAccess(strArtifactLocation);
}
return FuncDepBoolType.FunctionallityNotSupported;
}
#endregion
#region Microsoft Word IShowNHide Members
FuncDepBoolType QueryShow_MSWord(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
if(window.Document.FullName.ToLower() == strArtifactLocation.ToLower())
{
if(!window.Visible)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Show_MSWord(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
if (window.Document.FullName.ToLower() == strArtifactLocation.ToLower())
{
if (!window.Visible)
{
window.Visible = true;
return FuncDepBoolType.Success;
}
else
{
return FuncDepBoolType.Failed;
}
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType QueryHide_MSWord(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
if (window.Document.FullName.ToLower() == strArtifactLocation.ToLower())
{
if (window.Visible)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Hide_MSWord(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningWordDocuments = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Word.Document>();
foreach (Microsoft.Office.Interop.Word.Document doc in RunningWordDocuments)
{
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
if (window.Document.FullName.ToLower() == strArtifactLocation.ToLower())
{
if (window.Visible)
{
window.Visible = false;
return FuncDepBoolType.Success;
}
else
{
return FuncDepBoolType.Failed;
}
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft Excel IShowNHide Members
FuncDepBoolType QueryShow_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
var app = book.Application;
bool bIsTheOnlyDocumentInApp = (app.Workbooks.Count == 1);
if (!app.Visible && bIsTheOnlyDocumentInApp)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Show_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
var app = book.Application;
bool bIsTheOnlyDocumentInApp = (app.Workbooks.Count == 1);
if (!app.Visible && bIsTheOnlyDocumentInApp)
{
app.Visible = true;
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType QueryHide_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
var app = book.Application;
bool bIsTheOnlyDocumentInApp = (app.Workbooks.Count == 1);
if (app.Visible && bIsTheOnlyDocumentInApp)
{
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Hide_MSExcel(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningExcelWorkbooks = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Excel.Workbook>();
foreach (Microsoft.Office.Interop.Excel.Workbook book in RunningExcelWorkbooks)
{
if (book.FullName.ToLower() == strArtifactLocation.ToLower())
{
var app = book.Application;
bool bIsTheOnlyDocumentInApp = (app.Workbooks.Count == 1);
// We could potentially not hide the window but instead just minimize the selected workbook
// ~have to learn
//if (!bIsTheOnlyDocumentInApp)
//{
// foreach (Microsoft.Office.Interop.Excel.Window window in book.Windows)
// {
// window.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized;
// }
//}
if (app.Visible && bIsTheOnlyDocumentInApp)
{
app.Visible = false;
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
}
return FuncDepBoolType.ArtifactLocationUnavailable;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft PowerPoint IShowNHide Members
FuncDepBoolType QueryShow_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
switch (presentation.Application.Visible)
{
case Microsoft.Office.Core.MsoTriState.msoTrue:
return FuncDepBoolType.Failed;
case Microsoft.Office.Core.MsoTriState.msoFalse:
return FuncDepBoolType.Success;
}
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Show_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
switch (presentation.Application.Visible)
{
case Microsoft.Office.Core.MsoTriState.msoTrue:
return FuncDepBoolType.Failed;
case Microsoft.Office.Core.MsoTriState.msoFalse:
{
//presentation.Application.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
Win32Functions.ShowWindow((IntPtr)presentation.Application.HWND, (int)WindowAction.SW_SHOW);
return FuncDepBoolType.Success;
}
}
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType QueryHide_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
switch (presentation.Application.Visible)
{
case Microsoft.Office.Core.MsoTriState.msoTrue:
return FuncDepBoolType.Success;
case Microsoft.Office.Core.MsoTriState.msoFalse:
return FuncDepBoolType.Failed;
}
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Hide_MSPowerPoint(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
try
{
var RunningPowerPoints = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.PowerPoint.Presentation>();
foreach (Microsoft.Office.Interop.PowerPoint.Presentation presentation in RunningPowerPoints)
{
if (presentation.FullName.ToLower() == strArtifactLocation.ToLower())
{
switch (presentation.Application.Visible)
{
case Microsoft.Office.Core.MsoTriState.msoTrue:
{
//presentation.Application.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
//foreach (Microsoft.Office.Interop.PowerPoint.DocumentWindow docWindow in presentation.Windows)
//{
// //docWindow.
//}
Win32Functions.ShowWindow((IntPtr) presentation.Application.HWND, (int)WindowAction.SW_HIDE);
return FuncDepBoolType.Success;
}
case Microsoft.Office.Core.MsoTriState.msoFalse:
{
return FuncDepBoolType.Failed;
}
}
}
}
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
return FuncDepBoolType.ErrorThrown;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
#region Microsoft Publisher IShowNHide Members
FuncDepBoolType QueryShow_MSPublisher(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
IntPtr hWnd = IntPtr.Zero;
try
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Get the Handle
hWnd = (IntPtr)pubDoc.ActiveWindow.Hwnd;
goto FOUND_DOCUMENT_HWND;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
FOUND_DOCUMENT_HWND:
return FuncDepBoolType.Success; // Check Window State... - TO DO Later
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Show_MSPublisher(string strArtifactLocation)
{
IntPtr hWnd = IntPtr.Zero;
try
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Save the Document
pubDoc.Save();
// Get the Handle
hWnd = (IntPtr)pubDoc.ActiveWindow.Hwnd;
goto FOUND_DOCUMENT_HWND;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
FOUND_DOCUMENT_HWND:
// Send Show Message
Win32Functions.ShowWindow(hWnd, (int)WindowAction.SW_SHOW);
return FuncDepBoolType.Success;
}
FuncDepBoolType QueryHide_MSPublisher(string strArtifactLocation)
{
if (!String.IsNullOrEmpty(strArtifactLocation))
{
IntPtr hWnd = IntPtr.Zero;
try
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Get the Handle
hWnd = (IntPtr)pubDoc.ActiveWindow.Hwnd;
goto FOUND_DOCUMENT_HWND;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
FOUND_DOCUMENT_HWND:
return FuncDepBoolType.Success; // Check Window State... - TO DO Later
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Hide_MSPublisher(string strArtifactLocation)
{
IntPtr hWnd = IntPtr.Zero;
try
{
var RunningPublisherApps = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Publisher.Application>();
foreach (Microsoft.Office.Interop.Publisher.Application app in RunningPublisherApps)
{
foreach (Microsoft.Office.Interop.Publisher.Document pubDoc in app.Documents)
{
if (pubDoc.FullName.ToLower() == strArtifactLocation.ToLower())
{
// Save the Document
pubDoc.Save();
// Get the Handle
hWnd = (IntPtr)pubDoc.ActiveWindow.Hwnd;
goto FOUND_DOCUMENT_HWND;
}
}
}
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
FOUND_DOCUMENT_HWND:
// Send Show Message
Win32Functions.ShowWindow(hWnd, (int)WindowAction.SW_HIDE);
return FuncDepBoolType.Success;
}
#endregion
#region Microsoft Visio IShowNHide Members
FuncDepBoolType QueryShow_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
bool bIsTheOnlyDocumentInApp = true; // TO DO: (doc.Application.Documents.Count == 1); not working
if (!doc.Application.Visible && bIsTheOnlyDocumentInApp)
return FuncDepBoolType.Success;
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Show_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
bool bIsTheOnlyDocumentInApp = true; // TO DO - (doc.Application.Documents.Count == 1); not working
if (!doc.Application.Visible && bIsTheOnlyDocumentInApp)
{
doc.Application.Visible = true;
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType QueryHide_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
bool bIsTheOnlyDocumentInApp = true; // (doc.Application.Documents.Count == 1); // TO DO - not working
if (doc.Application.Visible && bIsTheOnlyDocumentInApp)
{
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
return FuncDepBoolType.ParametersInvalid;
}
FuncDepBoolType Hide_MSVisio(string strArtifactLocation)
{
var RunningVisioDocs = Win32Functions.GetRunningObjectsOfType<Microsoft.Office.Interop.Visio.Document>();
foreach (Microsoft.Office.Interop.Visio.Document doc in RunningVisioDocs)
{
if (doc.FullName.ToLower() == strArtifactLocation.ToLower())
{
try
{
bool bIsTheOnlyDocumentInApp = true; // (doc.Application.Documents.Count == 1); // TO DO - not working
if (doc.Application.Visible && bIsTheOnlyDocumentInApp)
{
doc.Application.Visible = false;
return FuncDepBoolType.Success;
}
else
return FuncDepBoolType.Failed;
}
catch (Exception e)
{
string message = e.Message;
message = message + "";
// TODO: Log Something here
}
break;
}
}
return FuncDepBoolType.ParametersInvalid;
}
#endregion
}
}

View File

@@ -0,0 +1,248 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.DataAccessLayer;
using Foo.DataAccessLayer.DataTypes;
using Foo.WorkspaceMgr.Closers;
using Foo.WorkspaceMgr.Hiders;
using Foo.WorkspaceMgr.Launchers;
using System.Reflection;
namespace Foo.WorkspaceMgr
{
public class WorkspaceMgr : IWorkspaceMgr
{
#region IWorkspaceMgr Members
/// <summary>
/// Responsible for Launching a single artifact // ToDo: - CHECK RAT if Artifact is already running
/// </summary> // ToDo: - Test IEXPLORER LAUNCHER
/// <param name="artifactItem">artifact to launch</param> // ToDo: - Figgure out what to do in Error State
/// <returns>true if successful, false otherwise</returns>
public bool LaunchArtifact(ArtifactItem artifactItem)
{
AssemblyName assemblyName = new AssemblyName("Microsoft.Office.Interop.Access, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
Assembly assembly = Assembly.Load(assemblyName);
//if (artifactItem.IsValid && artifactItem.IsValidFileIntegrity)
if (artifactItem.IsLocationValid)
{
// Step One - Create the Launcher Obj
ILaunch launcher = WorkspaceTypeHelpers.CreateLauncherObj(artifactItem);
if (launcher == null)
return false;
// Step Two - Query if Launching for this Artifact is supported
FuncDepBoolType retVal = launcher.IQueryLaunch(artifactItem.Location);
// Step Three - launch it if supported
if (retVal == FuncDepBoolType.Success)
{
retVal = launcher.ILaunch(artifactItem.Location);
}
else
{
// * Log error or something and return otherwise * To Do
return false;
}
// Step Four - if success signal to the db the artifact was launched
if (retVal == FuncDepBoolType.Success)
{
Data.Artifacts.ArtifactWasLaunched(artifactItem);
}
return (retVal == FuncDepBoolType.Success);
}
return false;
}
/// <summary>
/// Responsible for Closing a single artifact // ToDo: - CHECK RAT if Artifact is running, if so Get Proccess that it is running in!!! ----
/// </summary> // ToDo: - Test Office, Generic, Notepad, IExplore Closers
/// <param name="artifactItem">artifact to close</param> // ToDo: - Figgure out what to do in Error State
/// <returns>true if successful, false otherwise</returns>
public bool CloseArtifact(ArtifactItem artifactItem)
{
if (artifactItem.IsValid && artifactItem.IsValidFileIntegrity)
{
// Step One - Create the Closer Obj
IClose closer = WorkspaceTypeHelpers.CreateCloserObj(artifactItem);
if (closer == null)
return false;
// Step Two - Query if Closing for this Artifact is possible
FuncDepBoolType retVal = closer.IQueryClose(artifactItem.Location);
// Step Three - close it if supported
if (retVal == FuncDepBoolType.Success)
{
retVal = closer.IClose(artifactItem.Location);
}
else
{
// * Log error or something and return otherwise * To Do
return false;
}
return (retVal == FuncDepBoolType.Success);
}
return false;
}
/// <summary>
/// Responsible for Hiding or showing a single artifact // ToDo: - CHECK RAT if Artifact is running, if so Get Proccess that it is running in!!! ----
/// </summary> // ToDo: - Test Office, Generic, Notepad, IExplore Hiders
/// <param name="artifactItem">artifact to hide</param> // ToDo: - Figgure out what to do in Error State
/// <param name="bShow">true to show, false to hide artifact</param>
/// <returns>true if successful, false otherwise</returns>
public bool HideShowArtifact(ArtifactItem artifactItem, bool bShow)
{
if (artifactItem.IsValid && artifactItem.IsValidFileIntegrity)
{
// Step One - Create the ShowNHider Obj
IShowNHide ShowHider = WorkspaceTypeHelpers.CreateShowNHiderObj(artifactItem);
if (ShowHider == null)
return false;
// Step Two - Query if Hiding or Showing is available for this Artifact
FuncDepBoolType retVal = FuncDepBoolType.Failed;
if (bShow)
retVal = ShowHider.IQueryShow(artifactItem.Location);
else
retVal = ShowHider.IQueryHide(artifactItem.Location);
// Step Three - Show or Hide it if supported
if (retVal == FuncDepBoolType.Success)
{
if(bShow)
retVal = ShowHider.IShow(artifactItem.Location);
else
retVal = ShowHider.IHide(artifactItem.Location);
}
else
{
// * Log error or something and return otherwise * To Do
return false;
}
return (retVal == FuncDepBoolType.Success);
}
return false;
}
/// <summary> // ToDo: -
/// Launches a Workspace. When for some reason an artifact location
/// is not available to launch we keep track of it and display it to the
/// user - however, we don't stop. we try to launch as many artifacts as
/// we can.
/// ---------------------------------------------------------------------
/// There are a few steps we have to do in order to successfully launch:
/// 1) Make sure all files that have the same file name are not launched together
/// 2) we must wait a little after each file to make sure that they can be resolved
///
/// </summary>
/// <param name="WorkspaceName">Name of Workspace to launch artifacts for</param>
/// <returns>true if 1 or more artifacts were launched, false otherwise</returns>
public bool LaunchWorkspace(string WorkspaceName)
{
// Step One - First Get all the Artifacts by Name
ArtifactItem[] artifacts = Data.Artifacts.GetAllArtifactsForWorkspace(WorkspaceName, SortOrderForArtifacts.Descending);
if (!DataTypeValidation.IsEmptyArtifactItemGroup(artifacts))
{
// Let's get the optimal Indexes for all the file artifacts
int[] optimalIndexes;
HelperFunc.IndexOptimizationQuality quality;
quality = HelperFunc.OptimalLaunchIndexesForFileArtifacts(artifacts, out optimalIndexes);
////
// Launch the file Artifacts according to their optimal indexes
////
foreach (int optIndex in optimalIndexes)
{
// Launch file artifact
LaunchArtifact(artifacts[optIndex]);
// depending on the quality of indexes sleep accordingly
int nSleepTime = HelperFunc.GetSleepTimeForQuality(quality);
// Sleep Now before launching again
System.Threading.Thread.Sleep(nSleepTime);
}
////
// Launch the url Artifacts according to their optimal indexes
////
foreach (ArtifactItem artifact in artifacts)
{
if (artifact.IsUrl)
{
LaunchArtifact(artifact);
System.Threading.Thread.Sleep(HelperFunc.DEFAULT_LAUNCH_SLEEP_TIME);
}
}
// Signal the Workspace as Launched
Data.Workspace.WorkspaceWasLaunched(WorkspaceName);
// Set it to this Workspace 'State'
Data.State.SetCurrentWorkspaceName(WorkspaceName);
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="WorkspaceName">Name of Workspace to close artifacts for</param>
/// <returns></returns>
public bool CloseWorkspace(string WorkspaceName)
{
ArtifactItem[] artifacts = Data.Artifacts.GetAllArtifactsForWorkspace(WorkspaceName, SortOrderForArtifacts.Ascending);
if (!DataTypeValidation.IsEmptyArtifactItemGroup(artifacts))
{
foreach (ArtifactItem artifact in artifacts)
{
CloseArtifact(artifact);
// Sleep a little
System.Threading.Thread.Sleep(HelperFunc.DEFAULT_CLOSE_SLEEP_TIME);
}
// Clear Workspace 'State'
Data.State.ClearCurrentWorkspaceName();
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="WorkspaceName"></param>
/// <param name="bShow">true to show, false to hide artifact</param>
/// <returns></returns>
public bool HideShowWorkspace(string WorkspaceName, bool bShow)
{
ArtifactItem[] artifacts = Data.Artifacts.GetAllArtifactsForWorkspace(WorkspaceName, SortOrderForArtifacts.Ascending);
if (!DataTypeValidation.IsEmptyArtifactItemGroup(artifacts))
{
foreach (ArtifactItem artifact in artifacts)
{
HideShowArtifact(artifact, bShow);
// Sleep a little
System.Threading.Thread.Sleep(HelperFunc.DEFAULT_SHOWNHIDE_SLEEP_TIME);
}
}
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{09ED5DCC-9350-42E5-8E3A-4A3EA25BCD35}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Foo.WorkspaceMgr</RootNamespace>
<AssemblyName>WorkspaceMgr</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MyKeyFile.SNK</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Target\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Target\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Office.Interop.Access, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.PowerPoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Publisher, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Visio, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Word, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Closers\Closer_Generic.cs" />
<Compile Include="Closers\Closer_Office.cs" />
<Compile Include="Closers\Closer_IE.cs" />
<Compile Include="Closers\IClose.cs" />
<Compile Include="Configurations.cs" />
<Compile Include="HelperFunc.cs" />
<Compile Include="Launchers\Launcher_Visio.cs" />
<Compile Include="Launchers\Launcher_Excel.cs" />
<Compile Include="Launchers\Launcher_Shell.cs" />
<Compile Include="Launchers\Launcher_Web.cs" />
<Compile Include="ShowNHide\ShowNHide_Generic.cs" />
<Compile Include="ShowNHide\IShowNHide.cs" />
<Compile Include="IWorkspaceMgr.cs" />
<Compile Include="Launchers\ILaunch.cs" />
<Compile Include="Launchers\Launcher_Generic.cs" />
<Compile Include="ShowNHide\ShowNHide_Office.cs" />
<Compile Include="WorkspaceMgr.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WorkspaceState.cs" />
<Compile Include="WorkspaceTypes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataAccessLayer\DataAccessLayer.csproj">
<Project>{C7E4B4C1-64D4-45FF-AAFD-C4B9AE216618}</Project>
<Name>DataAccessLayer</Name>
</ProjectReference>
<ProjectReference Include="..\Platform\Platform.csproj">
<Project>{F6929AFC-BF61-43A0-BABD-F807B65FFFA1}</Project>
<Name>Platform</Name>
</ProjectReference>
<ProjectReference Include="..\Settings\Settings.csproj">
<Project>{48D75C4F-2749-48BB-9386-721E0E94C144}</Project>
<Name>Settings</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="MyKeyFile.SNK" />
</ItemGroup>
<ItemGroup>
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Foo.WorkspaceMgr
{
static class WorkspaceState
{
static public List<Microsoft.Office.Interop.Excel.Application> Launched_ExcelInstances = new List<Microsoft.Office.Interop.Excel.Application>();
static public List<Microsoft.Office.Interop.PowerPoint.Application> Launched_PowerPointInstances = new List<Microsoft.Office.Interop.PowerPoint.Application>();
static WorkspaceState()
{
}
}
}

View File

@@ -0,0 +1,291 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foo.Settings;
using Foo.Platform.Win32;
using Foo.DataAccessLayer.DataTypes;
using Foo.WorkspaceMgr.Hiders;
using Foo.WorkspaceMgr.Closers;
using Foo.WorkspaceMgr.Launchers;
namespace Foo.WorkspaceMgr
{
/// <summary>
/// Allows us to extend functionallity by creating our own
/// Custom Types to be used in certain scenarios
/// </summary>
internal enum CustomStateChangingTypes
{
LaunchGenericUrl
}
/// <summary>
/// Useful for StateChanger Returns where we
/// need more information on failures
/// </summary>
public enum FuncDepBoolType
{
Success,
Failed,
ParametersInvalid,
ArtifactLocationUnavailable,
FunctionallityNotSupported,
ErrorThrown
}
/// <summary>
/// Use this to request the proper state
/// Changing Object
/// </summary>
public enum StateChangerReqType
{
Launcher,
ShowNHider,
Closer
}
/// <summary>
/// Class for useful Workspace Type Helpers
/// </summary>
internal static class WorkspaceTypeHelpers
{
private static configuration _configuration = null;
static WorkspaceTypeHelpers()
{
OoganizerSettingsAcc accessor = new OoganizerSettingsAcc();
_configuration = accessor.ReadConfigXMLFile();
}
#region Internal Object Creator Functions (Call these in this assembly)
/// <summary>
/// Creates a Launcher Object from an artifact Item
/// </summary>
/// <param name="artifactItem">valid artifact to create a launcher for</param>
/// <returns>object or null</returns>
internal static ILaunch CreateLauncherObj(ArtifactItem artifactItem)
{
if (artifactItem.IsUrl)
{
return CreateLauncherObj(CustomStateChangingTypes.LaunchGenericUrl.ToString());
}
else if (artifactItem.IsFile)
{
string strRegisteredProcessExe = Win32_WrapperFunc.GetRegisteredExeForFile(artifactItem.Location);
if (!String.IsNullOrEmpty(strRegisteredProcessExe))
return CreateLauncherObj(strRegisteredProcessExe);
//return CreateLauncherObj(LauncherGenericType.LaunchGenericFile);
}
return null;
}
/// <summary>
/// Creates a Hider Object from an artifact Item
/// </summary>
/// <param name="strProcessName">name for process to create object for</param>
/// <returns>object or null</returns>
internal static IShowNHide CreateShowNHiderObj(ArtifactItem artifactItem) // TO DO: We can check the RAT which Process the artifact was launched in!!
{
if (artifactItem.IsUrl)
{
// To Do: Query the RAT for the process this artifact is in, then call
// the object creator function for the correct process
return null;
}
else if (artifactItem.IsFile)
{
string strRegisteredProcessExe = Win32_WrapperFunc.GetRegisteredExeForFile(artifactItem.Location);
if (!String.IsNullOrEmpty(strRegisteredProcessExe))
return CreateShowNHiderObj(strRegisteredProcessExe);
}
return null;
}
/// <summary>
/// Creates a Closer Object from an artifact Item
/// </summary>
/// <param name="artifactItem">valid artifact to a closer for</param>
/// <returns>object or null</returns>
internal static IClose CreateCloserObj(ArtifactItem artifactItem) // TO DO: We can check the RAT which Process the artifact was launched in!!
{
if (artifactItem.IsUrl)
{
// To Do: Query the RAT for the process this artifact is in, then call
// the object creator function for the correct process
return null;
}
else if (artifactItem.IsFile)
{
string strRegisteredProcessExe = Win32_WrapperFunc.GetRegisteredExeForFile(artifactItem.Location);
if (!String.IsNullOrEmpty(strRegisteredProcessExe))
return CreateCloserObj(strRegisteredProcessExe);
}
return null;
}
#endregion
#region Private Object Creator Helper Functions
/// <summary>
/// Creates a Closer Object
/// </summary>
/// <param name="strProcessName">name for process to create object for</param>
/// <returns>object or null</returns>
private static IClose CreateCloserObj(string ProcessNameOrCustomType)
{
object o = CreateStateChangerObject(StateChangerReqType.Closer, ProcessNameOrCustomType);
if (IsObjectOfType(StateChangerReqType.Closer, o))
return (o as IClose);
else
return null;
}
/// <summary>
/// Creates a Hider Object
/// </summary>
/// <param name="strProcessName">name for process to create object for</param>
/// <returns>object or null</returns>
private static IShowNHide CreateShowNHiderObj(string ProcessNameOrCustomType)
{
object o = CreateStateChangerObject(StateChangerReqType.ShowNHider, ProcessNameOrCustomType);
if (IsObjectOfType(StateChangerReqType.ShowNHider, o))
return (o as IShowNHide);
else
return null;
}
/// <summary>
/// Creates a Launcher Object
/// </summary>
/// <param name="type">type of Launcher you want to create</param>
/// <returns>object or null</returns>
private static ILaunch CreateLauncherObj(string ProcessNameOrCustomType)
{
object o = CreateStateChangerObject(StateChangerReqType.Launcher, ProcessNameOrCustomType);
if (IsObjectOfType(StateChangerReqType.Launcher, o))
return (o as ILaunch);
else
return null;
}
/// <summary>
/// Useful for quick Interface Type checking of StateChangers
/// </summary>
/// <param name="reqType">A StateChangerRequestTyp</param>
/// <param name="o">a stateChanger Object</param>
/// <returns>true if object is of that Type</returns>
private static bool IsObjectOfType(StateChangerReqType reqType, object o)
{
if (o != null)
{
switch (reqType)
{
case StateChangerReqType.Launcher:
return (o is ILaunch);
case StateChangerReqType.ShowNHider:
return (o is IShowNHide);
case StateChangerReqType.Closer:
return (o is IClose);
}
}
return false;
}
#endregion
#region Main Object Factory Function (All calls ultimately end up here)
/// <summary>
/// Function is responsible for create the StateChanging Objects that we
/// need for the system. It will either be hardcoded in or be reading from
/// the settings file to know what object to create
/// </summary>
/// <param name="reqType">A StateChangerRequestType</param>
/// <param name="ProcessName">the name of the process to create it for</param>
/// <returns>an object of the correct type, the caller must then cast it</returns>
private static object CreateStateChangerObject(StateChangerReqType reqType, string ProcessNameOrCustomType)
{
if (!String.IsNullOrEmpty(ProcessNameOrCustomType))
{
////
// First Step - Create any Custom Types
////
switch (ProcessNameOrCustomType)
{
case "LaunchGenericUrl":
{
if (reqType == StateChangerReqType.Launcher)
return new Launchers.Launcher_Web();
}
break;
}
////
// Second Step - Read thru the Configuration and create the corresponding
// object as the Configuration says we should use
////
foreach (ButtonHookSettings.ProcessName processObj in _configuration.ButtonHook.AllowedProcessNames.ProcessNames)
{
if (processObj.ProcessExe == ProcessNameOrCustomType.ToUpper())
{
switch (reqType)
{
case StateChangerReqType.Launcher:
switch (processObj.Launcher.ToUpper())
{
case "WEB":
return new Launcher_Web();
case "SHELL":
return new Launcher_Shell();
case "EXCEL":
return new Launcher_Excel();
case "VISIO":
return new Launcher_Visio();
default:
return new Launcher_Generic();
}
case StateChangerReqType.Closer:
switch (processObj.Closer.ToUpper())
{
case "IE":
return new Closer_IE();
case "OFFICE":
return new Closer_Office();
default:
return new Closer_Generic();
}
case StateChangerReqType.ShowNHider:
switch (processObj.ShowHider.ToUpper())
{
case "OFFICE":
return new ShowNHide_Office();
default:
return new ShowNHide_Generic();
}
}
}
}
}
return null;
}
#endregion
}
}