<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPPMM.Liveview;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Phone;
using Microsoft.Xna.Framework.Media;
using System.Windows.Resources;
using System.Windows.Media.Imaging;

namespace WPPMM.CameraManager
{
    class CameraManager
    {

        // singleton instance
        private static CameraManager cameraManager = new CameraManager();


        private static int TIMEOUT = 10;
        private static String dd_location = null;

        private static String endpoint = null;
        private static String liveViewUrl = null;
        private Liveview.LVProcessor lvProcessor = null;

        private static String friendlyName = "NEX-5R";

        private static List<Action> UpdateListeners;
        private static Action<MemoryStream> LiveViewUpdateListener;

        private static BitmapImage screen = null;

        private CameraManager()
        {
            Debug.WriteLine("Constructor on CameraManager");
            UpdateListeners = new List<Action>();
           
        }

        public static CameraManager GetInstance()
        {
            return cameraManager;
        }

        public void InitializeConnection()
        {
            requestSearchDevices();
        }

        public void StartLiveView()
        {
            if (friendlyName == "NEX-5R")
            {
                RequestStartRecmode();
            }
            else
            {
                RequestStartLiveView();
            }
        }




        // request and callback
        public void RequestStartRecmode()
        {
            if (endpoint == null)
            {
                Debug.WriteLine("error: endpoint is null");
            }

            // override endpoint
            // endpoint = "http://192.168.122.1:8080/sony/index.html";

            Debug.WriteLine("endpoint: " + endpoint);
            String jsonReq = Json.Request.startRecMode();

            Debug.WriteLine("request json: " + jsonReq);
            
            Json.XhrPost.Post(endpoint, jsonReq, OnStartRecmode, OnError);
    
        }

        public void OnStartRecmode(String json)
        {
            Debug.WriteLine("OnStartRecmode: " + json);

            Json.ResultHandler.StartRecMode(json, OnError, OnStartRecmodeResult);
        }

        public void OnStartRecmodeResult()
        {
            // finally, startrecMode is done.
            // for NEX-5R, starting to request liveview

            RequestStartLiveView();
        }

        // live view
        public void RequestStartLiveView()
        {
            

            if (endpoint == null)
            {
                Debug.WriteLine("error: endpoint is null");
                return;
            }

            String requestJson = Json.Request.startLiveview();
            Debug.WriteLine("requestJson: " + requestJson);

            Json.XhrPost.Post(endpoint, requestJson, OnStartLiveViewRetrieved, OnError);
        }


        public void OnStartLiveViewRetrieved(String json)
        {
            Debug.WriteLine("StartLiveView retrieved: " + json);
            Json.ResultHandler.StartLiveview(json, OnError, OnStartLiveViewResult);

        }

        public void OnStartLiveViewResult(String result)
        {
            // finally, url for liveView has get
            Debug.WriteLine("OnStartLiveViewResult: " + result);
            liveViewUrl = result;
            NoticeUpdate();
        }

        // connect 
        public void ConnectLiveView()
        {
            lvProcessor = new LVProcessor();

            if (lvProcessor == null || liveViewUrl == null)
            {
                Debug.WriteLine("error: liveProcessor or liveViewUrl is null");
            }

            lvProcessor.OpenConnection(liveViewUrl, OnJpegRetrieved, OnLiveViewClosed);
        }

        // callback methods (liveview)
        public void OnJpegRetrieved(byte[] data)
        {
            int size = data.Length;
            Debug.WriteLine("Jpeg retrived. " + size + "bytes.");
            MemoryStream ms = new MemoryStream(data, 0, data.Length);



            Deployment.Current.Dispatcher.BeginInvoke(() => { LiveViewUpdateListener(ms); });
        }

        public void OnLiveViewClosed()
        {
            Debug.WriteLine("liveView connection closed.");
        }
<commit_msg>minor fix.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPPMM.Liveview;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Phone;
using Microsoft.Xna.Framework.Media;
using System.Windows.Resources;
using System.Windows.Media.Imaging;

namespace WPPMM.CameraManager
{
    class CameraManager
    {

