private async void PickAPackageFileButton_Click(object sender, RoutedEventArgs e) { //Get package and cert files and location PackageFolder = null; Dependencies = new List<StorageFile>(); PackageFile = await PickaFile(".appx"); if (PackageFile == null) return; ; PackageFileStr = encode; Certificate = await PickaFile(".cer"); if (Certificate == null) return; ; CertificateStr = encode; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { NameValue.NameValues.Clear(); DeviceInterfacesOutputList.DataContext = null; //DeviceInterfacesOutputList.Items.Clear(); NameValue nvPack = new NameValue("Package:", PackageFile.Name); NameValue nvCert = new NameValue("Certificate:", Certificate.Name); DeviceInterfacesOutputList.DataContext = NameValue.NameValues; //DeviceInterfacesOutputList.UpdateLayout(); }); //Create local folder to place AppInstall and package files. Clear it out if it exists StorageFolder fldrLocal = ApplicationData.Current.LocalFolder; try { var fldr = await fldrLocal.GetFolderAsync(PackageFile.Name); if (fldr != null) { var files = await fldr.GetFilesAsync(); foreach (StorageFile fi in files) await fi.DeleteAsync(); } } catch (Exception ex) { //Will be folder not found string msg = ex.Message; } //Get package and cert files StorageFolder fldrPackage = await fldrLocal.CreateFolderAsync(PackageFile.Name, CreationCollisionOption.OpenIfExists); await PackageFile.CopyAsync(fldrPackage, PackageFile.Name, NameCollisionOption.ReplaceExisting); await Certificate.CopyAsync(fldrPackage, Certificate.Name, NameCollisionOption.ReplaceExisting); //Get this app's installation folder StorageFolder fldrApp = Windows.ApplicationModel.Package.Current.InstalledLocation; //Get source files folder from <this app install dir>\AppInstall StorageFolder fldrAppInstall = await fldrApp.GetFolderAsync("AppInstall"); //Copy AppiNstall.cmd StorageFile AppInstall = await fldrAppInstall.GetFileAsync("AppInstall.cmd"); var buffer = await Windows.Storage.FileIO.ReadBufferAsync(AppInstall); StorageFile AppInstallOut = await fldrPackage.CreateFileAsync("AppInstall.cmd", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteBufferAsync(AppInstallOut, buffer); //Modify: AppConfig.cmd StorageFile AppxConfig = await fldrAppInstall.GetFileAsync("AppxConfig.cmd"); string AppInstallContents = await Windows.Storage.FileIO.ReadTextAsync(AppxConfig); AppInstallContents = AppInstallContents.Replace("MainAppx_1.0.0.0_arm", PackageFile.DisplayName); AppInstallContents = AppInstallContents.Replace("Microsoft.VCLibs.ARM.14.00 Microsoft.NET.Native.Runtime.1.1 Microsoft.NET.Native.Framework.1.2", " "); StorageFile AppxConfigdOut = await fldrPackage.CreateFileAsync("AppxConfig.cmd", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(AppxConfigdOut, AppInstallContents); //Copy DeployTask.cmd StorageFile DeployTask = await fldrAppInstall.GetFileAsync("DeployTask.cmd"); var buffer3 = await Windows.Storage.FileIO.ReadBufferAsync(DeployTask); StorageFile DeployTaskOut = await fldrPackage.CreateFileAsync("DeployTask.cmd", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteBufferAsync(DeployTaskOut, buffer3); //Modify: oemcustomization.cmd This goes to c$\Windows\system32 StorageFile oemcustomization = await fldrAppInstall.GetFileAsync("oemcustomization.cmd"); string oemcustomizationContents = await Windows.Storage.FileIO.ReadTextAsync(oemcustomization); oemcustomizationContents = oemcustomizationContents.Replace("INSTALLDIR", InstallDir); StorageFile oemcustomizationdOut = await fldrPackage.CreateFileAsync("oemcustomization.cmd", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(oemcustomizationdOut, oemcustomizationContents); PackageFolder = fldrPackage; }
private async void AddAPackageDependencyFileButton_Click(object sender, RoutedEventArgs e) { try { if (PackageFolder == null) return; StorageFile packageFile; //Make sure we don't select the app package; packageFile = await PickaFile(".appx"); if (packageFile == null) return; if (packageFile.Name == PackageFile.Name) return; Dependencies.Add(packageFile); DependenciesStr.Add(encode); await packageFile.CopyAsync(PackageFolder, packageFile.Name, NameCollisionOption.ReplaceExisting); //Update config file for this dependancy StorageFile AppxConfig = await PackageFolder.GetFileAsync("AppxConfig.cmd"); string AppInstallContents = await Windows.Storage.FileIO.ReadTextAsync(AppxConfig); AppInstallContents = AppInstallContents.Replace("set dependencylist=", "set dependencylist=" + packageFile.DisplayName + " "); StorageFile AppxConfigdOut = await PackageFolder.CreateFileAsync("AppxConfig.cmd", Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(AppxConfigdOut, AppInstallContents); NameValue nvDepend = new NameValue("Dependency:", packageFile.Name); DeviceInterfacesOutputList_DataContextRefresh(); } catch (Exception ex) { string msg = ex.Message; } }
private async void NavLinksList_Tapped(object sender, TappedRoutedEventArgs e) { if (NavLinksList.SelectedIndex == -1) return; Commands cmd = null; string Command = ""; //Get the command from the list item binding cmd = (Commands)NavLinksList.SelectedItem; if (cmd == null) return; Command = cmd.name; if (Command == "") return; bool exitNow = false; switch (Command) { case "": exitNow = true; break; case "localhost": case "minwinpc": case "192.168.0.28": textBoxDevice.Text = Command; exitNow = true; break; case "api params clr": textBoxAPI.Text = ""; textBoxAPI_Params.Text = ""; textBoxAppRelativeID.Text = ""; textBoxAppFullName.Text = ""; exitNow = true; break; case "clear details": NameValue.ClearList(); DeviceInterfacesOutputList_DataContextRefresh(); exitNow = true; break; case "cancel": SysInfo.cts.Cancel(); exitNow = true; break; case "startapp": break; case "stopapp": if (((bool)checkBoxAppForceStop.IsChecked) || (SysInfo.IsOSVersuion10_0_10531_OrGreater)) { DialogResult dr0 = await ShowDialog("Stop App", "Do you wish to stop the selected app?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr0 == DialogResult.Yes) { } else exitNow = true; } else { DialogResult dr1 = await ShowDialog("Stop App", "Do you wish to force the seleceted app to stop?", new List<DialogResult> { DialogResult.Yes, DialogResult.No, DialogResult.Cancel }); if (dr1 == DialogResult.Yes) SysInfo.ForceStop = true; else if (dr1 == DialogResult.No) SysInfo.ForceStop = false; else exitNow = true; } break; case "sysinfo": break; case "shutdown": DialogResult dr2 = await ShowDialog("Shutdown", "Do you wish shutdown the system?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr2 == DialogResult.Yes) { } else exitNow = true; break; case "restart": DialogResult dr3 = await ShowDialog("Reboot", "Do you wish reboot the system?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr3 == DialogResult.Yes) { } else exitNow = true; break; case "default_app": //url changed between versions break; case "packages": //url changed between versions break; case "packageUninstall": //url changed between versions DialogResult dr4 = await ShowDialog("Uninstall package", "Do you wish to uninstall the select package?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr4 == DialogResult.Yes) { } else exitNow = true; break; case "packageInstall": DialogResult dr7 = await ShowDialog("Install package", "This command not yet implemented", new List<DialogResult> { DialogResult.OK }); exitNow = true; break; case "packageInstallSelect": PickAPackageFileButton_Click(null, null); exitNow = true; break; case "packageInstallAddDependency": AddAPackageDependencyFileButton_Click(null, null); exitNow = true; break; case "packageInstallDeploy": PackageInstallDeploy(); exitNow = true; break; case "packageInstallCleanUp": PackageInstallCleanUp(); exitNow = true; break; case "renamesys": if (!SysInfo.IsOSVersuion10_0_10531_OrGreater) exitNow = true; else { DialogResult dr5 = await ShowDialog("Rename System", "Do you wish to rename the device?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr5 == DialogResult.Yes) { } else exitNow = true; } break; case "setpwd": if (!SysInfo.IsOSVersuion10_0_10531_OrGreater) exitNow = true; else { DialogResult dr6 = await ShowDialog("Set Admin Pwd", "Do you wish to reset the admin password?", new List<DialogResult> { DialogResult.Yes, DialogResult.Cancel }); if (dr6 == DialogResult.Yes) { } else exitNow = true; } break; } if (exitNow) return; if (cmd.name == "api") { //cmd = new Commands(cmd.name, textBoxAPI.Text, "", ""); cmd.url = textBoxAPI.Text; } else textBoxAPI.Text = Command; CurrentCmd = cmd; //Show this in the MainPage URL textbox //API buttomn actions what ever is here. this.textBoxAPI.Text = cmd.url; NameValue.NameValues.Clear(); DeviceInterfacesOutputList_DataContextRefresh(); //Do the REST query and JSON parsing bool res = await SysInfo.DoQuery(cmd); //If not OK then only show a generic error message if (!res) { NameValue.ClearList(); NameValue nv = new NameValue("Error:", "Target not found, timeout or processing error."); } else { if (cmd.name == "renamesys") { DialogResult dr7 = await ShowDialog("Renamed the device OK", "You will now need to run the command [Reboot].", new List<DialogResult> { DialogResult.OK }); } DetailsTextBlock.Text = Command; //If the query response list is from an array simplify by only showing one entry in the list per item //ie Only show the item name/description etc. if (NameValue.NameValues_IsFrom_Array) { NameValue.NameValuesStack.Push(NameValue.NameValues); string identity = cmd.id; //Get only the identity (name) record for each item var nameValuesIds = from nv in NameValue.NameValues where nv.Name.Contains(identity) select nv; NameValue.NameValues = nameValuesIds.ToList<NameValue>(); } } DeviceInterfacesOutputList_DataContextRefresh(); }
private void Copy(NameValue nv) { Windows.ApplicationModel.DataTransfer.DataPackage dp = new Windows.ApplicationModel.DataTransfer.DataPackage(); dp.SetText(nv.Value); Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dp); textBoxAPI_Params.Text = nv.Value; }
/// <summary> /// This is the "Powerhouse" /// Get all name-value pairs in the object /// - For each value get its value if simple type /// - If value is an array get objects in array an recursively call this for each item in the array /// - If value is an object call this recursiveky. /// </summary> /// <param name="preName">Text to prepend to name in list</param> /// <param name="oJson">The JSON object</param> public static void GetNameValues(string preName, JsonObject oJson) { foreach (KeyValuePair<string, IJsonValue> oJson_KVP in oJson) { string prefix = oJson_KVP.Key; if (preName != "") //Drilling into an object to indicate using -> prefix = preName + "->" + oJson_KVP.Key; //A bit of house keeping: List names are in plural. // int n = "address".Length; // if (prefix.Substring(prefix.Length - n, n).ToLower() != "address") // { // if (prefix.Substring(prefix.Length - 2, 2) == "es") // prefix = prefix.Substring(0, prefix.Length - 2); // else if (prefix.Substring(prefix.Length - 1, 1) == "s") // prefix = prefix.Substring(0, prefix.Length - 1); //} string typ = oJson_KVP.Value.ValueType.ToString().ToLower(); if (typ == "object") { //Recursively call this for the value GetNameValues(prefix , oJson.GetNamedObject(oJson_KVP.Key)); } else if (typ == "array") { JsonArray ja = oJson.GetNamedArray(oJson_KVP.Key); //foreach (JsonObject jajo in ja.) for(uint index = 0; index < ja.Count; index++) { string prfx = prefix; if (ja.Count > 1) { //If more than one item in the array, prepend the array index of the item to the name, NameValues_IsFrom_Array = true; prfx = index.ToString() + ". " + prfx; } JsonObject joja = ja.GetObjectAt(index).GetObject(); //Recursively call this for the values in teh array GetNameValues(prfx, joja); } } else { //Got a value to add to list NameValue nv = new NameValue(preName,-1, oJson_KVP); } } }
public async static Task<bool> DoQuery(Commands cmd) { NameValue.ClearList(); StreamReader SR = null; HttpStatusCode response; //The REST call for the command if (cmd.url[cmd.url.Length-1]=='*') { //POST response = await PostRequest(cmd); NameValue nv = new NameValue("Result:",response.ToString()); } else { //GET SR = await GetJsonStreamData(cmd); if (SR == null) { return false; } //Process the JSON stream data JsonObject ResultData = null; try { String JSONData; //Get the stream as text. JSONData = SR.ReadToEnd(); //Convert to JSON object ResultData = (JsonObject)JsonObject.Parse(JSONData); //Process the JSON data NameValue.GetNameValues("", ResultData); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return false; } } return true; }