Ejemplo n.º 1
0
 public void WriteManufacturerSettings()
 {
     //Do not save empty list.
     if (this.Count != 0)
     {
         if (!Directory.Exists(ObisCodesPath))
         {
             Directory.CreateDirectory(ObisCodesPath);
         }
         Type[]        extraTypes = new Type[] { typeof(GXManufacturerCollection), typeof(GXManufacturer), typeof(GXObisCodeCollection), typeof(GXObisCode), typeof(GXObisValueItem), typeof(GXObisValueItemCollection), typeof(GXDLMSAttribute), typeof(GXAttributeCollection) };
         XmlSerializer x          = new XmlSerializer(typeof(GXManufacturer), extraTypes);
         foreach (GXManufacturer it in this)
         {
             string path = Path.Combine(ObisCodesPath, it.Identification) + ".obx";
             if (!it.Removed)
             {
                 Stream stream = File.Open(path, FileMode.Create);
                 GXFileInfo.UpdateFileSecurity(path);
                 using (TextWriter writer = new StreamWriter(stream))
                 {
                     x.Serialize(writer, it);
                     writer.Close();
                 }
                 stream.Close();
             }
             else
             {
                 File.Delete(path);
             }
         }
     }
 }
        /// <summary>
        /// Is this first run.
        /// </summary>
        /// <returns></returns>
        public static bool IsFirstRun()
        {
            string path = Path.Combine(ObisCodesPath, "files.xml");

            if (!System.IO.Directory.Exists(ObisCodesPath))
            {
                System.IO.Directory.CreateDirectory(ObisCodesPath);
            }
            if (!System.IO.File.Exists(path))
            {
                System.IO.FileStream stream = System.IO.File.Create(path);
                stream.Close();
                GXFileInfo.UpdateFileSecurity(path);
                return(true);
            }
            return(new FileInfo(path).Length == 0);
        }
 public void WriteManufacturerSettings(string directory)
 {
     //Do not save empty list.
     if (this.Count != 0)
     {
         if (!Directory.Exists(directory))
         {
             Directory.CreateDirectory(directory);
         }
         Type[]        extraTypes = new Type[] { typeof(GXManufacturerCollection), typeof(GXManufacturer), typeof(GXObisCodeCollection), typeof(GXObisCode), typeof(GXObisValueItem), typeof(GXObisValueItemCollection), typeof(GXDLMSAttribute), typeof(GXAttributeCollection) };
         XmlSerializer x          = new XmlSerializer(typeof(GXManufacturer), extraTypes);
         foreach (GXManufacturer it in this)
         {
             string name = it.Identification.ToLower();
             string path = Path.Combine(directory, name) + ".obx";
             if (it.Identification == "AUX")
             {
                 path = Path.Combine(directory, "_" + name) + ".obx";
             }
             else if (it.Identification == "CON")
             {
                 path = Path.Combine(directory, "_" + name) + ".obx";
             }
             if (!it.Removed)
             {
                 using (Stream stream = File.Open(path, FileMode.Create))
                 {
                     GXFileInfo.UpdateFileSecurity(path);
                     using (TextWriter writer = new StreamWriter(stream))
                     {
                         x.Serialize(writer, it);
                     }
                 }
             }
             else
             {
                 File.Delete(path);
             }
         }
     }
 }