Ejemplo n.º 1
0
        private void imageTextButtonSendErrorInfo_Click(object sender, EventArgs e)
        {
            var helpdeskMail = AdditionalInfo.SplitByTwoDifferentStrings("HelpdeskEmail:", ";", true)[0];
            var userCode     = AdditionalInfo.SplitByTwoDifferentStrings("UserCode:", ";", true)[0];
            var appVersion   = AdditionalInfo.SplitByTwoDifferentStrings("ApplicationVersion:", ";", true)[0];
            var valueText    = new ValueText {
                Value = ".NET Framework", Text = ""
            };
            var listValueText = new List <ValueText>();

            listValueText.Add(valueText);
            var installedNetFxes    = SystemInfoHelper.GetInstalledSoftwareList(listValueText);
            var installedNetFxesStr = "";

            for (int index = 0; index < installedNetFxes.Count; index++)
            {
                var installedSoftware = installedNetFxes[index];
                if (index == 0)
                {
                    installedNetFxesStr = installedSoftware.ProductName + " " +
                                          installedSoftware.VersionString;
                }
                else
                {
                    installedNetFxesStr = installedNetFxesStr + "; " + installedSoftware.ProductName + " " +
                                          installedSoftware.VersionString;
                }
            }
            var body = "Dear Developer%0D%0A"
                       + "%0D%0A"
                       + "Following is system running error infomation for you:"
                       + (userCode.IsNullOrEmpty() ? "" : " (send by " + userCode + ")") + "%0D%0A"
                       + "Application Version : " + appVersion + "%0D%0A"
                       + "Assembly Bits : " + IntPtr.Size * 8 + "%0D%0A"
                       + "OS : " + SystemInfoHelper.GetSystemInfo("osinfo") + " " + SystemInfoHelper.GetSystemInfo("osbit") + " bits" + "%0D%0A"
                       + "Machine Name: " + SystemInfoHelper.GetSystemInfo("machinename") + "%0D%0A"
                       + "IP: " + SystemInfoHelper.GetSystemInfo("Ips") + "%0D%0A"
                       + "Windows Account: " + SystemInfoHelper.GetSystemInfo("currentuser") + "%0D%0A"
                       + "Occurring Time: " + OccurringTime + "%0D%0A"
                       + "Installed dotNetFx: " + installedNetFxesStr + "%0D%0A"
                       + "Exception Message: " + ExceptionMsg;

            body = body.Replace("\n", "%0D%0A");
            var subject = ErrorText + " occured at " + OccurringTime;

            LocalEmailHelper.Send(helpdeskMail, subject, body);
        }
