private string GenerateRuby(DTInterface deviceTemplate, string moduleName)
        {
            string rubyCode = "";

            using (var writer = new CodeWriter()) {
                OutputRuby(deviceTemplate, moduleName, deviceTemplate.Type[0], writer);
                rubyCode += writer.ToString();
            }

            return(rubyCode);
        }
예제 #2
0
        private DTInterface ModifyForRestApi(DTInterface src)
        {
            DTInterface dst = new DTInterface();

            dst.Id = src.Id;

            if (src.Type != null)
            {
                dst.Type = new StringList {
                    OutputArray = true
                };
                dst.Type.AddRange(src.Type);
            }

            if (src.Description != null)
            {
                dst.Description = new DTLocalizable {
                    OutputString = true
                };
                foreach (var kvp in src.Description)
                {
                    dst.Description.Add(kvp.Key, kvp.Value);
                }
            }

            if (src.DisplayName != null)
            {
                dst.DisplayName = new DTLocalizable {
                    OutputString = true
                };
                foreach (var kvp in src.DisplayName)
                {
                    dst.DisplayName.Add(kvp.Key, kvp.Value);
                }
            }

            //if (src.Context != null) {
            //	dst.Context = new StringList { OutputArray = true };
            //	dst.Context.AddRange(src.Context);
            //}

            if (src.Contents != null)
            {
                dst.Contents = new List <DTInterfaceContent>();
                foreach (var implement in src.Contents)
                {
                    dst.Contents.Add(ModifyForRestApi(implement));
                }
            }

            return(dst);
        }
        private static void OutputRuby(DTInterface deviceTemplate, string moduleName, string className, CodeWriter stream)
        {
            var cls = new RBClass {
                Name = className
            };

            foreach (var content in deviceTemplate.Contents)
            {
                if (content.Type.Contains("Telemetry"))
                {
                    if (content.Type.Contains("SemanticType/State"))
                    {
                        cls.States.Add(content);
                    }
                    else
                    {
                        cls.Telemetries.Add(content);
                    }
                }
                else if (content.Type.Contains("Command"))
                {
                    cls.Commands.Add(content);
                }
                else if (content.Type.Contains("Property"))
                {
                    cls.Properties.Add(content);
                }
            }

            stream.WriteLine("module " + moduleName);
            stream.Indent++;
            OutputRuby(cls, stream);
            stream.Indent--;
            stream.WriteLine("end");

            stream.WriteLine();

            OutputMainRoop(moduleName, className, stream);
        }