Beispiel #1
0
        /// <summary>
        /// 插入用户留言
        /// </summary>
        /// <param name="leaveWordsModel"></param>
        /// <returns></returns>
        public bool InsertLeaveWords(UserLeaveWordsModel leaveWordsModel)
        {
            if (!leaveWordsModel.UserEmail.IsEmail())
            {
                throw new BusinessException("请输入有效的邮箱地址。");
            }
            if (string.IsNullOrWhiteSpace(leaveWordsModel.Content))
            {
                throw new BusinessException("请输入反馈内容。");
            }
            CustomerLeaveWords entity = new CustomerLeaveWords();

            entity.InDate           = DateTime.Now;
            entity.Subject          = HeaderHelper.GetClientType().ToString();
            entity.LeaveWords       = leaveWordsModel.Content;
            entity.CustomerEmail    = leaveWordsModel.UserEmail;
            entity.CompanyCode      = ConstValue.CompanyCode;
            entity.LanguageCode     = ConstValue.LanguageCode;
            entity.StoreCompanyCode = ConstValue.StoreCompanyCode;

            var loginedUser = UserMgr.ReadUserInfo();

            if (loginedUser != null)
            {
                entity.CustomerSysNo = loginedUser.UserSysNo;
                entity.CustomerName  = loginedUser.UserID;
            }

            return(CustomerFacade.InsertCustomerLeaveWords(entity));
        }
        internal MSearchResponse(IHttpResponse response)
        {
            try
            {
                ResponseCastMethod = Convert.GetCastMetod(response);
                HostIp             = response.RemoteAddress;
                HostPort           = response.RemotePort;
                StatusCode         = response.StatusCode;
                ResponseReason     = response.ResponseReason;
                CacheControl       = TimeSpan.FromSeconds(Convert.GetMaxAge(response.Headers));
                Location           = Convert.UrlToUri(Convert.GetHeaderValue(response.Headers, "LOCATION"));
                Date           = Convert.ToRfc2616Date(Convert.GetHeaderValue(response.Headers, "DATE"));
                Ext            = response.Headers.ContainsKey("EXT");
                Server         = Convert.ConvertToServer(Convert.GetHeaderValue(response.Headers, "SERVER"));
                ST             = Convert.GetHeaderValue(response.Headers, "ST");
                USN            = Convert.GetHeaderValue(response.Headers, "USN");
                BOOTID         = Convert.GetHeaderValue(response.Headers, "BOOTID.UPNP.ORG");
                CONFIGID       = Convert.GetHeaderValue(response.Headers, "CONFIGID.UPNP.ORG");
                SEARCHPORT     = Convert.GetHeaderValue(response.Headers, "SEARCHPORT.UPNP.ORG");
                SECURELOCATION = Convert.GetHeaderValue(response.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "DATE", "EXT", "SERVER", "ST", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG", "SEARCHPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, response.Headers);
            }
            catch (Exception)
            {
                InvalidRequest = true;
            }
        }
        public MSearchRequest(IHttpRequest request)
        {
            try
            {
                SearchCastMethod = Convert.GetCastMetod(request);
                MAN            = Convert.GetHeaderValue(request.Headers, "MAN");
                HostIp         = request.RemoteAddress;
                HostPort       = request.RemotePort;
                MX             = TimeSpan.FromSeconds(Convert.ConvertStringToInt(Convert.GetHeaderValue(request.Headers, "MX")));
                ST             = Convert.GetHeaderValue(request.Headers, "ST");
                UserAgent      = Convert.ConvertToUserAgent(Convert.GetHeaderValue(request.Headers, "USER-AGENT"));
                CPFN           = Convert.GetHeaderValue(request.Headers, "CPFN.UPNP.ORG");
                CPUUID         = Convert.GetHeaderValue(request.Headers, "CPUUID.UPNP.ORG");
                TCPPORT        = Convert.GetHeaderValue(request.Headers, "TCPPORT.UPNP.ORG");
                SECURELOCATION = Convert.GetHeaderValue(request.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "MAN", "MX", "ST", "USER-AGENT",
                    "CPFN.UPNP.ORG", "CPUUID.UPNP.ORG", "TCPPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, request.Headers);
            }
            catch (Exception)
            {
                InvalidRequest = true;
            }
        }
        public MSearchRequest(IHttpRequest request, ILogger logger = null)
        {
            try
            {
                LocalIpEndPoint  = request.LocalIpEndPoint;
                RemoteIpEndPoint = request.RemoteIpEndPoint;
                TransportType    = Convert.GetCastMetod(request);
                MAN       = Convert.GetHeaderValue(request.Headers, "MAN");
                MX        = TimeSpan.FromSeconds(Convert.ConvertStringToInt(Convert.GetHeaderValue(request.Headers, "MX")));
                ST        = new ST(Convert.GetHeaderValue(request.Headers, "ST"), ignoreError: true);
                UserAgent = Convert.ConvertToUserAgent(Convert.GetHeaderValue(request.Headers, "USER-AGENT"));
                HOST      = Convert.GetHeaderValue(request.Headers, "HOST");

                CPFN           = Convert.GetHeaderValue(request.Headers, "CPFN.UPNP.ORG");
                CPUUID         = Convert.GetHeaderValue(request.Headers, "CPUUID.UPNP.ORG");
                TCPPORT        = Convert.GetHeaderValue(request.Headers, "TCPPORT.UPNP.ORG");
                SECURELOCATION = Convert.GetHeaderValue(request.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "MAN", "MX", "ST", "USER-AGENT",
                    "CPFN.UPNP.ORG", "CPUUID.UPNP.ORG", "TCPPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, request.Headers);

                HasParsingError = request.HasParsingErrors;
            }
            catch (Exception ex)
            {
                logger?.Error(ex);
                InvalidRequest = true;
            }
        }
Beispiel #5
0
        public override List <string> GetHeaders(HeaderHelper h)
        {
            var result = new List <string>();

            result.Add(h.GetDateHeader(DateFrom));
            result.Add(h.GetRegionHeader(RegionCodeEqual));

            // если выбрано По всему ассортименту
            if (Var == CatalogVar.AllAssortment)
            {
                result.Add("В отчет включены все товары всех производителей");
            }
            // если выбрано По всем нашим товарам
            else if (Var == CatalogVar.AllCatalog)
            {
                result.Add("В отчет включены все товары производителя");
            }
            else
            {
                result.Add(h.GetProductHeader(CatalogIdEqual));
            }

            if (SupplierIdEqual != null)
            {
                result.Add(h.GetSupplierHeader(SupplierIdEqual));
            }

            if (SupplierIdNonEqual != null)
            {
                result.Add(h.GetNotSupplierHeader(SupplierIdNonEqual));
            }

            return(result);
        }
Beispiel #6
0
        internal Notify(IHttpRequest request)
        {
            try
            {
                LocalIpEndPoint     = request.LocalIpEndPoint;
                RemoteIpEndPoint    = request.RemoteIpEndPoint;
                HOST                = GetHeaderValue(request.Headers, "HOST");
                NotifyTransportType = GetCastMetod(request);
                CacheControl        = TimeSpan.FromSeconds(GetMaxAge(request.Headers));
                Location            = UrlToUri(GetHeaderValue(request.Headers, "LOCATION"));
                NT     = GetHeaderValue(request.Headers, "NT");
                NTS    = ConvertToNotificationSubTypeEnum(GetHeaderValue(request.Headers, "NTS"));
                Server = ConvertToServer(GetHeaderValue(request.Headers, "SERVER"));
                USN    = new USN(GetHeaderValue(request.Headers, "USN"));

                BOOTID         = uint.TryParse(GetHeaderValue(request.Headers, "BOOTID.UPNP.ORG"), out var b) ? b : 0;
                CONFIGID       = GetHeaderValue(request.Headers, "CONFIGID.UPNP.ORG");
                SEARCHPORT     = uint.TryParse(GetHeaderValue(request.Headers, "SEARCHPORT.UPNP.ORG"), out var s) ? s : 0;
                NEXTBOOTID     = uint.TryParse(GetHeaderValue(request.Headers, "NEXTBOOTID.UPNP.ORG"), out var n) ? n : 0;
                SECURELOCATION = GetHeaderValue(request.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "NT", "NTS", "SERVER", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG",
                    "SEARCHPORT.UPNP.ORG", "NEXTBOOTID.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, request.Headers);
            }
            catch (Exception)
            {
                InvalidRequest = true;
            }

            IsUuidUpnp2Compliant = Guid.TryParse(USN.DeviceUUID, out var guid);
        }
        /// <summary>
        /// A Lambda function that adds a product post.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> AddProductAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var product = JsonConvert.DeserializeObject <Product>(request?.Body);

            product.Id = Guid.NewGuid().ToString();
            product.CreatedTimestamp = DateTime.Now;

            context.Logger.LogLine($"Saving product with id {product.Id}");
            await DDBContext.SaveAsync <Product>(product);

            context.Logger.LogLine($"Conditions - {!string.IsNullOrEmpty(product.Id)} && {!string.IsNullOrWhiteSpace(product.Id)}");
            if (!string.IsNullOrEmpty(product.Id) && !string.IsNullOrWhiteSpace(product.Id))
            {
                context.Logger.LogLine($"Product Category - {product.Category}");
                // await FirebaseCloudMessagingHelper.SendPushNotification("dfrrFgYOHiU:APA91bGYyzADHof0ZLQg-on8l3JHIPYerYQtF8SS2VdUusVSh2bO3NntOZKy_W4_BUQ5_JB5kD7NZIZo915vEcdYwZEBKbwPg1n1gdR5pEV0kkiCIvhhD5i5alPY5Tv4VM8sPuNXmcJr", product.Name, "Just added and available for bidding.", product.ImageUrl, null);
                await FirebaseCloudMessagingHelper.SendPushNotification("/topics/" + product.Category, product.Name, "Just added and available for bidding.", product.ImageUrl, product);
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(product),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
 public override List <string> GetHeaders(HeaderHelper h)
 {
     return(new List <string> {
         h.GetDateHeader(DateFrom, DateTo),
         h.GetRegionHeader(RegionCodeEqual),
         GetCatalogHeader(h, AllCatalog, CatalogIdEqual)
     });
 }
Beispiel #9
0
        private static byte[] ComposeNotifyDatagram(INotifySsdp notifySsdp)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("NOTIFY * HTTP/1.1\r\n");

            stringBuilder.Append(notifySsdp.NotifyCastMethod == CastMethod.Multicast
                ? "HOST: 239.255.255.250:1900\r\n"
                : $"HOST: {notifySsdp.HostIp}:{notifySsdp.HostPort}\r\n");

            if (notifySsdp.NTS == NTS.Alive)
            {
                stringBuilder.Append($"CACHE-CONTROL: max-age = {notifySsdp.CacheControl.TotalSeconds}\r\n");
            }

            if (notifySsdp.NTS == NTS.Alive || notifySsdp.NTS == NTS.Update)
            {
                stringBuilder.Append($"LOCATION: {notifySsdp.Location.AbsoluteUri}\r\n");
            }

            stringBuilder.Append($"NT: {notifySsdp.NT}\r\n");
            stringBuilder.Append($"NTS: {Convert.GetNtsString(notifySsdp.NTS)}\r\n");

            if (notifySsdp.NTS == NTS.Alive)
            {
                stringBuilder.Append($"SERVER: " +
                                     $"{notifySsdp.Server.OperatingSystem}/{notifySsdp.Server.OperatingSystemVersion}/" +
                                     $" " +
                                     $"UPnP/{notifySsdp.Server.UpnpMajorVersion}.{notifySsdp.Server.UpnpMinorVersion}" +
                                     $" " +
                                     $"{notifySsdp.Server.ProductName}/{notifySsdp.Server.ProductVersion}\r\n");
            }

            stringBuilder.Append($"USN: {notifySsdp.USN}\r\n");
            stringBuilder.Append($"BOOTID.UPNP.ORG: {notifySsdp.BOOTID}\r\n");
            stringBuilder.Append($"CONFIGID.UPNP.ORG: {notifySsdp.CONFIGID}\r\n");

            if (notifySsdp.NTS == NTS.Alive || notifySsdp.NTS == NTS.Update)
            {
                HeaderHelper.AddOptionalHeader(stringBuilder, "SEARCHPORT.UPNP.ORG", notifySsdp.SEARCHPORT);
                HeaderHelper.AddOptionalHeader(stringBuilder, "SECURELOCATION.UPNP.ORG", notifySsdp.SECURELOCATION);
            }

            // Adding additional vendor specific headers if such are specified
            if (notifySsdp.Headers?.Any() ?? false)
            {
                foreach (var header in notifySsdp.Headers)
                {
                    stringBuilder.Append($"{header.Key}: {header.Value}\r\n");
                }
            }

            stringBuilder.Append("\r\n");

            return(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
        }
Beispiel #10
0
        /// <summary>
        /// Sets up a custom authorisation header. You need to fill the value of the header.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="authorisationHeaderValue">Value to be given as authorisation. This extension does not add any values to the one provided.</param>
        /// <returns></returns>
        public static RestRequest WithAuthorization(this RestRequest request, string authorisationHeaderValue)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            HeaderHelper.AddHeader(request.Request.Headers, DefaultValues.AuthorisationHeaderKey, authorisationHeaderValue, true);
            return(request);
        }
Beispiel #11
0
        /// <summary>
        /// Sets up a custom authorisation header. You need to fill the value of the header.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="authorisationHeaderValue">Value to be given as authorisation. This extension does not add any values to the one provided.</param>
        /// <returns></returns>
        public static RestConfiguration WithAuthorization(this RestConfiguration config, string authorisationHeaderValue)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            HeaderHelper.AddHeader(config.RequestDefaults.Headers, DefaultValues.AuthorisationHeaderKey, authorisationHeaderValue, true);
            return(config);
        }
Beispiel #12
0
        public List <CategoryModel> GetCategoryList()
        {
            var allInfo = CategoryFacade.QueryCategoryInfosForHomePage();
            List <CategoryModel> result     = new List <CategoryModel>();
            ClientType           clientType = HeaderHelper.GetClientType();
            string subFoler = "h";

            if (clientType == ClientType.Android)
            {
                if (HeaderHelper.IsAndroidXHigh())
                {
                    subFoler = "xh";
                }
            }
            else
            {
                subFoler = "ios";
            }
            string          baseUrl = "";
            MobileAppConfig config  = AppSettings.GetCachedConfig();

            if (config != null && config.MobileAppServiceHost != null)
            {
                config.MobileAppServiceHost = config.MobileAppServiceHost.Trim();
                if (!config.MobileAppServiceHost.EndsWith("/"))
                {
                    config.MobileAppServiceHost += "/";
                }
                baseUrl = config.MobileAppServiceHost;
            }
            foreach (var c1 in allInfo)
            {
                var m1 = Transform(c1);
                //获取一级分类图标
                m1.ICon = BuildCatIcon(baseUrl, "c1", subFoler, c1.CategoryID.ToString(), "png");//CatHelper.GetIcon(c1.CategoryID);
                result.Add(m1);
                foreach (var c2 in c1.SubCategories)
                {
                    var m2 = Transform(c2);
                    //获取二级分类图标
                    m2.ICon = BuildCatIcon(baseUrl, "c2", subFoler, c2.CategoryID.ToString(), "jpg");//CatHelper.GetSubIcon(c1.CategoryID, c2.CategoryID);
                    m1.SubCategories.Add(m2);
                    foreach (var c3 in c2.SubCategories)
                    {
                        var m3 = Transform(c3);
                        m2.SubCategories.Add(m3);
                    }
                }
            }

            return(result);
        }
Beispiel #13
0
        public static ImageSize GetImageSize(ImageType imageType)
        {
            ImageSize imageSize;

            string          clientType      = HeaderHelper.GetClientType().ToString();
            ImageSizeConfig imageSizeConfig = GetImageSizeConfig();
            var             imageSettings   = imageSizeConfig.Settings.Where(item => string.Compare(item.ImageResolution, clientType, true) == 0).SingleOrDefault();
            var             deviceSettings  = imageSettings.ImageSizes.Where(item => string.Compare(imageType.ToString(), item.ImageType, true) == 0).SingleOrDefault();

            Enum.TryParse <ImageSize>(deviceSettings.ImageSize, out imageSize);

            return(imageSize);
        }
Beispiel #14
0
        public override List <string> GetHeaders(HeaderHelper h)
        {
            var result = new List <string>();

            result.Add(h.GetDateHeader(DateFrom, DateTo));
            result.Add(h.GetRegionHeader(RegionCodeEqual));
            var c = new List <long>();

            c.AddRange(CatalogIdEqual);
            c.AddRange(CatalogIdEqual2);
            result.Add(h.GetProductHeader(c));
            return(result);
        }
Beispiel #15
0
        private void Server_DataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data.Length > 0)
            {
                lock (_lockDevice)
                    _datablockToDevice = e.Data;
                lock (_lockVcom)
                    HeaderHelper.UpdateHeaderOut(ref _datablockToVcom);

                if (HeaderHelper.ParseHeaderIn(e.Data).requestUpdate == 1 && _server.IsConnected())
                {
                    Task.Run(() => _server.SendData(_datablockToVcom));
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Adds a header into the request defaults.
        /// </summary>
        /// <param name="config">Request to be modified</param>
        /// <param name="headerKey">Header key to add</param>
        /// <param name="headerValue">Value of the key</param>
        /// <param name="overrideExistingValue">If <code>true</code> will dispose of any existing value on the header key</param>
        /// <returns></returns>
        public static RestConfiguration WithHeader(this RestConfiguration config, string headerKey, string headerValue,
                                                   bool overrideExistingValue = true)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config), ErrorMessages.NoConfiguration);
            }

            if (string.IsNullOrEmpty(headerKey))
            {
                throw new ArgumentException(ErrorMessages.HeaderMustHaveKey);
            }

            HeaderHelper.AddHeader(config.RequestDefaults.Headers, headerKey, headerValue, overrideExistingValue);
            return(config);
        }
