Example #1
0
        public static bool RealRemove(List <string> packageList)
        {
            //start recorder
            var recorder = new Record();

            recorder.Init();

            foreach (var item in packageList)
            {
                Console.WriteLine(I18N.Core("Remove_Removing", item));
                var res = ScriptInvoker.Core(Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, ScriptInvoker.InvokeMethod.Remove, "");
                if (!res.status)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_ScriptError"), ConsoleColor.Red);
                    ConsoleAssistance.WriteLine(res.desc, ConsoleColor.Red);
                    return(false);
                }
                Directory.Delete(Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, true);
                recorder.Remove(item);

                Console.WriteLine(I18N.Core("Remove_Success", item));
            }

            recorder.Save();
            return(true);
        }
Example #2
0
        public static void Core()
        {
            //remove all file

            ConsoleAssistance.WriteLine(I18N.Core("Clean_CleanAll"), ConsoleColor.Yellow);
            //confirm
            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            var strDownload   = Information.WorkPath.Enter("cache").Enter("download").Path;
            var strDependency = Information.WorkPath.Enter("cache").Enter("dependency").Path;

            Console.WriteLine(I18N.Core("Clean_Deleting", "download"));
            Directory.Delete(strDownload, true);
            Directory.CreateDirectory(strDownload);

            Console.WriteLine(I18N.Core("Clean_Deleting", "dependency"));
            Directory.Delete(strDependency, true);
            Directory.CreateDirectory(strDependency);

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Example #3
0
        public static void Core(string packageName, string parameter)
        {
            if (!packageName.Contains("@"))
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_SpecificVersion"), ConsoleColor.Red);
                return;
            }

            //get info
            var installFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("installed").Path);

            var directoryList = installFolder.GetDirectories($"{packageName}");

            if (directoryList.Count() == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                return;
            }

            var finalFolder = directoryList[0];
            var res         = ScriptInvoker.Core(finalFolder.FullName, ScriptInvoker.InvokeMethod.Deploy, parameter);

            if (!res.status)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_ScriptError"), ConsoleColor.Red);
                ConsoleAssistance.WriteLine(res.desc, ConsoleColor.Red);
                return;
            }

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Example #4
0
        public static void Core(string packageName)
        {
            //get info
            var installFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("installed").Path);

            DirectoryInfo[] directoryList;
            if (packageName.Contains("@"))
            {
                directoryList = installFolder.GetDirectories($"{packageName}");
            }
            else
            {
                directoryList = installFolder.GetDirectories($"{packageName}@*");
            }

            if (directoryList.Count() == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                return;
            }

            //sort remove package for ensure correctly remove
            var recorder = new Record();

            recorder.Init();
            var realPackage = recorder.SortPackage((from i in directoryList select i.Name).ToList());

            recorder.Save();

            ConsoleAssistance.WriteLine(I18N.Core("Remove_RemoveList"), ConsoleColor.Yellow);
            foreach (var item in realPackage)
            {
                Console.WriteLine($"{item}");
            }

            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            //remove
            var res = RealRemove(realPackage);

            if (!res)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_OperationAborted"), ConsoleColor.Red);
                return;
            }

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Example #5
0
        static (bool res, Dictionary <string, PackageJson> topologyMap) GetPackageInfo(string corePackage, Database sql)
        {
            Download.DownloadResult res;
            //corePackage = GetTopVersion(corePackage, sql);

            Dictionary <string, PackageJson> result = new Dictionary <string, PackageJson>();
            List <string> nowList = new List <string>()
            {
                corePackage
            };

            while (nowList.Count != 0)
            {
                var nextList = new List <string>();

                foreach (var item in nowList)
                {
                    //download
                    Console.WriteLine(I18N.Core("Install_DownloadInfo", item));
                    res = Download.DownloadPackageInfo(item);
                    Console.WriteLine(Download.JudgeDownloadResult(res));
                    if (res != Download.DownloadResult.OK && res != Download.DownloadResult.ExistedLocalFile)
                    {
                        return(false, null);
                    }

                    var fs    = new StreamReader(Information.WorkPath.Enter("cache").Enter("dependency").Enter(item + ".json").Path, Encoding.UTF8);
                    var cache = JsonConvert.DeserializeObject <PackageJson>(fs.ReadToEnd());
                    fs.Close();
                    fs.Dispose();

                    //add item
                    result.Add(item, cache);

                    foreach (var dependency in cache.dependency)
                    {
                        var dependencyPackage = GetVersionNatrually(dependency, sql);
                        if (!result.ContainsKey(dependencyPackage))
                        {
                            nextList.Add(dependencyPackage);
                        }
                    }
                }

                nowList = new List <string>(nextList);
            }

            return(true, result);
        }
