Exemple #1
0
        private static List <ServiceTemplate> GetServices(string tocUrl)
        {
            var content = RemoteFileAccess.GetOnlineContent(tocUrl);

            //if 404 or no content then return empty list
            if (content == null)
            {
                return(new List <ServiceTemplate>());
            }
            //parse toc.json
            var urlAbsPath      = tocUrl.Replace("toc.json", "");
            var tocJsonObj      = JObject.Parse(content);
            var objWithChildren = tocJsonObj["items"].Where(obj => obj["children"] != null && obj["toc_title"] != null && obj["href"] != null);

            if (!objWithChildren.Any())
            {
                objWithChildren = tocJsonObj["items"].Where(obj => obj["children"] != null &&
                                                            obj["toc_title"] != null &&
                                                            obj["children"].First() != null &&
                                                            obj["children"].First()["toc_title"] != null &&
                                                            obj["children"].First()["toc_title"].ToString() == "Overview" &&
                                                            obj["children"].First()["href"] != null);
            }

            var services = objWithChildren.Select(obj =>
            {
                var name = (string)obj["toc_title"];
                var href = obj["href"] == null ? obj["children"].First()["href"] : obj["href"];
                var url  = new Uri(urlAbsPath + href).ToString();
                var des  = GetDes(url);
                return(new ServiceTemplate(name, url, des));
            }).ToList();

            return(services);
        }
Exemple #2
0
        public static List <string> GetFileNames(this RemoteFileAccess remoteFileAccess, string path = "")
        {
            List <string> peList = new List <string>();
            uint          handle = 0U;

            remoteFileAccess.OpenDir(FormatPath(path), ref handle);
            Value entries = null;

            remoteFileAccess.ReadDir(handle, ref entries, 100U, RemoteFileAccess.DirEntryFilter.FindFilesOnly);
            if (entries != null)
            {
                for (uint key = 0U; key < entries.ElementCount; ++key)
                {
                    Value obj = new Value();
                    entries.GetValue(key, ref obj);
                    string str = string.Empty;
                    obj.GetValue(ref str);
                    if (!str.Equals(".") && !str.Equals("..") && !peList.Contains(str))
                    {
                        peList.Add(str);
                    }
                    obj.Dispose();
                }
                entries.Dispose();
            }
            remoteFileAccess.CloseDir(handle);
            return(peList);
        }
Exemple #3
0
        private static string GetDes(string serviceUrl)
        {
            var          content           = WebUtility.HtmlDecode(RemoteFileAccess.GetOnlineContent(serviceUrl));
            const string defaultDesContent = "";

            //if 404 or parse error then return ""
            if (content == null)
            {
                return(defaultDesContent);
            }
            //parse the html
            Console.WriteLine($"Parse description from {serviceUrl}");
            var doc = new HtmlDocument();

            doc.LoadHtml(content);
            var desNodes = doc.DocumentNode.SelectSingleNode("//main/div[contains(@class, 'content')]/p");
            var des      = desNodes?.InnerText ?? defaultDesContent;

            return(des);
        }
Exemple #4
0
        internal static IConfigFile ReadConfigFile(this RemoteFileAccess remoteFileAccess,
                                                   IMetaService m_metaService,
                                                   string configFileName)
        {
            IConfigFile configFile = null;
            uint        handle     = 0U;
            string      path       = configFileName;

            remoteFileAccess.OpenFile(path, RemoteFileAccess.FileAccessMode.ReadAccess, ref handle);
            Siemens.Automation.OMSPlus.Managed.FileInfo info = new Siemens.Automation.OMSPlus.Managed.FileInfo();
            remoteFileAccess.GetFileInfo(configFileName, ref info);
            uint bytes_to_read = (uint)info.size;

            byte[] buffer = new byte[(int)bytes_to_read];
            uint   read   = 0U;

            remoteFileAccess.ReadFile(handle, ref buffer, bytes_to_read, RemoteFileAccess.CurrentPosition, ref read);
            byte[] bytes = new byte[(int)read];
            for (uint index = 0U; index < read; ++index)
            {
                bytes[(int)index] = buffer[(int)index];
            }
            string @string = new UTF8Encoding().GetString(bytes);

            remoteFileAccess.CloseFile(handle);
            XDocument innerDocument = m_metaService.ParseConfigFile(@string);

            if (innerDocument != null)
            {
                string fileName = Path.GetFileName(configFileName);
                ConfigFileParameters configFileParameters = GetConfigFileParameters(innerDocument, fileName);
                if (configFileParameters != null)
                {
                    configFile = new ConfigFile(configFileParameters);
                }
            }
            return(configFile);
        }