Exemple #1
0
        public static Property Deserialise(System.IO.Stream stream)
        {
            Property property = new Property();

            property.PropertyDefinitionID = IPCHelper.ReadGuid(stream);
            property.PropertyID           = IPCHelper.ReadString(stream);
            byte nullItem = IPCHelper.ReadByte(stream);

            if (nullItem == 1)
            {
                property.Value = new PropertyValue()
                {
                    Value = IPCHelper.ReadString(stream)
                };
            }
            int valueCount = IPCHelper.ReadInt32(stream);

            for (int valueIndex = 0; valueIndex < valueCount; valueIndex++)
            {
                PropertyValue value = new PropertyValue();
                value.PropertyValueID = IPCHelper.ReadString(stream);
                value.Value           = IPCHelper.ReadString(stream);
                if (property.Values == null)
                {
                    property.Values = new List <PropertyValue>();
                }
                property.Values.Add(value);
            }
            return(property);
        }
Exemple #2
0
        public static async Task ShowWallpaper(WallpaperModel wallpaper, params int[] screenIndexs)
        {
            if (_ipc == null)
            {
                _ipc = new IPCHelper(IPCHelper.ServerID, IPCHelper.RemoteRenderID);
            }

            if (_currentProcess == null)
            {
                var pList = Process.GetProcessesByName("LiveWallpaperEngineRender");
                _currentProcess = pList?.Length > 0 ? pList[0] : null;
                if (_currentProcess == null)
                {
                    _currentProcess = Process.Start("LiveWallpaperEngineRender.exe");
                    //等待render初始完成
                    await _ipc.Wait <Ready>();
                }
            }

            //显示壁纸
            await _ipc.Send(new InvokeRender()
            {
                InvokeMethod = nameof(IRender.ShowWallpaper),
                Parameters   = new object[] { wallpaper, screenIndexs },
            });
        }
Exemple #3
0
 public void Serialise(System.IO.Stream stream)
 {
     IPCHelper.Write(stream, PropertyDefinitionID);
     IPCHelper.Write(stream, PropertyID);
     if (Value == null)
     {
         IPCHelper.Write(stream, (byte)0);
     }
     else
     {
         IPCHelper.Write(stream, (byte)1);
         IPCHelper.Write(stream, Value.Value);
     }
     if (Values == null)
     {
         IPCHelper.Write(stream, (int)-1);
     }
     else
     {
         IPCHelper.Write(stream, Values.Count);
         foreach (PropertyValue itemValue in Values)
         {
             IPCHelper.Write(stream, itemValue.PropertyValueID);
             IPCHelper.Write(stream, itemValue.Value);
         }
     }
 }
Exemple #4
0
        public static Client Deserialise(Stream stream)
        {
            Client result = new Client();

            result.ClientID = IPCHelper.ReadGuid(stream);
            result.Name     = IPCHelper.ReadString(stream);
            DateTime?dateTime = IPCHelper.ReadDateTime(stream);

            if (dateTime.HasValue)
            {
                result.Lifetime = dateTime.Value;
            }
            string version = IPCHelper.ReadString(stream);

            result.Version = Version.Parse(version);
            string       bindingModeText = IPCHelper.ReadString(stream);
            TBindingMode bindingMode;

            if (Enum.TryParse <TBindingMode>(bindingModeText, true, out bindingMode))
            {
                result.BindingMode = bindingMode;
            }
            result.SMSNumber      = IPCHelper.ReadString(stream);
            result.SupportedTypes = ObjectTypes.Deserialise(stream);
            return(result);
        }
Exemple #5
0
 public static void Dispose()
 {
     _currentProcess?.Kill();
     _currentProcess = null;
     _ipc.Dispose();
     _ipc = null;
 }
Exemple #6
0
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, _ObjectTypeList.Count);
     foreach (ObjectType item in _ObjectTypeList)
     {
         item.Serialise(stream);
     }
 }
        public static DeviceConnectedStatus Deserialise(Stream stream)
        {
            DeviceConnectedStatus result = new DeviceConnectedStatus();

            result.Online           = IPCHelper.ReadBoolean(stream);
            result.LastActivityTime = IPCHelper.ReadDateTime(stream);
            return(result);
        }
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, MinimumPeriod);
     IPCHelper.Write(stream, MaximumPeriod);
     IPCHelper.Write(stream, GreaterThan);
     IPCHelper.Write(stream, LessThan);
     IPCHelper.Write(stream, Step);
     stream.Flush();
 }
