Esempio n. 1
0
        private void deactivate(ISettings stt)
        {
            string dir = getExtractDir(stt);

            if (Directory.Exists(dir))
            {
                PackInfoJson info;
                if (PackInfoJson.TryParse(dir, out info))
                {
                    foreach (var ci in info.copy)
                    {
                        string dest = ci.destination;
#if DEBUG
                        dest = string.Concat("/tmp/Netcad/NDU/GUA_test/custom_copy", dest);
#endif
                        foreach (string fn in this.CustomCopiedFiles)
                        {
                            File.Delete(fn);
                        }
                        this.CustomCopiedFiles.Clear();
                    }
                }
                Helper.DeleteDir(dir);
            }
        }
Esempio n. 2
0
        private static PackInfoJson _extract(string zipFn, string extractDir)
        {
            if (!Directory.Exists(extractDir))
            {
                Directory.CreateDirectory(extractDir);
            }
            else
            {
                Helper.CleanDir(extractDir);
            }

            ZipFile.ExtractToDirectory(zipFn, extractDir);
            return(PackInfoJson.Parse(extractDir));
        }
Esempio n. 3
0
            public static bool TryParse(string extractDir, out PackInfoJson p)
            {
                string infoJsonFn = getInfoJsonFn(extractDir);

                if (!File.Exists(infoJsonFn))
                {
                    p = null;
                    return(false);
                }
                else
                {
                    try
                    {
                        p = Helper.DeserializeFromJsonFile <PackInfoJson>(infoJsonFn);
                        return(p != null);
                    }
                    catch
                    {
                        p = null;
                        return(false);
                    }
                }
            }
Esempio n. 4
0
        private void install(ISettings stt)
        {
            this.deactivate(stt);
            string zipFn = this.getZipFileName(stt);

            if (!File.Exists(zipFn))
            {
                throw new Exception($"Downloaded file does not exist: {zipFn}");
            }
            else
            {
                string       extractDir = getExtractDir(stt);
                PackInfoJson info       = _extract(zipFn, extractDir);
                this.YamlConnectorItems = info.connector_config;

                //**NDU-317 - 2
                if (this.YamlConnectorItems == null)
                {
                    this.YamlConnectorItems = new Dictionary <string, object>();
                }
                const string  keyUuids = "uuids";
                List <string> lstUuid  = null;
                if (this.YamlConnectorItems.ContainsKey(keyUuids))
                {
                    lstUuid = this.YamlConnectorItems[keyUuids] as List <string>;
                }
                if (lstUuid == null)
                {
                    lstUuid = new List <string>();
                }
                if (!lstUuid.Contains(this.UUID))
                {
                    lstUuid.Add(this.UUID);
                }
                this.YamlConnectorItems[keyUuids] = lstUuid;
                //**

                if (info.copy != null)
                {
                    foreach (CopyInfo ci in info.copy)
                    {
                        string dest = ci.destination;
#if DEBUG
                        dest = string.Concat("/tmp/Netcad/NDU/GUA_test/custom_copy", dest);
#endif
                        string source = Path.Combine(extractDir, ci.source);
                        if (File.Exists(source))
                        {
                            File.Copy(source, dest, true);
                            File.Delete(source);
                            this.CustomCopiedFiles.Add(dest);
                        }
                        else if (Directory.Exists(source))
                        {
                            this.CustomCopiedFiles.AddRange(Helper.CopyDir(source, dest, false));
                            Helper.DeleteDir(source);
                        }
                        else
                        {
                            throw new Exception($"Cannot copy a file in pack! Source: {source} Destination: {dest}");
                        }
                    }
                }
            }
        }