using BeWoLauncher.ServiceProxy; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.ServiceModel; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; namespace BeWoLauncher { public static class LauncherUtils { public static Dictionary ParseQuery(string query) { try { if (query.IndexOf('?') >= 0) { query = query.Split('?')[1]; var valueArray = Regex.Split(query, @"[\&]{0,1}[A-Za-z0-9]+[\=]{1}"); var paramArray = Regex.Split(query, @"[\=][A-Za-z0-9;]+"); valueArray = valueArray.Where(t => !string.IsNullOrWhiteSpace(t)).ToArray(); paramArray = paramArray.Where(t => !string.IsNullOrWhiteSpace(t)).ToArray(); var queryDictionary = new Dictionary(); int ixg = 0; foreach (var item in paramArray) { queryDictionary.Add(item.Contains("&") ? Regex.Split(item, @"[\?]|[\&]")[1] : item, valueArray[ixg]); ixg++; if (ixg >= valueArray.Length) break; } return queryDictionary; } return new Dictionary(); } catch (Exception ex) { throw new Exception(String.Format("Error while parsing query '{0}'\n{1}", query, ex.Message), ex); } } public static string GetAndCreateUserAppDataPath() { try { string localAppData = Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData); string companyFilePath = Path.Combine(localAppData, "beyondSoft"); if (!Directory.Exists(companyFilePath)) Directory.CreateDirectory(companyFilePath); string bewoFilePath = Path.Combine(companyFilePath, "BeWoPlaner"); if (!Directory.Exists(bewoFilePath)) Directory.CreateDirectory(bewoFilePath); return bewoFilePath; } catch (Exception ex) { MessageBox.Show( "Fehler beim Anlegen des Anwendungsordners. Sie besitzen nicht die erforderlichen Rechte, bitte wenden Sie sich an Ihren Systemadministrator.\n" + ex.Message, "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } public static bool ImplementsInterface(this Type type, Type ifaceType) { Type[] intf = type.GetInterfaces(); for (int i = 0; i < intf.Length; i++) { if (intf[i] == ifaceType) { return true; } } return false; } } }