示例#1
0
        private APIReturnValue ProcessVendorSolicitation(DataRow VSRow, string CustomFields)
        {
            APIReturnValue            retVal     = new APIReturnValue();
            int                       VendorId   = Convert.ToInt32(VSRow["venId"]);
            string                    strResp    = string.Empty;
            VendorSolicitationRequest objVendSol = Util.CreateObjectFromRow <VendorSolicitationRequest>(VSRow);

            objVendSol.projectVendor.projectVendorStatusId = Preprocessor.projectVendorStatusList[VSRow["ProjectVendorStatus"].ToString().ToLower()];
            objVendSol.projectVendor.projectVendorId       = Preprocessor.GetProjectVendorId(Preprocessor.vendorMasterInfoList[VendorId].appVendorId, ProjectId);
            if (VSRow.Table.Columns.Contains("ActionTakenValue") && VSRow["ActionTakenValue"] != null)
            {
                objVendSol.actionTakenValueId = Preprocessor.vendorStatementActionList[VSRow["ActionTakenValue"].ToString()];
            }
            HttpResponseMessage respMsg;

            if (!string.IsNullOrEmpty(CustomFields))
            {
                dynamic       expando = Util.ConvertToExpando(objVendSol);
                List <String> lst     = CustomFields.Split(",").ToList();
                Dictionary <string, object> tempProps = new Dictionary <string, object>();
                foreach (string str in lst)
                {
                    if (VSRow.Table.Columns.Contains(str) && VSRow[str] != null)
                    {
                        tempProps.Add(str, VSRow[str]);
                    }
                }
                Util.AddProperties(expando, tempProps);
                string strPL = JsonConvert.SerializeObject(expando);
                respMsg = Util.AuditAPIURL.AppendPathSegment("projectvendorstatementactions").WithOAuthBearerToken(Util.bearerToken)
                          .WithHeader("Content-Type", "application/json").PostStringAsync(strPL).Result;
            }
            else
            {
                respMsg = Util.AuditAPIURL.AppendPathSegment("projectvendorstatementactions").WithOAuthBearerToken(Util.bearerToken)
                          .WithHeader("Content-Type", "application/json").PostJsonAsync(objVendSol).Result;
            }
            strResp           = respMsg.Content.ReadAsStringAsync().Result;
            retVal.StatusDesc = strResp;
            if (respMsg.IsSuccessStatusCode)
            {
                IDictionary <string, object> objResp = JsonConvert.DeserializeObject <ExpandoObject>(strResp);
                retVal.Status     = StatusCode.Complete;
                retVal.PanopticId = objResp["projectVendorStatementActionId"].ToString();
            }
            else
            {
                retVal.Status = StatusCode.Error;
            }
            return(retVal);
        }