Beispiel #17
0
        /// <summary>
        /// Adds a header into the request.
        /// </summary>
        /// <param name="request">Request to be modified</param>
        /// <param name="key">Header key to add</param>
        /// <param name="value">Value of the key</param>
        /// <param name="overrideExisting">If <code>true</code> will dispose of any existing value on the header key</param>
        /// <returns></returns>
        public static RestRequest WithHeader(this RestRequest request, string key, string value, bool overrideExisting = true)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException(ErrorMessages.HeaderMustHaveKey);
            }

            HeaderHelper.AddHeader(request.Request.Headers, key, value, overrideExisting);

            return(request);
        }
Beispiel #18
0
        /// <summary>
        /// 添加崩溃报告
        /// </summary>
        /// <param name="content"></param>
        public void AddCrashLog(string content)
        {
            ClientType clientType = HeaderHelper.GetClientType();

            List <KeyValuePair <string, object> > extList = new List <KeyValuePair <string, object> >();

            extList.Add(new KeyValuePair <string, object>("X-OSVersion", HeaderHelper.GetOSVersion()));
            extList.Add(new KeyValuePair <string, object>("X-HighResolution", HeaderHelper.GetHighResolution()));
            Logger.WriteLog(content, clientType.ToString(), "", extList);

            MobileAppConfig config = AppSettings.GetCachedConfig();

            content = content.Replace("\r\n", "<br/>");
            content = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "<br/>" + content;
            EmailFacade.SendEmail(clientType.ToString() + "-app-crash-log", content, config.CrashLogEmailTo, "*****@*****.**");
        }
