Exemple #1
0
        private static Deps GetDependencies(string csproj, HashSet <string> handledCsProj)
        {
            //Console.WriteLine($"TRACE: GetDependencies({csproj})");
            var baseName = Path.GetFileName(csproj);

            if (handledCsProj.Contains(baseName))
            {
                return(null);
            }
            handledCsProj.Add(baseName);

            var csprojFolder  = Path.GetDirectoryName(csproj);
            var csprojContent = File.ReadAllText(csproj);

            var result = new Deps();

            foreach (var reference in GetAllProjectReferences(csprojContent))
            {
                var innerCsProj = reference;
                //Console.WriteLine($"TRACE: GetDependencies(): innerCsProj={innerCsProj}");
                innerCsProj = innerCsProj.Replace("\\", "/");
                innerCsProj = Path.Combine(csprojFolder, innerCsProj);
                //Console.WriteLine($"TRACE: GetDependencies(): innerCsProj after combine ={innerCsProj}");
                innerCsProj = Path.GetFullPath(innerCsProj);
                //Console.WriteLine($"TRACE: GetDependencies(): innerCsProj after get full path ={innerCsProj}");
                result.Dependencies.Add(Path.GetFileName(innerCsProj), GetDependencies(innerCsProj, handledCsProj));
            }
            return(result);
        }
Exemple #2
0
        public RuntimeIshtarClass FindType(RuntimeToken type,
                                           bool findExternally = false)
        {
            var result = class_table.OfExactType <RuntimeIshtarClass>().FirstOrDefault(filter);

            if (result is not null)
            {
                return(result);
            }

            bool filter(RuntimeIshtarClass x) => x !.runtime_token.Equals(type);

            if (!findExternally)
            {
                return(null);
            }

            foreach (var module in Deps.OfExactType <RuntimeIshtarModule>())
            {
                result = module.FindType(type, true);
                if (result is not null)
                {
                    return(result);
                }
            }

            return(null);
        }
    public async Task Saving_doesnt_throw_exception_on_ignored_entities()
    {
        using var context = Deps.FoodStuffsContextAuditable().Seed();

        var cr = context.CategoryRecipe.First();

        cr.Name = "new name";
        await context.SaveChangesAsync();
    }
Exemple #4
0
        /// <summary>
        /// Finds dependencies to other XAMLS and resources (fonts, textures, sounds...).
        /// </summary>
        /// <param name="xaml">Stream with xaml content.</param>
        /// <param name="folder">Root directory used for relative dependencies.</param>
        /// <param name="callback">Called for each dependency found.</param>
        public static void GetXamlDependencies(Stream xaml, string folder,
                                               XamlDependencyCallback callback)
        {
            Deps deps = new Deps {
                Callback = callback
            };
            int callbackId = deps.GetHashCode();

            _depsCallbacks[callbackId] = deps;
            Noesis_GetXamlDependencies(Extend.GetInstanceHandle(xaml), folder, callbackId, _xamlDep);
            _depsCallbacks.Remove(callbackId);
        }
Exemple #5
0
 private static void PrintDeps(Deps deps, int depth = 0)
 {
     if (deps == null)
     {
         return;
     }
     foreach (var dep in deps.Dependencies)
     {
         Console.WriteLine($"{new string('\t', depth)}{dep.Key}");
         PrintDeps(dep.Value, depth + 1);
     }
 }
Exemple #6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Deps deps = (Deps)target;

            if (GUILayout.Button("Print Key"))
            {
                if (deps.Dependencies.Count > 0)
                {
                    Debug.LogError(deps.Dependencies[0].AssetReference.RuntimeKey.ToString());
                }
            }
        }
    public async Task Add_sets_creation_properties_offset()
    {
        using var context = Deps.FoodStuffsContextAuditable().Seed();

        var c = new Category() { Name = "new category" };
        context.Category.Add(c);
        await context.SaveChangesAsync();

        Assert.Equal(Deps.CurrentUserAccessor.User.Login, c.CreatedBy);
        Assert.Equal(Deps.CurrentUserAccessor.User.Login, c.ModifiedBy);

        Assert.Equal(Deps.DateTimeServiceLate.MomentWithOffset, c.CreatedOn);
        Assert.Equal(Deps.DateTimeServiceLate.MomentWithOffset, c.ModifiedOn);
    }
    public async Task Add_sets_creation_properties()
    {
        using var context = Deps.FoodStuffsContextAuditable().Seed();

        var r = new Recipe() { Name = "new recipe", Directions = "", Ingredients = "" };
        context.Recipe.Add(r);
        await context.SaveChangesAsync();

        Assert.Equal(Deps.CurrentUserAccessor.User.Login, r.CreatedBy);
        Assert.Equal(Deps.CurrentUserAccessor.User.Login, r.ModifiedBy);

        Assert.Equal(Deps.DateTimeServiceLate.Moment, r.CreatedOn);
        Assert.Equal(Deps.DateTimeServiceLate.Moment, r.ModifiedOn);
    }
