public DrwBlock ExtractDrwBlockFromNav(XPathNavigator nav, ReplacementConfiguration config)
        {
            if (!nav.HasChildren)
            {
                return(null);
            }

            int    id          = -1;
            string description = null;

            nav.MoveToFirstChild();

            do
            {
                if (nav.Name.ToLower() == "id")
                {
                    try
                    {
                        id = int.Parse(nav.Value.Trim());
                    }
                    catch (Exception e) { throw new Exception("Id not an integer in DrwFile", e); }
                }
                else if (nav.Name.ToLower() == "description")
                {
                    description = ReplacementConfigurationSanitizer(nav.Value, config);
                }
            } while (nav.MoveToNext());

            DrwBlock block = new DrwBlock(id, description);

            return(block);
        }
Exemplo n.º 2
0
        public FBPGraph GenerateFBPGraph(string filepath)
        {
            ReplacementConfiguration config = utility.ReadConfigurationFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ICANSEEDrwReplacementConfiguration.json"));
            FBPGraph graph = helper.GenerateFBPGraphFromDrwFile(File.OpenRead(filepath), config);

            return(graph);
        }
 private string ReplacementConfigurationSanitizer(string value, ReplacementConfiguration config)
 {
     foreach (var pair in config.ReplacementStrings)
     {
         value = value.Replace(pair.Key, pair.Value);
     }
     return(value);
 }
        public ReplacementConfiguration ReadConfigurationFromFile(string path)
        {
            Dictionary <string, string> replacementStrings = new Dictionary <string, string>();

            List <DrwReplacementConfigurationUnit> replacers = JsonConvert.DeserializeObject <List <DrwReplacementConfigurationUnit> >(File.ReadAllText(path));

            foreach (var item in replacers)
            {
                replacementStrings[item.ToReplace] = item.ReplaceWith;
            }

            ReplacementConfiguration configuration = new ReplacementConfiguration(replacementStrings);

            return(configuration);
        }
Exemplo n.º 5
0
        //public string ExecutePreset(int cameraId, string presetId)
        //{
        //    CameraConfiguration cameraConfiguration = helper.QueryCameraDescription(cameraId);
        //    return helper.ExecutePreset(presetId, cameraConfiguration);
        //}

        public FBPGraph ReadFBPConfiguration(string filepath)
        {
            ReplacementConfiguration config = utility.ReadConfigurationFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ICANSEEDrwReplacementConfiguration.json"));

            FBPGraph graph = helper.GenerateFBPGraphFromDrwFile(File.OpenRead(filepath), config);

            // Debug Replacers
            string dumpOfConvertedValue = string.Empty;

            foreach (var pair in graph.GetBlockFromId)
            {
                dumpOfConvertedValue += pair.Value.description + "\r\n\r\n\r\n";
            }
            File.WriteAllText("Debug Replacers Result.txt", dumpOfConvertedValue);

            return(graph);
        }
        public FBPGraph GenerateFBPGraphFromDrwFile(Stream drwFileStream, ReplacementConfiguration configuration)
        {
            XPathDocument  xmlPathDoc = new XPathDocument(drwFileStream);
            XPathNavigator navigator  = xmlPathDoc.CreateNavigator();

            XPathNodeIterator blockIterator      = navigator.SelectDescendants("block", "", false);
            XPathNodeIterator connectionIterator = navigator.SelectDescendants("connection", "", false);

            int count = connectionIterator.Count;

            List <DrwBlock>      blocks      = new List <DrwBlock>();
            List <DrwConnection> connections = new List <DrwConnection>();

            while (blockIterator.MoveNext())
            {
                XPathNavigator nav = blockIterator.Current.Clone();

                DrwBlock block = utility.ExtractDrwBlockFromNav(nav, configuration);

                if (block != null)
                {
                    blocks.Add(block);
                }
            }

            while (connectionIterator.MoveNext())
            {
                XPathNavigator nav = connectionIterator.Current.Clone();

                DrwConnection connection = utility.ExtractDrwConnectionFromNav(nav);

                if (connection != null)
                {
                    connections.Add(connection);
                }
            }

            FBPGraph graph = new FBPGraph(blocks, connections);

            return(graph);
        }
Exemplo n.º 7
0
 public FBPGraph GenerateFBPGraphFromDrwFile(Stream drwFileStream, ReplacementConfiguration configuration)
 {
     return(utility.GenerateFBPGraphFromDrwFile(drwFileStream, configuration));
 }