Beispiel #19
0
        public async Task <IActionResult> GetAsync(string drive, string path)
        {
            var request = Request;

            bool lm = HeaderHelper.GetIfLastModify(request.Headers);

            if (lm)
            {
                return(StatusCode((int)HttpStatusCode.NotModified));
            }

            var content = await _webDavService.GetAsync(drive, path);

            await Response.Body.WriteAsync(content);

            return(StatusCode((int)HttpStatusCode.OK));
        }
Beispiel #20
0
        /// <summary>
        /// Sets up a bearer token authorisation header.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="username">Username to generate the basic header authorization</param>
        /// <param name="password">Password to generate the basic header authorization</param>
        /// <returns></returns>
        public static RestConfiguration WithBasicAuthorization(this RestConfiguration config, string username, string password)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }


            config.WithAuthorization($"Basic {HeaderHelper.BasicAuthorizationHeaderValue(username, password)}");

            return(config);
        }
        /// <summary>
        /// A Lambda function that update a product post.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> UpdateProductAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var product = JsonConvert.DeserializeObject <Product>(request?.Body);

            string productId = null;

            if (request.PathParameters != null && request.PathParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                productId = request.PathParameters[ID_QUERY_STRING_NAME];
            }
            else if (request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                productId = request.QueryStringParameters[ID_QUERY_STRING_NAME];
            }

            if (string.IsNullOrEmpty(productId))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = $"Missing required parameter {ID_QUERY_STRING_NAME}"
                });
            }
            else
            {
                product.Id = productId;
            }

            context.Logger.LogLine($"Saving product with id {product.Id}");
            await DDBContext.SaveAsync <Product>(product);

            if (!string.IsNullOrEmpty(product.Id) && !string.IsNullOrWhiteSpace(product.Id))
            {
                // await FirebaseCloudMessagingHelper.SendPushNotification("dfrrFgYOHiU:APA91bGYyzADHof0ZLQg-on8l3JHIPYerYQtF8SS2VdUusVSh2bO3NntOZKy_W4_BUQ5_JB5kD7NZIZo915vEcdYwZEBKbwPg1n1gdR5pEV0kkiCIvhhD5i5alPY5Tv4VM8sPuNXmcJr", product.Name, "Just added and available for bidding.", product.ImageUrl, null);
                await FirebaseCloudMessagingHelper.SendPushNotification("/topic/" + product.Category, product.Name, "Just updated and available for bidding.", product.ImageUrl, null);
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(product),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
Beispiel #22
0
        /// <summary>
        /// A Lambda function that returns back a page worth of bid posts.
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The list of bids</returns>
        public async Task <APIGatewayProxyResponse> GetBidsAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.LogLine("Getting bids");
            var search = this.DDBContext.ScanAsync <Bid>(null);
            var page   = await search.GetNextSetAsync();

            context.Logger.LogLine($"Found {page.Count} bids");

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(page),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
Beispiel #23
0
        /// <summary>
        /// Sets up a bearer token authorisation header.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="username">Username to generate the basic header authorization</param>
        /// <param name="password">Password to generate the basic header authorization</param>
        /// <returns></returns>
        public static RestRequest WithBasicAuthorization(this RestRequest request, string username, string password)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }


            request.WithAuthorization($"Basic {HeaderHelper.BasicAuthorizationHeaderValue(username, password)}");

            return(request);
        }
