public static bool ValidateAllPluins() { var plugins = Directory.EnumerateFiles("Plugins/"); var jsonFiles = plugins.Where(a => a.Contains(".json")); bool result = false; foreach (var json in jsonFiles) { var content = File.ReadAllText(Path.GetFullPath(json)); var config = JsonConvert.DeserializeObject <PluginConfig>(content); if (config == null) { throw new Exception($"Fichier configuration Module {json} invalide"); } var jsonIsValide = ModuleErp.PluginIsValide(config.Name, config.User, config.Key); if (jsonIsValide == false) { throw new Exception($"Le module {json} n'est pas valide"); } result = result && jsonIsValide; } return(result); }
public static void ReloadModules() { var modules = DataHelpers.GetMongoDataSync("ModuleErp") as IEnumerable <ModuleErp>; DataHelpers.Modules = modules as IEnumerable <ModuleErp>; var collections = modules.Select(z => z.Libelle).ToList(); string nspace = "ErpAlgerie.Modules.CRM"; var q = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && t.Namespace == nspace && (t.IsSubclassOf(typeof(ExtendedDocument)) && !typeof(NoModule).IsAssignableFrom(t)) select t; q.ToList().ForEach(t => { try { Console.Write(t.Name); var instance = Activator.CreateInstance(t); var collection = t.GetProperty("CollectionName").GetValue(instance)?.ToString(); if (!collections.Contains(collection)) { var moduleName = t.GetProperty("ModuleName").GetValue(instance)?.ToString(); var iconName = t.GetProperty("IconName").GetValue(instance)?.ToString(); var showInDesktop = t.GetProperty("ShowInDesktop").GetValue(instance) as bool?; var isInstance = bool.Parse(t.GetProperty("IsInstance").GetValue(instance)?.ToString()); if (!string.IsNullOrWhiteSpace(moduleName)) { Console.Write("EXIT"); } var moduleErp = new ModuleErp(); moduleErp.Libelle = collection; moduleErp.EstAcceRapide = showInDesktop.Value; moduleErp.ClassName = $"{nspace}.{t.Name}"; moduleErp.GroupeModule = moduleName; moduleErp.ModuleIcon = iconName; moduleErp.ModuleSubmitable = (instance as ExtendedDocument).Submitable; moduleErp.IsInstanceModule = isInstance; moduleErp.Save(); } } catch (Exception s) { Console.WriteLine("ERROR\n"); Console.WriteLine(s.Message); } } ); modules = DataHelpers.GetMongoDataSync("ModuleErp") as IEnumerable <ModuleErp>; DataHelpers.Modules = modules; }
public async void ModifierModule() { try { var instance = Activator.CreateInstance <T>(); ModuleErp module = this.type.GetMethod("MyModule")?.Invoke(instance, null) as ModuleErp; // if (module != null) { await DataHelpers.Shell.OpenScreenDetach(module, module.CollectionName); } } catch (Exception s) { DataHelpers.Logger.LogError(s); throw; } }
public static void CreateSeries(ModuleErp module, long currentIndex, bool createAnyway = false) { if (!module.HasSeries && createAnyway == false) { return; } var serie = new SeriesName(); serie.Libelle = _(module.Name); string suffix = ""; string libelle = module.Libelle; var trim = libelle.Split(' '); if (trim.Length == 1) { var word = trim.FirstOrDefault(); suffix += word.Substring(0, 2).ToUpper(); } else { foreach (var item in trim) { if (item.Length > 2) { var firstCharcter = new string(item.Take(1).ToArray()); suffix += firstCharcter.ToUpper(); } } } serie.Sufix = suffix + "-########"; serie.Indexe = currentIndex++; serie.ForceIgniorValidatUnique = true; serie.Save(); // module.SeriesNames = new List<SeriesName>(); module.SeriesNames.Add(serie); if (module.SeriesDefault.IsValide() == false) { module.SeriesDefault = serie.Id; } module.ForceIgniorValidatUnique = true; module.Save(); }
public async Task OpenModuleErp(ModuleErp module) { var displayname = module.Libelle; var className = module.ClassName; var iconImg = module.ModuleIcon; var instance = module.IsInstanceModule; var instanceFunction = module.InstanceFunction; var found = Items.FirstOrDefault(a => a.DisplayName == displayname); if (found != null) { ActivateItem(found); } else { if (instance == false) { var baseView = DataHelpers.GetBaseViewModelScreen(Type.GetType(className), aggre, false); baseView.DisplayName = displayname; Items.Add(baseView); ActivateItem(baseView); } else { try { var one = Activator.CreateInstance(Type.GetType(className)); var oneInstance = (ExtendedDocument)one.GetType() .GetMethod(instanceFunction). Invoke(one, null); this.OpenScreen(await DetailViewModel.Create(oneInstance, oneInstance.GetType(), aggre, this), $"{displayname}"); } catch (Exception s) { MessageBox.Show(s.Message); return; } } } }
public static void UpdateModules(bool DoUpdate = true) { var users = DS.db.GetAll <User>(); var modules = DS.db.GetAll <ModuleErp>(); DataHelpers.Modules = modules as IEnumerable <ModuleErp>; if (DoUpdate == false) { //check in db if (modules?.Count() < 1) { DoUpdate = true; } } // deleteAll Modules if (!DoUpdate) { return; } foreach (var module in modules) { (module).Delete(false); } //Ovresko.Generix.Core.Modules. string nspace = "Ovresko.Generix.Core.Modules"; string plugins = "Ovresko.Generix.Extentions"; var asm = AppDomain.CurrentDomain.GetAssemblies(); var types = asm.SelectMany(a => a.GetTypes()); var pluginsType = types.Where(a => a.Namespace == plugins); var pluginsCore = types.Where(a => a.Namespace == nspace); var result = new List <Type>(); result.AddRange(pluginsType); var names = result.Select(a => a.Name); foreach (var item in pluginsCore) { if (names.Contains(item.Name) == false) { result.Add(item); } } var q = from t in result where t.IsClass && (t.Namespace == nspace || t.Namespace == plugins) && (typeof(Document).IsAssignableFrom(t) && !typeof(NoModule).IsAssignableFrom(t)) select t; q.ToList().ForEach(t => { try { Console.Write(t.Name); var instance = Activator.CreateInstance(t); var collection = t.GetProperty("CollectionName").GetValue(instance)?.ToString(); var moduleName = t.GetProperty("ModuleName").GetValue(instance)?.ToString(); var iconName = t.GetProperty("IconName").GetValue(instance)?.ToString(); var showInDesktop = t.GetProperty("ShowInDesktop").GetValue(instance) as bool?; var isInstance = bool.Parse(t.GetProperty("IsInstance").GetValue(instance)?.ToString()); var indexMnu = int.Parse(t.GetProperty("MenuIndex").GetValue(instance)?.ToString()); bool hasserie = false; try { hasserie = (t.GetProperty("Series").GetValue(instance) != null); } catch { } if (!string.IsNullOrWhiteSpace(moduleName)) { Console.Write("EXIT"); } var moduleErp = new ModuleErp(); moduleErp.Libelle = collection; moduleErp.EstAcceRapide = showInDesktop.Value; moduleErp.ClassName = t.FullName;// t.AssemblyQualifiedName;// $"{nspace}.{t.Name}"; moduleErp.GroupeModule = moduleName; moduleErp.ModuleIcon = iconName; moduleErp.ModuleSubmitable = (instance as IDocument).Submitable; moduleErp.IsInstanceModule = isInstance; moduleErp.ModuleMenuIndex = indexMnu; moduleErp.HasSeries = hasserie; moduleErp.Save(); try { DataHelpers.GetTypesModule.Add(collection, t); } catch { } try { DataHelpers.GetTypesModule.Add(moduleErp.ClassName, t); } catch { } try { DataHelpers.GetTypesModule.Add(t.FullName, t); } catch { } try { DataHelpers.GetTypesModule.Add(t.Name, t); } catch { } } catch (Exception s) { Console.WriteLine("ERROR\n"); Console.WriteLine(s.Message); } } ); modules = DS.db.GetAll <ModuleErp>(a => true); DataHelpers.Modules = modules as IEnumerable <ModuleErp>; }
public static void ReloadModules() { // return; var modules = DS.db.GetAll <ModuleErp>();// DataHelpers.GetMongoDataSync("ModuleErp") as IEnumerable<ModuleErp>; DataHelpers.Modules = modules as IEnumerable <ModuleErp>; var collections = modules.Select(z => z.ClassName).ToList(); string nspace = "Ovresko.Generix.Core.Modules"; string plugins = "Ovresko.Generix.Extentions"; var asm = AppDomain.CurrentDomain.GetAssemblies(); var types = asm.SelectMany(a => a.GetTypes()); //var q = from t in Assembly.GetExecutingAssembly().GetTypes() // where t.IsClass && t.Namespace == nspace // && (t.IsSubclassOf(typeof(IDocument)) // && !typeof(NoModule).IsAssignableFrom(t)) // select t; var pluginsType = types.Where(a => a.Namespace == plugins); var pluginsCore = types.Where(a => a.Namespace == nspace); var result = new List <Type>(); result.AddRange(pluginsType); var names = result.Select(a => a.Name); foreach (var item in pluginsCore) { if (names.Contains(item.Name) == false) { result.Add(item); } } var q = from t in result where t.IsClass && (t.Namespace == nspace || t.Namespace == plugins) && (typeof(Document).IsAssignableFrom(t) && !typeof(NoModule).IsAssignableFrom(t)) select t; List <string> AssemblyCollection = new List <string>(); q.ToList().ForEach(t => { try { Console.Write(t.Name); var instance = Activator.CreateInstance(t); var CollectionName = t.GetProperty("CollectionName").GetValue(instance)?.ToString(); AssemblyCollection.Add(t.FullName); //Install IDocument extended = (instance as IDocument); (instance as IDocument).InstallWithBootstrap(); if (!collections.Contains(t.FullName)) { var moduleName = t.GetProperty("ModuleName").GetValue(instance)?.ToString(); var iconName = t.GetProperty("IconName").GetValue(instance)?.ToString(); var showInDesktop = t.GetProperty("ShowInDesktop").GetValue(instance) as bool?; var isInstance = bool.Parse(t.GetProperty("IsInstance").GetValue(instance)?.ToString()); var indexMnu = int.Parse(t.GetProperty("MenuIndex").GetValue(instance)?.ToString()); if (!string.IsNullOrWhiteSpace(moduleName)) { Console.Write("EXIT"); } var moduleErp = new ModuleErp(); moduleErp.Libelle = CollectionName; moduleErp.EstAcceRapide = showInDesktop.Value; moduleErp.ClassName = t.FullName;// t.AssemblyQualifiedName;// $"{nspace}.{t.Name}"; moduleErp.GroupeModule = moduleName; moduleErp.ModuleIcon = iconName; moduleErp.ModuleSubmitable = (instance as IDocument).Submitable; moduleErp.IsInstanceModule = isInstance; moduleErp.ModuleMenuIndex = indexMnu; moduleErp.Save(); try { DataHelpers.GetTypesModule.Add(CollectionName, t); } catch { } try { DataHelpers.GetTypesModule.Add(moduleErp.ClassName, t); } catch { } try { DataHelpers.GetTypesModule.Add(t.FullName, t); } catch { } try { DataHelpers.GetTypesModule.Add(t.Name, t); } catch { } } if (extended.MyModule() != null && (extended.MyModule() as ModuleErp).SeriesDefault.IsValide() == false) { FrameworkManager.CreateSeries(extended.MyModule() as ModuleErp, 1, true); } } catch (Exception s) { Console.WriteLine("ERROR\n"); Console.WriteLine(s.Message); } } ); foreach (var item in modules) { if (!AssemblyCollection.Contains(item.ClassName)) { item.Delete(false); } } modules = DS.db.GetAll <ModuleErp>();// DataHelpers.GetMongoDataSync("ModuleErp") as IEnumerable<ModuleErp>; DataHelpers.Modules = modules; }
public static bool InstallPlugin(string fullPath, string filenameWithExtention, InstallMode mode) { switch (mode) { case InstallMode.Zip: try { ZipArchive archive = ZipFile.OpenRead(Path.GetFullPath(fullPath)); string tempPath = $"temp/plugin_{DateTime.Now.Ticks}"; Directory.CreateDirectory(tempPath); archive.ExtractToDirectory(Path.GetFullPath(tempPath), true); var allfiles = Directory.EnumerateFiles(Path.GetFullPath($"{tempPath}/Plugins")).ToList(); var json = allfiles.FirstOrDefault(a => a.Contains(".json")); //string json = $"{tempPath}/{filenameWithExtention}.json"; if (!File.Exists(json)) { DataHelpers.ShowMessage(_("Invalide package!")); return(false); } var jsonPlugin = File.ReadAllText(json); PluginConfig configC = JsonConvert.DeserializeObject <PluginConfig>(jsonPlugin); if (configC == null) { DataHelpers.ShowMessage(_("Invalide package!")); return(false); } PluginPackage pluginPackage = new PluginPackage(); pluginPackage.Libelle = configC?.Name; pluginPackage.PluginVersion = configC?.Version; pluginPackage.PluginDate = configC?.Release; pluginPackage.PluginLien = configC?.Link; archive.ExtractToDirectory(Environment.CurrentDirectory, true); if (Directory.Exists($"{tempPath}/Plugins")) { var filesPlugins = Directory.EnumerateFiles($"{tempPath}/Plugins"); foreach (var item in filesPlugins) { pluginPackage.AllPluginFiles.Add(new PluginFile(item.Replace(tempPath, ""))); } } if (Directory.Exists($"{tempPath}/templates")) { var filesTemplates = Directory.EnumerateFiles($"{tempPath}/templates"); foreach (var item in filesTemplates) { pluginPackage.AllPluginFiles.Add(new PluginFile(item.Replace(tempPath, ""))); } } if (Directory.Exists($"{tempPath}/Languages")) { var filesLanguages = Directory.EnumerateFiles($"{tempPath}/Languages"); foreach (var item in filesLanguages) { pluginPackage.AllPluginFiles.Add(new PluginFile(item.Replace(tempPath, ""))); } } if (Directory.Exists($"{tempPath}/Reports")) { var filesReports = Directory.EnumerateFiles($"{tempPath}/Reports"); foreach (var item in filesReports) { pluginPackage.AllPluginFiles.Add(new PluginFile(item.Replace(tempPath, ""))); } } pluginPackage.Save(); DataHelpers.ShowMessage(_("Plugin installé, redémarrer l'application")); } catch (Exception s) { DataHelpers.ShowMessageError(s); return(false); } break; case InstallMode.Path: try { if (!string.IsNullOrWhiteSpace(fullPath)) { var file = Path.GetFullPath(fullPath); var safe = Path.GetFileNameWithoutExtension(file); var json = file.Replace(".dll", ".json"); // Path.Combine(location, $"/{safe}.json"); if (File.Exists(json)) { var jsonContent = File.ReadAllText(json); PluginConfig config = JsonConvert.DeserializeObject <PluginConfig>(jsonContent); if (ModuleErp.PluginIsValide(config.Name, config.User, config.Key)) { // Check Dependencies var deps = config.Dependencies; File.Copy(file, $"Plugins/{safe}.dll"); File.Copy(Path.GetFullPath(json), $"Plugins/{safe}.json"); DataHelpers.ShowMessage("Fermer l'application pour que le systéme recharge cette extention"); return(true); } else { DataHelpers.ShowMessage("Key config invalide"); return(false); } } else { DataHelpers.ShowMessage($"Le fichier de configuration {safe}.json est introuvable"); return(false); } } } catch (Exception s) { DataHelpers.ShowMessage(s.Message); } break; default: break; } return(false); }
public static void UpdateModules(bool DoUpdate = true) { var modules = DataHelpers.GetMongoDataSync("ModuleErp"); DataHelpers.Modules = modules as IEnumerable <ModuleErp>; if (DoUpdate == false) { //check in db if (modules?.Count() < 1) { DoUpdate = true; } } // deleteAll Modules if (!DoUpdate) { return; } foreach (var module in modules) { (module as IModel).Delete(false); } //ErpAlgerie.Modules.CRM string nspace = "ErpAlgerie.Modules.CRM"; var q = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && t.Namespace == nspace && (t.IsSubclassOf(typeof(ExtendedDocument)) && !typeof(NoModule).IsAssignableFrom(t)) select t; q.ToList().ForEach(t => { try { Console.Write(t.Name); var instance = Activator.CreateInstance(t); var collection = t.GetProperty("CollectionName").GetValue(instance)?.ToString(); var moduleName = t.GetProperty("ModuleName").GetValue(instance)?.ToString(); var iconName = t.GetProperty("IconName").GetValue(instance)?.ToString(); var showInDesktop = t.GetProperty("ShowInDesktop").GetValue(instance) as bool?; var isInstance = bool.Parse(t.GetProperty("IsInstance").GetValue(instance)?.ToString()); if (!string.IsNullOrWhiteSpace(moduleName)) { Console.Write("EXIT"); } var moduleErp = new ModuleErp(); moduleErp.Libelle = collection; moduleErp.EstAcceRapide = showInDesktop.Value; moduleErp.ClassName = $"{nspace}.{t.Name}"; moduleErp.GroupeModule = moduleName; moduleErp.ModuleIcon = iconName; moduleErp.ModuleSubmitable = (instance as ExtendedDocument).Submitable; moduleErp.IsInstanceModule = isInstance; moduleErp.Save(); } catch (Exception s) { Console.WriteLine("ERROR\n"); Console.WriteLine(s.Message); } } ); modules = DataHelpers.GetMongoDataSync("ModuleErp"); DataHelpers.Modules = modules as IEnumerable <ModuleErp>; }
public async Task OpenModuleErp(ModuleErp module) { var displayname = module.Libelle; var className = module.ClassName; var iconImg = module.ModuleIcon; var instance = module.IsInstanceModule; var instanceFunction = module.InstanceFunction; //var found = Items.FirstOrDefault(a => a.DisplayName == displayname); //if (found != null) //{ // ActivateItem(found); //} //else //{ if (instance == false) { //var type_ = Type.GetType(className); try { Type atype = DataHelpers.GetTypesModule.Resolve(className); if (atype == null) { return; } // var fqn = type_.FullName; var baseView = await DataHelpers.GetBaseViewModelScreen(atype, aggre, false); baseView.DisplayName = displayname; // Items.Add(baseView); ActivateItem(baseView); } catch (Exception s) { DataHelpers.ShowMessageError(s); } } else { try { Type type = DataHelpers.GetTypesModule.Resolve(className); var one = Activator.CreateInstance(type); //Activator.CreateInstance(Type.GetType(className)); var oneInstance = (IDocument)one.GetType() .GetMethod(instanceFunction). Invoke(one, null); if (oneInstance == null) { return; } this.OpenScreen(await DetailViewModel.Create(oneInstance, oneInstance.GetType(), aggre, this), $"{displayname}"); } catch (Exception s) { DataHelpers.ShowMessageError(s); return; } // } } }