Exemple #9
0
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, Path);
     IPCHelper.Write(stream, ObjectTypeID);
     IPCHelper.Write(stream, Instances.Count);
     foreach (int item in Instances)
     {
         IPCHelper.Write(stream, item);
     }
 }
        public static NotificationParameters Deserialise(Stream stream)
        {
            NotificationParameters result = new NotificationParameters();

            result.MinimumPeriod = IPCHelper.ReadInt32Nullable(stream);
            result.MaximumPeriod = IPCHelper.ReadInt32Nullable(stream);
            result.GreaterThan   = IPCHelper.ReadDoubleNullable(stream);
            result.LessThan      = IPCHelper.ReadDoubleNullable(stream);
            result.Step          = IPCHelper.ReadDoubleNullable(stream);
            return(result);
        }
Exemple #11
0
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, ObjectDefinitionID);
     IPCHelper.Write(stream, ObjectID);
     IPCHelper.Write(stream, InstanceID);
     IPCHelper.Write(stream, Properties.Count);
     foreach (Property item in Properties)
     {
         item.Serialise(stream);
     }
     stream.Flush();
 }
Exemple #12
0
        public static ObjectTypes Deserialise(Stream stream)
        {
            ObjectTypes result = new ObjectTypes();
            int         count  = IPCHelper.ReadInt32(stream);

            if (count > 0)
            {
                for (int index = 0; index < count; index++)
                {
                    ObjectType objectType = ObjectType.Deserialise(stream);
                    result.AddObjectType(objectType);
                }
                result._ObjectTypeList.Sort(ObjectType.Compare);
            }
            return(result);
        }
Exemple #13
0
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, ClientID);
     IPCHelper.Write(stream, Name);
     IPCHelper.Write(stream, Lifetime);
     IPCHelper.Write(stream, Version.ToString());
     IPCHelper.Write(stream, BindingMode.ToString());
     IPCHelper.Write(stream, SMSNumber);
     if (SupportedTypes == null)
     {
         IPCHelper.Write(stream, (int)-1);
     }
     else
     {
         SupportedTypes.Serialise(stream);
     }
     stream.Flush();
 }
Exemple #14
0
        public static ObjectType Deserialise(Stream stream)
        {
            ObjectType result = new ObjectType();

            result.Path         = IPCHelper.ReadString(stream);
            result.ObjectTypeID = IPCHelper.ReadInt32(stream);
            int count = IPCHelper.ReadInt32(stream);

            if (count > 0)
            {
                for (int index = 0; index < count; index++)
                {
                    int item = IPCHelper.ReadInt32(stream);
                    result.Instances.Add(item);
                }
            }
            return(result);
        }
Exemple #15
0
        public static Object Deserialise(Stream stream)
        {
            Object result = new Object();

            result.ObjectDefinitionID = IPCHelper.ReadGuid(stream);
            result.ObjectID           = IPCHelper.ReadString(stream);
            result.InstanceID         = IPCHelper.ReadString(stream);
            int count = IPCHelper.ReadInt32(stream);

            if (count > 0)
            {
                for (int index = 0; index < count; index++)
                {
                    Property property = Property.Deserialise(stream);
                    result.Properties.Add(property);
                }
            }
            return(result);
        }
Exemple #16
0
        private async Task <IPCHelper> GetIPCHelper()
        {
            if (_ipc == null)
            {
                _ipc = new IPCHelper(IPCHelper.ServerID, IPCHelper.RemoteRenderID);
            }

            if (_currentProcess == null)
            {
                var pList = Process.GetProcessesByName("LiveWallpaperEngineRender");
                _currentProcess = pList?.Length > 0 ? pList[0] : null;
                if (_currentProcess == null)
                {
                    _currentProcess = Process.Start("LiveWallpaperEngineRender.exe");
                    //等待render初始完成
                    await _ipc.Wait <Ready>();
                }
            }
            return(_ipc);
        }
        static void Main()
        {
            WallpaperManager.Instance.Initlize();
            WatchParent();

            _ipc              = new IPCHelper(IPCHelper.RemoteRenderID, IPCHelper.ServerID);
            _ipc.MsgReceived += Ipc_MsgReceived;

            //winform设置
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //异常捕获
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _mainForm       = new Main();
            _mainForm.Load += Main_Load;
            Application.Run(_mainForm);
        }
Exemple #18
0
 private void CheckError()
 {
     if (_ErrorResponse)
     {
         using (MemoryStream stream = new MemoryStream(_ResponseBytes))
         {
             string    typeName = IPCHelper.ReadString(stream);
             string    message  = IPCHelper.ReadString(stream);
             Exception exception;
             try
             {
                 Type type = Type.GetType(typeName);
                 exception = (Exception)Activator.CreateInstance(type, message);
             }
             catch
             {
                 exception = new Exception(message);
             }
             throw exception;
         }
     }
 }
