コード例 #1
0
        /// <summary>
        /// Method to invoke Service Request
        /// </summary>
        /// <param name="instance">instance of the operation context request</param>
        /// <param name="inputs">input patameters array</param>
        /// <param name="outputs">output parameter arrays</param>
        /// <returns>returns execution context</returns>
        public Object Invoke(Object instance, Object[] inputs, out Object[] outputs)
        {
            outputs = null;
            var    request         = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            string apiKeyHeader    = AppUtil.GetAppSettings(AspectEnums.ConfigKeys.APIKeyHeader);
            string apiSecretHeader = AppUtil.GetAppSettings(AspectEnums.ConfigKeys.APITokenHeader);
            string apiHeaderUserID = AppUtil.GetAppSettings(AspectEnums.ConfigKeys.HeaderUserID);
            string headerValue     = request.Headers[apiKeyHeader];
            string secretTokenKey  = request.Headers[apiSecretHeader];
            string headerUserID    = request.Headers[apiHeaderUserID];

            if (!String.IsNullOrEmpty(headerValue) && !String.IsNullOrEmpty(secretTokenKey) && !String.IsNullOrEmpty(headerUserID))
            {
                //call method to get the api key authorization from database
                bool isValid = SystemBusinessInstance.IsValidServiceUser(RemoveUnwantedCharacters(headerValue), RemoveUnwantedCharacters(secretTokenKey), RemoveUnwantedCharacters(headerUserID));
                if (isValid)
                {
                    if (IsValidTokenUser(headerValue, secretTokenKey, operationName, Convert.ToInt32(headerUserID), inputs))
                    {
                        return(InnerOperationInvoker.Invoke(instance, inputs, out outputs));
                    }
                    else
                    {
                        //returns exception for missing API Credentials
                        throw new System.Security.VerificationException(Messages.ApiAccessDenied + operationName + " Unauthorized" + " UserID=" + headerUserID);
                    }
                }
                else
                {
                    //returns exception for missing API Credentials
                    throw new System.Security.SecurityException(Messages.ApiAccessDenied + operationName + " UserID=" + headerUserID + ";ApkiKey=" + headerValue + ";ApiToken=" + secretTokenKey);
                }
            }
            //returns exception for missing API Credentials
            throw new System.Security.SecurityException(Messages.CredentialsNotFound + operationName);
        }
