2

fogbugz API を使用して添付ファイルをアップロードできません。私はfogbugzのドキュメントに従いましたが、何か間違っているかもしれません。発生するエラーは次のとおりです。Ex.Message = "指定されたキーは辞書に存在しませんでした。"

StackTrace = " c:\Dev\RapidAppsFogbugz\trunk\Business\Services\Fogbugz.cs:line 114の System.Collections.Generic.Dictionary 2.get_Item(TKey key) at UBR.Products.TimeTrakker.Client.Lib.FogBugz.FBApi.CallRESTAPIFiles(String sURL, Dictionary2 rgArgs、Dictionary 2[] rgFiles) at UBR.Products.TimeTrakker.Client.Lib.FogBugz.FBApi.Cmd(String cmd, Dictionary2 args、Dictionary 1 fileData) で"2[] files) at Business.Services.Fogbugz.CreateBug(String title, String areaId, String summary, List

            public string CreateBug(string title, string areaId, string summary)
            {
                try
                {
                    string bugIdResult;
                    //Build args from Bug object
                    var args = FillArgsDictionaryForCreatingBug(title, GetDefaultProjectID(), areaId, summary);
                    var fileArgs = GetAttachmentArgs(GetAttachmentList());

                    //args.Add("nFileCount", "1");

                    if (fileArgs != null) //WITH ATTACHMENTS
                        bugIdResult = GetBugId(_fogbugz.Cmd("new", args, fileArgs));
                    else //NO ATTACHMENTS
                        bugIdResult = GetBugId(_fogbugz.Cmd("new", args));

                    return bugIdResult;
                }
                catch (Exception ex)
                {
                    throw new Exception(typeof(Fogbugz).ToString() + " : Method = CreateBug", ex);
                }
            }

            private List<byte[]> GetAttachmentList()
            {
                List<byte[]> fileData = null;

                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    fileData = new List<byte[]>();

                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        HttpPostedFileBase file = Request.Files[i];
                        if (file.ContentLength > 0)
                        {
                            using (var binaryReader = new BinaryReader(file.InputStream))
                            {
                                fileData.Add(binaryReader.ReadBytes(file.ContentLength));
                            }
                        }
                    }
                }

             private Dictionary<string, string> FillArgsDictionaryForCreatingBug(string title, string projectId, string areaId, string summary)
                {
                    var args = new Dictionary<string, string>
                    {
                        {"sTitle", title},
                        {"ixProject", projectId},
                        {"ixArea", areaId},
                        {"sEvent", summary}
                    };
                    return args;
                }

            private Dictionary<string,byte[]>[] GetAttachmentArgs(List<byte[]> fileData)
            {
                Dictionary<string, byte[]>[] result = null;
                if (fileData != null)
                {
                    var fileArgs = new List<Dictionary<string, byte[]>>();
                    for (int i = 0; i < fileData.Count; i++)
                    {
                        var dictionary = new Dictionary<string, byte[]> { { "File" + (i+1).ToString(), fileData[i] } };
                        fileArgs.Add(dictionary);
                    }
                    result = fileArgs.ToArray();
                }

                return result;
            }
4

1 に答える 1