示例#2
0
        private APIReturnValue ProcessDocuments(string EntityName, DataRow Row, string CustomFields)
        {
            List <string> lstFailedFiles = new List <string>();
            List <string> lstPanIds      = new List <string>();
            //string tempFilePath = Path.Combine("temp", Path.GetFileName(Row["filePath"].ToString()));
            string         tempFilePath = Row["filePath"].ToString();
            string         APIPath      = string.Empty;
            APIReturnValue retVal       = new APIReturnValue();
            string         AppVenId     = Preprocessor.vendorMasterInfoList[Convert.ToInt32(Row["venId"])].appVendorId;
            string         strResp      = string.Empty;
            //File.Copy(Row["filePath"].ToString(), tempFilePath, true);
            FileMetadata metadata = Util.CreateObjectFromRow <FileMetadata>(Row);

            metadata.appVendorId = AppVenId;
            metadata.projectId   = ProjectId;
            switch (EntityName)
            {
            case "SolicitationDocument":
            {
                APIPath = $"projects({ProjectId})/doc-attach/objectstore/documents";
                metadata.projectVendorId = Preprocessor.GetProjectVendorId(AppVenId, ProjectId);
                break;
            }

            case "CreditDocument":
            {
                APIPath = $"vendorCredits({Convert.ToInt32(Row["PanopticParentId"])})/doc-attach/objectstore/documents";
                break;
            }
            }
            if (Row.Table.Columns.Contains("DocumentType") && Row["DocumentType"] != null)
            {
                metadata.docType = Preprocessor.documentTypeList[Row["DocumentType"].ToString().ToLower()];
            }

            Dictionary <string, Stream> files = null;

            if (Path.GetExtension(tempFilePath).ToLower() == ".msg")
            {
                //files = GetFileStreams(tempFilePath);
                files = ExtractMSG(tempFilePath);
                Logger.log.Debug($"Get File Stream finished for {tempFilePath}");
            }
            else
            {
                files = new Dictionary <string, Stream>();
                files.Add(Path.GetFileName(tempFilePath), new FileStream(tempFilePath, FileMode.Open, FileAccess.Read));
            }

            if (files != null)
            {
                foreach (KeyValuePair <string, Stream> kvp in files)
                {
                    try
                    {
                        metadata.fileName  = kvp.Key;
                        metadata.aliasName = kvp.Key;
                        Dictionary <string, string> kvfn = new Dictionary <string, string>();
                        if (!string.IsNullOrEmpty(CustomFields))
                        {
                            dynamic       expando = Util.ConvertToExpando(metadata);
                            List <String> lst     = CustomFields.Split(",").ToList();
                            Dictionary <string, object> tempProps = new Dictionary <string, object>();
                            foreach (string str in lst)
                            {
                                if (Row.Table.Columns.Contains(str) && Row[str] != null)
                                {
                                    tempProps.Add(str, Row[str]);
                                }
                            }
                            Util.AddProperties(expando, tempProps);
                            kvfn.Add(metadata.fileName, JsonConvert.SerializeObject(expando));
                        }
                        else
                        {
                            kvfn.Add(metadata.fileName, JsonConvert.SerializeObject(metadata));
                        }
                        Dictionary <string, Dictionary <string, string> > fileMetadata = new Dictionary <string, Dictionary <string, string> >();
                        fileMetadata.Add("fileMetadata", kvfn);
                        string s = JsonConvert.SerializeObject(fileMetadata);

                        /*
                         * using (FileStream outputFileStream = new FileStream(kvp.Key, FileMode.Create))
                         * {
                         *  kvp.Value.CopyTo(outputFileStream);
                         * }
                         */
                        HttpResponseMessage respMsg = Util.AuditAPIURL
                                                      .AppendPathSegment(APIPath).WithOAuthBearerToken(Util.bearerToken)
                                                      .PostMultipartAsync(mp => mp.AddStringParts(new { request = s }).AddFile("file", kvp.Value, kvp.Key)).Result;
                        strResp = respMsg.Content.ReadAsStringAsync().Result;
                        Logger.log.Debug($"Upload finished for {kvp.Key}");
                        if (respMsg.IsSuccessStatusCode)
                        {
                            List <Dictionary <string, object> > objResp = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(strResp);
                            retVal.Status = StatusCode.PartiallyComplete;
                            lstPanIds.Add(objResp[0]["documentId"].ToString());
                        }
                        else
                        {
                            retVal.StatusDesc += strResp;
                            lstFailedFiles.Add(kvp.Key);
                            Logger.log.Error($"Error Occurred while Processing File {kvp.Key} for Record Id: {Row["RecordId"]}, Response: {strResp}");
                        }
                    }
                    catch (AggregateException ae)
                    {
                        lstFailedFiles.Add(kvp.Key);
                        ae.Handle(e =>
                        {
                            if (e is FlurlHttpException)
                            {
                                string es          = ((FlurlHttpException)e).GetResponseStringAsync().Result;
                                retVal.StatusDesc += es;
                                Logger.log.Error(e, $"Error Occurred while Processing File {kvp.Key} for Record Id: {Row["RecordId"]}, Response: {es}");
                            }
                            else
                            {
                                Logger.log.Error(e, $"Error Occurred while Processing File {kvp.Key} for Record Id: {Row["RecordId"]}");
                                retVal.StatusDesc += strResp;
                            }
                            return(true); //continue execution... set to false to break.
                        });
                    }
                    catch (Exception e)
                    {
                        lstFailedFiles.Add(kvp.Key);
                        retVal.StatusDesc += strResp;
                        Logger.log.Error(e, $"Error Occurred while Processing File {kvp.Key} for Record Id: {Row["RecordId"]}");
                    }
                }
            }
            else
            {
                throw new Exception("Error Occurred while Reading File Stream");
            }
            if ((lstPanIds.Count > 0) && (lstFailedFiles.Count == 0))
            {
                retVal.Status = StatusCode.Complete;
            }
            else if ((lstPanIds.Count > 0) && (lstFailedFiles.Count > 0))
            {
                retVal.Status = StatusCode.PartiallyComplete;
            }
            else
            {
                retVal.Status = StatusCode.Error;
            }
            if (lstFailedFiles.Count > 0)
            {
                retVal.StatusDesc = $"Failed Files: {string.Join(",", lstFailedFiles)}, Response: {retVal.StatusDesc}";
            }
            if (lstPanIds.Count > 0)
            {
                retVal.PanopticId = string.Join(",", lstPanIds);
            }
            //File.Delete(tempFilePath);
            return(retVal);
        }