        // singleton instance
        private static CameraManager cameraManager = new CameraManager();


        private static int TIMEOUT = 10;
        private static String dd_location = null;

        private static String endpoint = null;
        private static String liveViewUrl = null;
        private Liveview.LVProcessor lvProcessor = null;

        private static String friendlyName = "NEX-5R";

        private static List<Action> UpdateListeners;
        private static Action<MemoryStream> LiveViewUpdateListener;

        private static BitmapImage screen = null;

        private CameraManager()
        {
            Debug.WriteLine("Constructor on CameraManager");
            UpdateListeners = new List<Action>();
           
        }

        public static CameraManager GetInstance()
        {
            return cameraManager;
        }

        public void InitializeConnection()
        {
            requestSearchDevices();
        }

        public void StartLiveView()
        {
            if (friendlyName == "NEX-5R")
            {
                RequestStartRecmode();
            }
            else
            {
                RequestStartLiveView();
            }
        }




        // request and callback
        public void RequestStartRecmode()
        {
            if (endpoint == null)
            {
                Debug.WriteLine("error: endpoint is null");
            }

            // override endpoint
            // endpoint = "http://192.168.122.1:8080/sony/index.html";

            Debug.WriteLine("endpoint: " + endpoint);
            String jsonReq = Json.Request.startRecMode();

            Debug.WriteLine("request json: " + jsonReq);
            
            Json.XhrPost.Post(endpoint, jsonReq, OnStartRecmode, OnError);
    
        }

        public void OnStartRecmode(String json)
        {
            Debug.WriteLine("OnStartRecmode: " + json);

            Json.ResultHandler.StartRecMode(json, OnError, OnStartRecmodeResult);
        }

        public void OnStartRecmodeResult()
        {
            // finally, startrecMode is done.
            // for NEX-5R, starting to request liveview

            RequestStartLiveView();
        }

        // live view
        public void RequestStartLiveView()
        {
            

            if (endpoint == null)
            {
                Debug.WriteLine("error: endpoint is null");
                return;
            }

            String requestJson = Json.Request.startLiveview();
            Debug.WriteLine("requestJson: " + requestJson);

            Json.XhrPost.Post(endpoint, requestJson, OnStartLiveViewRetrieved, OnError);
        }


        public void OnStartLiveViewRetrieved(String json)
        {
            Debug.WriteLine("StartLiveView retrieved: " + json);
            Json.ResultHandler.StartLiveview(json, OnError, OnStartLiveViewResult);

        }

        public void OnStartLiveViewResult(String result)
        {
            // finally, url for liveView has get
            Debug.WriteLine("OnStartLiveViewResult: " + result);
            liveViewUrl = result;
            NoticeUpdate();
        }

        // connect 
        public void ConnectLiveView()
        {
            lvProcessor = new LVProcessor();

            if (lvProcessor == null || liveViewUrl == null)
            {
                Debug.WriteLine("error: liveProcessor or liveViewUrl is null");
            }

            lvProcessor.OpenConnection(liveViewUrl, OnJpegRetrieved, OnLiveViewClosed);
        }

        // callback methods (liveview)
        public void OnJpegRetrieved(byte[] data)
        {
            int size = data.Length;
            Debug.WriteLine("Jpeg retrived. " + size + "bytes.");
            MemoryStream ms = new MemoryStream(data, 0, data.Length);

            Deployment.Current.Dispatcher.BeginInvoke(() => { LiveViewUpdateListener(ms); });

        }

        public void OnLiveViewClosed()
        {
            Debug.WriteLine("liveView connection closed.");
        }

{'fraction_non_alphanumeric': 0.08778796689778573, 'fraction_numerical': 0.004473272198613286, 'mean_word_length': 1.7911985018726593, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120845', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2133, 'n_words': 511}