Пример #1
0
        public static void CleanupBaseAddressConfigFile(string manufacturer, string applicationName, bool isService)
        {
            // ReSharper disable LocalizableElement
            string[] relativePathItems;

            if (isService)
            {
                relativePathItems = new string[] { };

                var configurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(manufacturer, applicationName, @"WCF", true, false, relativePathItems, @"WcfBaseAddress.config", true);
                configurationFile.Delete();
            }
            else
            {
                relativePathItems = new string[] { Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) };

                var configurationPath = ConfigurationFileSupport.GetConfigurationPath(manufacturer, applicationName, @"WCF", true, false, relativePathItems, true);
                try
                {
                    configurationPath.Delete(true);
                }
                catch (Exception)
                {
                }
            }

            // ReSharper restore LocalizableElement
        }
Пример #2
0
        public static void CleanupBaseAddressConfigFiles(string manufacturer, string applicationName)
        {
            var myOtherProcesses      = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
            var baseRelativePathItems = new string[] { };
            var basePath = ConfigurationFileSupport.GetConfigurationPath(manufacturer, applicationName, @"WCF", true, false, baseRelativePathItems, true);

            try
            {
                foreach (var subDirectory in basePath.EnumerateDirectories())
                {
                    int subDirectoryNameAsInt;

                    if (int.TryParse(subDirectory.Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out subDirectoryNameAsInt))
                    {
                        if (myOtherProcesses.All(p => p.Id != subDirectoryNameAsInt))
                        {
                            try
                            {
                                subDirectory.Delete(true);
                            }
                            catch (System.Exception)
                            {
                            }
                        }
                    }
                }
            }
            catch (System.Exception)
            {
            }
        }
Пример #3
0
        /// <summary>
        /// Contacts the support pressed.
        /// </summary>
        private void ContactSupportPressed()
        {
            // ReSharper disable LocalizableElement
            var relativePathItems = new[] { @"SupportFiles" };
            var supportFiles      = ConfigurationFileSupport.GetConfigurationPath(@"Endress+Hauser", @"DeviceCare", null, false, true, relativePathItems, true);
            var systemInfo        = new SystemInfo(supportFiles);

            systemInfo.WriteInTextFiles();

            //// // ReSharper restore LocalizableElement
            ////using (var zipFile = new ZipFile())
            ////{
            ////    zipFile.AddDirectory(supportFiles.FullName);

            ////    // ReSharper disable LocalizableElement
            ////    zipFile.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\DC_SupportFiles.zip");

            ////    // ReSharper restore LocalizableElement
            ////}
        }
        public static void ConfigureLogging(IBaseHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException(@"host");
            }

            var isService = host.IsService;

            var myOtherProcesses      = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
            var baseRelativePathItems = new[] { RelativeLoggingPath };
            var basePath = ConfigurationFileSupport.GetConfigurationPath(host.Manufacturer, host.ApplicationName, @"ImsOpcBridge", isService, false, baseRelativePathItems, true);

            try
            {
                foreach (var subDirectory in basePath.EnumerateDirectories())
                {
                    int subDirectoryNameAsInt;

                    if (int.TryParse(subDirectory.Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out subDirectoryNameAsInt))
                    {
                        if (myOtherProcesses.All(p => p.Id != subDirectoryNameAsInt))
                        {
                            try
                            {
                                subDirectory.Delete(true);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            string[] relativePathItems;

            if (isService)
            {
                // relative path { "Logging" } leads to ...\Users\UserX\AppData\Local\<manufacturer>\<application>\ImsOpcBridge\Shared\Logging
                relativePathItems = new[] { RelativeLoggingPath };
            }
            else
            {
                // relative path { "Logging" } leads to ...\Users\UserX\AppData\Local\<manufacturer>\<application>\ImsOpcBridge\Shared\Logging\<ProcessId>
                relativePathItems = new[] { RelativeLoggingPath, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) };
            }

            // ReSharper disable LocalizableElement
            Log4NetConfigurationFile = ConfigurationFileSupport.GetConfigurationFileInfo(host.Manufacturer, host.ApplicationName, @"ImsOpcBridge", isService, false, relativePathItems, Log4NetConfigurationFileName, false);

            // ReSharper restore LocalizableElement
            if (!Log4NetConfigurationFile.Exists)
            {
                InstallDefaultLog4NetConfiguration(Log4NetConfigurationFile);
                Log4NetConfigurationFile.Refresh();
            }

            if (Log4NetConfigurationFile.Exists)
            {
                ConfigureLogging(Log4NetConfigurationFile, true);
            }
        }