private async Task UninstallAppAsync(AppInfo appInfo, string packageFamilyId, string packageFamilyName)
        {
            Logger.Log("Processing uninstall request...", LoggingLevel.Verbose);

            AppxManagementDataContract.AppReportedState reportedState = null;
            try
            {
                Windows.ApplicationModel.PackageId thisPackage = Windows.ApplicationModel.Package.Current.Id;
                Debug.WriteLine("FamilyName = " + thisPackage.FamilyName);
                Debug.WriteLine("Name       = " + thisPackage.Name);

                if (packageFamilyName == thisPackage.FamilyName)
                {
                    throw new Error(ErrorCodes.CANNOT_UNINSTALL_DM_APPLICATION, "Cannot uninstall the DM application: " + thisPackage.FamilyName);
                }

                // ToDo: We need to handle store and system apps too.
                AppUninstallResponse response = await UninstallAppAsync(new AppUninstallRequestData(packageFamilyName, false /*non-store app*/));

                reportedState = new AppxManagementDataContract.AppReportedState(packageFamilyId,
                                                                                packageFamilyName,
                                                                                AppxManagementDataContract.VersionNotInstalled,
                                                                                AppxStartUpType.None,
                                                                                null, // no install date
                                                                                0,    // no error
                                                                                null,
                                                                                JsonReport.Report);
                _stateToReport[packageFamilyId] = reportedState;
                return;
            }
            catch (Error e)
            {
                reportedState = new AppxManagementDataContract.AppReportedState(packageFamilyId,
                                                                                packageFamilyName,
                                                                                appInfo.Version,
                                                                                AppUtils.StartUpTypeFromMessage(appInfo.StartUp),
                                                                                appInfo.InstallDate,
                                                                                e.HResult,
                                                                                e.Message,
                                                                                JsonReport.Report);
            }
            catch (Exception e)
            {
                reportedState = new AppxManagementDataContract.AppReportedState(packageFamilyId,
                                                                                packageFamilyName,
                                                                                appInfo.Version,
                                                                                AppUtils.StartUpTypeFromMessage(appInfo.StartUp),
                                                                                appInfo.InstallDate,
                                                                                e.HResult,
                                                                                e.Message,
                                                                                JsonReport.Report);
            }
            _stateToReport[packageFamilyId] = reportedState;
            throw new Exception("Failed to uninstall " + packageFamilyName);
        }
Esempio n. 2
0
 public void PageRefresh()
 {
     Windows.ApplicationModel.Package        ThisPackage = Windows.ApplicationModel.Package.Current;
     Windows.ApplicationModel.PackageId      ThisId      = ThisPackage.Id;
     Windows.ApplicationModel.PackageVersion ThisVersion = ThisId.Version;
     NameOfApp.Text    = ThisPackage.DisplayName;
     VersionOfApp.Text = String.Format("版本: {0}.{1}.{2}.{3} [{4}]",
                                       ThisVersion.Major, ThisVersion.Minor, ThisVersion.Build, ThisVersion.Revision,
                                       ThisId.Architecture);
     InstalledDateOfApp.Text = Windows.ApplicationModel.Package.Current.InstalledDate.ToString("安装日期: yyyy-MM-dd");
     Debug.WriteLine("刷新了" + this.GetType().ToString() + "的内容");
 }
