public Package UserDataToPackage(TypeData data, Messagetype messagetype = Messagetype.package)
        {
            Package package = new Package();

            package.data = null;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    switch (messagetype)
                    {
                    case Messagetype.package: bf.Serialize(ms, data); break;

                    default: bf.Serialize(ms, data); break;
                    }
                    ms.Flush();

                    package.message = messagetype;
                    package.data    = ms.ToArray();
                }
                return(package);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(package);
        }
        void NewUserData(Package package, Messagetype messagetype)
        {
            try
            {
                UserData data = new UserData();
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.Write(package.data, 0, package.data.Length);
                    ms.Flush();
                    ms.Position = 0;
                    BinaryFormatter bf = new BinaryFormatter();

                    data = (UserData)bf.Deserialize(ms);
                }
                switch (messagetype)
                {
                case Messagetype.package: Data = data; break;

                // case Messagetype.update:
                //Data.messagetype = package.message;
                //Data.configtime = data.configtime;
                //Data.volume = data.volume;break;
                default: Console.WriteLine("Func:NewUserData.messagetype is null"); break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Func(NewUserData) error:" + ex.ToString());
            }
        }
        /// <summary>
        /// 整合数据的对象在devidce中传递的device对象
        /// </summary>
        /// <param name="data"></param>
        /// <param name="messagetype"></param>
        /// <returns></returns>
        public Package DeviceDataToPackageReal(DeviceData data, Messagetype messagetype = Messagetype.package)
        {
            Package package = new Package();

            package.data = null;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    switch (messagetype)
                    {
                    case Messagetype.barvolumepackage: bf.Serialize(ms, data.barvolumedata.Bvdata[data.barvolumedata.volpointer - 1]); break;
                    }
                    ms.Flush();

                    package.message = messagetype;
                    package.data    = ms.ToArray();
                }
                return(package);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(package);
        }
Пример #4
0
        /// <summary>
        /// 这个方法需要重写,根据需要制定新的case
        /// </summary>
        /// <param name="data"></param>
        /// <param name="messagetype"></param>
        /// <returns></returns>
        public Package UserDataToPackage(TypeData data, Messagetype messagetype = Messagetype.package)
        {
            Package package = new Package();

            package.data = null;
            //try
            //{
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                switch (messagetype)
                {
                case Messagetype.package: bf.Serialize(ms, data); break;

                case Messagetype.codeus: MessageBox.Show("调用1"); bf.Serialize(ms, data); MessageBox.Show("调用2"); break;

                default: bf.Serialize(ms, data); break;
                }
                ms.Flush();
                MessageBox.Show("调用3");
                package.message = messagetype;
                package.data    = ms.ToArray();
            }
            MessageBox.Show("调用4");
            MessageBox.Show(package.message.ToString());
            return(package);

            //}
            //catch (Exception ex)
            //{
            //Console.WriteLine(ex.Message);

            //}
            return(package);
        }
Пример #5
0
        public Package DataToPackage(Messagetype messagetype = Messagetype.package)
        {
            Package package = new Package();

            package.data = null;
            UserData data = Data.GetData();

            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    switch (messagetype)
                    {
                    case Messagetype.carinfomessage: bf.Serialize(ms, data.volume); break;

                    case Messagetype.volumepackage: bf.Serialize(ms, data.volume); break;

                    case Messagetype.package: bf.Serialize(ms, data); break;

                    default: bf.Serialize(ms, data); break;
                    }
                    ms.Flush();

                    package.message = messagetype;
                    package.data    = ms.ToArray();
                }
                return(package);
            }
            catch (Exception ex)
            {
                ErrorMessage.GetError(ex);
            }
            return(package);
        }
Пример #6
0
        private string TextWithPrefix(Messagetype mtype, string msg)
        {
            string prefix;

            switch (mtype)
            {
            case Messagetype.FromKiosk:
                prefix = ">> ";
                break;

            case Messagetype.ToKiosk:
                prefix = "<< ";
                break;

            case Messagetype.Message:
                prefix = "** ";
                break;

            case Messagetype.Error:
                prefix = "!! ";
                break;

            default:
                prefix = "** ";
                break;
            }

            return(prefix + msg + "\n");
        }
Пример #7
0
    public bool GiveMessage(Messagetype msgType, GameObject go, MessageData msgData)
    {
        bool approved = false;

        for (int i = 0; i < messages.Count; i++)
        {
            if (messages[i] == msgType)
            {
                approved = true;
                break;
            }
        }

        if (!approved)
        {
            return(false);
        }

        for (int i = 0; i < m_messageDelegates.Count; i++)
        {
            m_messageDelegates[i](msgType, go, msgData);
        }

        return(true);
    }