Ejemplo n.º 2
0
        public static string Act(string funcName, string[] funcParamArray)
        {
            var returnStr = "";

            //##dir
            if (funcName.ToLower() == "CreateDirectory".ToLower())
            {
                if (!Directory.Exists(funcParamArray[0]))
                {
                    Directory.CreateDirectory(funcParamArray[0]);
                }
                if (funcParamArray[1] == "true")
                {
                    var di = new DirectoryInfo(funcParamArray[0]);
                    if (!((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
                    {
                        di.Attributes = FileAttributes.Hidden;
                    }
                }
            }
            else if (funcName.ToLower() == "OpenDirectory".ToLower())
            {
                if (!Directory.Exists(funcParamArray[0]))
                {
                    throw new ArgumentException("Directory does not exist! ");;
                }
                else
                {
                    System.Diagnostics.Process.Start(funcParamArray[0]);
                }
            }

            //##file
            else if (funcName.ToLower() == "SaveContentToTextFile".ToLower())
            {
                var path   = funcParamArray[0];
                var ctt    = funcParamArray[1];
                var append = false;
                if (funcParamArray.Length > 2)
                {
                    if (funcParamArray[2].ToLower() == "true")
                    {
                        append = true;
                    }
                }

                FileHelper.SaveContentToTextFile(ctt, path, append);
            }
            else if (funcName.ToLower() == "DeleteFile".ToLower())
            {
                var path = funcParamArray[0];
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            else if (funcName.ToLower() == "CopyFile".ToLower())
            {
                var path  = funcParamArray[0];
                var path1 = funcParamArray[1];

                var overWrite = false;
                if (funcParamArray.Length > 2)
                {
                    overWrite = funcParamArray[2].ToLower() == "true";
                }

                File.Copy(path, path1, true);
            }
            else if (funcName.ToLower() == "SendLocalEmail".ToLower())
            {
                var mailTo  = funcParamArray[0];
                var subject = funcParamArray.Length > 1 ? funcParamArray[1] : "";
                var body    = funcParamArray.Length > 2 ? funcParamArray[2] : "";
                if (body.Contains("\r\n"))
                {
                    body = body.Replace("\r\n", "%0D%0A");
                }
                if (body.Contains("\n\r"))
                {
                    body = body.Replace("\n\r", "%0D%0A");
                }
                if (body.Contains("\r"))
                {
                    body = body.Replace("\r", "%0D%0A");
                }
                if (body.Contains("\n"))
                {
                    body = body.Replace("\n", "%0D%0A");
                }
                LocalEmailHelper.Send(mailTo, subject, body);
            }

            //##process

            else if (funcName.ToLower() == "OpenFile".ToLower())
            {
                var actArgsStr = "";
                SysProcessHelper.OpenFile(funcParamArray[0], actArgsStr);
            }
            else if (funcName.ToLower() == "OpenFolder".ToLower())
            {
                SysProcessHelper.OpenFolder(funcParamArray[0]);
            }
            else if (funcName.ToLower() == ("OpenUrl").ToLower())
            {
                SysProcessHelper.OpenUrl(funcParamArray[0]);
            }
            else if (funcName.ToLower() == "ExecCmd".ToLower())
            {
                var inputStr = funcParamArray[0];
                var execCmdWindowOptionStr = "";
                if (funcParamArray.Length > 1)
                {
                    execCmdWindowOptionStr = funcParamArray[1];
                }
                var execCmdWindowOption = ExecCmdWindowOption.ShowWindow;
                execCmdWindowOption = EnumHelper.GetByName <ExecCmdWindowOption>(execCmdWindowOptionStr, execCmdWindowOption);

                var execCmdOutputOptionStr = "";
                if (funcParamArray.Length > 2)
                {
                    execCmdOutputOptionStr = funcParamArray[2];
                }
                var execCmdOutputOption = ExecCmdOutputOption.None;
                execCmdOutputOption = EnumHelper.GetByName <ExecCmdOutputOption>(execCmdOutputOptionStr, execCmdOutputOption);
                returnStr           = SysProcessHelper.ExecCmd(inputStr, execCmdWindowOption, execCmdOutputOption, null);
            }
            else if (funcName.ToLower() == "ExecCmdA".ToLower())
            {
                var inputStr = funcParamArray[0];
                var execCmdWindowOptionStr = "";
                if (funcParamArray.Length > 1)
                {
                    execCmdWindowOptionStr = funcParamArray[1];
                }
                var execCmdWindowOption = ExecCmdWindowOption.ShowWindow;
                execCmdWindowOption = EnumHelper.GetByName <ExecCmdWindowOption>(execCmdWindowOptionStr, execCmdWindowOption);
                var popupOutput = false;
                if (funcParamArray.Length > 2)
                {
                    popupOutput = funcParamArray[2] == "true";
                }

                SysProcessHelper.ExecCmdA(inputStr, execCmdWindowOption, popupOutput, null);
            }
            else if (funcName.ToLower() == "ExecBat".ToLower() | funcName.ToLower() == "ExecBatA".ToLower())
            {
                var path = funcParamArray[0];
                var args = "";
                if (funcParamArray.Length > 1)
                {
                    args = funcParamArray[1];
                }
                var execCmdWindowOptionStr = "";
                if (funcParamArray.Length > 2)
                {
                    execCmdWindowOptionStr = funcParamArray[2];
                }
                var execCmdWindowOption = ExecCmdWindowOption.ShowWindow;
                execCmdWindowOption = EnumHelper.GetByName <ExecCmdWindowOption>(execCmdWindowOptionStr, execCmdWindowOption);
                var popupOutput = false;
                if (funcParamArray.Length > 3)
                {
                    popupOutput = funcParamArray[3] == "true";
                }
                var raiseUacLevel = funcName.ToLower() == "ExecBat".ToLower() ? false : true;

                SysProcessHelper.ExecBat(raiseUacLevel, path, args, execCmdWindowOption, popupOutput, null);
            }
            else if (funcName.ToLower() == "Run".ToLower() | funcName.ToLower() == "RunA".ToLower())
            {
                var path = funcParamArray[0];
                var args = "";
                if (funcParamArray.Length > 1)
                {
                    args = funcParamArray[1];
                }
                var isSync = false;
                if (funcParamArray.Length > 2)
                {
                    isSync = funcParamArray[2] == "true";
                }
                var raiseUacLevel = funcName.ToLower() == "Run".ToLower() ? false : true;

                SysProcessHelper.Run(raiseUacLevel, path, args, isSync, null);
            }
            else if (funcName.ToLower() == "ExecPython".ToLower() | funcName.ToLower() == "ExecPythonA".ToLower())
            {
                var path = funcParamArray[0];
                var args = "";
                if (funcParamArray.Length > 1)
                {
                    args = funcParamArray[1];
                }
                var execCmdWindowOptionStr = "";
                if (funcParamArray.Length > 2)
                {
                    execCmdWindowOptionStr = funcParamArray[2];
                }
                var execCmdWindowOption = ExecCmdWindowOption.ShowWindow;
                execCmdWindowOption = EnumHelper.GetByName <ExecCmdWindowOption>(execCmdWindowOptionStr, execCmdWindowOption);

                var execCmdOutputOptionStr = "";
                if (funcName.ToLower() == "ExecPython".ToLower())
                {
                    if (funcParamArray.Length > 3)
                    {
                        execCmdOutputOptionStr = funcParamArray[3];
                    }
                    var execCmdOutputOption = ExecCmdOutputOption.None;
                    execCmdOutputOption = EnumHelper.GetByName <ExecCmdOutputOption>(execCmdOutputOptionStr, execCmdOutputOption);
                    returnStr           = SysProcessHelper.ExecPython(path, args, execCmdWindowOption, execCmdOutputOption, null);
                }
                else
                {
                    var popupOutput = false;
                    if (funcParamArray.Length > 3)
                    {
                        popupOutput = funcParamArray[3] == "true";
                    }
                    SysProcessHelper.ExecPythonA(path, args, execCmdWindowOption, popupOutput, null);
                }
            }

            else
            {
                return("OutOfScope");
            }

            return(returnStr);
        }
Ejemplo n.º 3
0
        //#act
        public static string Act(string funcName, string[] funcParamArray)
        {
            var returnStr = "";

            try
            {
                if (funcName.ToLower() == "CreateDirectory".ToLower())
                {
                    if (!Directory.Exists(funcParamArray[0]))
                    {
                        Directory.CreateDirectory(funcParamArray[0]);
                    }
                    if (funcParamArray[1] == "true")
                    {
                        var di = new DirectoryInfo(funcParamArray[0]);
                        if (!((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
                        {
                            di.Attributes = FileAttributes.Hidden;
                        }
                    }
                }
                else if (funcName.ToLower() == "OpenDirectory".ToLower())
                {
                    if (!Directory.Exists(funcParamArray[0]))
                    {
                        throw new ArgumentException("Directory does not exist! ");;
                    }
                    else
                    {
                        System.Diagnostics.Process.Start(funcParamArray[0]);
                    }
                }
                else if (funcName.ToLower() == "SelectAndRenameFile".ToLower())
                {
                    var dlgOpenFile = new OpenFileDialog();

                    dlgOpenFile.Title            = funcParamArray[0];
                    dlgOpenFile.Filter           = funcParamArray[1];
                    dlgOpenFile.InitialDirectory = funcParamArray[2];
                    dlgOpenFile.Multiselect      = false;
                    dlgOpenFile.RestoreDirectory = true;
                    if (dlgOpenFile.ShowDialog() == DialogResult.OK)
                    {
                        if (dlgOpenFile.FileNames.Length > 0)
                        {
                            var firstFilePath = dlgOpenFile.FileNames[0];
                            var folder        = FileHelper.GetFileDetailByOption(firstFilePath, FilePathComposition.Directory);
                            if (File.Exists(firstFilePath))
                            {
                                File.Move(firstFilePath, folder + "\\" + funcParamArray[3]);
                            }
                            else
                            {
                                throw new ArgumentException("File does not exist! ");;
                            }
                        }
                    }
                    else
                    {
                        //throw new ArgumentException("Operation Cancelled! ");
                    }
                }

                else if (funcName.ToLower() == "Run".ToLower())
                {
                    var actArgsStr = "";
                    if (funcParamArray.Length > 1)
                    {
                        actArgsStr = funcParamArray[1];
                    }
                    ProcessHelper.Run(funcParamArray[0], actArgsStr);
                }


                else if (funcName.ToLower() == "OpenFile".ToLower())
                {
                    var actArgsStr = "";
                    ProcessHelper.OpenFile(funcParamArray[0], actArgsStr);
                }
                else if (funcName.ToLower() == "OpenFolder".ToLower())
                {
                    ProcessHelper.OpenFolder(funcParamArray[0]);
                }


                else if (funcName.ToLower() == ("Redirect").ToLower())
                {
                    ProcessHelper.Redirect(funcParamArray[0]);
                }

                else if (funcName.ToLower() == "SendLocalEmail".ToLower())
                {
                    var mailTo  = funcParamArray[0];
                    var subject = funcParamArray[1];
                    var body    = "";
                    if (funcParamArray.Length > 2)
                    {
                        body = funcParamArray[2];
                    }
                    if (body.Contains("\r\n"))
                    {
                        body = body.Replace("\r\n", "%0D%0A");
                    }
                    if (body.Contains("\\r\\n"))
                    {
                        body = body.Replace("\\r\\n", "%0D%0A");
                    }
                    LocalEmailHelper.Send(mailTo, subject, body);
                }

                else if (funcName.ToLower() == ("RunCmd".ToLower()) | funcName.ToLower() == ("ExecCmd".ToLower()))
                {
                    var actArgsStr     = "";
                    var inputStr       = "";
                    var execCmdModeStr = "0";
                    if (funcName.ToLower() == ("RunCmd".ToLower()))
                    {
                        if (!File.Exists(funcParamArray[0]))
                        {
                            throw new ArgumentException("File:'" + funcParamArray[0] + "' does not exist!");
                        }
                        if (funcParamArray.Length > 1)
                        {
                            actArgsStr = funcParamArray[1];
                        }
                        if (funcParamArray.Length > 2)
                        {
                            if (funcParamArray[2].IsPlusInteger())
                            {
                                execCmdModeStr = funcParamArray[2];
                            }
                        }
                        inputStr = actArgsStr.IsNullOrEmpty() ? funcParamArray[0] : funcParamArray[0] + " " + actArgsStr;
                    }

                    else if (funcName.ToLower() == "ExecCmd".ToLower())
                    {
                        if (funcParamArray.Length > 1)
                        {
                            if (funcParamArray[1].IsPlusInteger())
                            {
                                execCmdModeStr = funcParamArray[1];
                            }
                        }
                        inputStr = funcParamArray[0];
                    }

                    var execCmdModeInt = (ExecCmdMode)Convert.ToInt16(execCmdModeStr);
                    var execCmdMode    = (ExecCmdMode)(execCmdModeInt);
                    returnStr = ProcessHelper.Cmd(inputStr, execCmdMode);
                }

                else if (funcName.ToLower() == "ExportToExcel".ToLower())
                {
                    var content = funcParamArray[0];
                    content = "UTF格式";
                    var title  = "ExpertToExcel".ToUniqueStringByNow();
                    var folder = DirectoryHelper.GetSpecialDir("personal");

                    var path = folder + "\\" + title + ".xls";
                    File.WriteAllText(path, content, Encoding.Default);
                    ProcessHelper.OpenFile(path, "");
                }
                else if (funcName.ToLower() == "EncryptTextFile".ToLower())
                {
                    var path = funcParamArray[0];
                    path = FileHelper.GetFilePath(path, Path.GetDirectoryName(Application.ExecutablePath));
                    var folder    = FileHelper.GetFileDetailByOption(path, FilePathComposition.Directory);
                    var fileTitle = FileHelper.GetFileDetailByOption(path, FilePathComposition.FileTitle);
                    var postfix   = FileHelper.GetFileDetailByOption(path, FilePathComposition.Postfix);
                    var txt       = EncryptionHelper.SmEncrypt(File.ReadAllText(path));
                    var path1     = folder + "\\" + fileTitle + ".E" + postfix.Substring(1, postfix.Length - 1);
                    File.WriteAllText(path1, txt, Encoding.Default);

                    if (funcParamArray.Length > 1 & funcParamArray[1].ToLower() == "true")
                    {
                        File.Delete(path);
                    }
                }
                else
                {
                    return("OutOfScope");
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".Act error: " + ex.Message);
            }
            return(returnStr);
        }