Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> Create(MT_Localization LOMD)
        {
            Db = con.SurgeryCenterDb(LOMD.Slug);
            LocalizationResponse Response = new LocalizationResponse();

            try
            {
                UniqueID             = con.GetUniqueKey();
                LOMD.Loc_Unique_ID   = UniqueID;
                LOMD.Loc_Create_Date = con.ConvertTimeZone(LOMD.Loc_TimeZone, Convert.ToDateTime(LOMD.Loc_Create_Date));
                LOMD.Loc_Modify_Date = con.ConvertTimeZone(LOMD.Loc_TimeZone, Convert.ToDateTime(LOMD.Loc_Modify_Date));

                DocumentReference docRef = Db.Collection("MT_Localization").Document(UniqueID);
                WriteResult       Result = await docRef.SetAsync(LOMD);

                if (Result != null)
                {
                    Response.Status  = con.StatusSuccess;
                    Response.Message = con.MessageSuccess;
                    Response.Data    = LOMD;
                }
                else
                {
                    Response.Status  = con.StatusNotInsert;
                    Response.Message = con.MessageNotInsert;
                    Response.Data    = null;
                }
            }
            catch (Exception ex)
            {
                Response.Status  = con.StatusFailed;
                Response.Message = con.MessageFailed + ", Exception : " + ex.Message;
            }
            return(ConvertToJSON(Response));
        }
Ejemplo n.º 2
0
        public async Task <List <Task <LocalizationResponse> > > Import([FromBody] LocalizedData localizedData)
        {
            string tempLocalizationFolder = Path.Combine(CurrentHostEnvironment.WebRootPath, "Temp", "ExtractedLocalized");
            string srcZip = Path.Combine(CurrentHostEnvironment.WebRootPath, "Temp", localizedData.Value);

            ZipFile.ExtractToDirectory(srcZip, tempLocalizationFolder);
            List <Task <LocalizationResponse> > localizationResponses = new List <Task <LocalizationResponse> >();

            string[] applications = Directory.GetDirectories(tempLocalizationFolder);

            DirectoryInfo diInfo = new DirectoryInfo(tempLocalizationFolder);

            DirectoryInfo[] diInfoArr = diInfo.GetDirectories();
            foreach (DirectoryInfo DirInfo in diInfoArr)
            {
                string   applicationDir = DirInfo.FullName;
                string   appName        = DirInfo.Name;
                string[] files          = Directory.GetFiles(applicationDir, "*", SearchOption.AllDirectories);
                foreach (string userFile in files)
                {
                    string filedir    = Path.GetDirectoryName(userFile).Replace(applicationDir, String.Empty);
                    string systemfile = CurrentHostEnvironment.WebRootPath + filedir + "\\" + Path.GetFileNameWithoutExtension(filedir) + ".json";
                    LocalizationResponse localizationResponse = new LocalizationResponse
                    {
                        FilePath = filedir
                    };
                    localizationResponses.Add(JsonCompare(userFile, systemfile, localizationResponse));
                }
                await Task.WhenAll(localizationResponses);
            }
            //NoError_

            return(localizationResponses);
        }
Ejemplo n.º 3
0
        public async Task <HttpResponseMessage> ListFilterWithLanguageShorname(MT_Localization LOMD)
        {
            Db = con.SurgeryCenterDb(LOMD.Slug);
            LocalizationResponse Response = new LocalizationResponse();

            try
            {
                List <MT_Localization> Loclist = new List <MT_Localization>();
                Query         Qry       = Db.Collection("MT_Localization").WhereEqualTo("Loc_Is_Deleted", false).WhereEqualTo("Loc_Is_Active", true).WhereEqualTo("Loc_Language_Shortname", LOMD.Loc_Language_Shortname);
                QuerySnapshot QSnapshot = await Qry.GetSnapshotAsync();

                if (QSnapshot != null)
                {
                    foreach (DocumentSnapshot Dsnap in QSnapshot.Documents)
                    {
                        Loclist.Add(Dsnap.ConvertTo <MT_Localization>());
                    }
                    Response.Status   = con.StatusSuccess;
                    Response.Message  = con.MessageSuccess;
                    Response.DataList = Loclist.OrderBy(o => o.Loc_Resource_ID).ToList();
                }
                else
                {
                    Response.Status  = con.StatusDNE;
                    Response.Message = con.MessageDNE;
                    Response.Data    = null;
                }
            }
            catch (Exception ex)
            {
                Response.Status  = con.StatusFailed;
                Response.Message = con.MessageFailed + ", Exception : " + ex.Message;
            }
            return(ConvertToJSON(Response));
        }
