Пример #1
0
        public List <DeviceWrapper> GetWrappers(int deviceId)
        {
            List <DeviceWrapper> wrappers = new List <DeviceWrapper>();

            List <DBSchema> schemas = dbContext.timeschema.Where(p => p.DeviceId == deviceId)
                                      .OrderByDescending(x => x.DayOfWeek)
                                      .OrderByDescending(z => z.TimePoint).ToList();

            foreach (DBSchema schema in schemas)
            {
                DBDevice d = dbContext.devices.Find(schema.DeviceId);

                DeviceWrapper wrap = new DeviceWrapper
                                     (
                    new Schema
                    (
                        new Device()
                {
                    DeviceId          = d.deviceID,
                    DeviceDescription = d.DeviceType,
                    DeviceName        = d.DeviceName
                }
                    )
                {
                    WeekDay    = schema.DayOfWeek,
                    ActionText = schema.Action.ToString(),
                    TimePoint  = schema.TimePoint
                });

                wrappers.Add(wrap);
            }

            return(wrappers);
        }
Пример #2
0
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="accessToken">The <see cref="AccessToken"/> you want to re-use.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into UniteGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale locale = playerLocale ?? new CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;

            if (accessToken == null || string.IsNullOrEmpty(accessToken.Token) || accessToken.IsExpired)
            {
                accessToken = await loginProvider.GetAccessToken(device.UserAgent, language);

                if (accessToken == null || string.IsNullOrEmpty(accessToken.Token) || accessToken.IsExpired)
                {
                    throw new SessionStateException($"{nameof(accessToken)} is expired.");
                }
            }

            var session = new Session(loginProvider, accessToken, coordinate, device, locale);

            session.Logger.Debug("Authenticated from cache.");
            session.Logger.Debug("Authenticated through Google.");
            return(session);
        }
Пример #3
0
        /// <summary>
        /// Stores data like assets and item templates. Defaults to an in-memory cache, but can be implemented as writing to disk by the platform
        /// </summary>
        // public IDataCache DataCache { get; set; } = new MemoryDataCache();
        // public Templates Templates { get; private set; }

        internal Session(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate geoCoordinate, DeviceWrapper deviceWrapper, GetPlayerMessage.Types.PlayerLocale playerLocale)
        {
            if (!ValidLoginProviders.Contains(loginProvider.ProviderId))
            {
                throw new ArgumentException("LoginProvider ID must be one of the following: " + string.Join(", ", ValidLoginProviders));
            }
            Logger = new Logger();

            State = SessionState.Stopped;

            Device = deviceWrapper;

            var handler = new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                UseProxy = Device.Proxy != null,
                Proxy    = Device.Proxy
            };

            HttpClient = new HttpClient(handler);

            HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(Constants.ApiUserAgent);
            HttpClient.DefaultRequestHeaders.ExpectContinue = false;

            AccessToken   = accessToken;
            LoginProvider = loginProvider;
            Player        = new Player(this, geoCoordinate, playerLocale);
            Map           = new Map(this);
            Templates     = new Templates(this);
            RpcClient     = new RpcClient(this);
            _heartbeat    = new HeartbeatDispatcher(this);
        }
Пример #4
0
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="accessToken">The <see cref="AccessToken"/> you want to re-use.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static Session GetSession(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, GetPlayerMessage.Types.PlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            GetPlayerMessage.Types.PlayerLocale locale = playerLocale ?? new GetPlayerMessage.Types.PlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;

            if (accessToken.IsExpired)
            {
                accessToken = loginProvider.GetAccessToken(device.UserAgent, language).Result;
                //throw new ArgumentException($"{nameof(accessToken)} is expired.");
            }

            var session = new Session(loginProvider, accessToken, coordinate, device, locale);

            session.Logger.Debug("Authenticated from cache.");
            if (loginProvider is PtcLoginProvider)
            {
                session.Logger.Debug("Authenticated through PTC.");
            }
            else
            {
                session.Logger.Debug("Authenticated through Google.");
            }
            return(session);
        }
