private void _FinalizeReturn(int iObjectId)
    {
        ReturningObject currentObject = (ReturningObject)m_ReturningObjects[iObjectId];

        currentObject.Object.transform.localPosition = currentObject.TargetLocalPosition;
        currentObject.Object.transform.localRotation = currentObject.TargetLocalRotation;

        _ResetObjectProperties(currentObject);

        m_ReturningObjects.Remove(m_ReturningObjects[iObjectId]);
    }
    private void _ResetObjectProperties(ReturningObject iObject)
    {
        // Reset Grabbable
        VRActor actor = iObject.Object.GetComponent <VRActor>();

        if (actor != null)
        {
            actor.Grabable = iObject.WasGrabbable;
        }

        // Reset collisions
        Collider collider = iObject.Object.GetComponent <Collider>();

        if (collider != null)
        {
            collider.enabled = iObject.WasCollidable;
        }
    }
Example #3
0
        private void MergeDocument(string Filename, object Data)
        {
            // create a new PassingObject that is used to send
            // data to the ProcessingApplication using pipes
            PassingObject dataObject = new PassingObject()
            {
                Data     = JsonConvert.SerializeObject(Data),
                Document = File.ReadAllBytes(Filename)
            };

            // call the processing app and pass the data object
            ReturningObject returnObject = ParallelProcessing.CallProcessingApp(dataObject);

            // create destination folder if it doesn't exists
            Directory.CreateDirectory(sResultsFolder);

            // write the returned byte array as a file
            File.WriteAllBytes(sResultsFolder + "\\" + Path.GetFileNameWithoutExtension(Filename) + ".pdf", returnObject.Document);
        }
    private void _ReturnObjects()
    {
        for (int i = 0; i < m_ReturningObjects.Count; ++i)
        {
            ReturningObject currentObject = (ReturningObject)m_ReturningObjects[i];

            // Move directly to final position if object asked for it or if transition speed is null
            bool finalizeReturn = currentObject.InstantReturn || (ObjectReturnSpeed < 0.0f) || Mathf.Approximately(ObjectReturnSpeed, 0.0f);

            if (!finalizeReturn)
            {
                float distanceToMove = ObjectReturnSpeed * (float)(MiddleVR.VRKernel.GetDeltaTime());

                Vector3 vectorToTarget = currentObject.TargetLocalPosition - currentObject.Object.transform.localPosition;

                if (vectorToTarget.magnitude > distanceToMove)
                {
                    // Apply translation
                    currentObject.Object.transform.localPosition += vectorToTarget.normalized * distanceToMove;

                    float state = (currentObject.Object.transform.localPosition - currentObject.StartLocalPosition).magnitude
                                  / (currentObject.TargetLocalPosition - currentObject.StartLocalPosition).magnitude;
                    Quaternion rotation = Quaternion.Lerp(currentObject.StartLocalRotation, currentObject.TargetLocalRotation, state);

                    // Apply rotation
                    currentObject.Object.transform.localRotation = rotation;
                }
                else
                {
                    finalizeReturn = true;
                }
            }

            if (finalizeReturn)
            {
                _FinalizeReturn(i);
            }
        }
    }
    private void _ResetObjectProperties(ReturningObject iObject)
    {
        // Reset Grabbable
        VRActor actor = iObject.Object.GetComponent<VRActor>();
        if (actor != null)
        {
            actor.Grabable = iObject.WasGrabbable;
        }

        // Reset collisions
        Collider collider = iObject.Object.GetComponent<Collider>();
        if (collider != null)
        {
            collider.enabled = iObject.WasCollidable;
        }
    }
