Ejemplo n.º 1
0
        public static KNXDataType GetDPTType(string sizeInBit)
        {
            KNXDataType type = KNXDataType.Bit1;

            switch (sizeInBit)
            {
            case "1":
                type = KNXDataType.Bit1;
                break;

            case "2":
                type = KNXDataType.Bit2;
                break;

            case "4":
                type = KNXDataType.Bit4;
                break;

            case "8":
                type = KNXDataType.Bit8;
                break;

            case "16":
                type = KNXDataType.Bit16;
                break;

            case "24":
                type = KNXDataType.Bit24;
                break;

            case "32":
                type = KNXDataType.Bit32;
                break;

            case "48":
                type = KNXDataType.Bit48;
                break;

            case "64":
                type = KNXDataType.Bit64;
                break;

            case "80":
                type = KNXDataType.Bit80;
                break;

            case "112":
                type = KNXDataType.Bit112;
                break;

            default:
                MessageBox.Show(UIResMang.GetString("Message41"), UIResMang.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            return(type);
        }
Ejemplo n.º 2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            Image img = value as Image;

            if ((typeof(string) == destinationType) && (null != img))
            {
                return(img.ToString());
            }
            else
            {
                return(UIResMang.GetString("None"));
            }

            //return base.ConvertTo(context, culture, value, destinationType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 删除文件夹及其子
        /// </summary>
        /// <param name="folderName"></param>
        public static void DeleteFolder(string folderName)
        {
            // 可靠删除,先重命名文件夹,然后在后台删除
            var deleteFolder = folderName + DateTime.Now.Ticks;

            if (Directory.Exists(folderName))
            {
                try
                {
                    Directory.Move(folderName, deleteFolder);
                    Directory.Delete(deleteFolder, true);
                }
                catch (Exception)
                {
                    MessageBox.Show(folderName + UIResMang.GetString("Message40"));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 解析ETS文件
        /// </summary>
        /// <param name="etsProjectFile"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static List <ImGroupAddr> ParseEtsProjectFile(string etsProjectFile, BackgroundWorker worker)
        {
            List <ImGroupAddr> listAddress = new List <ImGroupAddr>();

            // 如果文件存在
            if (File.Exists(etsProjectFile) == true)
            {
                worker.ReportProgress(0, UIResMang.GetString("TextIsUnziping"));

                // 在当前位置解压文件
                string directoryName = Path.GetDirectoryName(etsProjectFile);
                ZipHelper.UnZipDir(etsProjectFile, directoryName);

                worker.ReportProgress(0, UIResMang.GetString("TextIsCaluculating"));

                // 查找 0.xml 文件
                const string addressFileName = "0.xml";
                var          addressFiles    = Directory.GetFiles(directoryName, addressFileName, SearchOption.AllDirectories);

                if (addressFiles.Length > 0)
                {
                    string addressFile = addressFiles[0];
                    var    addressXDoc = XDocument.Load(addressFile);
                    addressXDoc.Element("KNX");
                    XNamespace xns = addressXDoc.Root.Name.Namespace;

                    // 从导入的ETS项目中获取group address
                    var groupAddress = from item in addressXDoc.Root.Descendants(xns + attrGroupAddress)
                                       select new ImGroupAddr
                    {
                        Id         = item.Attribute(attrId).Value,
                        Name       = item.Attribute(attrName).Value,
                        KnxAddress = item.Attribute(attrAddress).Value,
                        DPTName    = (null != item.Attribute(attrDatapointType)) ? item.Attribute(attrDatapointType).Value : "",
                    };

                    // 获取数据类型
                    var comObjectInstanceRef = (from item in addressXDoc.Descendants(xns + strSend)
                                                let xElement = item.Parent
                                                               where xElement != null
                                                               select new
                    {
                        GroupAddressRefId = item.Attribute(strGroupAddressRefId).Value,
                        ComObjectInstance = xElement.Parent,
                        //ComObjectInstanceRefId = xElement.Parent.Attribute(strRefId).Value,
                    }).ToLookup(
                        p => p.GroupAddressRefId,
                        p => p.ComObjectInstance
                        //p => p.ComObjectInstanceRefId
                        );

                    Dictionary <string, XDocument> xDocs = new Dictionary <string, XDocument>();

                    int   len = groupAddress.ToList().Count;
                    float i   = 0;

                    /* 获取组地址的大小 */
                    foreach (var address in groupAddress.ToList())
                    {
                        ImGroupAddr addr = new ImGroupAddr();
                        addr.Id         = address.Id;
                        addr.Name       = address.Name;
                        addr.KnxAddress = KNXAddressHelper.AddressToString(Convert.ToUInt16(address.KnxAddress));
                        addr.DPTName    = address.DPTName;
                        parseDatapointType(addr);

                        float f = i++ / len;
                        worker.ReportProgress((int)(f * 100), UIResMang.GetString("TextIsImportingGroupAddress") + " " + address.Name + " " + addr.KnxAddress);

                        if (comObjectInstanceRef.Contains(address.Id))
                        {
                            XElement comObjectInstance = comObjectInstanceRef[address.Id].First <XElement>();
                            if ((null == addr.DPTName) || (addr.DPTName.Trim().Length <= 0) || (addr.DPTName.Contains("*")))
                            {
                                if (null != comObjectInstance.Attribute(attrDatapointType))
                                {
                                    addr.DPTName = comObjectInstance.Attribute(attrDatapointType).Value;
                                    parseDatapointType(addr);
                                }
                            }
                            var comObjectInstanceRefId = comObjectInstance.Attribute(strRefId).Value;

                            var index1 = comObjectInstanceRefId.IndexOf('_');
                            var index2 = comObjectInstanceRefId.IndexOf('_', index1 + 1);
                            var index3 = comObjectInstanceRefId.IndexOf('_', index2 + 1);
                            var comObjectInstanceFile = comObjectInstanceRefId.Substring(0, index2);
                            var comObjectInstanceId   = comObjectInstanceRefId.Substring(0, index3);

                            var manufacturerDataFiles = Directory.GetFiles(directoryName, comObjectInstanceFile + ".xml", SearchOption.AllDirectories);
                            if (manufacturerDataFiles.Length > 0)
                            {
                                string    manufacturerDataFile = manufacturerDataFiles[0];
                                XDocument manufacturerDataXDoc;
                                if (xDocs.ContainsKey(manufacturerDataFile))
                                {
                                    manufacturerDataXDoc = xDocs[manufacturerDataFile];
                                }
                                else
                                {
                                    manufacturerDataXDoc = XDocument.Load(manufacturerDataFile);
                                    xDocs.Add(manufacturerDataFile, manufacturerDataXDoc);
                                }

                                var comObject = (from p in manufacturerDataXDoc.Descendants(xns + strComObject)
                                                 where p.Attribute(attrId).Value == comObjectInstanceId
                                                 select p).FirstOrDefault();
                                parseComObject(addr, comObject);

                                var comObjectRef = (from p in manufacturerDataXDoc.Descendants(xns + strComObjectRef)
                                                    where p.Attribute(attrId).Value == comObjectInstanceRefId
                                                    select p).FirstOrDefault();
                                parseComObject(addr, comObjectRef);
                            }

                            //parseDatapointType(addr);
                            var formName = typeof(FrmGroupAddressMgt).Name;
                            if (Application.OpenForms[formName] != null)
                            {
                                var frm = Application.OpenForms[formName] as FrmGroupAddressMgt;
                                if (frm != null)
                                {
                                    if (frm.AddressIsExsit(addr.KnxAddress))
                                    {
                                        addr.IsSelected = false;
                                    }
                                }
                            }
                            //if (ProjResManager.AddressIsExsit(addr.KnxAddress))
                            //{
                            //    addr.IsSelected = false;
                            //}
                            listAddress.Add(addr);
                        }
                        else
                        {
                            //parseDatapointType(addr);
                            //addr.IsSelected = false;
                        }

                        //if (MyCache.AddressIsExsit(addr.KnxAddress))
                        //{
                        //    addr.IsSelected = false;
                        //}

                        //listAddress.Add(addr);
                    }
                }
            }

            return(listAddress);
        }
Ejemplo n.º 5
0
        public static KNXDataType GetKnxDataType(string objectSize)
        {
            KNXDataType type = KNXDataType.Bit1;

            switch (objectSize)
            {
            case "1 Bit":
                type = KNXDataType.Bit1;
                break;

            case "2 Bit":
                type = KNXDataType.Bit2;
                break;

            case "3 Bit":
                type = KNXDataType.Bit3;
                break;

            case "4 Bit":
                type = KNXDataType.Bit4;
                break;

            case "5 Bit":
                type = KNXDataType.Bit5;
                break;

            case "6 Bit":
                type = KNXDataType.Bit6;
                break;

            case "7 Bit":
                type = KNXDataType.Bit7;
                break;

            case "1 Byte":
                type = KNXDataType.Bit8;
                break;

            case "2 Bytes":
            case "2 Byte":
                type = KNXDataType.Bit16;
                break;

            case "3 Bytes":
            case "3 Byte":
                type = KNXDataType.Bit24;
                break;

            case "4 Bytes":
            case "4 Byte":
                type = KNXDataType.Bit32;
                break;

            case "6 Bytes":
            case "6 Byte":
                type = KNXDataType.Bit48;
                break;

            case "8 Bytes":
            case "8 Byte":
                type = KNXDataType.Bit64;
                break;

            case "10 Bytes":
            case "10 Byte":
                type = KNXDataType.Bit80;
                break;

            case "14 Bytes":
            case "14 Byte":
                type = KNXDataType.Bit112;
                break;

            default:
                type = KNXDataType.None;
                //MessageBox.Show(UIResMang.GetString("Message41"), UIResMang.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Console.WriteLine(objectSize + " ===> " + UIResMang.GetString("Message41"));
                break;
            }

            return(type);
        }
Ejemplo n.º 6
0
        public static string GetSize(KNXDataType type)
        {
            string size = "";

            switch (type)
            {
            case KNXDataType.Bit1:
                size = "1 Bit";
                break;

            case KNXDataType.Bit2:
                size = "2 Bit";
                break;

            case KNXDataType.Bit3:
                size = "3 Bit";
                break;

            case KNXDataType.Bit4:
                size = "4 Bit";
                break;

            case KNXDataType.Bit5:
                size = "5 Bit";
                break;

            case KNXDataType.Bit6:
                size = "6 Bit";
                break;

            case KNXDataType.Bit7:
                size = "7 Bit";
                break;

            case KNXDataType.Bit8:
                size = "1 Byte";
                break;

            case KNXDataType.Bit16:
                size = "2 Bytes";
                break;

            case KNXDataType.Bit24:
                size = "3 Bytes";
                break;

            case KNXDataType.Bit32:
                size = "4 Bytes";
                break;

            case KNXDataType.Bit48:
                size = "6 Bytes";
                break;

            case KNXDataType.Bit64:
                size = "8 Bytes";
                break;

            case KNXDataType.Bit80:
                size = "10 Bytes";
                break;

            case KNXDataType.Bit112:
                size = "14 Bytes";
                break;

            default:
                MessageBox.Show(UIResMang.GetString("Message41"), UIResMang.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            return(size);
        }
Ejemplo n.º 7
0
 public static string GetDefaultCollectionName()
 {
     return(UIResMang.GetString("MyCollection") + (index++).ToString());
 }