Пример #5
0
        public static ONT GetONT(DeviceWrapper device)
        {
            string ontId = "";
            switch (DeviceLogic.GetDeviceType(device))
            {
                case DeviceTypeEnum.ONT: ontId = device.DeviceId; break;
                case DeviceTypeEnum.ONTPort: ontId = DeviceLogic.DetermineONTSerial(ONTPortFactory.GetONTPort(device)); break;
            }

            if (!string.IsNullOrEmpty(ontId))
            {
                switch (DeviceLogic.GetONTType(device))
                {
                    case ONTType.SFU: return new SFUONT(device.DeviceId)
                    {
                        SerialNumber = device.DeviceId,
                        IsActive = device.DeviceStatus == "ACTIVE",
                        HeadendCode = device.Location.HeadendCode,
                        Model = device.DeviceModel,
                        DeviceType = device.DeviceType,
                        Status = device.DeviceStatus,
                        LocationId = device.LocationId,
                        UnitAddress = device.UnitAddress
                    };
                    case ONTType.MDU: return new MDUONT() { SerialNumber = device.DeviceId };

                    default: return null;
                    //TODO: Employ better construction encapsulation (i.e. common constructor args)
                }
            }
            else
                throw new ArgumentException("GONT136: Not a valid ONT Id");
        }
        //public static FiberDeviceConnectionHelper Instance(HookHelperExt hookHelper, ESRI.ArcGIS.Editor.IEditor editor)
        //{
        //    if(_instance != null)
        //    {
        //        return _instance;
        //    }
        //    else
        //    {
        //        _instance = new FiberDeviceConnectionHelper(hookHelper, editor);
        //        return _instance;
        //    }
        //}


        /// <summary>
        /// Returns cables which have an endpoint coincident with the device point
        /// </summary>
        /// <param name="deviceWrapper">Device to check</param>
        /// <returns>List of ConnectableCableWrapper</returns>
        public List <ConnectableCableWrapper> GetCoincidentCables(DeviceWrapper deviceWrapper)
        {
            List <ConnectableCableWrapper> result = new List <ConnectableCableWrapper>();

            if (null == deviceWrapper)
            {
                throw new ArgumentNullException("deviceWrapper");
            }

            ESRI.ArcGIS.Geometry.IPoint devicePoint = deviceWrapper.Feature.Shape as ESRI.ArcGIS.Geometry.IPoint;

            ESRI.ArcGIS.Carto.IFeatureLayer       cableLayer   = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName);
            ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cableLayer.FeatureClass;
            int displayIdx = cableFtClass.FindField(cableLayer.DisplayField);

            double buffer = _hookHelper.ConvertPixelsToMapUnits(1);
            List <ESRI.ArcGIS.Geodatabase.IFeature> coincidentCables = GdbUtils.GetLinearsWithCoincidentEndpoints(devicePoint, cableFtClass, buffer);

            for (int i = 0; i < coincidentCables.Count; i++)
            {
                ESRI.ArcGIS.Geodatabase.IFeature         ft          = coincidentCables[i];
                ESRI.ArcGIS.Geometry.IPolyline           line        = ft.Shape as ESRI.ArcGIS.Geometry.IPolyline;
                ESRI.ArcGIS.Geometry.IRelationalOperator lineToPoint = line.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                bool isFromEnd = true;
                if (lineToPoint.Equals(devicePoint))
                {
                    isFromEnd = false;
                }

                result.Add(new ConnectableCableWrapper(ft, isFromEnd, displayIdx));
            }

            return(result);
        }
        /// <summary>
        /// Resets the available range labels
        /// </summary>
        private void UpdateAvailableRanges()
        {
            List <Range> availableFrom = null;
            List <Range> availableTo   = null;

            // Get the ranges and connections based on whether we are port-strand or strand-port
            #region Determine Direction
            if (cboFrom.SelectedItem is FiberCableWrapper &&
                cboTo.SelectedItem is ConnectableDeviceWrapper)
            {
                FiberCableWrapper        cable  = (FiberCableWrapper)cboFrom.SelectedItem;
                ConnectableDeviceWrapper device = (ConnectableDeviceWrapper)cboTo.SelectedItem;

                availableFrom = SpliceAndConnectionUtils.GetAvailableRanges(cable, device.IsCableFromEnd);
                availableTo   = SpliceAndConnectionUtils.GetAvailableRanges(device, PortType.Input);
            }
            else if (cboFrom.SelectedItem is DeviceWrapper &&
                     cboTo.SelectedItem is ConnectableCableWrapper)
            {
                DeviceWrapper           device = (DeviceWrapper)cboFrom.SelectedItem;
                ConnectableCableWrapper cable  = (ConnectableCableWrapper)cboTo.SelectedItem;

                availableFrom = SpliceAndConnectionUtils.GetAvailableRanges(device, PortType.Output);
                availableTo   = SpliceAndConnectionUtils.GetAvailableRanges(cable, cable.IsThisFromEnd);
            }
            #endregion

            lblAvailableFrom.Text = GetAvailableRangesString(availableFrom);
            lblAvailableTo.Text   = GetAvailableRangesString(availableTo);
        }
        /// <summary>
        /// Determines if a device has any connections on its ports
        /// </summary>
        /// <param name="deviceWrapper">Device to check</param>
        /// <returns>True if any port is connected</returns>
        public static bool HasAnyConnections(DeviceWrapper deviceWrapper)
        {
//            int? inputPortCount = GdbUtils.GetDomainedIntName(deviceWrapper.Feature, ConfigUtil.InputPortsFieldName);
//            int? outputPortCount = GdbUtils.GetDomainedIntName(deviceWrapper.Feature, ConfigUtil.OutputPortsFieldName);

            int?inputPortCount  = deviceWrapper.inputPorts;
            int?outputPortCount = deviceWrapper.outputPorts;

            List <Range> ranges = null;

            bool isInputClear = true;

            if (null != inputPortCount && 0 < inputPortCount)
            {
                ranges       = GetAvailableRanges(deviceWrapper, PortType.Input);
                isInputClear = AreRangesWholeUnitCount(ranges, (int)inputPortCount);
            }

            bool isOutputClear = true;

            if (null != outputPortCount && 0 < outputPortCount)
            {
                ranges        = GetAvailableRanges(deviceWrapper, PortType.Output);
                isOutputClear = AreRangesWholeUnitCount(ranges, (int)outputPortCount);
            }

            // If either port type is not clear, there are connections
            return(!isInputClear || !isOutputClear);
        }
