Example #1
0
        private static void UpdateChannel(FreeSCADA.CLServer.ChannelState state, RemoutingChannel channel)
        {
            object channelValue = null;
            Type   valueType    = Type.GetType(state.Type);

            if (valueType != null)
            {
                channelValue = Convert.ChangeType(state.Value, valueType);
            }
            else
            {
                channelValue = Convert.ChangeType(state.Value, channel.Type);
            }

            ChannelStatusFlags flags = ChannelStatusFlags.Unknown;

            switch (state.Status)
            {
            case FreeSCADA.CLServer.ChannelStatusFlags.Bad:
                flags = ChannelStatusFlags.Bad;
                break;

            case FreeSCADA.CLServer.ChannelStatusFlags.Good:
                flags = ChannelStatusFlags.Good;
                break;

            case FreeSCADA.CLServer.ChannelStatusFlags.NotUsed:
                flags = ChannelStatusFlags.NotUsed;
                break;
            }

            channel.DoUpdate(channelValue, state.ModifyTime, flags);
        }
Example #2
0
        public static void SaveChannel(XmlElement node, IChannel channel)
        {
            RemoutingChannel channelBase = (RemoutingChannel)channel;

            node.SetAttribute("name", channelBase.Name);
            node.SetAttribute("server", channelBase.Server);
            node.SetAttribute("fullId", channelBase.ServerFullId);
            node.SetAttribute("port", channelBase.Port.ToString(CultureInfo.InvariantCulture));
            node.SetAttribute("type", channelBase.Type.ToString());
        }
Example #3
0
        public bool Connect()
        {
            if (IsConnected)
            {
                return(false);
            }

            connectedFlag = true;

            foreach (ConnectionGroup group in connectionGroups)
            {
                group.Dispose();
            }
            connectionGroups.Clear();
            System.GC.Collect();

            if (channels.Count > 0)
            {
                try
                {
                    List <IChannel> originalChannels = new List <IChannel>();
                    originalChannels.AddRange(channels);
                    do
                    {
                        List <RemoutingChannel> groupChannels = new List <RemoutingChannel>();
                        RemoutingChannel        lhc           = (RemoutingChannel)originalChannels[0];
                        groupChannels.Add(lhc);
                        originalChannels.RemoveAt(0);
                        for (int i = originalChannels.Count - 1; i >= 0; i--)
                        {
                            RemoutingChannel rhc = (RemoutingChannel)originalChannels[i];
                            if (lhc.Server == rhc.Server && lhc.Port == rhc.Port)
                            {
                                groupChannels.Add(rhc);
                                originalChannels.RemoveAt(i);
                            }
                        }
                        connectionGroups.Add(new ConnectionGroup(lhc.Server, lhc.Port, groupChannels));
                    } while (originalChannels.Count > 0);
                }
                catch (Exception e)
                {
                    connectedFlag = false;
                    FreeSCADA.Common.Env.Current.Logger.LogError(string.Format("Problem with connection to remote server: {0}", e.Message));
                }
            }

            return(IsConnected);
        }