Exemple #19
0
        public List <Client> GetClients()
        {
            List <Client> result  = null;
            IPCRequest    request = new IPCRequest();

            request.Method = "GetClients";
            SendRequest(request);
            if (_ResponseBytes.Length > 0)
            {
                result = new List <Client>();
                MemoryStream stream = new MemoryStream(_ResponseBytes);
                int          count  = IPCHelper.ReadInt32(stream);
                if (count > 0)
                {
                    for (int index = 0; index < count; index++)
                    {
                        result.Add(Client.Deserialise(stream));
                    }
                }
            }
            return(result);
        }
Exemple #20
0
 public void AddToPayload(string value)
 {
     IPCHelper.Write(_Payload, value);
 }
        public void StartProcess(eAssignedLane_Printer Lane, string filename)
        {
            if (PrinterManager.getInstance() == null)
            {
                return;
            }
            else
            {
                Log4.PrinterLogger.InfoFormat("[SOA]StartProcess({0},{1})", Lane.ToString(), filename);
                //如果檔案是用XML則需要enqueue
                if (PrinterManager.getInstance().ExchangeMethod == SFCData.eSFCDataExchangeMethod.XML)
                {
                    InspectedPanel panel = null;
                    while (panel == null)
                    {
                        panel = null;
                        try
                        {
                            panel = IPCHelper.DeserializeFromXML <InspectedPanel>(filename);
                        }
                        catch (Exception ex)
                        {
                            //Log4.SFCLogger.InfoFormat("Pause {0} ms", iPause);
                            //Thread.Sleep(iPause);
                            //Log4.SFCLogger.ErrorFormat("DeserializeFromXML File {0} Exception:{1}", AssemblyPath + "\\DataExchange\\" + e.Name, ex.Message);
                        }
                    }
                    switch (Lane)
                    {
                    case eAssignedLane_Printer.None:
                        break;

                    case eAssignedLane_Printer.Lane1:
                        ViewModelLocator.Atom.FlowHostVM.spiInspectedData.Add("[" + eAssignedLane_Printer.Lane1.ToString() + "]" + panel.InspectStartTime);
                        Log4.PrinterLogger.InfoFormat(" -Push [{0}] CurrentInspectModeTemp.InspectMode={1} .InspectResult={2}", Lane.ToString(), panel.InspectMode, panel.InspectResult);
                        PrinterManager.getInstance().CurrentInspectModeTemp[0].InspectMode   = panel.InspectMode;
                        PrinterManager.getInstance().CurrentInspectModeTemp[0].InspectResult = panel.InspectResult;
                        Log4.PrinterLogger.InfoFormat(" -Enqueue [{0}] SPI Data InspectTime = {1}", Lane.ToString(), panel.InspectStartTime);
                        PrinterManager.getInstance().RemotePrinter[0].Printer.InspectedPanels.Enqueue(panel);

                        break;

                    case eAssignedLane_Printer.Lane2:
                        ViewModelLocator.Atom.FlowHostVM.spiInspectedData.Add("[" + eAssignedLane_Printer.Lane2.ToString() + "]" + panel.InspectStartTime);
                        Log4.PrinterLogger.InfoFormat(" -Push [{0}] CurrentInspectModeTemp.InspectMode={1} .InspectResult={2}", Lane.ToString(), panel.InspectMode, panel.InspectResult);
                        PrinterManager.getInstance().CurrentInspectModeTemp[1].InspectMode   = panel.InspectMode;
                        PrinterManager.getInstance().CurrentInspectModeTemp[1].InspectResult = panel.InspectResult;
                        Log4.PrinterLogger.InfoFormat(" -Enqueue [{0}] SPI Data InspectTime = {1}", Lane.ToString(), panel.InspectStartTime);
                        PrinterManager.getInstance().RemotePrinter[1].Printer.InspectedPanels.Enqueue(panel);

                        break;
                    }
                }
                switch (Lane)
                {
                case eAssignedLane_Printer.None:
                    break;

                case eAssignedLane_Printer.Lane1:
                    PrinterManager.getInstance().RemotePrinter[0].Printer.StartProcess();
                    break;

                case eAssignedLane_Printer.Lane2:
                    PrinterManager.getInstance().RemotePrinter[1].Printer.StartProcess();
                    break;
                }
            }
        }
