Beispiel #1
0
        public static ReturnValue SaveThumbnail(this HttpPostedFileBase upload, string SavePath, int width, int height)
        {
            var result = new ReturnValue();

            if (upload != null)
            {
                try
                {
                    using (var tempStream = new MemoryStream())
                    {
                        upload.InputStream.CopyTo(tempStream);
                        tempStream.Position = 0;
                        using (Image image = Image.FromStream(tempStream, false, false))
                            using (Image pThumbnail = image.GetThumbnailImage(width, height, delegate { return(false); }, IntPtr.Zero))
                            {
                                pThumbnail.Save(SavePath);
                                result.Success(tempStream.Length, SavePath);
                            }
                    }
                }
                catch (Exception ex)
                {
                    result.Error(ex);
                }
            }
            else
            {
                result.Error(new NullReferenceException("upload is null"));
            }

            return(result);
        }
Beispiel #2
0
        public ReturnValue GetSampleMessage()
        {
            var temp   = new ReturnValues <List <long> >();
            var result = new ReturnValue();

            if (MainActivity.MainActivityInstance != null)
            {
                try
                {
                    temp = MainActivity.MainActivityInstance.ContentResolver.FindLastKey();
                    if (result.Check)
                    {
                        Coupon coupon = null;
                        foreach (long num in temp.Data)
                        {
                            coupon = MainActivity.MainActivityInstance.ContentResolver.GetMMS(num);
                            if (coupon != null)
                            {
                                string content   = JsonConvert.SerializeObject(coupon);
                                string key       = Repository.GetMyPhoneNumber(MainActivity.MainActivityInstance);
                                string url       = "http:" + $"//giftipangpang.com/Api/External/Log";
                                var    paramData = new FormUrlEncodedContent(new[]
                                {
                                    new KeyValuePair <string, string>("key", key),
                                    new KeyValuePair <string, string>("content", content)
                                });

                                ApiClient client = new ApiClient();
                                string    tmp    = client.PostRequest(url, paramData);
                                if (!string.IsNullOrWhiteSpace(tmp))
                                {
                                    result = JsonConvert.DeserializeObject <ReturnValue>(tmp);
                                    if (result.Check)
                                    {
                                        result.Message = "ok";
                                        break;
                                    }
                                }
                                else
                                {
                                    result.Error("ReturnValue is Empty!!");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.Error(ex);
                }
            }
            else
            {
                result.Error("MainActivity is null.");
            }

            return(result);
        }
Beispiel #3
0
        public async Task <ReturnValue> sendMessage(string title, string msg, string instanceIdToken)
        {
            var result = new ReturnValue();


            try
            {
                //1. 전송정보 생성
                string serverKey = $"key={ServerKey}";
                string url       = "https://fcm.googleapis.com/fcm/send";
                string postJson  = (@"{
                            'content_available': false,
                            'data':
                            {
                                'title': '" + HttpUtility.UrlEncode(title) + @"',
                                'body': '" + HttpUtility.UrlEncode(msg) + @"',
                                'icon': '',
                            },
                            'to': '" + instanceIdToken + @"'
                        }")
                                   .Replace("'", "\"")
                                   .Trim();

                //2. Firebase 서버에 REST 전송
                using (HttpClient client = new HttpClient()
                {
                    BaseAddress = new Uri(url)
                })
                {
                    //1) 요청
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", serverKey);
                    StringContent       postEncoded  = new StringContent(postJson.Replace("\t", "").Replace("\r\n", ""), Encoding.UTF8, "application/json");
                    HttpResponseMessage httpResponse = await client.PostAsync("", postEncoded);

                    //2) 응답분석
                    string responseText = await httpResponse.Content.ReadAsStringAsync();

                    if (httpResponse.IsSuccessStatusCode)
                    {
                        result.Success(1);
                    }
                    else
                    {
                        result.Error(responseText);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Error(ex);
            }

            return(result);
        }
Beispiel #4
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(ACTION_MMS_RECEIVED) || intent.Action.Equals(MMS_DATA_TYPE))
            {
                ReturnValue result = new ReturnValue();
                Bundle      bundle = intent.Extras;
                if (bundle != null)
                {
                    try
                    {
                        //android.telephony.extra.SUBSCRIPTION_INDEX,header,pduType,data,phone,subscription,transactionId
                        //byte[] buffer = bundle.GetByteArray("data");
                        //string content = (buffer == null) ? "data" : Encoding.Default.GetString(buffer);
                        result = context.ContentResolver.FindLastKey();
                        if (result.Check)
                        {
                            var coupon = context.ContentResolver.GetMMS(result.Code);

                            if (coupon != null)
                            {
                                string content   = JsonConvert.SerializeObject(coupon);
                                string key       = context.GetMyPhoneNumber();
                                string url       = "http:" + $"//giftipangpang.com/Api/External/Log";
                                var    paramData = new FormUrlEncodedContent(new[]
                                {
                                    new KeyValuePair <string, string>("key", key),
                                    new KeyValuePair <string, string>("content", content)
                                });

                                string tmp = DependencyService.Get <IApiClient>().PostRequest(url, paramData);
                                if (!string.IsNullOrWhiteSpace(tmp))
                                {
                                    result = JsonConvert.DeserializeObject <ReturnValue>(tmp);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Error(ex);
                    }
                }
                else
                {
                    result.Error("Bundle is null");
                }

                if (!result.Check)
                {
                    Toast.MakeText(context, result.Message, ToastLength.Short).Show();
                }
            }
        }
Beispiel #5
0
        public static ReturnValue SaveCrop(this HttpPostedFileBase upload, string SavePath, int width, int height)
        {
            var result = new ReturnValue();

            if (upload != null)
            {
                try
                {
                    using (var tempStream = new MemoryStream())
                    {
                        upload.InputStream.CopyTo(tempStream);
                        tempStream.Position = 0;
                        using (Image image = Image.FromStream(tempStream, false, false))
                        {
                            if (image.Width > width && image.Height > height)
                            {
                                Point point = new Point();
                                point.X = (image.Width - width) / 2;
                                if (height > (image.Height * 2))
                                {
                                    point.Y = height / 2;
                                }
                                else
                                {
                                    point.Y = (image.Height - height) / 2;
                                }
                                Rectangle cropRect = new Rectangle(point, new Size(width, height));
                                Bitmap    src      = image as Bitmap;
                                var       tmp      = src.Clone(cropRect, image.PixelFormat);
                                tmp.Save(SavePath);
                                result.Success(tempStream.Length, SavePath);
                            }
                            else
                            {
                                var tmp2 = image.GetThumbnailImage(width, height, delegate { return(false); }, IntPtr.Zero);
                                tmp2.Save(SavePath);
                                result.Success(tempStream.Length, SavePath);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.Error(ex);
                }
            }
            else
            {
                result.Error(new NullReferenceException("upload is null"));
            }

            return(result);
        }
        private ReturnValue ProcessStateStopStartOutput(StateContext context)
        {
            string state = context.Output.SplitAndTrim(Environment.NewLine)
                           .Where(x => x.StartsWith("STATE"))
                           .Select(x => x.EverythingAfterLast(" "))
                           .FirstOrDefault();

            ReturnValue returnValue = ReturnValue.Ok();

            if (context.CommandType == CommandType.Start)
            {
                returnValue = CheckOutputForErrors(context.Output, 1056);
            }
            else if (context.CommandType == CommandType.Stop)
            {
                returnValue = CheckOutputForErrors(context.Output, 1062);
            }
            else if (context.CommandType == CommandType.State && state == null)
            {
                returnValue = ReturnValue.Error(ErrorType.ServiceStateNotFound, "Failed to find the state");
            }

            return(returnValue.IsSuccess
                ? ReturnValue.Ok(state)
                : returnValue);
        }
        private ReturnValue CheckOutputForErrors(string output, int errorCode)
        {
            var lines = output.SplitAndTrim(Environment.NewLine);

            if (lines.Count > 0 && lines[0].Contains(errorCode.ToString()))
            {
                ErrorType errorType = ErrorType.ScError;

                switch (errorCode)
                {
                case 1056:
                    errorType = ErrorType.StartServiceFailed;
                    break;

                case 1062:
                    errorType = ErrorType.StopServiceFailed;
                    break;
                }

                var errorMessage = lines.Skip(1).FirstOrDefault() ?? "Unknown error";

                return(ReturnValue.Error(errorType, errorMessage));
            }

            return(ReturnValue.Ok());
        }
Beispiel #8
0
        private ReturnValue execute(IMessage msg, bool send)
        {
            SendingStep step = SendingStep.MessageReceived;

            try
            {
                msg.Check();
                step = SendingStep.MessageChecked;

                if (msg.MessageAction == MessageAction.Calculate)
                {
                    return(ReturnValue.ProtectiveMarkCalculated(step, msg));
                }

                msg.SurroundWithSoap();
                step = SendingStep.SoapEnvelopeGenerated;

                msg.Sign();
                step = SendingStep.MessageSigned;

                msg.Validate();
                step = SendingStep.MessageValidated;

                msg.SendToFURS();
                step = SendingStep.MessageSend;

                return(ReturnValue.Sent(step, msg));
            }
            catch (System.Exception ex)
            {
                return(ReturnValue.Error(step, msg, ex.Message));
            }
        }
Beispiel #9
0
        public static ReturnValue Crop(string importPath, string exportPath, int targetX, int targetY)
        {
            var result = new ReturnValue();

            try
            {
                System.Drawing.Image originalImage = System.Drawing.Image.FromFile(importPath);


                double ratioX = targetX / (double)originalImage.Width;
                double ratioY = targetY / (double)originalImage.Height;

                double ratio = Math.Max(ratioX, ratioY);

                int newWidth  = (int)(originalImage.Width * ratio);
                int newHeight = (int)(originalImage.Height * ratio);

                Bitmap newImage = new Bitmap(targetX, targetY);
                using (Graphics g = Graphics.FromImage(newImage))
                {
                    //g.FillRectangle(Brushes.White, 0, 0, newImage.Width, newImage.Height);
                    g.DrawImage(originalImage, (targetX - newWidth) / 2, (targetY - newHeight) / 2, newWidth, newHeight);
                }

                newImage.Save(exportPath);
                FileInfo fi = new FileInfo(exportPath);
                if (fi.Exists)
                {
                    result.Success(fi.Length, exportPath);
                }
                else
                {
                    result.Error("File Save Fail.");
                }

                originalImage.Dispose();
                newImage.Dispose();
            }
            catch (Exception ex)
            {
                result.Error(ex);
            }

            return(result);
        }
Beispiel #10
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(ACTION_MMS_RECEIVED) || intent.Action.Equals(MMS_DATA_TYPE))
            {
                ReturnValue result = new ReturnValue();
                Bundle      bundle = intent.Extras;
                if (bundle != null)
                {
                    try
                    {
                        byte[] buffer         = bundle.GetByteArray("data");
                        string incomingNumber = Encoding.UTF8.GetString(buffer);
                        string url            = $"//giftipangpang.com/Api/External/Log?key=01032550295&content={incomingNumber}";
                        using (var wc = new WebClient())
                        {
                            wc.Encoding = Encoding.UTF8;
                            string tmp = wc.DownloadString("http:" + url);
                            if (!string.IsNullOrWhiteSpace(tmp))
                            {
                                result = JsonConvert.DeserializeObject <ReturnValue>(tmp);
                                if (result.Check)
                                {
                                    result.Message = "ok";
                                }
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        result.Error(ex);
                    }
                }
                else
                {
                    result.Error("Bundle is null");
                }

                Toast.MakeText(context, result.Message, ToastLength.Short).Show();
            }
        }
Beispiel #11
0
        private ReturnValue SetCurrentWorkingDirectory(Context context)
        {
            try
            {
                Directory.SetCurrentDirectory(context.Args.DirectoryPath);

                return(ReturnValue.Ok($"Current Directory set to {Directory.GetCurrentDirectory()}"));
            }
            catch (Exception e)
            {
                return(ReturnValue.Error(ErrorType.FailedToSetCurrentDirectory, $@"Failed to set Current Directory {e.Message}"));
            }
        }
Beispiel #12
0
 public ReturnValue Send(string message)
 {
     try
     {
         XmlDocument xmlDoc = XmlHelperFunctions.CreateNewXmlDocument();
         xmlDoc.LoadXml(message);
         return(this.Send(xmlDoc));
     }
     catch (System.Exception ex)
     {
         return(ReturnValue.Error(SendingStep.MessageReceived, null, ex.Message));
     }
 }
Beispiel #13
0
        public ReturnValue Send(XmlDocument message)
        {
            string root = message.DocumentElement.LocalName;

            XmlNode node = XmlHelperFunctions.GetSubNode(message.DocumentElement, "fu:InvoiceRequest");

            if (string.Compare(root, "InvoiceRequest", true) == 0)
            {
                return(this.SendInvoice(message));
            }
            if (string.Compare(root, "BusinessPremiseRequest", true) == 0)
            {
                return(this.SendBusinessPremise(message));
            }
            if (string.Compare(root, "EchoRequest", true) == 0)
            {
                return(this.SendEcho(message));
            }

            return(ReturnValue.Error(SendingStep.MessageReceived, null, "Neznani dokument / Unknown document"));
        }
Beispiel #14
0
        private void Check_Send_Tick(object state)
        {
            Coupon coupon = null;

            if (this.Sender.TryDequeue(out coupon))
            {
                ReturnValue result = new ReturnValue();

                try
                {
                    string content   = coupon.Body;
                    string key       = coupon.ID;
                    string url       = "http:" + $"//giftipangpang.com/Api/External/Log";
                    var    paramData = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("key", key),
                        new KeyValuePair <string, string>("content", content)
                    });
                    string tmp = ApiClient.PostRequest(url, paramData);
                    if (!string.IsNullOrWhiteSpace(tmp))
                    {
                        result = JsonConvert.DeserializeObject <ReturnValue>(tmp);
                        if (result.Check)
                        {
                            result.Message = "ok";
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    result.Error(ex);
                }

                msgText.Text = result.Message;
            }
        }