Beispiel #24
0
        /// <summary>
        /// A Lambda function that returns the bid identified by bidId
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> GetBidAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            string bidId = null;

            if (request.PathParameters != null && request.PathParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                bidId = request.PathParameters[ID_QUERY_STRING_NAME];
            }
            else if (request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey(ID_QUERY_STRING_NAME))
            {
                bidId = request.QueryStringParameters[ID_QUERY_STRING_NAME];
            }

            if (string.IsNullOrEmpty(bidId))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = $"Missing required parameter {ID_QUERY_STRING_NAME}"
                });
            }

            context.Logger.LogLine($"Getting bid {bidId}");
            var bid = await DDBContext.LoadAsync <Bid>(bidId);

            context.Logger.LogLine($"Found bid: {bid != null}");

            if (bid == null)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.NotFound
                });
            }

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(bid),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
Beispiel #25
0
        /// <summary>
        /// A Lambda function that adds a bid post.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> AddBidAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var bid = JsonConvert.DeserializeObject <Bid>(request?.Body);

            bid.Id = Guid.NewGuid().ToString();
            bid.CreatedTimestamp = DateTime.Now;

            context.Logger.LogLine($"Saving bid with id {bid.Id}");
            await DDBContext.SaveAsync <Bid>(bid);

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(bid),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }
Beispiel #26
0
        private static byte[] ComposeMSearchDatagram(IMSearchRequest request)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("M-SEARCH * HTTP/1.1\r\n");

            stringBuilder.Append(request.SearchCastMethod == CastMethod.Multicast
                ? "HOST: 239.255.255.250:1900\r\n"
                : $"HOST: {request.HostIp}:{request.HostPort}\r\n");

            stringBuilder.Append("MAN: \"ssdp:discover\"\r\n");

            if (request.SearchCastMethod == CastMethod.Multicast)
            {
                stringBuilder.Append($"MX: {request.MX.TotalSeconds}\r\n");
            }
            stringBuilder.Append($"ST: {request.ST}\r\n");
            stringBuilder.Append($"USER-AGENT: " +
                                 $"{request.UserAgent.OperatingSystem}/{request.UserAgent.OperatingSystemVersion}" +
                                 $" " +
                                 $"UPnP/{request.UserAgent.UpnpMajorVersion}.{request.UserAgent.UpnpMinorVersion}" +
                                 $" " +
                                 $"{request.UserAgent.ProductName}/{request.UserAgent.ProductVersion}\r\n");

            if (request.SearchCastMethod == CastMethod.Multicast)
            {
                stringBuilder.Append($"CPFN.UPNP.ORG: {request.CPFN}\r\n");

                HeaderHelper.AddOptionalHeader(stringBuilder, "TCPPORT.UPNP.ORG", request.TCPPORT);
                HeaderHelper.AddOptionalHeader(stringBuilder, "CPUUID.UPNP.ORG", request.CPUUID);

                if (request.Headers != null)
                {
                    foreach (var header in request.Headers)
                    {
                        stringBuilder.Append($"{header.Key}: {header.Value}\r\n");
                    }
                }
            }

            stringBuilder.Append("\r\n");
            return(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
        }