Example #6
0
        public static ReturningObject CallProcessingApp(DataContainer.PassingObject data)
        {
            string sProcessingAppLocation = Assembly.GetExecutingAssembly().Location;

            var lsResult = new List <string>();

            // Create separate process
            var newProcess = new Process
            {
                StartInfo =
                {
                    FileName        = sProcessingAppLocation,
                    CreateNoWindow  = true,
                    UseShellExecute = false,
                }
            };

            // Create 2 anonymous pipes (read and write) for duplex communications
            // (each pipe is one-way)
            using (var pipeRead = new AnonymousPipeServerStream(PipeDirection.In,
                                                                HandleInheritability.Inheritable))
                using (var pipeWrite = new AnonymousPipeServerStream(PipeDirection.Out,
                                                                     HandleInheritability.Inheritable))
                {
                    // Pass to the other process handles to the 2 pipes
                    newProcess.StartInfo.Arguments = pipeRead.GetClientHandleAsString() + " " +
                                                     pipeWrite.GetClientHandleAsString();

                    try
                    {
                        newProcess.Start();
                    }
                    catch { }

                    pipeRead.DisposeLocalCopyOfClientHandle();
                    pipeWrite.DisposeLocalCopyOfClientHandle();

                    try
                    {
                        using (var sw = new StreamWriter(pipeWrite))
                        {
                            // Send a 'sync message' and wait for the other process to receive it
                            sw.WriteLine("SYNC");
                            pipeWrite.WaitForPipeDrain();

                            sw.WriteLine(JsonConvert.SerializeObject(data));
                            sw.WriteLine("END");
                        }

                        // Get message from the other process
                        using (var sr = new StreamReader(pipeRead))
                        {
                            string sTempResult;

                            // Wait for 'sync message' from the other process
                            do
                            {
                                sTempResult = sr.ReadLine();
                            } while (sTempResult == null || !sTempResult.StartsWith("SYNC"));

                            // Read until 'end message' from the other process
                            while ((sTempResult = sr.ReadLine()) != null && !sTempResult.StartsWith("END"))
                            {
                                lsResult.Add(sTempResult);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        newProcess.WaitForExit();
                        newProcess.Close();
                    }
                }

            ReturningObject dataReturnObject;

            if (lsResult.Count == 0)
            {
                dataReturnObject = new ReturningObject()
                {
                    Error = "Error"
                };
            }
            else if (lsResult[0] != null)
            {
                dataReturnObject = JsonConvert.DeserializeObject <ReturningObject>(lsResult[0]);
            }
            else
            {
                dataReturnObject = new ReturningObject()
                {
                    Error = "Error"
                }
            };

            return(dataReturnObject);
        }
    }
Example #7
0
        static void Main(string[] args)
        {
            if (args == null || args.Length < 2)
            {
                return;
            }

            // get read and write pipe handles
            // note: Roles are now reversed from how the other process is passing the handles in
            string pipeWriteHandle = args[0];
            string pipeReadHandle  = args[1];

            // create 2 anonymous pipes (read and write) for duplex communications
            // (each pipe is one-way)
            using (var pipeRead = new AnonymousPipeClientStream(PipeDirection.In, pipeReadHandle))
                using (var pipeWrite = new AnonymousPipeClientStream(PipeDirection.Out, pipeWriteHandle))
                {
                    try
                    {
                        var lsValues = new List <string>();

                        // get message from other process
                        using (var sr = new StreamReader(pipeRead))
                        {
                            string sTempMessage;

                            // wait for "sync message" from the other process
                            do
                            {
                                sTempMessage = sr.ReadLine();
                            } while (sTempMessage == null || !sTempMessage.StartsWith("SYNC"));

                            // read until "end message" from the server
                            while ((sTempMessage = sr.ReadLine()) != null && !sTempMessage.StartsWith("END"))
                            {
                                lsValues.Add(sTempMessage);
                            }
                        }

                        // send value to calling process
                        using (var sw = new StreamWriter(pipeWrite))
                        {
                            sw.AutoFlush = true;
                            // send a "sync message" and wait for the calling process to receive it
                            sw.WriteLine("SYNC");
                            pipeWrite.WaitForPipeDrain(); // wait here

                            PassingObject   dataObject   = JsonConvert.DeserializeObject <PassingObject>(lsValues[0]);
                            ReturningObject returnObject = new ReturningObject();

                            try
                            {
                                // create a new ServerTextControl for the document processing
                                using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
                                {
                                    tx.Create();
                                    tx.Load(dataObject.Document, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

                                    using (MailMerge mailMerge = new MailMerge())
                                    {
                                        mailMerge.TextComponent = tx;
                                        mailMerge.MergeJsonData(dataObject.Data.ToString());
                                    }

                                    byte[] data;
                                    tx.Save(out data, TXTextControl.BinaryStreamType.AdobePDF);

                                    returnObject.Document = data;
                                }

                                sw.WriteLine(JsonConvert.SerializeObject(returnObject));
                                sw.WriteLine("END");
                            }
                            catch (Exception exc)
                            {
                                returnObject.Error = exc.Message;

                                sw.WriteLine(JsonConvert.SerializeObject(returnObject));
                                sw.WriteLine("END");
                            }
                        }
                    }
                    catch
                    {
                    }
                }
        }