Пример #9
0
 public MultiFileInput(IEnumerable <string> files)
 {
     foreach (var file in files)
     {
         var inputDevice = new CaptureFileReaderDevice(file);
         inputDevice.Open();
         var wrapper = new DeviceWrapper(inputDevice);
         _devices[wrapper.Name] = wrapper;
     }
 }
Пример #10
0
 internal SFUONT(DeviceWrapper device)
 {
     if (device.DatabaseDataLoad)
     {
         PopulateFromDeviceWrapper(device);
     }
     else
     {
         PerformDeviceLoad(device.DeviceId);
     }
     TNManager = new OntTNManager(this);
 }
        /// <summary>
        /// Gets a list of all port numbers from a device that are not connected on the given end
        /// </summary>
        /// <param name="device">Device to check</param>
        /// <param name="portType">Check input or output ports</param>
        /// <returns>List of int</returns>
        private static List <int> GetOpenPorts(DeviceWrapper device, PortType portType)
        {
            #region Validation
            if (null == device)
            {
                throw new ArgumentNullException("device");
            }

            if (null == device.Feature)
            {
                throw new ArgumentException("device.Class cannot be null");
            }
            #endregion

            List <int> result = new List <int>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IFeatureClass      deviceFtClass  = device.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass;
                ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass);
                if (null != deviceHasPorts)
                {
                    ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable;
                    if (null != portTable)
                    {
                        ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                        releaser.ManageLifetime(filter);
                        filter.WhereClause = string.Format("{0}='{1}' AND {2} IS NULL AND {3}='{4}'",
                                                           deviceHasPorts.OriginForeignKey,
                                                           device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)),
                                                           ConfigUtil.ConnectedCableFieldName,
                                                           ConfigUtil.PortTypeFieldName,
                                                           (PortType.Input == portType ? "1" : "2"));

                        ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Search(filter, true);
                        ESRI.ArcGIS.Geodatabase.IRow    portRow    = portCursor.NextRow();
                        int portIdIdx = portTable.FindField(ConfigUtil.PortIdFieldName);

                        while (null != portRow)
                        {
                            result.Add((int)portRow.get_Value(portIdIdx));

                            ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow);
                            portRow = portCursor.NextRow();
                        }

                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portCursor);
                    }
                }
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// Login through OAuth with Google.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="initialLatitude">The initial latitude you will spawn at after logging into UniteGo.</param>
        /// <param name="initialLongitude">The initial longitude you will spawn at after logging into UniteGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, double initialLatitude, double initialLongitude, DeviceWrapper deviceWrapper = null, CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale locale = playerLocale ?? new CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;
            var    session  = new Session(loginProvider, await loginProvider.GetAccessToken(device.UserAgent, language), new GeoCoordinate(initialLatitude, initialLongitude), device, locale);

            session.Logger.Debug("Authenticated through Google.");
            return(session);
        }
        /// <summary>
        /// Update the dropdowns of features on the UI
        /// </summary>
        /// <param name="helper">Helper class</param>
        private void PopulateDropDowns(FiberDeviceConnectionHelper helper)
        {
            // Clear the existing choices
            cboFrom.Items.Clear();
            cboTo.Items.Clear();
            lblAvailableFrom.Text = "";
            lblAvailableTo.Text   = "";

            // Get the features and the display index for use when creating the wrapper
            ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName);
            int displayIdx = ftLayer.FeatureClass.FindField(ftLayer.DisplayField);

            // Get the selected features
            List <ESRI.ArcGIS.Geodatabase.IFeature> selectedFts = _hookHelper.GetSelectedFeatures(ftLayer);

            // Add each of the fiber features to the drop down
            for (int ftIdx = 0; ftIdx < selectedFts.Count; ftIdx++)
            {
                FiberCableWrapper w = new FiberCableWrapper(selectedFts[ftIdx], displayIdx);
                cboFrom.Items.Add(w);
            }

            // Now do that same thing for each of the device feature classes
            string[] deviceClassNames = ConfigUtil.DeviceFeatureClassNames;
            for (int deviceClassIdx = 0; deviceClassIdx < deviceClassNames.Length; deviceClassIdx++)
            {
                string ftClassName = deviceClassNames[deviceClassIdx];

                // Get the features and the display index for use when creating the wrapper
                ftLayer = _hookHelper.FindFeatureLayer(ftClassName);
                if (ftLayer != null) // what if layer removed from map
                {
                    selectedFts = _hookHelper.GetSelectedFeatures(ftLayer);

                    displayIdx = ftLayer.FeatureClass.FindField(ftLayer.DisplayField);

                    for (int ftIdx = 0; ftIdx < selectedFts.Count; ftIdx++)
                    {
                        DeviceWrapper w = new DeviceWrapper(selectedFts[ftIdx], displayIdx);
                        cboFrom.Items.Add(w);
                    }
                }
            }

            // Preselect the first choice
            if (0 < cboFrom.Items.Count)
            {
                cboFrom.SelectedItem = cboFrom.Items[0];
            }
        }