Exemple #22
0
 public string ReadString()
 {
     return(IPCHelper.ReadString(_Payload));
 }
Exemple #23
0
 public void AddToPayload(int value)
 {
     IPCHelper.Write(_Payload, value);
 }
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, Online);
     IPCHelper.Write(stream, LastActivityTime);
     stream.Flush();
 }
Exemple #25
0
 public Guid ReadGuid()
 {
     return(IPCHelper.ReadGuid(_Payload));
 }
Exemple #26
0
 public int ReadInt32()
 {
     return(IPCHelper.ReadInt32(_Payload));
 }
 private void ProcessRequest(Socket client, IPCRequest request)
 {
     byte[] response = new byte[4];
     try
     {
         if (string.Compare(request.Method, "CancelObserveObject", true) == 0)
         {
             Guid   clientID           = request.ReadGuid();
             Guid   objectDefinitionID = request.ReadGuid();
             string instanceID         = request.ReadString();
             bool   useReset           = request.ReadBoolean();
             _ServerAPI.CancelObserveObject(clientID, objectDefinitionID, instanceID, useReset);
         }
         else if (string.Compare(request.Method, "CancelObserveObjectProperty", true) == 0)
         {
             Guid   clientID             = request.ReadGuid();
             Guid   objectDefinitionID   = request.ReadGuid();
             string instanceID           = request.ReadString();
             Guid   propertyDefinitionID = request.ReadGuid();
             bool   useReset             = request.ReadBoolean();
             _ServerAPI.CancelObserveObjectProperty(clientID, objectDefinitionID, instanceID, propertyDefinitionID, useReset);
         }
         else if (string.Compare(request.Method, "CancelObserveObjects", true) == 0)
         {
             Guid clientID           = request.ReadGuid();
             Guid objectDefinitionID = request.ReadGuid();
             bool useReset           = request.ReadBoolean();
             _ServerAPI.CancelObserveObjects(clientID, objectDefinitionID, useReset);
         }
         else if (string.Compare(request.Method, "DeleteClient", true) == 0)
         {
             Guid clientID = request.ReadGuid();
             _ServerAPI.DeleteClient(clientID);
         }
         else if (string.Compare(request.Method, "ExecuteResource", true) == 0)
         {
             Guid         clientID             = request.ReadGuid();
             Guid         objectDefinitionID   = request.ReadGuid();
             string       instanceID           = request.ReadString();
             Guid         propertyDefinitionID = request.ReadGuid();
             bool         success = _ServerAPI.ExecuteResource(clientID, objectDefinitionID, instanceID, propertyDefinitionID);
             MemoryStream data    = new MemoryStream(4096);
             data.Position = 4;
             IPCHelper.Write(data, success);
             data.Position = 0;
             NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
             response = data.ToArray();
         }
         if (string.Compare(request.Method, "GetClients", true) == 0)
         {
             List <Client> clients = _ServerAPI.GetClients();
             if (clients != null)
             {
                 MemoryStream data = new MemoryStream(4096);
                 data.Position = 4;
                 IPCHelper.Write(data, clients.Count);
                 foreach (Client item in clients)
                 {
                     item.Serialise(data);
                 }
                 data.Position = 0;
                 NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "GetDeviceConnectedStatus", true) == 0)
         {
             Guid clientID = request.ReadGuid();
             DeviceConnectedStatus responseObject = _ServerAPI.GetDeviceConnectedStatus(clientID);
             if (responseObject != null)
             {
                 MemoryStream data = new MemoryStream(4096);
                 data.Position = 4;
                 responseObject.Serialise(data);
                 data.Position = 0;
                 NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "GetObject", true) == 0)
         {
             Guid         clientID           = request.ReadGuid();
             Guid         objectDefinitionID = request.ReadGuid();
             string       instanceID         = request.ReadString();
             Model.Object responseObject     = _ServerAPI.GetObject(clientID, objectDefinitionID, instanceID);
             if (responseObject != null)
             {
                 MemoryStream data = new MemoryStream(4096);
                 data.Position = 4;
                 responseObject.Serialise(data);
                 data.Position = 0;
                 NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "GetObjectProperty", true) == 0)
         {
             Guid     clientID             = request.ReadGuid();
             Guid     objectDefinitionID   = request.ReadGuid();
             string   instanceID           = request.ReadString();
             Guid     propertyDefinitionID = request.ReadGuid();
             Property responseProperty     = _ServerAPI.GetObjectProperty(clientID, objectDefinitionID, instanceID, propertyDefinitionID);
             if (responseProperty != null)
             {
                 MemoryStream data = new MemoryStream(4096);
                 data.Position = 4;
                 responseProperty.Serialise(data);
                 data.Position = 0;
                 NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "GetObjects", true) == 0)
         {
             Guid clientID                       = request.ReadGuid();
             Guid objectDefinitionID             = request.ReadGuid();
             List <Model.Object> responseObjects = _ServerAPI.GetObjects(clientID, objectDefinitionID);
             if (responseObjects != null)
             {
                 MemoryStream data = new MemoryStream(4096);
                 data.Position = 4;
                 foreach (Model.Object responseObject in responseObjects)
                 {
                     responseObject.Serialise(data);
                 }
                 data.Position = 0;
                 NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "ObserveObject", true) == 0)
         {
             Guid   clientID           = request.ReadGuid();
             Guid   objectDefinitionID = request.ReadGuid();
             string instanceID         = request.ReadString();
             _ServerAPI.ObserveObject(clientID, objectDefinitionID, instanceID);
         }
         else if (string.Compare(request.Method, "ObserveObjectProperty", true) == 0)
         {
             Guid   clientID             = request.ReadGuid();
             Guid   objectDefinitionID   = request.ReadGuid();
             string instanceID           = request.ReadString();
             Guid   propertyDefinitionID = request.ReadGuid();
             _ServerAPI.ObserveObjectProperty(clientID, objectDefinitionID, instanceID, propertyDefinitionID);
         }
         else if (string.Compare(request.Method, "ObserveObjects", true) == 0)
         {
             Guid clientID           = request.ReadGuid();
             Guid objectDefinitionID = request.ReadGuid();
             _ServerAPI.ObserveObjects(clientID, objectDefinitionID);
         }
         else if (string.Compare(request.Method, "SaveObject", true) == 0)
         {
             Guid         clientID   = request.ReadGuid();
             Model.Object item       = Model.Object.Deserialise(request.Payload);
             TObjectState state      = (TObjectState)request.ReadInt32();
             string       responseID = _ServerAPI.SaveObject(clientID, item, state);
             if (responseID != null)
             {
                 MemoryStream data   = new MemoryStream(4096);
                 byte[]       buffer = Encoding.UTF8.GetBytes(responseID);
                 NetworkByteOrderConverter.WriteInt32(data, (int)(buffer.Length + 4));
                 NetworkByteOrderConverter.WriteInt32(data, buffer.Length);
                 data.Write(buffer, 0, buffer.Length);
                 response = data.ToArray();
             }
         }
         else if (string.Compare(request.Method, "SaveObjectProperty", true) == 0)
         {
             Guid         clientID           = request.ReadGuid();
             Guid         objectDefinitionID = request.ReadGuid();
             string       instanceID         = request.ReadString();
             Property     property           = Property.Deserialise(request.Payload);
             TObjectState state = (TObjectState)request.ReadInt32();
             _ServerAPI.SaveObjectProperty(clientID, objectDefinitionID, instanceID, property, state);
         }
         else if (string.Compare(request.Method, "SetDataFormat", true) == 0)
         {
             TDataFormat dataFormat = (TDataFormat)request.ReadInt32();
             _ServerAPI.SetDataFormat(dataFormat);
         }
         else if (string.Compare(request.Method, "SetNotificationParameters", true) == 0)
         {
             Guid   clientID             = request.ReadGuid();
             Guid   objectDefinitionID   = request.ReadGuid();
             string instanceID           = request.ReadString();
             Guid   propertyDefinitionID = request.ReadGuid();
             NotificationParameters notificationParameters = NotificationParameters.Deserialise(request.Payload);
             bool         success = _ServerAPI.SetNotificationParameters(clientID, objectDefinitionID, instanceID, propertyDefinitionID, notificationParameters);
             MemoryStream data    = new MemoryStream(4096);
             data.Position = 4;
             IPCHelper.Write(data, success);
             data.Position = 0;
             NetworkByteOrderConverter.WriteInt32(data, (int)data.Length - 4);
             response = data.ToArray();
         }
     }
     catch (Exception ex)
     {
         MemoryStream data = new MemoryStream(4096);
         data.Position = 4;
         IPCHelper.Write(data, ex.GetType().AssemblyQualifiedName);
         IPCHelper.Write(data, ex.Message);
         data.Position = 0;
         NetworkByteOrderConverter.WriteInt32(data, -((int)data.Length - 4));
         response = data.ToArray();
     }
     client.Send(response, SocketFlags.None);
 }
Exemple #28
0
 public bool ReadBoolean()
 {
     return(IPCHelper.ReadBoolean(_Payload));
 }