コード例 #1
0
ファイル: Chameleon.cs プロジェクト: rubitek/OpenADK-csharp
        private void _processSIF_ZoneStatus(SIF_ZoneStatus zoneStatus, IZone zone)
        {
            if (zoneStatus == null)
            {
                return;
            }

            bool sync     = getChameleonProperty(zone, "sync", false);
            bool events   = getChameleonProperty(zone, "logEvents", true);
            bool logEntry = getChameleonProperty(zone, "sifLogEntrySupport", false);

            fLogger.UseLogEntry = logEntry;

            string syncObjects = zone.Properties.GetProperty("chameleon.syncObjects");

            ArrayList objectDefs = new ArrayList();

            SIF_Providers providers = zoneStatus.SIF_Providers;

            if (providers != null)
            {
                foreach (SIF_Provider p in providers)
                {
                    if (p.SIF_ObjectList != null)
                    {
                        foreach (SIF_Object obj in p.SIF_ObjectList)
                        {
                            // Lookup the topic for each provided object in the zone
                            IElementDef def = Adk.Dtd.LookupElementDef(obj.ObjectName);
                            if (def != null)
                            {
                                // Pull out just the objects specified according to configuration settings
                                // or all, if the syncObjects setting is not specified
                                if (syncObjects == null || (syncObjects.Length > 0 && syncObjects.IndexOf(def.Name) > -1))
                                {
                                    objectDefs.Add(def);
                                    if (events)
                                    {
                                        ITopic topic = TopicFactory.GetInstance(def);
                                        if (topic.GetSubscriber() == null)
                                        {
                                            topic.SetSubscriber(fLogger, null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (logEntry)
            {
                ITopic sifLogEntryTopic = TopicFactory.GetInstance(InfraDTD.SIF_LOGENTRY);
                sifLogEntryTopic.SetSubscriber(fLogger, null);
            }

            // Disconnect the zone before provisioning
            zone.Disconnect(ProvisioningFlags.None);

            foreach (ITopic topic in TopicFactory.GetAllTopics(SifContext.DEFAULT))
            {
                try
                {
                    // Join the topic to each zone ( causes the agent to subscribe to the joined objects )
                    // TODO: Add an "isJoinedTo()" API to topic so that it doesn't throw an exception
                    if (topic.ObjectType != InfraDTD.SIF_ZONESTATUS.Name)
                    {
                        topic.Join(zone);
                    }
                }
                catch (Exception ex)
                {
                    zone.Log.Error(ex.Message, ex);
                }
            }


            zone.Connect(ProvisioningFlags.Register);

            if (sync)
            {
                if (objectDefs.Count == 0)
                {
                    zone.ServerLog.Log
                        (LogLevel.WARNING, "No objects are being provided in this zone", null,
                        "1001");
                }

                foreach (IElementDef def in objectDefs)
                {
                    if (def.IsSupported(Adk.SifVersion))
                    {
                        Query q = new Query(def);

                        // Query by specific parameters
                        string condition =
                            zone.Properties.GetProperty
                                ("chameleon.syncConditions." + def.Name);
                        if (condition != null && condition.Length > 0)
                        {
                            // The condition should be in the format "path=value" e.g "@RefId=123412341...1234|@Name=asdfasdf"
                            String[] queryConditions = condition.Split('|');
                            foreach (String cond in queryConditions)
                            {
                                string[] conds = cond.Split('=');
                                if (conds.Length == 2)
                                {
                                    q.AddCondition(conds[0], "EQ", conds[1]);
                                }
                            }
                        }

                        if (logEntry)
                        {
                            zone.ServerLog.Log
                                (LogLevel.INFO,
                                "Requesting " + q.ObjectType.Name + " from the zone",
                                q.ToXml(Adk.SifVersion), "1002");
                        }

                        zone.Query(q);
                    }
                    else
                    {
                        String debug = "Will not request " + def.Name +
                                       " because it is not supported in " +
                                       Adk.SifVersion.ToString();
                        Console.WriteLine(debug);
                        zone.ServerLog.Log(LogLevel.WARNING, debug, null, "1001");
                    }
                }
            }
        }