Esempio n. 1
0
        public virtual void WriteEDATA(JSONNode inNode)
        {
            int currentVersion = Genie.TELEMETRY_VERSION;

            JSONNode eks = inNode["eks"] = new JSONClass();
            JSONNode ext = inNode["ext"] = new JSONClass();

            var fields = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var f in fields)
            {
                JSONNode target = null;

                if (Attribute.IsDefined(f, typeof(EKSAttribute)))
                {
                    target = eks;
                }
                else if (Attribute.IsDefined(f, typeof(EXTAttribute)))
                {
                    target = ext;
                }
                else
                {
                    continue;
                }

                object value = f.GetValue(this);
                string name  = f.Name;

                bool bWriteOut = value != null;
                if (bWriteOut)
                {
                    RemovedInVersionAttribute[] removedVersions = TypeHelper.GetCustomAttributes <RemovedInVersionAttribute>(f);
                    foreach (var removedAttribute in removedVersions)
                    {
                        if (currentVersion >= removedAttribute.VersionRemoved && currentVersion < removedAttribute.VersionReinstated)
                        {
                            bWriteOut = false;
                            break;
                        }
                    }
                }
                if (bWriteOut)
                {
                    RenamedInVersionAttribute[] renamedVersions = TypeHelper.GetCustomAttributes <RenamedInVersionAttribute>(f);
                    int minProcessed = 0;
                    foreach (var renameAttribute in renamedVersions)
                    {
                        if (minProcessed < renameAttribute.Version)
                        {
                            minProcessed = renameAttribute.Version;
                            if (currentVersion >= renameAttribute.Version)
                            {
                                name = renameAttribute.Name;
                            }
                        }
                    }

                    target.Add(name, JSONUtils.Parse(value));
                }
            }
        }