Ejemplo n.º 1
0
    //取得目前該金鑰權限下的所有Bucket列表
    public static List <string> GetBucketList()
    {
        var buckets     = new List <string>();
        var credentials = new StoredProfileAWSCredentials("developer"); //若config檔裡有指定profileName屬性,則此段可省略,下面改寫為 var client = new AmazonS3Client()

        using (var client = new AmazonS3Client(credentials))
        {
            try
            {
                ListBucketsResponse response = client.ListBuckets();

                foreach (S3Bucket bucket in response.Buckets)
                {
                    buckets.Add(bucket.BucketName);
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    LogTools.Error("Please check the provided AWS Credentials. If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                }
                else
                {
                    LogTools.Error(string.Format("An Error, number {0}, occurred when listing buckets with the message '{1}", amazonS3Exception.ErrorCode, amazonS3Exception.Message));
                }
            }
        }

        return(buckets);
    }
 private static void PrintExcepitonLog(Exception e)
 {
     if (e.GetType() == typeof(InvalidOperationException))
     {
         LogTools.PrintError("打包失败,文件已损坏");
     }
     else
     {
         LogTools.PrintError(e.GetType().Name + e.Message);
     }
     LogTools.Error(GetDetailsInfo(), e);
     //将失败的文件拷贝至指定目录
     try
     {
         String exceptionFilePath = GlobalConstants.AbsoluteResourcesPath + "/" + FileTools.GetFileName(srcPath);
         if (FileTools.FileExists(exceptionFilePath))
         {
             LogTools.Info("发生异常的文件存在,文件路径为:" + exceptionFilePath);
             if (!FileTools.DirectoryExists(GlobalConstants.ExceptionFBXFolder))
             {
                 FileTools.CreateDirectory(GlobalConstants.ExceptionFBXFolder);
             }
             String destFilePath = GlobalConstants.ExceptionFBXFolder + "/" + FileTools.GetFileName(exceptionFilePath) + "(" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss") + ")";
             FileTools.CopyFile(exceptionFilePath, destFilePath);
         }
         else
         {
             LogTools.Info("发生异常的文件不存在,文件路径为");
         }
     }
     catch (Exception ee)
     {
         LogTools.Error(GetDetailsInfo(), ee);
     }
 }
Ejemplo n.º 3
0
    //取得指定目錄之檔案列表
    public static List <string> GetFileList(string bucket, string path = "")
    {
        var files       = new List <string>();
        var credentials = new StoredProfileAWSCredentials("developer");

        using (var client = new AmazonS3Client(credentials))
        {
            try
            {
                ListObjectsRequest request = new ListObjectsRequest();
                request.BucketName = bucket;
                request.Prefix     = path;
                ListObjectsResponse response = client.ListObjects(request);

                do
                {
                    response = client.ListObjects(request);
                    foreach (S3Object entry in response.S3Objects)
                    {
                        files.Add(entry.Key);
                    }

                    if (response.IsTruncated)
                    {
                        request.Marker = response.NextMarker;
                    }
                    else
                    {
                        request = null;
                    }
                } while (request != null);
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    LogTools.Error("Please check the provided AWS Credentials. If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                }
                else
                {
                    LogTools.Error(string.Format("An error occurred with the message '{0}' when listing objects", amazonS3Exception.Message));
                }
            }
        }

        return(files);
    }
Ejemplo n.º 4
0
        public CreateScriptTaskResult CreateScriptTask(ScriptBase script)
        {
            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;
            var task        = new Task(() =>
            {
                var viewportRect    = mumuTools.GetMumuViewportRect();
                var viewportCapture = tools.DoCaptureScreen(viewportRect);
                logTools.Info("ScriptStart", $"Script: {script.Name} OnStart");
                script.OnStart(viewportCapture.ToOpenCvMat(), viewportRect);
                while (true)
                {
                    if (token.IsCancellationRequested)
                    {
                        logTools.Info("ScriptLoop", Trans.T("脚本: {0} 被终止", script.Name));
                        break;
                    }
                    try
                    {
                        Thread.Sleep(script.Interval);
                        viewportRect    = mumuTools.GetMumuViewportRect();
                        viewportCapture = tools.DoCaptureScreen(viewportRect);
                        //logTools.Info("ScriptLoop", $"Script: {script.Name} Tick");
                        var viewportMat = viewportCapture.ToOpenCvMat();
                        var startTime   = DateTime.Now;
                        script.Tick(viewportMat, viewportRect);
                        var endTime = DateTime.Now;
                        //logTools.Info("ScriptLoop", $"Tick Takes {(endTime - startTime).TotalMilliseconds}ms");
                    }
                    catch (Exception e)
                    {
                        var needBreak = logTools.IsSelfOrChildrenBreakException(e);
                        if (!script.CanKeepOnWhenException || needBreak)
                        {
                            logTools.Error("ScriptLoop", Trans.T("脚本: {0} 因发生错误或主动结束而被终止", script.Name), false);
                            throw e;
                        }
                        else
                        {
                            logTools.Error("ScriptLoop", Trans.T("脚本: {0} 发生错误", script.Name), false);
                            logTools.Error("ScriptLoop", e);
                        }
                    }
                }
            }, tokenSource.Token);

            task.ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    logTools.Error("ScriptTask", t.Exception);
                }
                else if (t.IsCanceled)
                {
                    logTools.Error("ScriptTask", Trans.T("脚本: {0} 被终止", script.Name));
                }
                OnScriptEnded?.Invoke(script);
            });
            return(new CreateScriptTaskResult()
            {
                Task = task,
                Script = script,
                TaskTokenSource = tokenSource,
                TaskToken = token,
            });
        }