Exemple #9
0
 private static void OnXamlDependency(int callbackId, IntPtr uri, int type)
 {
     try
     {
         if (_initialized)
         {
             Deps deps = _depsCallbacks[callbackId];
             deps.Callback(Extend.StringFromNativeUtf8(uri), (XamlDependencyType)type);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
    public async Task Modify_sets_modification_properties_offset()
    {
        using var context = Deps.FoodStuffsContextAuditable().Seed();

        var c = context.Category.First();

        c.Name = "new name";
        await context.SaveChangesAsync();

        Assert.Equal("Void", c.CreatedBy);
        Assert.Equal(Deps.CurrentUserAccessor.User.Login, c.ModifiedBy);

        Assert.Equal(Deps.DateTimeServiceEarly.MomentWithOffset, c.CreatedOn);
        Assert.Equal(Deps.DateTimeServiceLate.MomentWithOffset, c.ModifiedOn);
    }
Exemple #11
0
 private static void OnXamlDependency(int callbackId, IntPtr uri, int type)
 {
     try
     {
         if (_initialized)
         {
             Deps   deps   = _depsCallbacks[callbackId];
             string uriStr = Extend.StringFromNativeUtf8(uri);
             deps.Callback(new Uri(uriStr, UriKind.RelativeOrAbsolute), (XamlDependencyType)type);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
        public List <Deps> AllDepsTreeBasedOrg(UserContext db, int OrgId)

        {
            deps = new List <Deps>();
            List <int> l = db.department.Where(x => x.OrgId == OrgId).Select(x => x.Id).ToList();

            //recursive(l, db);
            foreach (department x in db.Org.Find(OrgId).department.ToList())
            {
                Deps dp = new Deps();
                dp.Child  = db.DepPointer.Where(z => z.ParentId == x.Id).Select(z => z.ChildId).ToList();
                dp.Parent = db.DepPointer.Where(z => z.ChildId == x.Id).ToList().Count > 0? db.DepPointer.Where(z => z.ChildId == x.Id).ToList()[0].ParentId:0;
                dp.Dep    = x;

                deps.Add(dp);
            }
            //db.Org.Find(OrgId).department.ToList().ForEach(x => deps.Add(new Deps {Child=db.DepPointer.Where(z=>z.ParentId==x.Id).Select(z=>z.ChildId).ToList(),Parent=db.DepPointer.FirstOrDefault(z=>z.ChildId==x.Id).ParentId,Dep=x}));
            return(deps);
        }
    public async Task Delete_sets_soft_delete_properties_offset()
    {
        using var context = Deps.FoodStuffsContextAuditable().Seed();

        var c = context.Category.First();

        context.CategoryRecipe.RemoveRange(context.CategoryRecipe.Where(x => x.Category == c).ToList());
        context.Remove(c);
        await context.SaveChangesAsync();

        Assert.Equal("Void", c.CreatedBy);
        Assert.Equal("Void", c.ModifiedBy);

        Assert.Equal(Deps.DateTimeServiceEarly.MomentWithOffset, c.CreatedOn);
        Assert.Equal(Deps.DateTimeServiceEarly.MomentWithOffset, c.ModifiedOn);

        Assert.Equal(Deps.CurrentUserAccessor.User.Login, c.DeletedBy);
        Assert.Equal(Deps.DateTimeServiceLate.MomentWithOffset, c.DeletedOn);
        Assert.True(c.IsDeleted);
    }
    public async Task Get_recipe_returns_recipe_by_id_when_found()
    {
        using var context = Deps.FoodStuffsContext();
        var data = context.Seed().FoodStuffsData();

        var recipes = await data.Recipes.ListAll(default);
Exemple #15
0
        private static void Install(Session Session, string ManifestFile, string ServerApplication, string ProgramDataFolder)
        {
            // Same code as for custom action InstallManifest in Waher.IoTGateway.Installers

            if (string.IsNullOrEmpty(ManifestFile))
            {
                throw new Exception("Missing manifest file.");
            }

            if (string.IsNullOrEmpty(ServerApplication))
            {
                throw new Exception("Missing server application.");
            }

            if (string.IsNullOrEmpty(ProgramDataFolder))
            {
                ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "IoT Gateway");
                Session.Log("Using default program data folder: " + ProgramDataFolder);
            }

            if (!File.Exists(ServerApplication))
            {
                throw new Exception("Server application not found: " + ServerApplication);
            }

            Session.Log("Getting assembly name of server.");
            AssemblyName ServerName = AssemblyName.GetAssemblyName(ServerApplication);

            Session.Log("Server assembly name: " + ServerName.ToString());

            string DepsJsonFileName;

            int i = ServerApplication.LastIndexOf('.');

            if (i < 0)
            {
                DepsJsonFileName = ServerApplication;
            }
            else
            {
                DepsJsonFileName = ServerApplication.Substring(0, i);
            }

            DepsJsonFileName += ".deps.json";

            Session.Log("deps.json file name: " + DepsJsonFileName);

            if (!File.Exists(DepsJsonFileName))
            {
                throw new Exception("Invalid server executable. No corresponding deps.json file found.");
            }

            Session.Log("Opening " + DepsJsonFileName);

            string s = File.ReadAllText(DepsJsonFileName);

            Session.Log("Parsing " + DepsJsonFileName);

            if (!(JSON.Parse(s) is Dictionary <string, object> Deps))
            {
                throw new Exception("Invalid deps.json file. Unable to install.");
            }

            Session.Log("Loading manifest file.");

            XmlDocument Manifest = new XmlDocument();

            Manifest.Load(ManifestFile);

            XmlElement Module       = Manifest["Module"];
            string     SourceFolder = Path.GetDirectoryName(ManifestFile);
            string     AppFolder    = Path.GetDirectoryName(ServerApplication);

            Session.Log("Source folder: " + SourceFolder);
            Session.Log("App folder: " + AppFolder);

            foreach (XmlNode N in Module.ChildNodes)
            {
                if (N is XmlElement E && E.LocalName == "Assembly")
                {
                    string FileName       = XML.Attribute(E, "fileName");
                    string SourceFileName = Path.Combine(SourceFolder, FileName);

                    if (CopyFileIfNewer(Session, SourceFileName, Path.Combine(AppFolder, FileName), true))
                    {
                        if (FileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
                        {
                            string PdbFileName = FileName.Substring(0, FileName.Length - 4) + ".pdb";
                            if (File.Exists(PdbFileName))
                            {
                                CopyFileIfNewer(Session, Path.Combine(SourceFolder, PdbFileName), Path.Combine(AppFolder, PdbFileName), false);
                            }
                        }
                    }

                    Assembly     A  = Assembly.LoadFrom(SourceFileName);
                    AssemblyName AN = A.GetName();

                    if (Deps != null && Deps.TryGetValue("targets", out object Obj) && Obj is Dictionary <string, object> Targets)
                    {
                        foreach (KeyValuePair <string, object> P in Targets)
                        {
                            if (P.Value is Dictionary <string, object> Target)
                            {
                                foreach (KeyValuePair <string, object> P2 in Target)
                                {
                                    if (P2.Key.StartsWith(ServerName.Name + "/") &&
                                        P2.Value is Dictionary <string, object> App &&
                                        App.TryGetValue("dependencies", out object Obj2) &&
                                        Obj2 is Dictionary <string, object> Dependencies)
                                    {
                                        Dependencies[AN.Name] = AN.Version.ToString();
                                        break;
                                    }
                                }

                                Dictionary <string, object> Dependencies2 = new Dictionary <string, object>();

                                foreach (AssemblyName Dependency in A.GetReferencedAssemblies())
                                {
                                    Dependencies2[Dependency.Name] = Dependency.Version.ToString();
                                }

                                Dictionary <string, object> Runtime = new Dictionary <string, object>()
                                {
                                    { Path.GetFileName(SourceFileName), new Dictionary <string, object>() }
                                };

                                Target[AN.Name + "/" + AN.Version.ToString()] = new Dictionary <string, object>()
                                {
                                    { "dependencies", Dependencies2 },
                                    { "runtime", Runtime }
                                };
                            }
                        }
                    }

                    if (Deps != null && Deps.TryGetValue("libraries", out object Obj3) && Obj3 is Dictionary <string, object> Libraries)
                    {
                        foreach (KeyValuePair <string, object> P in Libraries)
                        {
                            if (P.Key.StartsWith(AN.Name + "/"))
                            {
                                Libraries.Remove(P.Key);
                                break;
                            }
                        }

                        Libraries[AN.Name + "/" + AN.Version.ToString()] = new Dictionary <string, object>()
                        {
                            { "type", "project" },
                            { "serviceable", false },
                            { "sha512", string.Empty }
                        };
                    }
                }
            }

            if (SourceFolder == AppFolder)
            {
                Session.Log("Skipping copying of content. Source and application folders the same. Assuming content files are located where they should be.");
            }
            else
            {
                CopyContent(Session, SourceFolder, AppFolder, ProgramDataFolder, Module);
            }

            Session.Log("Encoding JSON");
            s = JSON.Encode(Deps, true);

            Session.Log("Writing " + DepsJsonFileName);
            File.WriteAllText(DepsJsonFileName, s, Encoding.UTF8);
        }
Exemple #16
0
        private static void Uninstall(Session Session, string ManifestFile, string ServerApplication, string ProgramDataFolder, bool Remove)
        {
            // Same code as for custom action InstallManifest in Waher.IoTGateway.Installers

            if (string.IsNullOrEmpty(ManifestFile))
            {
                throw new Exception("Missing manifest file.");
            }

            if (string.IsNullOrEmpty(ServerApplication))
            {
                throw new Exception("Missing server application.");
            }

            if (string.IsNullOrEmpty(ProgramDataFolder))
            {
                ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "IoT Gateway");
                Session.Log("Using default program data folder: " + ProgramDataFolder);
            }

            if (!File.Exists(ServerApplication))
            {
                throw new Exception("Server application not found: " + ServerApplication);
            }

            Session.Log("Getting assembly name of server.");
            AssemblyName ServerName = AssemblyName.GetAssemblyName(ServerApplication);

            Session.Log("Server assembly name: " + ServerName.ToString());

            string DepsJsonFileName;

            int i = ServerApplication.LastIndexOf('.');

            if (i < 0)
            {
                DepsJsonFileName = ServerApplication;
            }
            else
            {
                DepsJsonFileName = ServerApplication.Substring(0, i);
            }

            DepsJsonFileName += ".deps.json";

            Session.Log("deps.json file name: " + DepsJsonFileName);

            if (!File.Exists(DepsJsonFileName))
            {
                throw new Exception("Invalid server executable. No corresponding deps.json file found.");
            }

            Session.Log("Opening " + DepsJsonFileName);

            string s = File.ReadAllText(DepsJsonFileName);

            Session.Log("Parsing " + DepsJsonFileName);

            if (!(JSON.Parse(s) is Dictionary <string, object> Deps))
            {
                throw new Exception("Invalid deps.json file. Unable to install.");
            }

            Session.Log("Loading manifest file.");

            XmlDocument Manifest = new XmlDocument();

            Manifest.Load(ManifestFile);

            XmlElement Module    = Manifest["Module"];
            string     AppFolder = Path.GetDirectoryName(ServerApplication);

            Session.Log("App folder: " + AppFolder);

            foreach (XmlNode N in Module.ChildNodes)
            {
                if (N is XmlElement E && E.LocalName == "Assembly")
                {
                    string FileName    = XML.Attribute(E, "fileName");
                    string AppFileName = Path.Combine(AppFolder, FileName);

                    Assembly     A   = Assembly.LoadFrom(AppFileName);
                    AssemblyName AN  = A.GetName();
                    string       Key = AN.Name + "/" + AN.Version.ToString();

                    if (Deps != null && Deps.TryGetValue("targets", out object Obj) && Obj is Dictionary <string, object> Targets)
                    {
                        Targets.Remove(Key);

                        foreach (KeyValuePair <string, object> P in Targets)
                        {
                            if (P.Value is Dictionary <string, object> Target)
                            {
                                foreach (KeyValuePair <string, object> P2 in Target)
                                {
                                    if (P2.Key.StartsWith(ServerName.Name + "/") &&
                                        P2.Value is Dictionary <string, object> App &&
                                        App.TryGetValue("dependencies", out object Obj2) &&
                                        Obj2 is Dictionary <string, object> Dependencies)
                                    {
                                        Dependencies.Remove(AN.Name);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (Deps != null && Deps.TryGetValue("libraries", out object Obj3) && Obj3 is Dictionary <string, object> Libraries)
                    {
                        foreach (KeyValuePair <string, object> P in Libraries)
                        {
                            if (P.Key.StartsWith(AN.Name + "/"))
                            {
                                Libraries.Remove(P.Key);
                                break;
                            }
                        }
                    }

                    if (Remove)
                    {
                        RemoveFile(Session, AppFileName);
                        if (FileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
                        {
                            string PdbFileName = FileName.Substring(0, FileName.Length - 4) + ".pdb";
                            RemoveFile(Session, PdbFileName);
                        }
                    }
                }
            }

            Session.Log("Encoding JSON");
            s = JSON.Encode(Deps, true);

            Session.Log("Writing " + DepsJsonFileName);
            File.WriteAllText(DepsJsonFileName, s, Encoding.UTF8);

            if (Path.GetDirectoryName(ManifestFile) == AppFolder)
            {
                RemoveFile(Session, ManifestFile);
            }
        }