Esempio n. 3
0
        public Adapter()
        {
            byte[] ConfigurationDataPtr;
            if (GetConfiguration(out ConfigurationDataPtr) == ERROR_SUCCESS)
            {
                var temp = System.Text.Encoding.UTF8.GetString(ConfigurationDataPtr);
                m_gateway = new ModbusGateway(System.Text.Encoding.UTF8.GetString(ConfigurationDataPtr));  // The Designated IP address of the Modbus Gateway
            }

            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.Vendor      = "Microsoft";
            this.AdapterName = "Modbus Device System Bridge";

            // the adapter prefix must be something like "com.mycompany" (only alpha num and dots)
            // it is used by the Device System Bridge as root string for all services and interfaces it exposes
            this.ExposedAdapterPrefix   = "com." + this.Vendor.ToLower();
            this.ExposedApplicationGuid = Guid.Parse("{0xd3982475,0x38eb,0x4e53,{0xb8,0xd8,0x54,0x04,0xd8,0x78,0x88,0x1a}}");

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = "ModbusDeviceSystemBridge";
                this.Version = "0.0.0.0";
            }

            try
            {
                this.Signals         = new List <IAdapterSignal>();
                this.devices         = new List <IAdapterDevice>();
                this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();

                //Create Adapter Signals
                this.createSignals();
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
Esempio n. 4
0
        public Adapter()
        {
            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.Vendor      = "Morten Nielsen";
            this.AdapterName = "Philips Hue DSB";

            // the adapter prefix must be something like "com.mycompany" (only alpha num and dots)
            // it is used by the Device System Bridge as root string for all services and interfaces it exposes
            this.ExposedAdapterPrefix   = "com.dotMorten";
            this.ExposedApplicationGuid = Guid.Parse("{0x07c19f14,0x76c6,0x4d2f,{0xb4,0xd1,0x7d,0x4f,0x89,0x24,0x17,0x36}}");

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = "PhilipsHueDeviceSystemBridge";
                this.Version = "0.0.0.0";
            }

            try
            {
                this.Signals         = new List <IAdapterSignal>();
                this.devices         = new List <IAdapterDevice>();
                this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();

                //var EnableJoinMethod = new AdapterMethod("Find Hue Bridges", "Searches for new hue bridges", 0);
                //EnableJoinMethod.InvokeAction = LoadBridges;

                //Create Adapter Signals
                this.createSignals();

                checkForBridgesTimer = new System.Threading.Timer((s) => { LoadBridges(); }, null,
                                                                  0, (int)TimeSpan.FromMinutes(5).TotalMilliseconds);
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
        }
Esempio n. 5
0
        public BridgeAdapter(string adapterName)
        {
            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.Vendor      = "win10";
            this.AdapterName = adapterName;

            // the adapter prefix must be something like "com.mycompany" (only alpha num and dots)
            // it is used by the Device System Bridge as root string for all services and interfaces it exposes
            this.ExposedAdapterPrefix   = "com." + this.Vendor.ToLower();
            this.ExposedApplicationGuid = Guid.Parse("{0x6516a3e3,0xcc3e,0x4c67,{0xb7,0x5f,0x73,0x75,0x8b,0x09,0x23,0xae}}");

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = "DeviceSystemBridge";
                this.Version = "0.0.0.0";
            }

            this.Signals         = new List <IAdapterSignal>();
            this.devices         = new List <IAdapterDevice>();
            this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();

            // Device Arrival Signal
            var deviceArrivalSignal  = new BridgeAdapterSignal(Constants.DEVICE_ARRIVAL_SIGNAL);
            var deviceHandle_arrival = new BridgeAdapterValue(Constants.DEVICE_ARRIVAL__DEVICE_HANDLE, null);

            deviceArrivalSignal.Params.Add(deviceHandle_arrival);
            this.Signals.Add(deviceArrivalSignal);

            // Device Removal Signal
            var deviceRemovalSignal  = new BridgeAdapterSignal(Constants.DEVICE_REMOVAL_SIGNAL);
            var deviceHandle_removal = new BridgeAdapterValue(Constants.DEVICE_REMOVAL__DEVICE_HANDLE, null);

            deviceRemovalSignal.Params.Add(deviceHandle_removal);
            this.Signals.Add(deviceRemovalSignal);
        }
Esempio n. 6
0
        public Adapter()
        {
            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.DeviceName  = GetDeviceName();
            this.Vendor      = "glovebox";
            this.AdapterName = "rover";

            // the adapter prefix must be something like "com.mycompany" (only alpha num and dots)
            // it is used by the Device System Bridge as root string for all services and interfaces it exposes
            this.ExposedAdapterPrefix   = "com." + this.Vendor.ToLower();
            this.ExposedApplicationGuid = Guid.Parse("{0xc1e7ce4a,0x66fb,0x40e6,{0xb4,0xb7,0x74,0x2b,0x88,0x71,0x83,0x27}}");

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = "DeviceSystemBridge";
                this.Version = "0.0.0.0";
            }

            try
            {
                this.Signals         = new List <IAdapterSignal>();
                this.devices         = new List <IAdapterDevice>();
                this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();

                //Create Adapter Signals
                this.createSignals();
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
Esempio n. 7
0
        public Adapter()
        {
            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.Vendor      = VENDOR_NAME;
            this.AdapterName = ADAPTER_NAME;

            this.ExposedAdapterPrefix   = ADAPTER_PREFIX + this.Vendor.ToLower();
            this.ExposedApplicationGuid = Guid.Parse(APLICATION_GUID);

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = EXPOSED_APPLICATION_NAME;
                this.Version = VERSION_NUMBER;
            }

            try
            {
                this.Signals         = new List <IAdapterSignal>();
                this.devices         = new List <IAdapterDevice>();
                this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();

                //Create Adapter Signals
                this.createSignals();
            }
            catch (OutOfMemoryException ex)
            {
                Debug.WriteLine("Out of memory while trying to allocate adapter value parameter containers." + ex.Message);
                throw;
            }
        }