Example #6
0
        public static void Core(string packageName)
        {
            //get info
            var downloadFolder   = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("download").Path);
            var dependencyFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("dependency").Path);

            var filelist = new List <string>();

            if (packageName.Contains("@"))
            {
                //special version
                filelist.AddRange(from item in downloadFolder.GetFiles($"{packageName}.zip") select item.FullName);
                filelist.AddRange(from item in dependencyFolder.GetFiles($"{packageName}.json") select item.FullName);
            }
            else
            {
                //all version
                filelist.AddRange(from item in downloadFolder.GetFiles($"{packageName}@*.zip") select item.FullName);
                filelist.AddRange(from item in dependencyFolder.GetFiles($"{packageName}@*.json") select item.FullName);
            }

            ConsoleAssistance.WriteLine(I18N.Core("Clean_FileList"), ConsoleColor.Yellow);
            foreach (var item in filelist)
            {
                Console.WriteLine($"{item}");
            }

            //confirm
            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            foreach (var item in filelist)
            {
                Console.WriteLine(I18N.Core("Clean_Deleting", item));
                File.Delete(item);
            }

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Example #7
0
File: Show.cs Project: yyc12345/bpm
        public static void Core(string packageName)
        {
            if (!packageName.Contains("@"))
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_SpecificVersion"), ConsoleColor.Red);
                return;
            }

            //read database
            var packageDbConn = new Database();

            packageDbConn.Open();

            var reader = (from item in packageDbConn.CoreDbContext.package
                          where item.name == packageName.Split("@", StringSplitOptions.None)[0]
                          select item).ToList();

            //detect existing
            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                packageDbConn.Close();
                return;
            }
            //detect version
            if (!reader[0].version.Split('@').Contains(packageName.Split("@")[1]))
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                packageDbConn.Close();
                return;
            }

            //read json file
            var res = Download.DownloadPackageInfo(packageName);

            Console.WriteLine(Download.JudgeDownloadResult(res));
            if (res != Download.DownloadResult.OK && res != Download.DownloadResult.ExistedLocalFile)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Show_FailJson"), ConsoleColor.Red);
                return;
            }

            ConsoleAssistance.WriteLine(packageName, ConsoleColor.Green);
            Console.WriteLine("");

            //databse data
            ConsoleAssistance.WriteLine($"{I18N.Core("Search&Show_Aka")}{reader[0].aka}", ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine($"{I18N.Core("Search&Show_Type")}{I18N.Core($"PackageType_{((PackageType)reader[0].type).ToString()}")}", ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine($"{I18N.Core("Search&Show_Desc")}{reader[0].desc}", ConsoleColor.Yellow);

            packageDbConn.Close();

            var fs    = new StreamReader(Information.WorkPath.Enter("cache").Enter("dependency").Enter(packageName + ".json").Path, Encoding.UTF8);
            var cache = JsonConvert.DeserializeObject <PackageJson>(fs.ReadToEnd());

            fs.Close();
            fs.Dispose();

            Console.WriteLine("");
            //output json
            ConsoleAssistance.WriteLine(I18N.Core("Show_Dependency"), ConsoleColor.Yellow);
            if (cache.dependency.Count() == 0)
            {
                ConsoleAssistance.WriteLine("None", ConsoleColor.Yellow);
            }
            foreach (var item in cache.dependency)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("");
            if (!cache.reverseConflict)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Show_Conflict"), ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine(I18N.Core("Show_Compatible"), ConsoleColor.Yellow);
            }
            if (cache.conflict.Count() == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_None"), ConsoleColor.Yellow);
            }
            foreach (var item in cache.conflict)
            {
                Console.WriteLine(item);
            }
        }