Ejemplo n.º 4
0
        public void poseHandlerMultiMap(LocalizationResponse respose, Vector3 camPos, Quaternion camRot)
        {
            Matrix4x4 cloudpose = new Matrix4x4();

            cloudpose = Matrix4x4.identity;

            int cloudid = respose.cloudid;

            cloudpose.m00 = respose.pose[0]; cloudpose.m01 = respose.pose[1]; cloudpose.m02 = respose.pose[2]; cloudpose.m03 = respose.pose[3];
            cloudpose.m10 = respose.pose[4]; cloudpose.m11 = respose.pose[5]; cloudpose.m12 = respose.pose[6]; cloudpose.m13 = respose.pose[7];
            cloudpose.m20 = respose.pose[8]; cloudpose.m21 = respose.pose[9]; cloudpose.m22 = respose.pose[10]; cloudpose.m23 = respose.pose[11];

            Vector3 pos = new Vector3(cloudpose[0, 3] * -1f, cloudpose[1, 3], cloudpose[2, 3]);

            Quaternion rot   = Quaternion.Euler((360 - cloudpose.rotation.eulerAngles.x) % 360, (360 - cloudpose.rotation.eulerAngles.y) % 360, cloudpose.rotation.eulerAngles.z);
            Matrix4x4  cloud = Matrix4x4.TRS(pos, rot, Vector3.one);


            if (MultiMapAssetImporter.mapIdToOffset.ContainsKey(cloudid))
            {
                Vector3    Mapoffsetposition = MultiMapAssetImporter.mapIdToOffset[cloudid].position;
                Quaternion Mapoffsetrotation = MultiMapAssetImporter.mapIdToOffset[cloudid].rotation;
                Matrix4x4  cloudMapOffset    = Matrix4x4.TRS(Mapoffsetposition, Mapoffsetrotation, Vector3.one);

                GetGlobalPose(cloud, cloudMapOffset, camPos, camRot);
            }
        }