Esempio n. 8
0
        public Adapter()
        {
            Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
            Windows.ApplicationModel.PackageId      packageId      = package.Id;
            Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;

            this.Vendor      = AdapterHelper.ADAPTER_VENDOR;
            this.AdapterName = AdapterHelper.ADAPTER_NAME;

            // the adapter prefix must be something like "com.mycompany" (only alpha num and dots)
            // it is used by the Device System Bridge as root string for all services and interfaces it exposes
            this.ExposedAdapterPrefix   = AdapterHelper.ADAPTER_DOMAIN + "." + this.Vendor.ToLower();
            this.ExposedApplicationGuid = Guid.Parse(AdapterHelper.ADAPTER_APPLICATION_GUID);

            if (null != package && null != packageId)
            {
                this.ExposedApplicationName = packageId.Name;
                this.Version = versionFromPkg.Major.ToString() + "." +
                               versionFromPkg.Minor.ToString() + "." +
                               versionFromPkg.Revision.ToString() + "." +
                               versionFromPkg.Build.ToString();
            }
            else
            {
                this.ExposedApplicationName = AdapterHelper.ADAPTER_DEFAULT_APPLICATION_NAME;
                this.Version = AdapterHelper.ADAPTER_DEFAULT_VERSION;
            }

            try
            {
                this.Signals           = new List <IAdapterSignal>();
                this.m_signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >();
            }
            catch (OutOfMemoryException ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
Esempio n. 9
0
 private PackageId(Windows.ApplicationModel.PackageId packageId)
 {
     _packageId = packageId;
 }
Esempio n. 10
0
 public KnxAdapter() : base("KnxNetIP")
 {
     Windows.ApplicationModel.Package        package        = Windows.ApplicationModel.Package.Current;
     Windows.ApplicationModel.PackageId      packageId      = package.Id;
     Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version;
 }
        private async Task <CommandStatus> InstallAppAsync(
            AppInfo installedAppInfo,
            Version installedAppVersion,
            string connectionString,
            IDictionary <string, AppInfo> installedApps,
            AppxManagementDataContract.AppDesiredState desiredState)
        {
            Logger.Log("Processing install request for " + desiredState.packageFamilyId, LoggingLevel.Verbose);

            if (installedAppInfo == null)
            {
                // It is a new application.
                Logger.Log("    Can't find an installed version... Installing a fresh copy...", LoggingLevel.Verbose);
                await InstallAppFromAzureAsync(installedAppInfo, connectionString, desiredState, false /*not self update*/);       // ---> InstallAppFromAzureAsync
            }
            else
            {
                Windows.ApplicationModel.PackageId thisPackage = Windows.ApplicationModel.Package.Current.Id;
                Debug.WriteLine("FamilyName = " + thisPackage.FamilyName);
                Debug.WriteLine("Name       = " + thisPackage.Name);

                bool isSelf = desiredState.packageFamilyName == thisPackage.FamilyName;

                // A version of this application is installed.
                Logger.Log("    Found an installed version...", LoggingLevel.Verbose);

                if (desiredState.version == installedAppVersion)
                {
                    Logger.Log("        Same version is installed...", LoggingLevel.Verbose);
                    AppxManagementDataContract.AppReportedState appReportedState = null;

                    if (AppUtils.StartUpTypeToMessage(desiredState.startUp) == installedAppInfo.StartUp)
                    {
                        Logger.Log("        App StartUp is the same: desired = " + desiredState.startUp, LoggingLevel.Verbose);

                        appReportedState = new AppxManagementDataContract.AppReportedState(
                            desiredState.packageFamilyId,
                            desiredState.packageFamilyName,
                            installedAppVersion.ToString(),
                            AppUtils.StartUpTypeFromMessage(installedAppInfo.StartUp),
                            installedAppInfo.InstallDate,
                            0,
                            null,                 // no error
                            JsonReport.Report);
                    }
                    else
                    {
                        Logger.Log("        App StartUp is different: desired = " + desiredState.startUp.ToString() + ", current = " + installedAppInfo.StartUp.ToString(), LoggingLevel.Verbose);

                        switch (desiredState.startUp)
                        {
                        case AppxStartUpType.None:
                        {
                            bool background = installedAppInfo.StartUp == StartUpType.Background;
                            if (background)
                            {
                                Logger.Log("            Removing app from background apps.", LoggingLevel.Verbose);
                                StartupAppInfo startupAppInfo = new StartupAppInfo(desiredState.packageFamilyName, background);
                                await RemoveStartupAppAsync(startupAppInfo);
                            }
                            else
                            {
                                Logger.Log("            App is no longer marked to be start-up app. Change takes effect when another app is set to be the start-up app.", LoggingLevel.Verbose);
                            }
                        }
                        break;

                        case AppxStartUpType.Foreground:
                        {
                            Logger.Log("            Setting app to be the foreground app.", LoggingLevel.Verbose);
                            StartupAppInfo startupAppInfo = new StartupAppInfo(desiredState.packageFamilyName, false /*background*/);
                            await AddStartupAppAsync(startupAppInfo);
                        }
                        break;

                        case AppxStartUpType.Background:
                        {
                            Logger.Log("            Adding app to the background apps.", LoggingLevel.Verbose);
                            StartupAppInfo startupAppInfo = new StartupAppInfo(desiredState.packageFamilyName, true /*background*/);
                            await AddStartupAppAsync(startupAppInfo);
                        }
                        break;
                        }

                        AppxStartUpType appStartUp = await GetAppStartup(desiredState.packageFamilyName);

                        Logger.Log("            Querying returned app startup: " + appStartUp.ToString(), LoggingLevel.Verbose);

                        appReportedState = new AppxManagementDataContract.AppReportedState(
                            desiredState.packageFamilyId,
                            desiredState.packageFamilyName,
                            installedAppVersion.ToString(),
                            appStartUp,
                            installedAppInfo.InstallDate,
                            0,
                            null,                 // no error
                            JsonReport.Report);
                    }

                    _stateToReport[desiredState.packageFamilyId] = appReportedState;
                }
                else if (desiredState.version > installedAppVersion)
                {
                    Logger.Log("        Older version is installed...", LoggingLevel.Verbose);

                    if (!String.IsNullOrEmpty(desiredState.appxSource))
                    {
                        // Trigger the update...
                        await InstallAppFromAzureAsync(installedAppInfo, connectionString, desiredState, isSelf);

                        if (isSelf)
                        {
                            // If isSelf == true, it means that SystemConfigurator will force this application to exit very soon.
                            // Let's stop processing any further desired properties.
                            return(CommandStatus.PendingDMAppRestart);
                        }
                    }
                    else
                    {
                        // Note that store updates are not control through DM desired properties.
                        // Instead, they are triggered by the system scan for all store applications.
                        throw new Error(ErrorCodes.INVALID_DESIRED_APPX_SRC, "Appx package is required to update " + desiredState.packageFamilyName);
                    }
                }
                else
                {
                    // desiredState.version < installedAppVersion
                    Logger.Log("       Newer version is installed...rolling back.", LoggingLevel.Verbose);

                    if (String.IsNullOrEmpty(desiredState.appxSource))
                    {
                        AppxManagementDataContract.AppReportedState appReportedState = new AppxManagementDataContract.AppReportedState(
                            desiredState.packageFamilyId,
                            desiredState.packageFamilyName,
                            installedAppVersion.ToString(),
                            AppUtils.StartUpTypeFromMessage(installedAppInfo.StartUp),
                            installedAppInfo.InstallDate,
                            ErrorCodes.INVALID_DESIRED_APPX_SRC,
                            "Cannot install appx without a source.",
                            JsonReport.Report);

                        _stateToReport[desiredState.packageFamilyId] = appReportedState;

                        throw new Exception("Failed to roll back application version.");
                    }

                    if (isSelf)
                    {
                        // The reverting is implemented as an 'uninstall' followed by an 'install'.
                        // The package to be installed is downloaded in the 'install' step.
                        // So, if we were to revert self to an older version, we would have to:
                        //  - (1) download the old version first,
                        //  - (2) send an atomic uninstall-install request to SystemConfigurator to
                        //        uninstall and follow with an install and re-launch.
                        //  The above two steps are not implemented yet.
                        throw new Error(ErrorCodes.CANNOT_REVERT_DM_APPLICATION, "Reverting to an older version of the device management application (" + desiredState.packageFamilyName + ") is not supported.");
                    }
                    // Note that UninstallAppAsync will throw if it fails - and correctly avoid launching the install...
                    await UninstallAppAsync(installedAppInfo,
                                            packageFamilyId : desiredState.packageFamilyId,
                                            packageFamilyName : desiredState.packageFamilyName);
                    await InstallAppFromAzureAsync(installedAppInfo, connectionString, desiredState, isSelf);
                }
            }

            return(CommandStatus.Committed);
        }
Esempio n. 12
0
 public static Windows.ApplicationModel.PackageVersion GetAppVersion()
 {
     Windows.ApplicationModel.Package   package   = Windows.ApplicationModel.Package.Current;
     Windows.ApplicationModel.PackageId packageId = package.Id;
     return(packageId.Version);
 }
Esempio n. 13
0
 private PackageId(Windows.ApplicationModel.PackageId packageId)
 {
     _packageId = packageId;
 }