/// <summary> /// Workout the source (application) that the log is assigned to. /// </summary> private void WorkoutSource() { // check that we are registered as a source try { SmartAssembly exeAss = new SmartAssembly(Assembly.GetEntryAssembly()); m_applicationName = exeAss.ProductName; } catch( ArgumentNullException ) { // More then likely the Assembly.GetEntryAssembly has returned nothing. try { SmartAssembly exeAss = new SmartAssembly(Assembly.GetCallingAssembly()); m_applicationName = exeAss.ProductName; } catch( ArgumentNullException ) { // We are really having a bad day. m_applicationName = ""; } } // Fall back our own name..... if ( m_applicationName.Length == 0 ) { string name= Assembly.GetAssembly(typeof(SmartEventLog)).GetName().Name; m_applicationName = name.Substring(0, name.LastIndexOf(".")); } }
public static string GetLocation(SmartLocationType location) { string sloc = ""; string sCompany = ""; string sProduct = ""; // Get the common path location switch (location) { case SmartLocationType.AllUsers: sloc = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData); break; case SmartLocationType.Personal: sloc = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); break; case SmartLocationType.Installed: string assloc = Assembly.GetEntryAssembly().Location; // Check to make sure that the last \ and the first \ is not the // same as in C:\ if (assloc.IndexOf("\\") != assloc.LastIndexOf("\\")) sloc = assloc.Substring(0, assloc.LastIndexOf("\\")); else sloc = assloc; break; case SmartLocationType.DefaultUser: StringBuilder path = new StringBuilder(); IntPtr p = new IntPtr(-1); int res = NativeMethods.GetFolderPath(IntPtr.Zero, 0x001a, p, 0, path); if (res == 0) sloc = path.ToString(); break; default: // Return an empty string if we do not know. sloc = ""; break; } // Get the assembly attributes // If executing assembly is null then more then likely // we are in another application domain, so use the application // settings. If they are not available then use the calling assembly // as a last resort. if (location != SmartLocationType.Installed && location != SmartLocationType.Specific && location != SmartLocationType.DefaultUser) { SmartAssembly assatt; if (Assembly.GetEntryAssembly() != null) { assatt = new SmartAssembly(Assembly.GetEntryAssembly()); sCompany = assatt.Company; sProduct = assatt.ProductName; } // Now application settings. if (sCompany.Trim().Length == 0 && Assembly.GetCallingAssembly() != null) { assatt = new SmartAssembly(Assembly.GetCallingAssembly()); sCompany = assatt.Company; sProduct = assatt.ProductName; } // Now paste them together. sloc += "\\" + sCompany + "\\" + sProduct; if (!Directory.Exists(sloc)) { // It does not so lets create it. Directory.CreateDirectory(sloc); } } return sloc; }
public void Test_04_AssemblyTest() { SmartAssembly sa = new SmartAssembly(Assembly.GetAssembly(typeof(TestCommon))); Assert.IsTrue(sa.AssemblyName.Equals("Workshare.Common.Tests"),"Wrong Assembly Name! ["+sa.AssemblyName + "]"); }