Ejemplo n.º 5
0
        public async Task <HttpResponseMessage> Update(MT_Localization LOMD)
        {
            Db = con.SurgeryCenterDb(LOMD.Slug);
            LocalizationResponse Response = new LocalizationResponse();

            try
            {
                Dictionary <string, object> initialData = new Dictionary <string, object>
                {
                    { "Loc_Resource_ID", LOMD.Loc_Resource_ID },
                    { "Loc_Resource_Type", LOMD.Loc_Resource_Type },
                    { "Loc_Value", LOMD.Loc_Value },
                    { "Loc_Modify_Date", con.ConvertTimeZone(LOMD.Loc_TimeZone, Convert.ToDateTime(LOMD.Loc_Modify_Date)) },
                    { "Loc_TimeZone", LOMD.Loc_TimeZone }
                };

                DocumentReference docRef = Db.Collection("MT_Localization").Document(LOMD.Loc_Unique_ID);
                WriteResult       Result = await docRef.UpdateAsync(initialData);

                if (Result != null)
                {
                    Response.Status  = con.StatusSuccess;
                    Response.Message = con.MessageSuccess;
                    Response.Data    = LOMD;
                }
                else
                {
                    Response.Status  = con.StatusNotUpdate;
                    Response.Message = con.MessageNotUpdate;
                    Response.Data    = null;
                }
            }
            catch (Exception ex)
            {
                Response.Status  = con.StatusFailed;
                Response.Message = con.MessageFailed + ", Exception : " + ex.Message;
            }
            return(ConvertToJSON(Response));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// handles pose from cloud response
        /// </summary>
        /// <param name="respose"></param>
        /// <param name="camPos"></param>
        /// <param name="camRot"></param>
        public void poseHandler(LocalizationResponse respose, Vector3 camPos, Quaternion camRot)
        {
            Matrix4x4 cloudpose = new Matrix4x4();

            cloudpose = Matrix4x4.identity;

            cloudpose.m00 = respose.pose[0]; cloudpose.m01 = respose.pose[1]; cloudpose.m02 = respose.pose[2]; cloudpose.m03 = respose.pose[3];
            cloudpose.m10 = respose.pose[4]; cloudpose.m11 = respose.pose[5]; cloudpose.m12 = respose.pose[6]; cloudpose.m13 = respose.pose[7];
            cloudpose.m20 = respose.pose[8]; cloudpose.m21 = respose.pose[9]; cloudpose.m22 = respose.pose[10]; cloudpose.m23 = respose.pose[11];

            Vector3 pos = new Vector3(cloudpose[0, 3] * -1f, cloudpose[1, 3], cloudpose[2, 3]);

            Quaternion rot = Quaternion.Euler((360 - cloudpose.rotation.eulerAngles.x) % 360, (360 - cloudpose.rotation.eulerAngles.y) % 360, cloudpose.rotation.eulerAngles.z);

            Matrix4x4 cloud = Matrix4x4.TRS(pos, rot, Vector3.one);
            Matrix4x4 requestcameratracker = Matrix4x4.TRS(camPos, camRot, Vector3.one);

            Matrix4x4 result = requestcameratracker * cloud.inverse;

            ARSpace.transform.rotation = result.rotation;
            ARSpace.transform.position = new Vector3(result[0, 3], result[1, 3], result[2, 3]);
        }
Ejemplo n.º 7
0
        private async Task <LocalizationResponse> JsonCompare(string userFile, string systemfile, LocalizationResponse localizationResponse)
        {
            Task <JObject> userJson    = ReadFile(userFile);
            Task <JObject> systemJson  = ReadFile(systemfile);
            JObject        userJson_   = await userJson;
            JObject        systemJson_ = await systemJson;

            NoError_ = JToken.DeepEquals(userJson_, systemJson_);
            localizationResponse.Equal = NoError_;
            return(localizationResponse);
        }
Ejemplo n.º 8
0
        IEnumerator sendCameraImages(string rawdata, Vector3 camPos, Quaternion camRot)
        {
            Debug.Log("RawString: " + rawdata);

            using (UnityWebRequest www = UnityWebRequest.Put(m_Sdk.localizationServer + m_Sdk.developerToken + "/" + EndPoint.REQ_POSE, rawdata))
            {
                www.method = UnityWebRequest.kHttpVerbPOST;
                www.SetRequestHeader("Content-Type", "application/json");
                www.SetRequestHeader("Accept", "application/json");

                if (sessionCookieString.Length > 0)
                {
                    //Debug.Log("Saved Cookie >> " + sessionCookieString);
                    www.SetRequestHeader("Cookie", sessionCookieString);
                }

                // Get and Set Cookies
                www.GetResponseHeaders();

                yield return(www.SendWebRequest());

                Debug.Log("***************");

                if (www.error != null)
                {
                    loaderPanel.SetActive(false);
                    Debug.Log("Error: " + www.error);
                }
                else
                {
                    //Try to get a cookie and set in next API calls
                    if (www.GetResponseHeaders().ContainsKey("SET-COOKIE"))
                    {
                        if (www.GetResponseHeaders().TryGetValue("SET-COOKIE", out string result))
                        {
                            if (sessionCookieString.Length == 0)
                            {
                                sessionCookieString = result;
                                PlayerPrefs.SetString("COOKIE", sessionCookieString);
                            }
                        }
                    }

                    loaderPanel.SetActive(false);

                    Debug.Log("All OK");
                    Debug.Log("Status Code: " + www.downloadHandler.text);

                    requestCount++;

                    LocalizationResponse localization = JsonUtility.FromJson <LocalizationResponse>(www.downloadHandler.text);
                    Debug.Log(localization);

                    if (localization.poseAvailable == true)
                    {
                        counts += 1;
                        Debug.Log("Calling POSE Setter...");
                        poseSetterGO.GetComponent <PoseSetter>().poseHandler(localization, camPos, camRot);

                        if (vibrateOnLocalize)
                        {
                            Handheld.Vibrate();
                        }
                    }

                    loc_attempts_txt.text = "Localization attempts:  " + counts + " / " + requestCount;
                }
            }
        }
        public async void ConnectWS()
        {
            websocket.OnOpen += () =>
            {
                Debug.Log("Connection open!");
                Invoke("RequestLocalization", 1f);

                if (isFirstRequest)
                {
                    connectionLoaderPanel.SetActive(true);
                }
            };

            websocket.OnError += (e) =>
            {
                Debug.Log("Error! " + e);
                //hide loader panel..
                loaderPanel.SetActive(false);

                if (isFirstRequest)
                {
                    connectionLoaderPanel.SetActive(false);
                }
            };

            websocket.OnClose += (e) =>
            {
                Debug.Log("Connection closed!");
                //hide loader panel..
                loaderPanel.SetActive(false);

                if (isFirstRequest)
                {
                    connectionLoaderPanel.SetActive(false);
                }
            };

            websocket.OnMessage += (bytes) =>
            {
                Debug.Log("OnMessage!");

                Vector3    camPos;
                Quaternion camRot;

                if (isFirstRequest)
                {
                    connectionLoaderPanel.SetActive(false);
                    isFirstRequest = false;
                    InvokeRepeating("RequestLocalization", 1f, localizationFrequency);
                    StartCoroutine(showInstructions());
                }

                if (ArCameraPoseQueue.Count > 0)
                {
                    ArCameraOffset arCameraOffset = new ArCameraOffset();
                    arCameraOffset = ArCameraPoseQueue.Dequeue();

                    camPos = arCameraOffset.position;
                    camRot = arCameraOffset.rotation;

                    //hide loader panel..
                    loaderPanel.SetActive(false);

                    // getting the message as a string
                    var Response = System.Text.Encoding.UTF8.GetString(bytes);

                    requestCount++;

                    LocalizationResponse localization = JsonUtility.FromJson <LocalizationResponse>(Response);
                    Debug.Log(localization);

                    if (localization.poseAvailable == true)
                    {
                        counts += 1;
                        poseSetterGO.GetComponent <PoseSetter>().poseHandlerMultiMap(localization, camPos, camRot);

                        if (vibrateOnLocalize)
                        {
                            Handheld.Vibrate();
                        }
                        CancelInvoke("RequestLocalization");

                        m_Sdk.GetComponent <MultiMapAssetImporter>().AddARAnchors();
                    }

                    loc_attempts_txt.text = "Localization attempts:  " + counts + " / " + requestCount;

                    // show ARSpace GameObject if counts > 0
                    if (counts > 0)
                    {
                        ArSpace.SetActive(true);
                        destinationDropdown.SetActive(true);
                    }
                }
            };

            // waiting for messages
            await websocket.Connect();
        }