Пример #14
0
        private void DoSaveNewSchema()
        {
            Schema schema = new Schema(_selectedDevice);

            schema.ActionText = _selectedAction.Content.ToString();
            schema.TimePoint  = DateTime.Parse(_TextBoxTimePoint);
            Int32.TryParse(_selectedWeekday.Tag.ToString(), out int veckodag);
            schema.WeekDay = veckodag;
            DeviceWrapper wrapper = new DeviceWrapper(schema);

            MyDeviceWrapper.Add(wrapper);

            MyDeviceWrapper.OrderBy(p => p.TimePoint);

            TextBoxTimePoint = string.Empty;
        }
        /// <summary>
        /// Finds ranges of ports that are not yet connected
        /// </summary>
        /// <param name="device">Device to check for</param>
        /// <param name="portType">Check input ports or output ports?</param>
        /// <returns>List of Range</returns>
        public static List <Range> GetAvailableRanges(DeviceWrapper device, PortType portType)
        {
            if (null == device)
            {
                throw new ArgumentNullException("device");
            }

            List <int> openPorts = new List <int>();

            openPorts.AddRange(GetOpenPorts(device, portType));
            openPorts.Sort();

            List <Range> openRanges = MergeRanges(openPorts);

            return(openRanges);
        }
Пример #16
0
        public void SetSettings(Manager manager)
        {
            Settings      = manager.UserSettings;
            ClientManager = manager;

            int osId = OsVersions[Settings.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            Proxy = new ProxyEx
            {
                Address  = Settings.ProxyIP,
                Port     = Settings.ProxyPort,
                Username = Settings.ProxyUsername,
                Password = Settings.ProxyPassword
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId              = Settings.DeviceId,
                    DeviceBrand           = Settings.DeviceBrand,
                    DeviceModelBoot       = Settings.DeviceModelBoot,
                    HardwareModel         = Settings.HardwareModel,
                    HardwareManufacturer  = Settings.HardwareManufacturer,
                    FirmwareBrand         = Settings.FirmwareBrand,
                    FirmwareType          = Settings.FirmwareType,
                    AndroidBoardName      = Settings.AndroidBoardName,
                    AndroidBootloader     = Settings.AndroidBootloader,
                    DeviceModel           = Settings.DeviceModel,
                    DeviceModelIdentifier = Settings.DeviceModelIdentifier,
                    FirmwareFingerprint   = Settings.FirmwareFingerprint,
                    FirmwareTags          = Settings.FirmwareTags
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = Settings.Country,
                Language = Settings.Language,
                Timezone = Settings.TimeZone
            };
        }
Пример #17
0
        public RawCapture NextPacket()
        {
            PosixTimeval  timestamp = null;
            DeviceWrapper wrapper   = null;

            List <string> devNeedClose = null;

            foreach (var device in _devices.Values)
            {
                var currentPkt = device.CurrentPacket;
                if (currentPkt == null)
                {
                    if (devNeedClose == null)
                    {
                        devNeedClose = new List <string>();
                    }
                    devNeedClose.Add(device.Name);
                }
                else if (timestamp == null || currentPkt.Timeval < timestamp)
                {
                    timestamp = currentPkt.Timeval;
                    wrapper   = device;
                }
            }

            if (devNeedClose != null)
            {
                foreach (var name in devNeedClose)
                {
                    var d = _devices[name];
                    _devices.Remove(name);
                    d.Device.Close();
                }
            }

            if (wrapper == null)
            {
                return(null);
            }

            var pkt = wrapper.CurrentPacket;

            wrapper.NextPacket();

            return(pkt);
        }
        /// <summary>
        /// Determines if all given ranges are available (neither spliced nor connected)
        /// </summary>
        /// <param name="units">Units to check</param>
        /// <param name="cableWrapper">Device to check</param>
        /// <param name="isFromEnd">Flag of which port type we are checking</param>
        /// <returns>True if they are all available</returns>
        public static bool AreRangesAvailable(ICollection <int> units, DeviceWrapper deviceWrapper, PortType portType)
        {
            bool result = true;

            List <int> openPorts = GetOpenPorts(deviceWrapper, portType);

            foreach (int unit in units)
            {
                if (!openPorts.Contains(unit))
                {
                    result = false;
                    break;
                }
            }

            return(result);
        }
Пример #19
0
        ///////////////////////////////////////////////////////////////////////

        public void connect()
        {
            new Thread(delegate() {
                try {
                    switch (userInterface.cameraSelection)
                    {
                    case PixisDeviceUserControl.CameraSelection.North:
                        wrapper = new DeviceWrapper(0);
                        break;

                    case PixisDeviceUserControl.CameraSelection.East:
                        wrapper = new DeviceWrapper(1);
                        break;

                    default:
                        //error; this should never happen
                        userInterface.printMessage("Error: Invalid camera selection.\n");
                        return;
                    }
                    //    userInterface.printMessage("new DeviceWrapper: " + wrapper.ToString() + "\n");
                }
                catch (Exception e)
                {
                    //catch all
                    userInterface.printMessage("Failed to make DeviceWrapper\n");
                    MessageBox.Show("Failed to make DeviceWrapper: " + e.Message);
                    return;
                }

                installDelegates();

                deviceThread = new Thread(startDeviceWrapper);
//                deviceThread.IsBackground = true;

                if (!deviceThread.IsAlive)
                {
                    deviceThread.Start();
                }
                else
                {
                    MessageBox.Show("Cannot connect; device thread IsAlive already.");
                }
            }).Start();
        }
Пример #20
0
        public void SetSettings(Manager manager)
        {
            ClientManager = manager;

            Proxy = new ProxyEx
            {
                Address  = ClientManager.UserSettings.ProxyIP,
                Port     = ClientManager.UserSettings.ProxyPort,
                Username = ClientManager.UserSettings.ProxyUsername,
                Password = ClientManager.UserSettings.ProxyPassword
            };

            Dictionary <string, string> Header = new Dictionary <string, string>()
            {
                { "11.1.0", "CFNetwork/889.3 Darwin/17.2.0" },
                { "11.2.0", "CFNetwork/893.10 Darwin/17.3.0" },
                { "11.2.5", "CFNetwork/893.14.2 Darwin/17.4.0" }
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {Header[ClientManager.UserSettings.FirmwareType]}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId             = ClientManager.UserSettings.DeviceId,
                    DeviceBrand          = ClientManager.UserSettings.DeviceBrand,
                    DeviceModel          = ClientManager.UserSettings.DeviceModel,
                    DeviceModelBoot      = ClientManager.UserSettings.DeviceModelBoot,
                    HardwareManufacturer = ClientManager.UserSettings.HardwareManufacturer,
                    HardwareModel        = ClientManager.UserSettings.HardwareModel,
                    FirmwareBrand        = ClientManager.UserSettings.FirmwareBrand,
                    FirmwareType         = ClientManager.UserSettings.FirmwareType
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = ClientManager.UserSettings.Country,
                Language = ClientManager.UserSettings.Language,
                Timezone = ClientManager.UserSettings.TimeZone
            };
        }
Пример #21
0
        /// <summary>
        /// Login through OAuth with PTC / Google.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, GetPlayerMessage.Types.PlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            GetPlayerMessage.Types.PlayerLocale locale = playerLocale ?? new GetPlayerMessage.Types.PlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;
            var    session  = new Session(loginProvider, await loginProvider.GetAccessToken(device.UserAgent, language), coordinate, device, locale);

            if (loginProvider is PtcLoginProvider)
            {
                session.Logger.Debug("Authenticated through PTC.");
            }
            else
            {
                session.Logger.Debug("Authenticated through Google.");
            }
            return(session);
        }