示例#3
0
        private APIReturnValue ProcessComments(string EntityName, DataRow Row, string CustomFields)
        {
            APIReturnValue retVal = new APIReturnValue();
            int            ParentId;
            string         qry = string.Empty;

            switch (EntityName)
            {
            case "SolicitationComment":
            {
                ParentId = Convert.ToInt32(Preprocessor.GetProjectVendorId(Preprocessor.vendorMasterInfoList[Convert.ToInt32(Row["VenId"])].appVendorId, ProjectId));
                qry      = $"vendorSolicitation({ParentId})/comment-attach/comments";
                break;
            }

            case "CreditComment":
            {
                ParentId = Convert.ToInt32(Row["PanopticParentId"]);
                qry      = $"vendorCredits({ParentId})/comment-attach/comments";
                break;
            }

            case "ClaimComment":
            {
                ParentId = Convert.ToInt32(Row["PanopticParentId"]);
                qry      = $"claims({ParentId})/comment-attach/comments";
                break;
            }
            }
            string              strResp   = string.Empty;
            CommentRequest      objComReq = Util.CreateObjectFromRow <CommentRequest>(Row);
            HttpResponseMessage respMsg;

            if (!string.IsNullOrEmpty(CustomFields))
            {
                dynamic       expando = Util.ConvertToExpando(objComReq);
                List <String> lst     = CustomFields.Split(",").ToList();
                Dictionary <string, object> tempProps = new Dictionary <string, object>();
                foreach (string str in lst)
                {
                    if (Row.Table.Columns.Contains(str) && Row[str] != null)
                    {
                        tempProps.Add(str, Row[str]);
                    }
                }
                Util.AddProperties(expando, tempProps);
                string strPL = JsonConvert.SerializeObject(expando);
                respMsg = Util.AuditAPIURL.AppendPathSegment(qry)
                          .WithOAuthBearerToken(Util.bearerToken).WithHeader("Content-Type", "application/json")
                          .PostStringAsync(strPL).Result;
            }
            else
            {
                respMsg = Util.AuditAPIURL.AppendPathSegment(qry)
                          .WithOAuthBearerToken(Util.bearerToken).WithHeader("Content-Type", "application/json")
                          .PostJsonAsync(objComReq).Result;
            }
            strResp           = respMsg.Content.ReadAsStringAsync().Result;
            retVal.StatusDesc = strResp;
            if (respMsg.IsSuccessStatusCode)
            {
                IDictionary <string, object> objResp = JsonConvert.DeserializeObject <ExpandoObject>(strResp);
                retVal.Status     = StatusCode.Complete;
                retVal.PanopticId = objResp["id"].ToString();
            }
            else
            {
                retVal.Status = StatusCode.Error;
            }
            return(retVal);
        }