コード例 #1
0
        public string Writetxt()
        {
            string name = "Infoglasses_Default";
            string path = IO_Helper.GetNamedPath(this, name, create: true);

            return(Writetxt(path));
        }
コード例 #2
0
        public void Readtxt()
        {
            string name = "Infoglasses_Default";

            string path = IO_Helper.GetNamedPath(this, name);

            Readtxt(path);
        }
コード例 #3
0
        /// <summary>
        /// Need Feed Back!
        /// </summary>
        /// <param name="path"></param>
        public string Readtxt(string path)
        {
            normalExceptionGuid = new List <Guid>();
            pluginExceptionGuid = new List <Guid>();

            if (path == null)
            {
                return(null);
            }

            int succeedCount = 0;
            int failCount    = 0;

            IO_Helper.ReadFileInLine(path, (str, index) =>
            {
                string[] strs = str.Split(',');
                foreach (var guid in strs)
                {
                    if (guid != "")
                    {
                        try
                        {
                            Guid uid = new Guid(guid);
                            switch (index)
                            {
                            case 0:
                                if (!normalExceptionGuid.Contains(uid))
                                {
                                    normalExceptionGuid.Add(uid);
                                }
                                break;

                            case 1:
                                if (!pluginExceptionGuid.Contains(uid))
                                {
                                    pluginExceptionGuid.Add(uid);
                                }
                                break;
                            }
                            succeedCount++;
                        }
                        catch
                        {
                            failCount++;
                        }
                    }
                }
            });

            string all = succeedCount.ToString() + LanguagableComponent.GetTransLation(new string[] { " data imported successfully!", "个数据导入成功!" });

            if (failCount > 0)
            {
                all += "\n" + failCount.ToString() + LanguagableComponent.GetTransLation(new string[] { " data imported failed!", "个数据导入失败!" });
            }
            return(all);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        //POST : api/Files
        public async Task <IHttpActionResult> Post()
        {
            //get server root physical path
            string root = IO_Helper.RootPath_MVC;
            //new folder
            string newRoot = root + @"Files/Files/";

            //check path is exist if not create it
            IO_Helper.CreateDirectoryIfNotExist(newRoot);
            List <string> fileNameList  = new List <string>();
            StringBuilder sb            = new StringBuilder();
            long          fileTotalSize = 0;
            int           fileIndex     = 1;
            //get files from request
            HttpFileCollection files = HttpContext.Current.Request.Files;
            await Task.Run(() =>
            {
                foreach (var f in files.AllKeys)
                {
                    HttpPostedFile file = files[f];
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        string fileLocalFullName = newRoot + file.FileName;
                        file.SaveAs(fileLocalFullName);
                        fileNameList.Add($"Files/Files/{file.FileName}");
                        FileInfo fileInfo = new FileInfo(fileLocalFullName);
                        fileTotalSize    += fileInfo.Length;
                        sb.Append($" #{fileIndex} Uploaded file: {file.FileName} ({ fileInfo.Length} bytes)");
                        fileIndex++;
                        Trace.WriteLine("1 file copied , filePath=" + fileLocalFullName);
                    }
                }
            });

            return(Json(Return_Helper.Success_Msg_Data_DCount_HttpCode($"{fileNameList.Count} file(s) /{fileTotalSize} bytes uploaded successfully!   Details -> {sb.ToString()}", fileNameList, fileNameList.Count)));
        }
コード例 #5
0
        public string Writetxt(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(LanguagableComponent.GetTransLation(new string[] { "Failed to get path.", "获取位置失败!" }));
            }
            IO_Helper.WriteString(path, () =>
            {
                string normalGuids = "";
                if (normalExceptionGuid.Count > 0)
                {
                    normalGuids = this.normalExceptionGuid[0].ToString();
                    for (int i = 1; i < normalExceptionGuid.Count; i++)
                    {
                        normalGuids += ',';
                        normalGuids += normalExceptionGuid[i].ToString();
                    }
                }

                string pluginGuids = "";
                if (pluginExceptionGuid.Count > 0)
                {
                    pluginGuids = this.pluginExceptionGuid[0].ToString();
                    for (int i = 1; i < pluginExceptionGuid.Count; i++)
                    {
                        pluginGuids += ',';
                        pluginGuids += pluginExceptionGuid[i].ToString();
                    }
                }

                return(normalGuids + "\n" + pluginGuids);
            });


            return(LanguagableComponent.GetTransLation(new string[] { "Export successfully! \n Location: ", "导出成功!\n 位置:" }) + path);
        }
コード例 #6
0
        private void SaveIO_Click(object sender, RoutedEventArgs e)
        {
            switch (this._ioType)
            {
            case IOType.Default:
                switch (DialogSelect.SelectedIndex)
                {
                case 0:
                    MessageBox.Content       = Owner.WriteColorTxt();
                    MessageSnackBar.IsActive = true;
                    break;

                case 1:
                    MessageBox.Content       = Owner.WriteInputTxt();
                    MessageSnackBar.IsActive = true;
                    break;

                case 2:
                    MessageBox.Content       = Owner.WriteOutputTxt();
                    MessageSnackBar.IsActive = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("SelectedIndex", "SelectedIndex is invalid!");
                }
                break;

            case IOType.Import:
                switch (DialogSelect.SelectedIndex)
                {
                case 0:
                    IO_Helper.ImportOpenFileDialog((path) =>
                    {
                        string result = Owner.ReadColorTxt(path);
                        //Owner.UpdateAllProxy();
                        SetShowProxy(Owner.AllParamProxy);

                        MessageBox.Content       = result;
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                case 1:
                    IO_Helper.ImportOpenFileDialog((path) =>
                    {
                        string result = Owner.ReadInputTxt(path);
                        //Owner.UpdateAllProxy();
                        //SetShowProxy(Owner.AllParamProxy);

                        MessageBox.Content       = result;
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                case 2:
                    IO_Helper.ImportOpenFileDialog((path) =>
                    {
                        string result = Owner.ReadOutputTxt(path);
                        //Owner.UpdateAllProxy();
                        //SetShowProxy(Owner.AllParamProxy);

                        MessageBox.Content       = result;
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException("SelectedIndex", "SelectedIndex is invalid!");
                }
                break;

            case IOType.Export:
                switch (DialogSelect.SelectedIndex)
                {
                case 0:
                    IO_Helper.ExportSaveFileDialog("WireColors_Default", (path) =>
                    {
                        MessageBox.Content       = Owner.WriteColorTxt(path);
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                case 1:
                    IO_Helper.ExportSaveFileDialog("InputControl_Default", (path) =>
                    {
                        MessageBox.Content       = Owner.WriteInputTxt(path);
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                case 2:
                    IO_Helper.ExportSaveFileDialog("OutputControl_Default", (path) =>
                    {
                        MessageBox.Content       = Owner.WriteOutputTxt(path);
                        MessageSnackBar.IsActive = true;
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException("SelectedIndex", "SelectedIndex is invalid!");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("_ioType", "ioType is invalid!");
            }
        }