Exemplo n.º 1
0
 /// <summary>
 ///   Monitors this instance.
 /// </summary>
 private static void Monitor()
 {
     while (!Closing)
     {
         if (InGame && _processPid != -1)
         {
             Thread.Sleep(500);
             continue;
         }
         if (!DoesProcessExsist(_processPid) && !_alearted)
         {
             InterfaceHelper.StopUpdate();
             Logging.Write(LogType.Info, "No wow process, cannot attach");
             ObjectList.Clear();
             ObjectDictionary.Clear();
             if (NoAttach != null)
             {
                 NoAttach(new object(), new NotifyEventNoAttach("Not attached"));
             }
             _alearted = true;
         }
         Initialized = false;
         if (_refresher != null)
         {
             if (_refresher.IsAlive)
             {
                 _refresher.Abort();
                 _refresher = null;
             }
         }
         if (DoesProcessExsist(_processPid))
         {
             _alearted = false;
             ObjectList.Clear();
             ObjectDictionary.Clear();
             if (NoAttach != null)
             {
                 NoAttach(new object(), new NotifyEventNoAttach("Not attached"));
             }
             Logging.Write(LogType.Info, "Not ingame");
             Thread.Sleep(1500);
             while (DoesProcessExsist(_processPid) && !InGame)
             {
                 Thread.Sleep(1000);
             }
             if (InGame)
             {
                 Initialize(_processPid);
             }
             else
             {
                 _processPid = -1;
             }
         }
         else
         {
             _processPid = -1;
         }
         Thread.Sleep(2000);
     }
 }