Пример #22
0
        public void SetSettings(ISettings settings)
        {
            Settings = settings;

            int osId = OsVersions[Settings.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId              = Settings.DeviceId,
                    DeviceBrand           = Settings.DeviceBrand,
                    DeviceModelBoot       = Settings.DeviceModelBoot,
                    HardwareModel         = Settings.HardwareModel,
                    HardwareManufacturer  = Settings.HardwareManufacturer,
                    FirmwareBrand         = Settings.FirmwareBrand,
                    FirmwareType          = Settings.FirmwareType,
                    AndroidBoardName      = Settings.AndroidBoardName,
                    AndroidBootloader     = Settings.AndroidBootloader,
                    DeviceModel           = Settings.DeviceModel,
                    DeviceModelIdentifier = Settings.DeviceModelIdentifier,
                    FirmwareFingerprint   = Settings.FirmwareFingerprint,
                    FirmwareTags          = Settings.FirmwareTags
                }
            };

            Proxy = new ProxyEx
            {
                Address  = Settings.ProxyIP,
                Port     = Settings.ProxyPort,
                Username = Settings.ProxyUsername,
                Password = Settings.ProxyPassword
            };

            LocaleInfo = new ILocaleInfo();
            LocaleInfo.SetValues(Settings.Country, Settings.Language, Settings.TimeZone);
            Configuration.LocaleInfo = LocaleInfo;
        }
        /// <summary>
        /// Gets the connections for the current combo drop down status
        /// </summary>
        private List <Connection> getConnections()
        {
            List <Connection> connections = null;

            if (cboFrom.SelectedItem is FiberCableWrapper &&
                cboTo.SelectedItem is ConnectableDeviceWrapper)
            {
                FiberCableWrapper        cable  = (FiberCableWrapper)cboFrom.SelectedItem;
                ConnectableDeviceWrapper device = (ConnectableDeviceWrapper)cboTo.SelectedItem;
                connections = _connectionHelper.GetConnections(cable, device, device.IsCableFromEnd, PortType.Input);
            }
            else if (cboFrom.SelectedItem is DeviceWrapper &&
                     cboTo.SelectedItem is ConnectableCableWrapper)
            {
                DeviceWrapper           device = (DeviceWrapper)cboFrom.SelectedItem;
                ConnectableCableWrapper cable  = (ConnectableCableWrapper)cboTo.SelectedItem;
                connections = _connectionHelper.GetConnections(cable, device, cable.IsThisFromEnd, PortType.Output);
            }

            return(connections);
        }