Beispiel #27
0
        public async Task <string> PropfindAsync(string drive, string path)
        {
            var request = Request;

            var    depth = HeaderHelper.GetDepth(request.Headers);
            string xml   = null;

            path = path ?? string.Empty;
            var url = request.GetDisplayUrl().TrimEnd('/');

            if (request.ContentLength > 0)
            {
                var result = await request.BodyReader.ReadAsync();

                xml = Encoding.UTF8.GetString(result.Buffer.ToArray());
            }

            try
            {
                var returnXml = await _webDavService.PropfindAsync(new PropfindRequest()
                {
                    Url   = $"{url}/",
                    Path  = path,
                    Drive = drive,
                    Depth = depth,
                    Xml   = xml
                });

                if (returnXml != null)
                {
                    //Response.Headers.Add("Content-Type", "application/xml");

                    Response.StatusCode = (int)HttpStatusCode.MultiStatus;
                }

                return(returnXml);
            }
            catch (Exception e)
            {
                //Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(string.Empty);
            }
        }
Beispiel #28
0
 protected string GetCatalogHeader(HeaderHelper h, bool allCatalog, List <long> catalogIdEqual)
 {
     // если выбрано По всем нашим товарам
     if (allCatalog)
     {
         if (ProducerId == null)
         {
             return("В отчет включены все товары");
         }
         else
         {
             return("В отчет включены все товары производителя");
         }
     }
     else
     {
         return(h.GetProductHeader(catalogIdEqual));
     }
 }
