Ejemplo n.º 1
0
        public Guid Save(ApiDevice model)
        {
            var deviceEntity = UnitOfWork.GetRepository <Device>().GetById(model.Id);

            if (deviceEntity == null)
            {
                deviceEntity = Mapper.Map <ApiDevice, Device>(model);

                UnitOfWork.GetRepository <Device>().Insert(deviceEntity);
            }
            else
            {
                deviceEntity = Mapper.Map(model, deviceEntity);

                UnitOfWork.GetRepository <Device>().Update(deviceEntity);
            }

            UnitOfWork.SaveChanges();

            return(deviceEntity.Id);
        }
Ejemplo n.º 2
0
        public JsonResult <ApiBaseResponse> SaveUserDeviceToken([FromUri] Guid userId, string token)
        {
            var result = new ApiBaseResponse();

            try
            {
                var userEntity = UserManager.FindById(userId);

                if (userEntity == null)
                {
                    result.Status = Core.Enums.ApiStatusCode.WrongArgumentsOrData;
                }
                else
                {
                    var device = ServicesHost.GetService <IDevicesProvider>().GetByToken(token);

                    if (device == null)
                    {
                        device = new ApiDevice
                        {
                            Token  = token,
                            UserId = userEntity.Id
                        };
                        ServicesHost.GetService <IDevicesProvider>().Save(device);
                    }
                    else if (device.UserId != userEntity.Id)
                    {
                        device.UserId = userEntity.Id;
                        ServicesHost.GetService <IDevicesProvider>().Save(device);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Status = Core.Enums.ApiStatusCode.SystemError;
                result.Error  = ex.Message;
            }

            return(Json(result));
        }
Ejemplo n.º 3
0
        // ------------------------------------------------------------

        public AppConfig(string fname)
        {
            // initialize
            HashSet <int> deviceIds     = new HashSet <int>();
            HashSet <int> deviceNumbers = new HashSet <int>();

            mSettings      = new ApiSettings();
            mDevices       = new ApiDevice[0];
            mDeviceConfigs = new ApiDeviceConfig[0];
            mAppProfiles   = new ApiAppProfile[0];
            mEvents        = new ApiEvent[0];
            mActions       = new ApiAction[0];

            // load the AppConfig
            if (!File.Exists(fname))
            {
                return;  // FIXME! can't do this - we have to notify the DLL
            }
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.IgnoreComments = true;
            xmlReaderSettings.IgnoreProcessingInstructions = true;
            xmlReaderSettings.IgnoreWhitespace             = true;
            XmlDocument xmlDoc = new XmlDocument();

            using (XmlReader xmlReader = XmlReader.Create(fname, xmlReaderSettings))
                xmlDoc.Load(xmlReader);

            // parse the app config
            XmlNode configXmlNode = xmlDoc.SelectSingleNode("/config");

            // parse the devices
            List <ApiDevice> devices = new List <ApiDevice>();

            foreach (XmlNode xn in configXmlNode.SelectNodes("device"))
            {
                ApiDevice device = new ApiDevice();
                device.mDeviceId = Int32.Parse(xn.Attributes["id"].Value);
                if (deviceIds.Contains(device.mDeviceId))
                {
                    throw new Exception(String.Format("Duplicate device ID: {0}", device.mDeviceId));
                }
                deviceIds.Add(device.mDeviceId);
                device.mHID          = xn.SelectSingleNode("hid").InnerText.Trim();
                device.mDeviceNumber = Int32.Parse(xn.SelectSingleNode("deviceNumber").InnerText);
                if (deviceNumbers.Contains(device.mDeviceNumber))
                {
                    throw new Exception(String.Format("Duplicate device number: {0}", device.mDeviceNumber));
                }
                deviceNumbers.Add(device.mDeviceNumber);
                if (deviceNumbers.Contains(device.mDeviceNumber))
                {
                    device.mDisplayName = Utils.getXmlChildVal(xn, "displayName");
                }
                device.mIsEnabled = Utils.getXmlChildVal(xn, "enabled", false);
                devices.Add(device);
            }
            mDevices = devices.ToArray();

            // parse the device configs
            List <ApiDeviceConfig> deviceConfigs = new List <ApiDeviceConfig>();
            List <ApiAppProfile>   appProfiles   = new List <ApiAppProfile>();
            List <ApiEvent>        events        = new List <ApiEvent>();
            List <ApiAction>       actions       = new List <ApiAction>();

            foreach (XmlNode deviceConfigXmlNode in configXmlNode.SelectNodes("deviceConfig"))
            {
                ApiDeviceConfig deviceConfig = new ApiDeviceConfig();
                deviceConfig.mDeviceId = Int32.Parse(deviceConfigXmlNode.Attributes["id"].Value);
                deviceConfig.mStrokeHistoryResetInterval = Utils.getXmlChildVal(deviceConfigXmlNode, "strokeHistoryResetInterval", -1);
                deviceConfig.mAppProfileStartIndex       = appProfiles.Count;
                deviceConfig.mAppProfileCount            = 0;
                // parse the app profiles
                foreach (XmlNode appProfileXmlNode in deviceConfigXmlNode.SelectNodes("appProfile"))
                {
                    ApiAppProfile appProfile = new ApiAppProfile();
                    appProfile.mApp = Utils.getXmlAttr(appProfileXmlNode, "app", "");
                    XmlNode xn = appProfileXmlNode.SelectSingleNode("sensitivity");
                    if (xn != null)
                    {
                        appProfile.mSensitivityX = Utils.getXmlAttr(xn, "x", 0);
                        appProfile.mSensitivityY = Utils.getXmlAttr(xn, "y", 0);
                    }
                    appProfile.mFallbackToDefaultAppProfile = Utils.getXmlChildVal(appProfileXmlNode, "fallbackToDefaultAppProfile", false);
                    appProfile.mEventStartIndex             = events.Count;
                    appProfile.mEventCount = 0;
                    // parse the events
                    foreach (XmlNode eventXmlNode in appProfileXmlNode.SelectNodes("event"))
                    {
                        ApiEvent evt = new ApiEvent();
                        evt.mEventType    = (int)Enum.Parse(typeof(ApiEvent.EventType), eventXmlNode.Attributes["type"].Value, true);
                        evt.mKeyModifiers = getKeyModifiers(eventXmlNode);
                        // parse the actions
                        evt.mActionStartIndex = actions.Count;
                        evt.mActionCount      = 0;
                        foreach (XmlNode actionXmlNode in eventXmlNode.SelectNodes("action"))
                        {
                            ApiAction action = new ApiAction();
                            action.mActionType = (int)Enum.Parse(typeof(ApiAction.ActionType), actionXmlNode.Attributes["type"].Value, true);
                            if (action.mActionType == (int)ApiAction.ActionType.keyPress)
                            {
                                action.mActionParam = Utils.getXmlAttr(actionXmlNode, "vKey", 0);
                                if (action.mActionParam <= 0)
                                {
                                    throw new Exception("Missing vKey.");
                                }
                            }
                            else
                            {
                                action.mActionParam = Utils.getXmlAttr(actionXmlNode, "speed", 0);
                            }
                            action.mKeyModifiers = getKeyModifiers(actionXmlNode);
                            actions.Add(action);
                            evt.mActionCount++;
                        }
                        events.Add(evt);
                        appProfile.mEventCount++;
                    }
                    // add the app profile to the table
                    appProfiles.Add(appProfile);
                    deviceConfig.mAppProfileCount++;
                }
                // add the device config to the table
                deviceConfigs.Add(deviceConfig);
            }
            mDeviceConfigs = deviceConfigs.ToArray();
            mAppProfiles   = appProfiles.ToArray();
            mEvents        = events.ToArray();
            mActions       = actions.ToArray();
        }
Ejemplo n.º 4
0
 public void Delete(ApiDevice model)
 {
     UnitOfWork.GetRepository <Device>().Delete(model.Id);
     UnitOfWork.SaveChanges();
 }