コード例 #2
0
ファイル: StoreService.cs プロジェクト: accuit/BaseProject
        /// <summary>
        /// UploadMDMDealerCreationImage
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public JsonResponse <string> UploadMDMDealerCreationImage(Stream image)
        {
            JsonResponse <string> response = new JsonResponse <string>();

            try
            {
                ExceptionEngine.AppExceptionManager.Process(() =>
                {
                    var parser              = new MultipartFormDataParser(image);
                    string apiKey           = parser.Parameters["APIKey"].Data;
                    string apiToken         = parser.Parameters["APIToken"].Data;
                    string userid           = parser.Parameters["userid"].Data;
                    DealerCreationBO dealer = new DealerCreationBO();
                    int dealerCreationID    = Convert.ToInt32(parser.Parameters["dealerCreationID"].Data);

                    MDMDealerCreationBO dealerMDM = new MDMDealerCreationBO();
                    bool isValid = SystemBusinessInstance.IsValidServiceUser(apiKey, apiToken, userid);
                    if (isValid)
                    {
                        FileStream fileData  = null;
                        MemoryStream ms      = null;
                        int counter          = 0;
                        string fileDirectory = AppUtil.GetUploadDirectory(AspectEnums.ImageFileTypes.DealerCreation);

                        foreach (var file in parser.Files)
                        {
                            string filename = file.FileName;
                            if (Directory.Exists(fileDirectory))
                            {
                                string newFileName      = AppUtil.GetUniqueKey().ToUpper() + DateTime.Now.ToString().Replace(" ", "").Replace(":", "").Replace("/", "") + counter.ToString() + ".jpeg";
                                string uploadedFileName = fileDirectory + @"\" + newFileName;
                                #region Step 1: Save Image
                                byte[] arrBite;
                                using (ms = new MemoryStream())
                                {
                                    file.Data.CopyTo(ms);
                                    arrBite = ms.ToArray();
                                    if (MimeType.GetMimeType(arrBite, filename))
                                    {
                                        using (fileData = new FileStream(uploadedFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                                        {
                                            ms.Position = 0;
                                            if (ms.Length != 0)
                                            {
                                                ms.CopyTo(fileData);
                                            }
                                            file.Data.Close();
                                            if (ms != null)
                                            {
                                                ms.Close();
                                                ms.Dispose();
                                            }
                                        }
                                        switch (filename)
                                        {
                                        case "ContactPersonPhoto": dealer.CONTACTPERSONPHOTO = newFileName; dealerMDM.ByteCONTACTPERSONPHOTO = arrBite; break;

                                        case "GSBPhoto": dealer.GSBPHOTO = newFileName; dealerMDM.ByteGSBPHOTO = arrBite; break;

                                        case "OwnerPhoto": dealer.OWNERPHOTO = newFileName; dealerMDM.ByteOWNERPHOTO = arrBite; break;

                                        case "PanPhoto": dealer.PANPHOTO = newFileName; dealerMDM.BytePANPHOTO = arrBite; break;

                                        case "Tinphoto": dealer.TINPHOTO = newFileName; dealerMDM.ByteTINPHOTO = arrBite; break;
                                        }
                                    }
                                    else
                                    {
                                        file.Data.Close();
                                        if (ms != null)
                                        {
                                            ms.Close();
                                            ms.Dispose();
                                        }
                                        response.Message = "Not a valid image type";
                                        return;
                                        //throw new System.Security.SecurityException("Not a valid image type");
                                    }
                                }
                                #endregion
                            }
                        }
                        #region Step 2: Save the Content
                        response.IsSuccess = StoreBusinessInstance.PhotoMDMDealerCreation(dealer, dealerCreationID);
                        //var dealerDBData = StoreBusinessInstance.GetDealerCreationData(dealerCreationID);
                        //dealerDBData.ByteCONTACTPERSONPHOTO = dealerMDM.ByteCONTACTPERSONPHOTO;
                        #region Filldata for dealercreation request in MDM
                        var tempCONTACTPERSONPHOTO = dealerMDM.ByteCONTACTPERSONPHOTO;
                        var tempGSBPHOTO           = dealerMDM.ByteGSBPHOTO;
                        var tempOWNERPHOTO         = dealerMDM.ByteOWNERPHOTO;
                        var tempPANPHOTO           = dealerMDM.BytePANPHOTO;
                        var tempTINPHOTO           = dealerMDM.ByteTINPHOTO;

                        EntityMapper.Map(StoreBusinessInstance.GetDealerCreationData(dealerCreationID), dealerMDM);
                        dealerMDM.ByteCONTACTPERSONPHOTO = tempCONTACTPERSONPHOTO;
                        dealerMDM.ByteGSBPHOTO           = tempGSBPHOTO;
                        dealerMDM.ByteOWNERPHOTO         = tempOWNERPHOTO;
                        dealerMDM.BytePANPHOTO           = tempPANPHOTO;
                        dealerMDM.ByteTINPHOTO           = tempTINPHOTO;
                        MDMServiceInstance.CreateDealer(dealerMDM);
                        #endregion
                        #endregion
                    }
                    else
                    {
                        throw new System.Security.SecurityException(Messages.ApiAccessDenied);
                    }
                }, AspectEnums.ExceptionPolicyName.ServiceExceptionPolicy.ToString());
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }
            return(response);
        }
コード例 #3
0
        public JsonResponse <string> UploadBillImageStream(Stream image)
        {
            JsonResponse <string> response = new JsonResponse <string>();

            try
            {
                ExceptionEngine.AppExceptionManager.Process(() =>
                {
                    // with the HTTP request. We can do that in WCF using the WebOperationConext:
                    // var type = System.ServiceModel.Web.WebOperationContext.Current.IncomingRequest.Headers["Content-Type"];
                    //Stream stream = new MemoryStream(image);
                    var parser = new MultipartFormDataParser(image);

                    string apiKey   = parser.Parameters["APIKey"].Data;
                    string apiToken = parser.Parameters["APIToken"].Data;
                    string userid   = parser.Parameters["userID"].Data;
                    bool isValid    = SystemBusinessInstance.IsValidServiceUser(apiKey, apiToken, userid);
                    if (isValid)
                    {
                        // From this point the data is parsed, we can retrieve the
                        // form data from the Parameters dictionary:

                        int EMSExpenseDetailId      = Convert.ToInt32(parser.Parameters["EMSExpenseDetailIDServer"].Data);
                        int EMSBillDetailID         = Convert.ToInt32(parser.Parameters["EMSBillDetailIDServer"].Data);
                        int EMSBillDocumentDetailID = Convert.ToInt32(parser.Parameters["EMSBillDocumentDetailIDServer"].Data);
                        int UserID          = Convert.ToInt32(parser.Parameters["userID"].Data);
                        int roelID          = Convert.ToInt32(parser.Parameters["roleID"].Data);
                        FileStream fileData = null;
                        MemoryStream ms     = null;

                        int counter          = 1;
                        string fileDirectory = string.Empty;

                        fileDirectory = AppUtil.GetUploadDirectory(AspectEnums.ImageFileTypes.Expense);


                        List <EMSBillDocumentDetailDTO> BillDocumentDetailDTOList = new List <EMSBillDocumentDetailDTO>();
                        foreach (var file in parser.Files)
                        {
                            string filename = file.FileName;

                            if (Directory.Exists(fileDirectory))
                            {
                                string newFileName      = UserID.ToString() + "_" + EMSBillDocumentDetailID.ToString() + "_" + AppUtil.GetUniqueKey().ToUpper() + DateTime.Now.ToString().Replace(" ", "").Replace(":", "").Replace("/", "") + counter.ToString() + ".jpeg";
                                string uploadedFileName = fileDirectory + @"\" + newFileName;

                                #region Step 1: Save Image

                                byte[] arrBite;
                                using (ms = new MemoryStream())
                                {
                                    file.Data.CopyTo(ms);
                                    arrBite = ms.ToArray();

                                    if (MimeType.GetMimeType(arrBite, filename))
                                    {
                                        using (fileData = new FileStream(uploadedFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                                        {
                                            ms.Position = 0;
                                            if (ms.Length != 0)
                                            {
                                                ms.CopyTo(fileData);
                                            }

                                            BillDocumentDetailDTOList.Add(new EMSBillDocumentDetailDTO {
                                                EMSBillDocumentDetailID = EMSBillDocumentDetailID, DocumentName = newFileName, CreatedBy = UserID
                                            });

                                            file.Data.Close();

                                            if (ms != null)
                                            {
                                                ms.Close();
                                                ms.Dispose();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        file.Data.Close();
                                        if (ms != null)
                                        {
                                            ms.Close();
                                            ms.Dispose();
                                        }
                                        response.Message = "Not a valid image type";
                                        return;
                                        //throw new System.Security.SecurityException("Not a valid image type");
                                    }
                                }

                                #endregion

                                counter++;
                            }
                        }


                        bool isSuccess = false;
                        isSuccess      = SalesCatalystInstance.UpdateBillIamge(BillDocumentDetailDTOList);

                        response.IsSuccess = true;
                    }
                    else
                    {
                        throw new System.Security.SecurityException(Messages.ApiAccessDenied);
                    }
                }, AspectEnums.ExceptionPolicyName.ServiceExceptionPolicy.ToString());
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = ex.Message;
            }
            return(response);
        }