Beispiel #29
0
        public override List <string> GetHeaders(HeaderHelper h)
        {
            var result = new List <string>();

            result.Add(h.GetDateHeader(DateFrom, DateTo));
            result.Add(h.GetRegionHeader(RegionCodeEqual));
            result.Add(GetCatalogHeader(h, AllCatalog, CatalogIdEqual));

            if (SupplierIdEqual.Count > 0)
            {
                result.Add(h.GetSupplierHeader(SupplierIdEqual));
            }

            if (SupplierIdNonEqual.Count > 0)
            {
                result.Add(h.GetNotSupplierHeader(SupplierIdNonEqual));
            }

            return(result);
        }
Beispiel #30
0
        /// <summary>
        /// A Lambda function that returns the bid identified by bidId
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> GetBidsByProductIdAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            string productId = null;

            if (request.PathParameters != null && request.PathParameters.ContainsKey(PRODUCT_ID_QUERY_STRING_NAME))
            {
                productId = request.PathParameters[PRODUCT_ID_QUERY_STRING_NAME];
            }
            else if (request.QueryStringParameters != null && request.QueryStringParameters.ContainsKey(PRODUCT_ID_QUERY_STRING_NAME))
            {
                productId = request.QueryStringParameters[PRODUCT_ID_QUERY_STRING_NAME];
            }

            if (string.IsNullOrEmpty(productId))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = $"Missing required parameter {ID_QUERY_STRING_NAME}"
                });
            }

            context.Logger.LogLine($"Getting bids {productId}");

            var conditions = new List <ScanCondition>();

            conditions.Add(new ScanCondition("ProductId", Amazon.DynamoDBv2.DocumentModel.ScanOperator.Equal, productId));
            var search = this.DDBContext.ScanAsync <Bid>(conditions);
            var page   = await search.GetNextSetAsync();

            context.Logger.LogLine($"Found {page.Count} bids");

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = JsonConvert.SerializeObject(page),
                Headers    = HeaderHelper.GetHeaderAttributes()
            };

            return(response);
        }