Exemplo n.º 2
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ObjectList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 GXDLMSObject obj = GetObject(settings, item);
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value != null)
         {
             ClientSAP = Convert.ToByte(((Object[])e.Value)[0]);
             ServerSAP = Convert.ToUInt16(((Object[])e.Value)[1]);
         }
     }
     else if (e.Index == 4)
     {
         //Value of the object identifier encoded in BER
         if (e.Value is byte[])
         {
             GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]);
             if (arr.GetUInt8(0) == 0x60)
             {
                 ApplicationContextName.JointIsoCtt            = arr.GetUInt8();
                 ApplicationContextName.Country                = arr.GetUInt8();
                 ApplicationContextName.CountryName            = arr.GetUInt8();
                 ApplicationContextName.IdentifiedOrganization = arr.GetUInt8();
                 ApplicationContextName.DlmsUA             = arr.GetUInt8();
                 ApplicationContextName.ApplicationContext = arr.GetUInt8();
                 ApplicationContextName.ContextId          = (ApplicationContextName)arr.GetUInt8();
             }
             else
             {
                 //Get Tag and Len.
                 if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.JointIsoCtt = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.Country = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.CountryName = arr.GetUInt16();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.IdentifiedOrganization = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.DlmsUA = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ApplicationContext = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ContextId = (ApplicationContextName)arr.GetUInt8();
             }
         }
         else if (e.Value != null)
         {
             Object[] arr = (Object[])e.Value;
             ApplicationContextName.JointIsoCtt            = Convert.ToByte(arr[0]);
             ApplicationContextName.Country                = Convert.ToByte(arr[1]);
             ApplicationContextName.CountryName            = Convert.ToUInt16(arr[2]);
             ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             ApplicationContextName.DlmsUA             = Convert.ToByte(arr[4]);
             ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]);
             ApplicationContextName.ContextId          = (ApplicationContextName)Convert.ToByte(arr[6]);
         }
     }
     else if (e.Index == 5)
     {
         if (e.Value != null)
         {
             Object[] arr = (Object[])e.Value;
             if (arr[0] is string || arr[0] is byte[])
             {
                 GXByteBuffer bb = new GXByteBuffer();
                 GXCommon.SetBitString(bb, arr[0], true);
                 bb.SetUInt8(0, 0);
                 XDLMSContextInfo.Conformance = (Conformance)bb.GetUInt32();
             }
             else
             {
                 XDLMSContextInfo.Conformance = (Conformance)Convert.ToUInt16(arr[0]);
             }
             XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]);
             XDLMSContextInfo.MaxSendPduSize    = Convert.ToUInt16(arr[2]);
             XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]);
             XDLMSContextInfo.QualityOfService  = Convert.ToSByte(arr[4]);
             XDLMSContextInfo.CypheringInfo     = (byte[])arr[5];
         }
     }
     else if (e.Index == 6)
     {
         //Value of the object identifier encoded in BER
         if (e.Value is byte[])
         {
             GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]);
             if (arr.GetUInt8(0) == 0x60)
             {
                 AuthenticationMechanismName.JointIsoCtt            = arr.GetUInt8();
                 AuthenticationMechanismName.Country                = arr.GetUInt8();
                 AuthenticationMechanismName.CountryName            = arr.GetUInt8();
                 AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8();
                 AuthenticationMechanismName.DlmsUA = arr.GetUInt8();
                 AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8();
                 AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8();
             }
             else
             {
                 //Get Tag and Len.
                 if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.JointIsoCtt = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.Country = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.CountryName = arr.GetUInt16();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.DlmsUA = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8();
             }
         }
         else if (e.Value != null)
         {
             Object[] arr = (Object[])e.Value;
             AuthenticationMechanismName.JointIsoCtt            = Convert.ToByte(arr[0]);
             AuthenticationMechanismName.Country                = Convert.ToByte(arr[1]);
             AuthenticationMechanismName.CountryName            = Convert.ToUInt16(arr[2]);
             AuthenticationMechanismName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             AuthenticationMechanismName.DlmsUA = Convert.ToByte(arr[4]);
             AuthenticationMechanismName.AuthenticationMechanismName = Convert.ToByte(arr[5]);
             AuthenticationMechanismName.MechanismId = (Authentication)Convert.ToByte(arr[6]);
         }
     }
     else if (e.Index == 7)
     {
         Secret = (byte[])e.Value;
     }
     else if (e.Index == 8)
     {
         if (e.Value == null)
         {
             AssociationStatus = AssociationStatus.NonAssociated;
         }
         else
         {
             AssociationStatus = (AssociationStatus)Convert.ToInt32(e.Value);
         }
     }
     else if (e.Index == 9)
     {
         SecuritySetupReference = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 10)
     {
         UserList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 UserList.Add(new KeyValuePair <byte, string>(Convert.ToByte(item[0]), Convert.ToString(item[1])));
             }
         }
     }
     else if (e.Index == 11)
     {
         if (e.Value != null)
         {
             Object[] tmp = (Object[])e.Value;
             if (tmp.Length == 1)
             {
                 CurrentUser = new KeyValuePair <byte, string>(Convert.ToByte(tmp[0]), null);
             }
             else
             {
                 CurrentUser = new KeyValuePair <byte, string>(Convert.ToByte(tmp[0]), Convert.ToString(tmp[1]));
             }
         }
         else
         {
             CurrentUser = new KeyValuePair <byte, string>(0, null);
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Exemplo n.º 3
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         ObjectList.Clear();
         if (value != null)
         {
             foreach (Object[] item in (Object[])value)
             {
                 ushort       sn      = (ushort)(Convert.ToInt32(item[0]) & 0xFFFF);
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[1]);
                 int          version = Convert.ToInt32(item[2]);
                 String       ln      = GXDLMSObject.toLogicalName((byte[])item[3]);
                 GXDLMSObject obj     = null;
                 if (Parent != null)
                 {
                     obj = Parent.FindBySN(sn);
                 }
                 if (obj == null)
                 {
                     obj = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     if (obj != null)
                     {
                         obj.LogicalName = ln;
                         obj.ShortName   = sn;
                         obj.Version     = version;
                     }
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (index == 3)
     {
         if (value == null)
         {
             foreach (GXDLMSObject it in ObjectList)
             {
                 for (int pos = 1; pos != (it as IGXDLMSBase).GetAttributeCount(); ++pos)
                 {
                     it.SetAccess(pos, AccessMode.NoAccess);
                 }
             }
         }
         else
         {
             UpdateAccessRights((Object[])value);
         }
     }
     else if (index == 4)
     {
         if (value is string)
         {
             SecuritySetupReference = value.ToString();
         }
         else
         {
             SecuritySetupReference = GXDLMSClient.ChangeType(value as byte[], DataType.OctetString).ToString();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ObjectList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[0]);
                 int          version = Convert.ToInt32(item[1]);
                 String       ln      = GXCommon.ToLogicalName((byte[])item[2]);
                 GXDLMSObject obj     = null;
                 if (settings.Objects != null)
                 {
                     obj = settings.Objects.FindByLN(type, ln);
                 }
                 if (obj == null)
                 {
                     obj             = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                     obj.Version     = version;
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase && item[3] != null)
                 {
                     UpdateAccessRights(obj, (Object[])item[3]);
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value != null)
         {
             ClientSAP = Convert.ToByte(((Object[])e.Value)[0]);
             ServerSAP = Convert.ToUInt16(((Object[])e.Value)[1]);
         }
     }
     else if (e.Index == 4)
     {
         //Value of the object identifier encoded in BER
         if (e.Value is byte[])
         {
             GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]);
             if (arr.GetUInt8(0) == 0x60)
             {
                 ApplicationContextName.JointIsoCtt = 0;
                 ++arr.Position;
                 ApplicationContextName.Country = 0;
                 ++arr.Position;
                 ApplicationContextName.CountryName = 0;
                 ++arr.Position;
                 ApplicationContextName.IdentifiedOrganization = arr.GetUInt8();
                 ApplicationContextName.DlmsUA             = arr.GetUInt8();
                 ApplicationContextName.ApplicationContext = arr.GetUInt8();
                 ApplicationContextName.ContextId          = arr.GetUInt8();
             }
             else
             {
                 //Get Tag and Len.
                 if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.JointIsoCtt = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.Country = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.CountryName = arr.GetUInt16();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.IdentifiedOrganization = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.DlmsUA = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ApplicationContext = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ContextId = arr.GetUInt8();
             }
         }
         else if (e.Value != null)
         {
             Object[] arr = (Object[])e.Value;
             ApplicationContextName.JointIsoCtt            = Convert.ToByte(arr[0]);
             ApplicationContextName.Country                = Convert.ToByte(arr[1]);
             ApplicationContextName.CountryName            = Convert.ToUInt16(arr[2]);
             ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             ApplicationContextName.DlmsUA             = Convert.ToByte(arr[4]);
             ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]);
             ApplicationContextName.ContextId          = Convert.ToByte(arr[6]);
         }
     }
     else if (e.Index == 5)
     {
         if (e.Value != null)
         {
             Object[]     arr = (Object[])e.Value;
             GXByteBuffer bb  = new GXByteBuffer();
             GXCommon.SetBitString(bb, arr[0]);
             bb.SetUInt8(0, 0);
             XDLMSContextInfo.Conformance       = (Conformance)bb.GetUInt32();
             XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]);
             XDLMSContextInfo.MaxSendPduSize    = Convert.ToUInt16(arr[2]);
             XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]);
             XDLMSContextInfo.QualityOfService  = Convert.ToSByte(arr[4]);
             XDLMSContextInfo.CypheringInfo     = (byte[])arr[5];
         }
     }
     else if (e.Index == 6)
     {
         //Value of the object identifier encoded in BER
         if (e.Value is byte[])
         {
             GXByteBuffer arr = new GXByteBuffer(e.Value as byte[]);
             if (arr.GetUInt8(0) == 0x60)
             {
                 AuthenticationMechanismName.JointIsoCtt = 0;
                 ++arr.Position;
                 AuthenticationMechanismName.Country = 0;
                 ++arr.Position;
                 AuthenticationMechanismName.CountryName = 0;
                 ++arr.Position;
                 AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8();
                 AuthenticationMechanismName.DlmsUA = arr.GetUInt8();
                 AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8();
                 AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8();
             }
             else
             {
                 //Get Tag and Len.
                 if (arr.GetUInt8() != (int)BerType.Integer && arr.GetUInt8() != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.JointIsoCtt = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.Country = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.CountryName = arr.GetUInt16();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.IdentifiedOrganization = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.DlmsUA = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.AuthenticationMechanismName = arr.GetUInt8();
                 //Get tag
                 if (arr.GetUInt8() != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismName.MechanismId = (Authentication)arr.GetUInt8();
             }
         }
         else if (e.Value != null)
         {
             Object[] arr = (Object[])e.Value;
             AuthenticationMechanismName.JointIsoCtt            = Convert.ToByte(arr[0]);
             AuthenticationMechanismName.Country                = Convert.ToByte(arr[1]);
             AuthenticationMechanismName.CountryName            = Convert.ToUInt16(arr[2]);
             AuthenticationMechanismName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             AuthenticationMechanismName.DlmsUA = Convert.ToByte(arr[4]);
             AuthenticationMechanismName.AuthenticationMechanismName = Convert.ToByte(arr[5]);
             AuthenticationMechanismName.MechanismId = (Authentication)Convert.ToByte(arr[6]);
         }
     }
     else if (e.Index == 7)
     {
         Secret = (byte[])e.Value;
     }
     else if (e.Index == 8)
     {
         if (e.Value == null)
         {
             AssociationStatus = AssociationStatus.NonAssociated;
         }
         else
         {
             AssociationStatus = (AssociationStatus)Convert.ToInt32(e.Value);
         }
     }
     else if (e.Index == 9)
     {
         SecuritySetupReference = GXCommon.ToLogicalName(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Exemplo n.º 5
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         ObjectList.Clear();
         if (e.Value != null)
         {
             foreach (Object[] item in (Object[])e.Value)
             {
                 ushort       sn      = (ushort)(Convert.ToInt32(item[0]) & 0xFFFF);
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[1]);
                 int          version = Convert.ToInt32(item[2]);
                 String       ln      = GXCommon.ToLogicalName((byte[])item[3]);
                 GXDLMSObject obj     = null;
                 if (settings.Objects != null)
                 {
                     obj = settings.Objects.FindBySN(sn);
                 }
                 if (obj == null)
                 {
                     obj = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     if (obj != null)
                     {
                         obj.LogicalName = ln;
                         obj.ShortName   = sn;
                         obj.Version     = version;
                     }
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (e.Index == 3)
     {
         if (e.Value == null)
         {
             foreach (GXDLMSObject it in ObjectList)
             {
                 for (int pos = 1; pos != (it as IGXDLMSBase).GetAttributeCount(); ++pos)
                 {
                     it.SetAccess(pos, AccessMode.NoAccess);
                 }
             }
         }
         else
         {
             UpdateAccessRights((Object[])e.Value);
         }
     }
     else if (e.Index == 4)
     {
         SecuritySetupReference = GXCommon.ToLogicalName(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Exemplo n.º 6
0
        private void CreateDesignObjects()
        {
            ObjectList.Clear();

            // string[] ln = File.ReadAllLines(fn);

            UIDesignTableClass tc;
            int x = 20;
            int y = 20;

            //foreach (string s in ln)
            int n = 0;

            //object ob1=null;
            //object ob2=null;
            foreach (ItemDataClass s in selDBObjects.CheckedItemDatas)
            {
                if (s.Object.GetType() == typeof(DesTableClass))
                {
                    //  string n = s.Substring(s.IndexOf("'")+1, s.LastIndexOf("'") - s.IndexOf("'") -1);
                    DesTableClass TableObject = (DesTableClass)s.Object;
                    n++;


                    tc = new UIDesignTableClass(pbDesign, s.Object.ToString(), true, TableObject.Design.posx, TableObject.Design.posy);

                    tc.TableNotify.Register4Info(Notify_OnRaiseInfoHandler1);
                    x += 160;
                    //y += 0;
                    if (x > 1000)
                    {
                        x  = 20;
                        y += 180;
                    }
                    var tob = (DesTableClass)s.Object;
                    foreach (var att in tob.Table.Fields.Values)
                    {
                        tc.AddAttribute(att.Name);
                    }
                    //if(n == 1) ob1 = tc;
                    //if(n == 2) ob2 = tc;

                    ObjectList.Add(tc);
                }

                /*
                 * else if (s.ToUpper().StartsWith("VIEW"))
                 * {
                 *
                 * }
                 * else if (s.ToUpper().StartsWith("FIELD"))
                 * {
                 *
                 * }
                 */
            }

            foreach (ItemDataClass s in selDBObjects.CheckedItemDatas)
            {
                if (s.Object.GetType() == typeof(DesTableClass))
                {
                    DesTableClass tb1 = (DesTableClass)s.Object;
                    foreach (var fld in tb1.Table.Fields)
                    {
                        if (fld.Key.EndsWith("_ID"))
                        {
                            UIDesignTableClass ob1 = (UIDesignTableClass)FindObject(tb1.Table.Name);
                            UIDesignTableClass ob2 = (UIDesignTableClass)FindObject(fld.Key.Remove(fld.Key.Length - 3));
                            if ((ob1 != null) && (ob2 != null))
                            {
                                ReferenzClass rc = new ReferenzClass
                                {
                                    Name        = fld.Key,
                                    StartObject = ob1,
                                    EndObject   = ob2
                                };
                                ob1.LineList.Add(rc);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         ObjectList.Clear();
         if (value != null)
         {
             foreach (Object[] item in (Object[])value)
             {
                 ObjectType   type    = (ObjectType)Convert.ToInt32(item[0]);
                 int          version = Convert.ToInt32(item[1]);
                 String       ln      = GXDLMSObject.toLogicalName((byte[])item[2]);
                 GXDLMSObject obj     = null;
                 if (Parent != null)
                 {
                     obj = Parent.FindByLN(type, ln);
                 }
                 if (obj == null)
                 {
                     obj             = Gurux.DLMS.GXDLMSClient.CreateObject(type);
                     obj.LogicalName = ln;
                     obj.Version     = version;
                 }
                 //Unknown objects are not shown.
                 if (obj is IGXDLMSBase)
                 {
                     UpdateAccessRights(obj, (Object[])item[3]);
                     ObjectList.Add(obj);
                 }
             }
         }
     }
     else if (index == 3)
     {
         ClientSAP = Convert.ToByte(((Object[])value)[0]);
         ServerSAP = Convert.ToUInt16(((Object[])value)[1]);
     }
     else if (index == 4)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 ApplicationContextName.JointIsoCtt = 0;
                 ++pos;
                 ApplicationContextName.Country = 0;
                 ++pos;
                 ApplicationContextName.CountryName = 0;
                 ++pos;
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 ApplicationContextName.DlmsUA             = arr[++pos];
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 ApplicationContextName.ContextId          = arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ApplicationContext = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 ApplicationContextName.ContextId = arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             ApplicationContextName.JointIsoCtt            = Convert.ToByte(arr[0]);
             ApplicationContextName.Country                = Convert.ToByte(arr[1]);
             ApplicationContextName.CountryName            = Convert.ToUInt16(arr[2]);
             ApplicationContextName.IdentifiedOrganization = Convert.ToByte(arr[3]);
             ApplicationContextName.DlmsUA             = Convert.ToByte(arr[4]);
             ApplicationContextName.ApplicationContext = Convert.ToByte(arr[5]);
             ApplicationContextName.ContextId          = Convert.ToByte(arr[6]);
         }
     }
     else if (index == 5)
     {
         Object[] arr = (Object[])value;
         XDLMSContextInfo.Conformance       = arr[0].ToString();
         XDLMSContextInfo.MaxReceivePduSize = Convert.ToUInt16(arr[1]);
         XDLMSContextInfo.MaxSendPpuSize    = Convert.ToUInt16(arr[2]);
         XDLMSContextInfo.DlmsVersionNumber = Convert.ToByte(arr[3]);
         XDLMSContextInfo.QualityOfService  = Convert.ToSByte(arr[4]);
         XDLMSContextInfo.CypheringInfo     = (byte[])arr[5];
     }
     else if (index == 6)
     {
         //Value of the object identifier encoded in BER
         if (value is byte[])
         {
             int    pos = -1;
             byte[] arr = value as byte[];
             if (arr[0] == 0x60)
             {
                 AuthenticationMechanismMame.JointIsoCtt = 0;
                 ++pos;
                 AuthenticationMechanismMame.Country = 0;
                 ++pos;
                 AuthenticationMechanismMame.CountryName = 0;
                 ++pos;
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
             else
             {
                 //Get Tag and Len.
                 if (arr[++pos] != (int)GXBer.IntegerTag && arr[++pos] != 7)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.JointIsoCtt = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.Country = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x12)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.CountryName = GXCommon.GetUInt16(arr, ref pos);
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.IdentifiedOrganization = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.DlmsUA = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.AuthenticationMechanismName = arr[++pos];
                 //Get tag
                 if (arr[++pos] != 0x11)
                 {
                     throw new ArgumentOutOfRangeException();
                 }
                 AuthenticationMechanismMame.MechanismId = (Authentication)arr[++pos];
             }
         }
         else
         {
             Object[] arr = (Object[])value;
             AuthenticationMechanismMame.JointIsoCtt            = Convert.ToByte(arr[0]);
             AuthenticationMechanismMame.Country                = Convert.ToByte(arr[1]);
             AuthenticationMechanismMame.CountryName            = Convert.ToUInt16(arr[2]);
             AuthenticationMechanismMame.IdentifiedOrganization = Convert.ToByte(arr[3]);
             AuthenticationMechanismMame.DlmsUA = Convert.ToByte(arr[4]);
             AuthenticationMechanismMame.AuthenticationMechanismName = Convert.ToByte(arr[5]);
             AuthenticationMechanismMame.MechanismId = (Authentication)Convert.ToByte(arr[6]);
         }
     }
     else if (index == 7)
     {
         Secret = (byte[])value;
     }
     else if (index == 8)
     {
         if (value == null)
         {
             AssociationStatus = AssociationStatus.NonAssociated;
         }
         else
         {
             AssociationStatus = (AssociationStatus)Convert.ToInt32(value);
         }
     }
     else if (index == 9)
     {
         SecuritySetupReference = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
 public void RemoveCards() => ObjectList.Clear();
Exemplo n.º 9
0
 public static void ClearDataBase()
 {
     ObjectList.Clear();
     FoundObjects.Clear();
 }