Пример #1
0
 public void onDeviceAttached(string deviceName)
 {
     device_name_attach = deviceName;
     attachstate        = AttachState.Connected;
     //DeviceAttachedCallback(true);
     Debug.Log(deviceName + "----" + attachstate);
 }
Пример #2
0
 public void onDeviceDetached(string deviceName)
 {
     device_name_detach = deviceName;
     attachstate        = AttachState.Disconnected;
     //DeviceAttachedCallback(false);
     Debug.Log(deviceName + "----" + attachstate);
 }
Пример #3
0
        private static void SmartAttach <T>(this ObjectSet <T> os, T input, AttachState state, params Expression <Func <T, object> >[] modifiedProperties) where T : class
        {
            var objectType = ObjectContext.GetObjectType(input.GetType());
            var osItem     = os.Context.MetadataWorkspace.GetItem <EntityType>(objectType.FullName, DataSpace.OSpace);
            var csItem     = (EntityType)os.Context.MetadataWorkspace.GetEdmSpaceType(osItem);
            var value      = ((XElement)(csItem.KeyMembers.First().MetadataProperties.First(p => p.Name == "http://EFEX:InsertWhen").Value)).Value;
            var id         = input.GetType().GetProperty(csItem.KeyMembers.First().Name).GetValue(input, null);
            var idType     = input.GetType().GetProperty(csItem.KeyMembers.First().Name).PropertyType;

            if (id.Equals(Convert.ChangeType(value, idType)))
            {
                os.AddObject(input);
            }
            else
            {
                os.Attach(input);
                var entry = os.Context.ObjectStateManager.GetObjectStateEntry(input);
                if (state == AttachState.Modified)
                {
                    if (modifiedProperties != null && modifiedProperties.Any())
                    {
                        foreach (var property in modifiedProperties)
                        {
                            entry.SetModifiedProperty(property);
                        }
                    }
                    else
                    {
                        entry.ChangeState(EntityState.Modified);
                    }
                }
                else if (state == AttachState.Deleted)
                {
                    entry.ChangeState(EntityState.Deleted);
                }
            }
        }
 public void onDeviceDetached(string deviceName)
 {
     device_name_detach = deviceName;
     attachstate        = AttachState.Disconnected;
     //MojingLog.LogTrace(deviceName + "disconnected");
 }
 public DeviceAttachedStateEventArgs(AttachState state, string type, string name)
 {
     Type  = type;
     Name  = name;
     State = state;
 }
Пример #6
0
        public void attach(ProcessCollectable process, AttachResultCallback callback)
        {
            Trace.Assert(attachState == AttachState.Detached, "Must be detached before attaching");
            Log.Info("attaching to process {0}", process);

            try
            {
                bool pipeServerStartRes = pipeServer.start();

                if(!pipeServerStartRes)
                {
                    callback(false, AttachResult.PipeServerStartup,
                        string.Format("Failed to start the pipe server for '{0}'. Reason: unknown", pipeServer.PipeName));
                    return;
                }
            }
            catch (IOException e)
            {
                callback(false, AttachResult.PipeServerStartup,
                    string.Format("Failed to start the pipe server for '{0}'. Reason: {1}", pipeServer.PipeName, e.Message));
                return;
            }

#if !WITHOUT_GAME
            DllInjectionResult dllResult = DLLInjector.Inject(process.Process, dllName);

            // DLL injection error handling;
            switch(dllResult)
            {
                case DllInjectionResult.Success:
                    break;
                case DllInjectionResult.DllNotFound:
                    pipeServer.stop();

                    callback(false, AttachResult.DllMissing,
                        string.Format("Failed to inject {0} in to {1} because it was missing from the current directory.", dllName, process));
                    return;
                case DllInjectionResult.GameProcessNotFound:
                    pipeServer.stop();

                    callback(false, AttachResult.DllNoProcess,
                        string.Format("Failed to inject {0} in to {1} because the process died before we could inject!", dllName, process));
                    return;
                case DllInjectionResult.InjectionFailed:
                    pipeServer.stop();

                    callback(false, AttachResult.DllInjectionFailure,
                        string.Format("Failed to inject {0} in to {1}. Possible bad DLL or process crash.", dllName, process));
                    return;
            }
#endif

            DllHandshake.process(pipeServer, process, (result, attachResult, message) =>
            {
                if (result)
                {
                    currentProcess = process;
                    attachState = AttachState.Attached;

                    // begin listening for events related to this process
                    //Process p = process.Process;

                    //p.EnableRaisingEvents = true;
                    //p.Exited += new EventHandler(AttachedProcessExited);

                    receiveTaskCancel = new CancellationTokenSource();

                    // start receive thread
                    receiveTask = Task.Factory.StartNew(async delegate
                    {
                        Log.Debug("Receive task started...");

                        while (!receiveTaskCancel.IsCancellationRequested)
                        {
                            List<byte> msg = await pipeServer.readMessageAsync(receiveTaskCancel.Token);

                            if (msg != null)
                            {
                                DllMessage msgDecoded = DllMessage.Factory.Decode(new BitStream(msg));

                                if (msgDecoded != null)
                                    handleMessage(msgDecoded);
                                else
                                    Log.Error("Failed to decode message");
                            }
                            else
                            {
                                Log.Warning("Receive task exiting due to null message");
                                break;
                            }
                        }

                        await Task.Factory.StartNew(delegate { if (isAttached()) detach(); }).ConfigureAwait(false);

                        Log.Debug("Receive task stopped...");
                    }, receiveTaskCancel.Token);
                }
                else
                {
                    pipeServer.stop();
                }

                callback(result, attachResult, message);
            });
        }
Пример #7
0
        public void detach()
        {
            Trace.Assert(attachState == AttachState.Attached, "Tried to detach twice");
            Log.Info("detaching from process {0}", currentProcess);

            if (captureState == CaptureState.Capturing)
            {
                Log.Info("currently capturing...stopping capture first");
                stopCapture((evt, success) =>
                {
                    Log.Info("Completed stopCapture");
                });
            }
            else
            {
                Log.Info("wasn't capturing...going ahead with detach");
            }

            notifyEvent(EventNotification.Attached);
            notifyEvent(EventNotification.Detaching);

            if (currentProcess.Process.HasExited)
                AttachedProcessExited(currentProcess.Process);

            Log.Debug("stopping receive task");
            receiveTaskCancel.Cancel();
            if(!receiveTask.IsFaulted)
                receiveTask.Wait();
            receiveTask = null;

            Log.Debug("stopping servers");
            pipeServer.stop();
            currentProcess.Process.Close();

            notifyEvent(EventNotification.Detached);
            attachState = AttachState.Detached;
        }
Пример #8
0
 public static void SmartAttach <T>(this ObjectSet <T> os, T input, AttachState state) where T : class
 {
     SmartAttach(os, input, state, null);
 }