Пример #24
0
        public ModelBrowser(DeviceWrapper device)
        {
            this.device  = device;
            FormClosing += (_, __) => { __.Cancel = true; Hide(); };
            InitializeComponent();
            Shown += (_, __) =>
            {
                RunLoop();
                Render();
            };

            MouseWheel += (_, __) =>
            {
                if (Level.modelIDs.Count == 0)
                {
                    return;
                }
                if (current != null)
                {
                    current.MakeInvisible(renderer);
                }
                if (__.Delta > 0)
                {
                    while (!Level.modelIDs.TryGetValue((byte)(currentIndex = (currentIndex + 1) % 256), out current))
                    {
                        ;
                    }
                }
                else
                {
                    while (!Level.modelIDs.TryGetValue((byte)(currentIndex = (currentIndex + 255) % 256), out current))
                    {
                        ;
                    }
                }
                current.MakeVisible(renderer);
                lblModelID.Text = "Model ID: 0x" + currentIndex.ToString("X2") + " (" + currentIndex.ToString() + ")";
                needsRefresh    = true;
            };
        }
Пример #25
0
        public void SetSettings(Manager manager)
        {
            ClientManager = manager;

            int osId = OsVersions[ClientManager.UserSettings.DeviceInfo.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            Proxy = new ProxyEx
            {
                Address  = ClientManager.UserSettings.ProxyIP,
                Port     = ClientManager.UserSettings.ProxyPort,
                Username = ClientManager.UserSettings.ProxyUsername,
                Password = ClientManager.UserSettings.ProxyPassword
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId             = ClientManager.UserSettings.DeviceInfo.DeviceId,
                    DeviceBrand          = ClientManager.UserSettings.DeviceInfo.DeviceBrand,
                    DeviceModel          = ClientManager.UserSettings.DeviceInfo.DeviceModel,
                    DeviceModelBoot      = ClientManager.UserSettings.DeviceInfo.DeviceModelBoot,
                    HardwareManufacturer = ClientManager.UserSettings.DeviceInfo.HardwareManufacturer,
                    HardwareModel        = ClientManager.UserSettings.DeviceInfo.HardwareModel,
                    FirmwareBrand        = ClientManager.UserSettings.DeviceInfo.FirmwareBrand,
                    FirmwareType         = ClientManager.UserSettings.DeviceInfo.FirmwareType
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = ClientManager.UserSettings.PlayerLocale.Country,
                Language = ClientManager.UserSettings.PlayerLocale.Language,
                Timezone = ClientManager.UserSettings.PlayerLocale.Timezone
            };
        }
Пример #26
0
        private void RunLoop(object sender, EventArgs e)
        {
            device = new DeviceWrapper();
            if (!device.Init(this))
            {
                MessageBox.Show("Unable to create Direct3D device!");
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
            device.device.DeviceResizing += CreatePickSurface;
            CreatePickSurface(null, null);
            Level.renderDevice = device;
            Level.renderer     = new Renderer(Level.renderDevice);

            toolBox = new ToolBox(this);
            toolBox.Show();
            modelBrowser = new ModelBrowser(device);

            logWindow     = new LogWindow();
            levelSettings = new LevelSettingsDialog();

            EmulationState.messages = logWindow;

            openToolStripMenuItem_Click(null, null);

            Stopwatch tm        = new Stopwatch();
            float     frameTime = 0;

            while (Created)
            {
                tm.Reset();
                tm.Start();
                UpdateFrame(frameTime);
                DrawFrame();
                System.Threading.Thread.Sleep(1);
                Application.DoEvents();
                tm.Stop();
                frameTime = (float)tm.ElapsedTicks / Stopwatch.Frequency;
            }
        }
Пример #27
0
        private List <DeviceWrapper> GetAllFakeItems()
        {
            List <DeviceWrapper> wrapper = new List <DeviceWrapper>();

            List <Device> someDevices = GetDevices();

            int n = 1;

            foreach (Device d in someDevices)
            {
                Schema schema = null;
                if (n % 2 == 0)
                {
                    schema = new Schema(d)
                    {
                        ActionText = "ON", TimePoint = DateTime.Now.Add(new TimeSpan(1, 1, 1, 1, 1)), WeekDay = 1
                    }
                }
                ;
                else
                {
                    schema = new Schema(d)
                    {
                        ActionText = "OFF", TimePoint = DateTime.Now.Add(new TimeSpan(-1, 1, -1, 1, -1)), WeekDay = 2
                    }
                };

                DeviceWrapper wrp = new DeviceWrapper(schema);

                wrapper.Add(wrp);
                n++;
            }



            return(wrapper);
        }
Пример #28
0
        private void SetSettings()
        {
            int osId = OsVersions[UserSettings.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId              = UserSettings.DeviceId,
                    DeviceBrand           = UserSettings.DeviceBrand,
                    DeviceModelBoot       = UserSettings.DeviceModelBoot,
                    HardwareModel         = UserSettings.HardwareModel,
                    HardwareManufacturer  = UserSettings.HardwareManufacturer,
                    FirmwareBrand         = UserSettings.FirmwareBrand,
                    FirmwareType          = UserSettings.FirmwareType,
                    AndroidBoardName      = UserSettings.AndroidBoardName,
                    AndroidBootloader     = UserSettings.AndroidBootloader,
                    DeviceModel           = UserSettings.DeviceModel,
                    DeviceModelIdentifier = UserSettings.DeviceModelIdentifier,
                    FirmwareFingerprint   = UserSettings.FirmwareFingerprint,
                    FirmwareTags          = UserSettings.FirmwareTags
                },
                //TODO: New in pogolib need port and user data!
                //ProxyAddress = UserSettings.ProxyIP
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = UserSettings.Country,
                Language = UserSettings.Language,
                Timezone = UserSettings.TimeZone
            };
        }
Пример #29
0
 /// <summary>
 /// Login through OAuth with PTC / Google.
 /// </summary>
 /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
 /// <param name="initialLatitude">The initial latitude you will spawn at after logging into PokémonGo.</param>
 /// <param name="initialLongitude">The initial longitude you will spawn at after logging into PokémonGo.</param>
 /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
 /// <returns></returns>
 public static async Task <Session> GetSession(ILoginProvider loginProvider, double initialLatitude, double initialLongitude, DeviceWrapper deviceWrapper = null)
 {
     return(new Session(loginProvider, await loginProvider.GetAccessToken(), new GeoCoordinate(initialLatitude, initialLongitude), deviceWrapper));
 }
Пример #30
0
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider"></param>
        /// <param name="accessToken"></param>
        /// <param name="initialLatitude">The initial latitude you will spawn at after logging into PokémonGo.</param>
        /// <param name="initialLongitude">The initial longitude you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <returns></returns>
        public static Session GetSession(ILoginProvider loginProvider, AccessToken accessToken, double initialLatitude, double initialLongitude, DeviceWrapper deviceWrapper = null)
        {
            if (accessToken.IsExpired)
            {
                throw new Exception("AccessToken is expired.");
            }

            Logger.Debug("Authenticated from cache.");

            return(new Session(loginProvider, accessToken, new GeoCoordinate(initialLatitude, initialLongitude), deviceWrapper));
        }
Пример #31
0
 internal void AssignBaseProperties(DeviceWrapper device)
 {
     this.SerialNumber = device.DeviceId;
     this.Model = device.DeviceModel;
     this.Status = device.DeviceStatus;
     this.DeviceType = device.DeviceType;
     this.HeadendCode = device.Location.HeadendCode;
     this.IsActive = device.DeviceStatus == "ACTIVE";
     this.LocationId = device.Location.LocationId;
     this._associatedSubscriberId = device.Location.SubscriberId;
     this.UnitAddress = device.UnitAddress;
 }
Пример #32
0
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="accessToken">The <see cref="AccessToken"/> you want to re-use.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <returns></returns>
        public static Session GetSession(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null)
        {
            if (accessToken.IsExpired)
            {
                throw new ArgumentException($"{nameof(accessToken)} is expired.");
            }

            Logger.Debug("Authenticated from cache.");
            return(new Session(loginProvider, accessToken, coordinate, deviceWrapper));
        }
Пример #33
0
 private void PopulateFromDeviceWrapper(DeviceWrapper device)
 {
     base.AssignBaseProperties(device);
     if (device.Location != null && !string.IsNullOrEmpty(device.Location.SubscriberId))
     {
         this.LoadAndSetPortsList();
     }
 }
Пример #34
0
        protected override bool PerformDeviceLoad(string deviceId)
        {
            string ontSerial = "";

            // We can only build an ONT off of an ONT serial number or ONT Port serial number
            switch (DeviceLogic.GetDeviceTypeById(deviceId))
            {
                case DeviceTypeEnum.ONT: ontSerial = deviceId; break;
                case DeviceTypeEnum.ONTPort: ontSerial = DeviceLogic.DetermineONTSerial(deviceId); break;
                default: throw new ArgumentException("OPDL139: Invalid ONT Id or ONT Port Id. Can't create object.");
            }

            // Now that we have the serial number, perform the magnum search for the ONT and related ports
            SearchWrapper s = new SearchWrapper();
            s.SearchByDevice = new DeviceSearchWrapper();
            s.SearchByDevice.DeviceId = ontSerial;
            s.SearchType = SearchTypeEnum.SearchByDevice;
            List<SearchWrapper> results = null;
            DeviceWrapper device = new DeviceWrapper() { DeviceId = ontSerial };
            using (_magnumProxy = new MagnumProxy())
            {
                results = _magnumProxy.Client.Search(s, CurrentUser.AsRosettianUser().Name).ToList();
            }

            if (results.Count > 0)
            {
                // Using the results, assign values to the properties of our ONT object
                try
                {
                    PopulateFromSearchResults(results);
                }
                catch (ArgumentException)
                {
                    // do nothing (omits bad port from list of ports)
                }

                DeviceLoaded = true;
            }
            return DeviceLoaded;
        }
Пример #35
0
 public static void Save(IValueSink sink, DeviceWrapper value)
 {
     Value<ObjectId>.Save(sink, value.Item);
 }
Пример #36
0
 /// <summary>
 /// Login through OAuth with PTC / Google.
 /// </summary>
 /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
 /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
 /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
 /// <returns></returns>
 public static async Task <Session> GetSession(ILoginProvider loginProvider, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null)
 {
     return(new Session(loginProvider, await loginProvider.GetAccessToken(), coordinate, deviceWrapper));
 }
Пример #37
0
        protected void LoadAndSetPortsList(List<SearchWrapper> results = null)
        {
            Boolean proceed = false;
            List<ONTPort> portList = new List<ONTPort>();

            // Create search objects
            //magnumHelper = new MagnumHelper();
            SearchWrapper srch = new SearchWrapper();
            srch.SearchByDevice = new DeviceSearchWrapper();
            srch.SearchType = SearchTypeEnum.SearchByDevice;

            // Determine Root ONT Serial number
            switch (DeviceLogic.GetDeviceTypeById(SerialNumber))
            {
                case DeviceTypeEnum.ONT:
                    {
                        proceed = true; // set proceed flag
                        srch.SearchByDevice.DeviceId = SerialNumber + "%"; // search for all ports for this ONT
                        break;
                    }
                case DeviceTypeEnum.ONTPort:
                    {
                        proceed = true; // set proceed flag
                        // get ONT serial from port ID, then get associated ports from Triad
                        srch.SearchByDevice.DeviceId = DeviceLogic.DetermineONTSerial(SerialNumber + "%");
                        break;
                    }
                default: break;
            }

            if (proceed)
            {
                // initialize individual portType lists (allows sorting into logical order --> voice, data, video
                List<ONTPort> voicePorts = new List<ONTPort>();
                List<ONTPort> dataPorts = new List<ONTPort>();
                List<ONTPort> mocaPorts = new List<ONTPort>();
                List<ONTPort> videoPorts = new List<ONTPort>();
                DeviceWrapper dev = new DeviceWrapper();
                SubscriberWrapper sub = new SubscriberWrapper();

                using (_magnumProxy = new MagnumProxy())
                {
                    // if no search wrapper was passed in, perform our own search
                    if (results == null)
                    {
                        results = _magnumProxy.Client.Search(srch, CurrentUser.AsRosettianUser().Name).ToList();
                    }

                    if (results.Count > 0)
                    {
                        dev = _magnumProxy.Client.LoadDevice(results[0].SearchByDevice.DeviceId, CurrentUser.AsRosettianUser().Name);
                    }
                }

                // once we have a definite result set, parse out the ports, assign the type and property values
                // from the search results
                foreach (SearchWrapper wrapper in results)
                {
                    ONTPort port = null;
                    // double check that we are working with an ONT Port
                    if (DeviceLogic.GetDeviceTypeById(wrapper.SearchByDevice.DeviceId) == DeviceTypeEnum.ONTPort)
                    {
                        // get new port from factory and add to correct type list
                        port = ONTPortFactory.GetONTPort(wrapper.SearchByDevice);
                        switch (port.PortType)
                        {
                            case ONTPortTypeEnum.Ethernet: dataPorts.Add(port); break;
                            case ONTPortTypeEnum.Moca: mocaPorts.Add(port); break;
                            case ONTPortTypeEnum.Video: videoPorts.Add(port); break;
                            case ONTPortTypeEnum.Voice: voicePorts.Add(port); break;
                        }
                    }
                }

                // internally order all port lists
                voicePorts = voicePorts.OrderBy(p => p.SerialNumber).ToList();
                dataPorts = dataPorts.OrderBy(p => p.SerialNumber).ToList();
                videoPorts = videoPorts.OrderBy(p => p.SerialNumber).ToList();
                mocaPorts = mocaPorts.OrderBy(p => p.SerialNumber).ToList();

                // add to main list in order of precedence
                portList.AddRange(voicePorts);
                portList.AddRange(dataPorts);
                portList.AddRange(videoPorts);
                portList.AddRange(mocaPorts);
            }

            Ports = portList;
        }