Example #8
0
        public static void Core(string packageName)
        {
            Console.WriteLine(I18N.Core("Install_CollectingPackageInfo"));

            //=================================================================pre-process
            //name is legal
            var packageDbConn = new Database();

            packageDbConn.Open();

            var reader = (from _i in packageDbConn.CoreDbContext.package
                          where _i.name == (packageName.Contains("@") ? packageName.Split('@', StringSplitOptions.None)[0] : packageName)
                          select _i).ToList();

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                return;
            }
            packageName = GetVersionNatrually(packageName, packageDbConn);

            //is installed ?
            var installFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("installed").Path);

            if (installFolder.GetDirectories($"{packageName}").Any())
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_InstalledPackage"), ConsoleColor.Red);
                return;
            }

            //====================================================================get-info
            //get denpendency tree
            Console.WriteLine(I18N.Core("Install_BuildingDependencyTree"));
            var cache1 = GetPackageInfo(packageName, packageDbConn);

            if (!cache1.res)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NetworkError"), ConsoleColor.Red);
                return;
            }

            //conflict detect
            Console.WriteLine(I18N.Core("Install_DetectConflict"));
            var cache2 = DetectConflict(cache1.topologyMap, packageDbConn);

            if (!cache2.status)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_SelfConflict"), ConsoleColor.Red);
                return;
            }

            //sort dependency
            Console.WriteLine(I18N.Core("Install_SortingDependencyTree"));
            var cache1_1 = new Dictionary <string, List <string> >();

            foreach (var item in cache1.topologyMap.Keys)
            {
                var cache = new List <string>();
                foreach (var depItem in cache1.topologyMap[item].dependency.ToList())
                {
                    cache.Add(GetTopVersion(depItem, packageDbConn));
                }
                cache1_1.Add(item, cache);
            }
            var cache3 = KahnTopologySort(cache1_1);

            if (!cache3.status)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_CloseLoop"), ConsoleColor.Red);
                return;
            }

            //remove installed package
            var realPackage = new List <string>(cache3.res);

            foreach (var item in installFolder.GetDirectories())
            {
                if (realPackage.Contains(item.Name))
                {
                    realPackage.Remove(item.Name);
                }
            }

            packageDbConn.Close();

            //sort removed package
            var sort_recorder = new Record();

            sort_recorder.Init();
            var realRemovedPackage = sort_recorder.SortPackage(cache2.res);

            sort_recorder.Save();
            //=======================================================================output

            ConsoleAssistance.WriteLine(I18N.Core("Install_InstallList"), ConsoleColor.Yellow);
            foreach (var item in realPackage)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("");

            ConsoleAssistance.WriteLine(I18N.Core("Install_RemoveList"), ConsoleColor.Yellow);
            if (realRemovedPackage.Count == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_None"), ConsoleColor.Yellow);
            }
            foreach (var item in realRemovedPackage)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("");

            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            //============================================================================install
            //remove
            Console.WriteLine(I18N.Core("Install_RemovingSelectedPackage"));
            Remove.RealRemove(realRemovedPackage);

            //install
            Console.WriteLine(I18N.Core("Install_InstallingSelectedPackage"));
            //ready recorder
            var recorder = new Record();

            recorder.Init();

            var zipExtractor = new FastZip();

            foreach (var item in realPackage)
            {
                Console.WriteLine(I18N.Core("Install_InstallItem", item));
                //download
                var downloadRes = Download.DownloadPackage(item);
                Console.WriteLine(Download.JudgeDownloadResult(downloadRes));

                if (downloadRes != Download.DownloadResult.OK && downloadRes != Download.DownloadResult.ExistedLocalFile)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_NetworkError"), ConsoleColor.Red);
                    return;
                }

                //remove decompress folder
                Directory.Delete(Information.WorkPath.Enter("cache").Enter("decompress").Path, true);
                Directory.CreateDirectory(Information.WorkPath.Enter("cache").Enter("decompress").Path);

                //decompress
                Console.WriteLine(I18N.Core("Install_ExtractItem", item));

                zipExtractor.ExtractZip(Information.WorkPath.Enter("cache").Enter("download").Enter(item + ".zip").Path, Information.WorkPath.Enter("cache").Enter("decompress").Path, "");

                Console.WriteLine(I18N.Core("Install_RunScriptItem", item));
                var cacheRes = ScriptInvoker.Core(Information.WorkPath.Enter("cache").Enter("decompress").Path, ScriptInvoker.InvokeMethod.Install, "");
                if (!cacheRes.status)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_ScriptError"), ConsoleColor.Red);
                    ConsoleAssistance.WriteLine(cacheRes.desc, ConsoleColor.Red);
                    //save installed package info
                    recorder.Save();
                    return;
                }

                //record first and copy folders
                Console.WriteLine(I18N.Core("Install_RecordItem", item));
                recorder.Add(item);
                PackageAssistance.DirectoryCopy(Information.WorkPath.Enter("cache").Enter("decompress").Path, Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, true);

                Console.WriteLine(I18N.Core("Install_Success", item));
            }

            //close recorder
            recorder.Save();

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }