예제 #1
0
        //internal object InsertData(DataAudiensi data)
        //{
        //    throw new NotImplementedException();
        //}

        public async Task <bool> InsertData(CCTVData data)
        {
            try
            {
                if (data != null)
                {
                    TableOperation tableOperation = TableOperation.Insert(data);
                    await cloudTable.ExecuteAsync(tableOperation);

                    Console.WriteLine("Record inserted");
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
        /*
         * private static async Task<MethodResponse> DoAction(MethodRequest methodRequest, object userContext)
         * {
         *  var data = Encoding.UTF8.GetString(methodRequest.Data);
         *  var action = JsonConvert.DeserializeObject<DeviceAction>(data);
         *  // Check the payload is a single integer value
         *  if (action != null)
         *  {
         *
         *      switch (action.ActionName)
         *      {
         *          case "PlaySound":
         *
         *          case "ChangeLED":
         *
         *          case "TurnOffLED":
         *
         *          case "OpenURL":
         *              //do nothing
         *              break;
         *          case "CCTVStatus":
         *              IsPatrol = Convert.ToBoolean(action.Params[0]);
         *              Console.WriteLine($"CCTV Watcher Set to {IsPatrol}");
         *              break;
         *          case "CCTVUpdateTime":
         *              TimeInterval = Convert.ToInt32(action.Params[0]);
         *              Console.WriteLine($"CCTV Update Time Set to {TimeInterval} seconds");
         *              break;
         *
         *      }
         *      // Acknowlege the direct method call with a 200 success message
         *      string result = "{\"result\":\"Executed direct method: " + methodRequest.Name + "\"}";
         *      return new MethodResponse(Encoding.UTF8.GetBytes(result), 200);
         *  }
         *  else
         *  {
         *      // Acknowlege the direct method call with a 400 error message
         *      string result = "{\"result\":\"Invalid parameter\"}";
         *      return new MethodResponse(Encoding.UTF8.GetBytes(result), 400);
         *  }
         * }*/
        protected static CCTVData LogAnalysisResult(ImageAnalysis result, string CCTVName)
        {
            var item = new CCTVData();

            Console.WriteLine($"----------------------------------------------");
            Console.WriteLine($"Waktu Pengambilan : {DateTime.Now.ToString("dd/MMM/yyyy HH:mm:ss")}");
            Console.WriteLine($"Hasil Analisa {CCTVName}:");
            item.CCTVName = CCTVName;
            string Speak = string.Empty;

            if (result == null)
            {
                Log("null");
                return(null);
            }

            if (result.Metadata != null)
            {
                Log("Image Format : " + result.Metadata.Format);
                Log("Image Dimensions : " + result.Metadata.Width + " x " + result.Metadata.Height);
            }

            if (result.ImageType != null)
            {
                string clipArtType;
                switch (result.ImageType.ClipArtType)
                {
                case 0:
                    clipArtType = "0 Non-clipart";
                    break;

                case 1:
                    clipArtType = "1 ambiguous";
                    break;

                case 2:
                    clipArtType = "2 normal-clipart";
                    break;

                case 3:
                    clipArtType = "3 good-clipart";
                    break;

                default:
                    clipArtType = "Unknown";
                    break;
                }
                Log("Clip Art Type : " + clipArtType);

                string lineDrawingType;
                switch (result.ImageType.LineDrawingType)
                {
                case 0:
                    lineDrawingType = "0 Non-LineDrawing";
                    break;

                case 1:
                    lineDrawingType = "1 LineDrawing";
                    break;

                default:
                    lineDrawingType = "Unknown";
                    break;
                }
                Log("Line Drawing Type : " + lineDrawingType);
            }


            if (result.Adult != null)
            {
                Log("Is Adult Content : " + result.Adult.IsAdultContent);
                Log("Adult Score : " + result.Adult.AdultScore);
                Log("Is Racy Content : " + result.Adult.IsRacyContent);
                Log("Racy Score : " + result.Adult.RacyScore);
            }

            if (result.Categories != null && result.Categories.Count > 0)
            {
                Log("Categories : ");
                foreach (var category in result.Categories)
                {
                    Log("   Name : " + category.Name + "; Score : " + category.Score);
                }
            }

            if (result.Faces != null && result.Faces.Count > 0)
            {
                Log("Faces : ");
                foreach (var face in result.Faces)
                {
                    Log("   Age : " + face.Age + "; Gender : " + face.Gender);
                }
            }

            if (result.Color != null)
            {
                Log("AccentColor : " + result.Color.AccentColor);
                Log("Dominant Color Background : " + result.Color.DominantColorBackground);
                Log("Dominant Color Foreground : " + result.Color.DominantColorForeground);

                if (result.Color.DominantColors != null && result.Color.DominantColors.Count > 0)
                {
                    string colors = "Dominant Colors : ";
                    foreach (var color in result.Color.DominantColors)
                    {
                        colors += color + " ";
                    }
                    Log(colors);
                }
            }

            if (result.Description != null)
            {
                Log("Description : ");
                item.Description = "";
                foreach (var caption in result.Description.Captions)
                {
                    Log("   Caption : " + caption.Text + "; Confidence : " + caption.Confidence);
                    Speak            += caption.Text;
                    item.Description += caption.Text + ". ";
                }
                string tags = "   Tags : ";

                foreach (var tag in result.Description.Tags)
                {
                    tags += tag + ", ";
                }
                Log(tags);
            }

            if (result.Tags != null)
            {
                Log("Tags : ");
                item.Tags = "";
                foreach (var tag in result.Tags)
                {
                    Log("   Name : " + tag.Name + "; Confidence : " + tag.Confidence + "; Hint : " + tag.Hint);
                    item.Tags += tag.Name + ";";
                }
            }
            return(item);
        }