Пример #8
0
 public bool SendMessage(Messagetype messagetype)
 {
     if (MailBox.Send(MailBox.DataToPackage(messagetype)))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #9
0
        public void AddTextWithParams(string msg, object[] args, Messagetype messagetype)
        {
            if (args != null && args.Length > 0)
            {
                msg += " With parameters: ";
                foreach (var item in args)
                {
                    msg += item.ToString() + "' ";
                }
            }

            AddText(msg, messagetype);
        }
Пример #10
0
    void RecieveMessage(Messagetype msgType, GameObject go, MessageData msgData)
    {
        switch (msgType)
        {
        case Messagetype.DAMAGED:
            DamageData dmgData = msgData as DamageData;

            if (dmgData != null)
            {
                DoDamage(dmgData.damage, go);
            }
            break;
        }
    }
Пример #11
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (Messagetype != 0)
        {
            hash ^= Messagetype.GetHashCode();
        }
        if (Data.Length != 0)
        {
            hash ^= Data.GetHashCode();
        }
        return(hash);
    }
Пример #12
0
    void RecieveMessage(Messagetype msgType, GameObject go, MessageData msgData)
    {
        switch (msgType)
        {
        case Messagetype.DIED:
            DeathData dthData = msgData as DeathData;

            if (dthData != null)
            {
                Die();
            }
            break;
        }
    }
Пример #13
0
    void RecieveMessage(Messagetype msgType, GameObject go, MessageData msgData)
    {
        switch (msgType)
        {
        case Messagetype.HEALTHCHANGED:
            HealthData hpData = msgData as HealthData;

            if (hpData != null)
            {
                UpdateUi(hpData.maxHealth, hpData.curHealth);
            }
            break;
        }
    }
Пример #14
0
        public static string GetMessage(Messagetype messageType, string customMessage)
        {
            switch (messageType)
            {
            case Messagetype.Saved:
                message = "Yeni " + customMessage + " Kayıt İşlemi Başarılı!...";
                break;

            case Messagetype.Updated:
                message = "Güncelleme İşlemi Başarılı!..." + customMessage;
                break;

            case Messagetype.Deleted:
                message = "Silme İşlemi Başarılı!..." + customMessage;
                break;

            case Messagetype.Found:
                message = "Bulma İşlemi Başarılı!..." + customMessage;
                break;

            case Messagetype.NotSaved:
                message = "Yeni Kayıt İşlemi Başarısız!..." + customMessage;
                break;

            case Messagetype.NotUpdated:
                message = "Güncelleme İşlemi Başarısız!..." + customMessage;
                break;

            case Messagetype.NotDeleted:
                message = "Silme İşlemi Başarısız!..." + customMessage;
                break;

            case Messagetype.NotFound:
                message = "Bulma İşlemi Başarısız!..." + customMessage;
                break;

            case Messagetype.Validation:
                message = "Kontrol İşlemi Başarısız!..." + customMessage;
                break;

            case Messagetype.Exception:
                message = "HATA!..." + customMessage;
                break;
            }
            return(message);
        }
        bool SendUpdate(Messagetype messagetype = Messagetype.update)
        {
            Codemode code;

            if (order.TryDequeue(out code))
            {
                Console.WriteLine("Orderqueue is not null.");
                return(false);
            }
            if (MailBox.Send(MailBox.DataToPackage(messagetype)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #16
0
        private Color GetColor(Messagetype mtype)
        {
            switch (mtype)
            {
            case Messagetype.FromKiosk:
                return(Color.Green);

            case Messagetype.ToKiosk:
                return(Color.Blue);

            case Messagetype.Message:
                return(Color.Black);

            case Messagetype.Error:
                return(Color.Red);

            default:
                return(Color.Black);
            }
        }
Пример #17
0
 public void AddText(string msg, Messagetype mtype)
 {
     if (ControlToInvoke == null)
     {
         return;
     }
     ControlToInvoke.BeginInvoke(new ThreadStart(delegate
     {
         Color oldColor = SelectionColor;
         SelectionColor = GetColor(mtype);
         msg            = TextWithPrefix(mtype, msg);
         if (!Text.EndsWith("\n"))
         {
             msg = "\n" + msg;
         }
         AppendText(msg);
         ScrollToCaret();
         SelectionColor = oldColor;
         Invalidate();
     }));
     return;
 }
        public static Package CreatIPListToPackage(Messagetype messagetype, IPList[] ipl)
        {
            Package package = new Package();

            package.message = messagetype;
            package.data    = null;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(ms, ipl);
                    ms.Flush();
                    package.data = ms.ToArray();
                }
                return(package);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(package);
        }