Exemple #1
0
        public string CreateFileIfNotExist(
            BasicFileType basicFileType = BasicFileType.READ,
            bool append       = true,
            string customPath = "")
        {
            string uri = customPath;

            if (string.IsNullOrEmpty(customPath))
            {
                string file_name      = (IsFixedName()) ? fixed_name : DateTime.Now.ToString("MMddyyyyHH") + "Log.xml";
                String filename_clean = Path.GetFileName(file_name);
                String rel_path       = file_name.Replace(filename_clean, "");

                if (rel_path.Length > 1 && rel_path.StartsWith("/"))
                {
                    rel_path = rel_path.Substring(1);
                }

                string full_new_path = Path.Combine(String.IsNullOrEmpty(Mobile.LogUserPath)?Mobile.LogPath:Mobile.LogUserPath, rel_path);

                Mobile.CreateDirectoryIfNotExist(Mobile.LogPath);

                Mobile.CreateDirectoryIfNotExist(full_new_path);

                uri = Path.Combine(full_new_path, filename_clean);
            }

            if (!File.Exists(uri))
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(uri, append))
                {
                    file.WriteLine(CreateBasicStructure(basicFileType));
                }
            }
            else if (!append)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(uri, false))
                {
                    file.WriteLine(CreateBasicStructure(basicFileType));
                }
            }
            else
            {
                try
                {
                    XDocument.Load(uri);
                }
                catch (Exception e)
                {
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(uri, false))
                    {
                        file.WriteLine(CreateBasicStructure(basicFileType));
                    }
                }
            }

            return(uri);
        }
Exemple #2
0
        public string CreateBasicStructure(
            BasicFileType basicFileType = BasicFileType.READ)
        {
            Configuration config = Singleton.Get.Configuration;

            string base_stream = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

            switch (basicFileType)
            {
            case BasicFileType.READ:
                base_stream += "<StarSystem>";
                base_stream += "    <AppInfo>";
                base_stream += "        <AppName>" + config.getApplicationName() + "</AppName>";
                base_stream += "        <Version>" + config.GetApplicationVersion() + "</Version>";
                base_stream += "        <Date>" + DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm") + "</Date>";
                base_stream += "        <UTCOffset>" + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).ToString() + "</UTCOffset>";
                base_stream += "        <UnitId>" + config.GetDeviceUUID() + "</UnitId>";
                base_stream += "        <AppType>" + (Data.Get.IsFromScripting ? "Scripted" : "Interactive") + "</AppType>";
                base_stream += "    </AppInfo>";
                base_stream += "    <Message />";
                base_stream += "    <Mtus />";
                base_stream += "    <Warning />";
                base_stream += "    <Error />";
                base_stream += "</StarSystem>";
                break;

            case BasicFileType.DATA_READ:
                base_stream += "<Log>";
                base_stream += "    <Transfer>";
                base_stream += "        <AppName>" + config.getApplicationName() + "</AppName>";
                base_stream += "        <Version>" + config.GetApplicationVersion() + "</Version>";
                base_stream += "        <Date>" + DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm") + "</Date>";
                base_stream += "        <UTCOffset>" + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).ToString() + "</UTCOffset>";
                base_stream += "        <UnitId>" + config.GetDeviceUUID() + "</UnitId>";
                base_stream += "        <AppType>" + (Data.Get.IsFromScripting ? "Scripted" : "Interactive") + "</AppType>";
                base_stream += "        <Events />";
                base_stream += "    </Transfer>";
                base_stream += "</Log>";
                break;
            }

            config = null;

            return(base_stream);
        }
Exemple #3
0
        /// <summary>
        /// 构建。
        /// </summary>
        /// <param name="material"></param>
        /// <returns></returns>
        public override string Build(string filePathWithoutExtension)
        {
            var extension = "";

            if (!String.IsNullOrWhiteSpace(SelfExtension))
            {
                extension = SelfExtension;
            }
            if (BasicFileType != GnsserFileType.None && BasicFileType != GnsserFileType.Data)
            {
                extension = "." + BasicFileType.ToString() + extension;
            }
            if (ClassifyType != GnsserFileType.None)
            {
                extension = "." + ClassifyType.ToString() + extension;
            }
            return(filePathWithoutExtension + extension);
        }