├── .gitattributes
├── OpenDefinery-DesktopApp
├── favicon.ico
├── assets
│ ├── favicon.ico
│ ├── screenshot-1.png
│ └── OpenDefinery-Logo_BlueGrayBG_512x512.png
├── OpenDefinery-Logo_BlueGrayBG_512x512.png
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── app.manifest
│ └── Resources.resx
├── App.xaml.cs
├── packages.config
├── App.config
├── App.xaml
├── DataCategory.cs
├── Definery.cs
├── Pager.cs
├── Exporter.cs
├── User.cs
├── app.manifest
├── DataType.cs
├── Tag.cs
├── Node.cs
├── Group.cs
├── OpenDefinery-DesktopApp.csproj
├── Collection.cs
├── MainWindow.xaml
└── SharedParameter.cs
├── OpenDefinery-DesktopApp.sln
├── README.md
├── .gitignore
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TripleZeroLabs/OpenDefinery-DesktopApp/HEAD/OpenDefinery-DesktopApp/favicon.ico
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/assets/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TripleZeroLabs/OpenDefinery-DesktopApp/HEAD/OpenDefinery-DesktopApp/assets/favicon.ico
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/assets/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TripleZeroLabs/OpenDefinery-DesktopApp/HEAD/OpenDefinery-DesktopApp/assets/screenshot-1.png
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/OpenDefinery-Logo_BlueGrayBG_512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TripleZeroLabs/OpenDefinery-DesktopApp/HEAD/OpenDefinery-DesktopApp/OpenDefinery-Logo_BlueGrayBG_512x512.png
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/assets/OpenDefinery-Logo_BlueGrayBG_512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TripleZeroLabs/OpenDefinery-DesktopApp/HEAD/OpenDefinery-DesktopApp/assets/OpenDefinery-Logo_BlueGrayBG_512x512.png
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace OpenDefinery_DesktopApp
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace OpenDefinery_DesktopApp.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29911.84
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDefinery-DesktopApp", "OpenDefinery-DesktopApp\OpenDefinery-DesktopApp.csproj", "{5070A6ED-8FCB-49E2-83B1-3316D75C53AF}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {5070A6ED-8FCB-49E2-83B1-3316D75C53AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {5070A6ED-8FCB-49E2-83B1-3316D75C53AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {5070A6ED-8FCB-49E2-83B1-3316D75C53AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {5070A6ED-8FCB-49E2-83B1-3316D75C53AF}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {C8B28CA3-FB2A-454F-B7E9-C8D235293A95}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OpenDefinery Desktop Application
2 | The OpenDefinery desktop application seeks to replace Revit's antiquated out-of-the-box process for managing shared parameters.
3 |
4 | 
5 |
6 | ### What is OpenDefinery?
7 | OpenDefinery is a cloud-based data warehouse of Revit Shared Parameters. This database includes the parameter definitions from Revit users throughout the industry who seek to decentralize their data standard. For more information, visit us at http://OpenDefinery.com.
8 |
9 | Note that the platform is currently in private beta and an account is required to use this application. Reach out to i@opendefinery.com to request an account.
10 |
11 | ## Desktop App Overview
12 |
13 | In its current state, the desktop application provides improved methods to manage and organize Revit Shared Parameters stored in the OpenDefinery repository.
14 |
15 | ### Features
16 | - Browse Shared Parameters
17 | - Browse Collections
18 | - Create new Shared Parameters
19 | - Create new Collections
20 | - Add Shared Parameters to Collections.
21 |
22 | ### Future State of the Desktop App
23 | - A Revit add-in to allow users to manage the Shared Parameters within their Revit projects or Revit families.
24 |
25 | # OpenDefinery API
26 | This application leverages the OpenDefinery REST API to manage Shared Parameters. For API documentation, refer to https://documenter.getpostman.com/view/5483074/T1LHGpQo.
27 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/DataCategory.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using OpenDefinery_DesktopApp;
3 | using RestSharp;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 |
11 | namespace OpenDefinery
12 | {
13 | public class DataCategory
14 | {
15 | [JsonProperty("id")]
16 | public long Id { get; set; }
17 |
18 | [JsonProperty("name")]
19 | public string Name { get; set; }
20 |
21 | [JsonProperty("hashcode")]
22 | public string Hashcode { get; set; }
23 |
24 | ///
25 | /// Retrieve all DataCategoreis from Drupal.
26 | ///
27 | /// The main Definery object provides the CSRF token.
28 | /// A list of DataType objects.
29 | public static List GetAll(Definery definery)
30 | {
31 | var dataCategories = new List();
32 |
33 | var client = new RestClient(Definery.BaseUrl + "rest/datacategories?_format=json");
34 | client.Timeout = -1;
35 | var request = new RestRequest(Method.GET);
36 | request.AddHeader("X-CSRF-Token", definery.CsrfToken);
37 | IRestResponse response = client.Execute(request);
38 | Console.WriteLine(response.Content);
39 |
40 | dataCategories = JsonConvert.DeserializeObject>(response.Content);
41 |
42 | return dataCategories;
43 | }
44 |
45 | ///
46 | /// Retrieve a DataCategory using its hascode from the Revit API.
47 | ///
48 | /// The main Definery object
49 | /// The hascode provided by the Revit API
50 | ///
51 | public static DataCategory GetByHashcode(Definery definery, string hashcode)
52 | {
53 | // Get DataCategory using the hashcode
54 | var dataCats = definery.DataCategories.Where(o => o.Hashcode == hashcode);
55 |
56 | // Only return one DataCategory
57 | if (dataCats.Count() == 1)
58 | {
59 | return dataCats.FirstOrDefault();
60 | }
61 | else
62 | {
63 | MessageBox.Show("Error retrieving Data Category.");
64 |
65 | return null;
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("OpenDefinery Desktop")]
11 | [assembly: AssemblyDescription("The official desktop application for managing OpenDefinery parameters")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("OpenDefinery")]
14 | [assembly: AssemblyProduct("OpenDefinery-DesktopApp")]
15 | [assembly: AssemblyCopyright("Copyright OpenDefinery © 2020")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("0.0.2.0")]
55 | [assembly: AssemblyFileVersion("0.0.2.0")]
56 | [assembly: Guid("72f3c578-88c1-40ed-bae0-a1db62b24f72")]
57 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Definery.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using RestSharp;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Collections.ObjectModel;
7 | using System.Linq;
8 | using System.Security.Policy;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using System.Windows;
12 |
13 | namespace OpenDefinery
14 | {
15 | public class Definery
16 | {
17 | public static string BaseUrl = "http://app.opendefinery.com/";
18 | public string CsrfToken { get; set; }
19 | public string AuthCode { get; set; }
20 |
21 | public List MyCollections { get; set; }
22 | public List PublishedCollections { get; set; }
23 | public List AllCollections { get; set; }
24 | public ObservableCollection Parameters { get; set; }
25 | public List DataTypes { get; set; }
26 | public List DataCategories { get; set; }
27 | public List Groups { get; set; }
28 | public static User CurrentUser { get; set; }
29 |
30 | ///
31 | /// Login to Drupal using a username and password.
32 | ///
33 | /// The main Definery object
34 | /// The Drupal username to login
35 | /// The password of the Drupal user
36 | public static System.Net.HttpStatusCode Authenticate(Definery definery, string username, string password)
37 | {
38 | var client = new RestClient(BaseUrl + "user/login?_format=json");
39 | client.Timeout = -1;
40 | var request = new RestRequest(Method.POST);
41 | request.AddHeader("Content-Type", "application/json");
42 | request.AddParameter("application/json", "{\r\n \"name\": \""+ username + "\",\r\n \"pass\": \"" + password + "\"\r\n}", ParameterType.RequestBody);
43 | IRestResponse response = client.Execute(request);
44 |
45 | // Return the CSRF token if the response was OK
46 | if (response.StatusCode == System.Net.HttpStatusCode.OK)
47 | {
48 | JObject json = JObject.Parse(response.Content);
49 |
50 | // Assign tokens to Definery members
51 | definery.CsrfToken = json.SelectToken("csrf_token").ToString();
52 |
53 | // Add logged in user data
54 | CurrentUser = new User();
55 | CurrentUser.Id = json.SelectToken("current_user.uid").ToString();
56 | CurrentUser.Name = json.SelectToken("current_user.name").ToString();
57 | }
58 | else
59 | {
60 | MessageBox.Show(response.Content, "Error Logging In", MessageBoxButton.OK, MessageBoxImage.Error);
61 | }
62 |
63 | return response.StatusCode;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Pager.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using OpenDefinery_DesktopApp;
4 | using RestSharp;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 |
12 | namespace OpenDefinery
13 | {
14 | public class Pager
15 | {
16 | // Ignoring the current_page property from Drupal response until it reports the correct value
17 | //[JsonProperty("current_page")]
18 | public int CurrentPage { get; set; }
19 |
20 | [JsonProperty("total_items")]
21 | public int TotalItems { get; set; }
22 |
23 | [JsonProperty("total_pages")]
24 | public int TotalPages { get; set; }
25 |
26 | [JsonProperty("items_per_page")]
27 | public int ItemsPerPage { get; set; }
28 |
29 | // The Offset is not included in the Drupal response, so it must be set elsewhere
30 | public int Offset { get; set; }
31 | public bool IsFirstPage { get; set; }
32 | public bool IsLastPage { get; set; }
33 |
34 | ///
35 | /// Helper method to update the Pager object based on a Response
36 | ///
37 | /// The IRestResponse.Content value as a string
38 | /// The new Pager object
39 | public static Pager SetFromParamReponse(IRestResponse response, bool resetTotals)
40 | {
41 | // Instantiate a new pager
42 | var pager = new Pager();
43 |
44 | // Cast the rows from the reponse to a generic JSON object
45 | JObject json = JObject.Parse(response.Content);
46 |
47 | // Add the Drupal pager data to the Pager object
48 | var pagerResponse = json.SelectToken("pager");
49 | pager = JsonConvert.DeserializeObject(pagerResponse.ToString());
50 |
51 | // Always reassign values for total pages and items because the pager property from Drupal is relative to the current request,
52 | // however we always want to report the absolute totals if they are greater than zero.
53 | if (!resetTotals)
54 | {
55 | // Add the MainWindow data to the Pager object
56 | pager.TotalPages = MainWindow.Pager.TotalPages;
57 | pager.TotalItems = MainWindow.Pager.TotalItems;
58 | pager.CurrentPage = MainWindow.Pager.CurrentPage;
59 | }
60 | else
61 | {
62 | pager.CurrentPage = 0;
63 | }
64 |
65 | return pager;
66 | }
67 |
68 | public static Pager Reset()
69 | {
70 | var pager = new Pager();
71 | pager.TotalItems = 0;
72 | pager.TotalPages = 0;
73 | pager.CurrentPage = 0;
74 | pager.ItemsPerPage = MainWindow.Pager.ItemsPerPage;
75 |
76 | return pager;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace OpenDefinery_DesktopApp.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenDefinery_DesktopApp.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Exporter.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using OpenDefinery;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 |
12 | namespace OpenDefinery_DesktopApp
13 | {
14 | class Exporter
15 | {
16 | ///
17 | /// Convert a list of Shared Parameters to a shared parameter text file usable by Revit.
18 | ///
19 | /// The main Definery object
20 | /// The List of SharedParameters to convert
21 | /// The full shared parameter text file contents
22 | public static string ToRevitTxt (Definery definery, List parameters)
23 | {
24 | // Instantiate parts of the txt file which are organized in tables separated by an asterisk per Revit standards
25 |
26 | // Create header text for introduction
27 | var header =
28 | "# This is a Revit shared parameter file.\n" +
29 | "# These parameters are part of an ongoing collaborative effort by OpenDefinery.\n" +
30 | "# If you would like to add, remove, or modify any parameters in this file, " +
31 | "please join us: http://opendefinery.com.\n";
32 |
33 | // Create the table for metadata
34 | var metaTable =
35 | "*META\tVERSION\tMINVERSION\n" +
36 | "META\t2\t1\n";
37 |
38 | // Create the table for groups
39 | // As of now, we are setting all parameters to a single Group
40 | var groupTable =
41 | "*GROUP\tID\tNAME\n" +
42 | "GROUP\t1\tDefault Group\n";
43 |
44 | // Create the parameters
45 | var parameterTable = SharedParameter.CreateParamTable(parameters);
46 |
47 | // Output a concatenated string
48 | var output = header + metaTable + groupTable + parameterTable;
49 | //Debug.WriteLine(output);
50 |
51 | // Save the file
52 | Stream stream;
53 | SaveFileDialog saveDialog = new SaveFileDialog();
54 |
55 | saveDialog.Filter = "txt files (*.txt)|*.txt";
56 | saveDialog.RestoreDirectory = true;
57 | saveDialog.FileName = "SharedParameters_" + MainWindow.SelectedCollection.Name + ".txt";
58 |
59 | if (saveDialog.ShowDialog() == true)
60 | {
61 | if ((stream = saveDialog.OpenFile()) != null)
62 | {
63 | // Write the entire output string to the selected txt file
64 | using (StreamWriter streamWriter = new StreamWriter(stream))
65 | {
66 | streamWriter.Write(output);
67 | }
68 |
69 | MessageBox.Show(string.Format("The shared parameter txt file has been saved."));
70 | }
71 | }
72 |
73 | // Return the string to be used by other methods
74 | return output;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/User.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using RestSharp;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows;
9 |
10 | namespace OpenDefinery
11 | {
12 | public class User
13 | {
14 | public string Id { get; set; }
15 | public string Name { get; set; }
16 |
17 | ///
18 | /// Retrieve a User by their user ID.
19 | ///
20 | /// The main Definery object provides the auth code
21 | /// The ID of the user
22 | ///
23 | public static User GetById(Definery definery, int userId)
24 | {
25 | var users = new List();
26 | var user = new User();
27 |
28 | try
29 | {
30 | var client = new RestClient(Definery.BaseUrl + string.Format("rest/user/id/{0}?_format=json", userId.ToString()));
31 | client.Timeout = -1;
32 | var request = new RestRequest(Method.GET);
33 | request.AddHeader("Authorization", "Basic " + definery.AuthCode);
34 | IRestResponse response = client.Execute(request);
35 | Console.WriteLine(response.Content);
36 |
37 | users = JsonConvert.DeserializeObject>(response.Content);
38 |
39 | if (users.Count() == 1)
40 | {
41 | return users.FirstOrDefault();
42 | }
43 | // If there are none or more than one result, return null
44 | else
45 | {
46 | return null;
47 | }
48 | }
49 | catch
50 | {
51 | return null;
52 | }
53 | }
54 |
55 | ///
56 | /// Retrieve a User by their username.
57 | ///
58 | /// The main Definery object provides the auth code
59 | /// The name of the user
60 | ///
61 | public static User GetByUserName(Definery definery, string username)
62 | {
63 | var users = new List();
64 | var user = new User();
65 |
66 | try
67 | {
68 | var client = new RestClient(Definery.BaseUrl + string.Format("rest/user/name/{0}?_format=json", username));
69 | client.Timeout = -1;
70 | var request = new RestRequest(Method.GET);
71 | request.AddHeader("Authorization", "Basic " + definery.AuthCode);
72 | IRestResponse response = client.Execute(request);
73 | Console.WriteLine(response.Content);
74 |
75 | users = JsonConvert.DeserializeObject>(response.Content);
76 |
77 | if (users.Count() == 1)
78 | {
79 | return users.FirstOrDefault();
80 | }
81 | // If there are none or more than one result, return null
82 | else
83 | {
84 | return null;
85 | }
86 | }
87 | catch
88 | {
89 | return null;
90 | }
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
48 |
55 |
56 |
70 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
53 |
54 |
55 |
58 | PerMonitorV2
59 | true/pm
60 |
61 |
62 |
63 |
64 |
65 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/DataType.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using RestSharp;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Security.Policy;
9 | using System.Text;
10 | using System.Text.RegularExpressions;
11 | using System.Threading.Tasks;
12 | using System.Windows;
13 |
14 | namespace OpenDefinery
15 | {
16 | public class DataType
17 | {
18 | [JsonProperty("id")]
19 | public long Id { get; set; }
20 |
21 | [JsonProperty("name")]
22 | public string Name { get; set; }
23 |
24 | ///
25 | /// Retrieve all DataTypes from Drupal.
26 | ///
27 | /// The main Definery object provides the CSRF token.
28 | /// A list of DataType objects.
29 | public static List GetAll(Definery definery)
30 | {
31 | var dataTypes = new List();
32 |
33 | var client = new RestClient(Definery.BaseUrl + "rest/datatypes?_format=json");
34 | client.Timeout = -1;
35 | var request = new RestRequest(Method.GET);
36 | request.AddHeader("X-CSRF-Token", definery.CsrfToken);
37 | IRestResponse response = client.Execute(request);
38 | Console.WriteLine(response.Content);
39 |
40 | dataTypes = JsonConvert.DeserializeObject>(response.Content);
41 |
42 | return dataTypes;
43 | }
44 |
45 | ///
46 | /// Retrieve the DataType object from Drupal from the name.
47 | ///
48 | /// A list of all DataTypes typically sourced from the main Definery object.
49 | /// The name the DataType to retrieve.
50 | /// The DataType object.
51 | public static DataType GetFromName(List allDataTypes, string dataTypeName)
52 | {
53 | var foundDataTypes = allDataTypes.Where(g => g.Name == dataTypeName);
54 |
55 | if (foundDataTypes.Count() == 1)
56 | {
57 | return foundDataTypes.FirstOrDefault();
58 | }
59 | if (foundDataTypes.Count() > 1)
60 | {
61 | MessageBox.Show(String.Format("Multiple datatypes exist with the name {0}. Using the first or default.", dataTypeName));
62 |
63 | return foundDataTypes.FirstOrDefault();
64 | }
65 |
66 | return null;
67 | }
68 |
69 | ///
70 | /// Retrive the DataType ID from its name. This ID is useful when the DataType ID in Drupal is required for an API call.
71 | ///
72 | /// A list of all DataTypes typically sourced from the main Definery object.
73 | /// The nane of the DataType.
74 | /// The DataType object.
75 | public static string GetIdFromName(List allDataTypes, string dataTypeName)
76 | {
77 | var foundDataTypes = allDataTypes.Where(g => g.Name == dataTypeName);
78 |
79 | if (foundDataTypes.Count() == 1)
80 | {
81 | return foundDataTypes.FirstOrDefault().Id.ToString();
82 | }
83 | if (foundDataTypes.Count() > 1)
84 | {
85 | MessageBox.Show(String.Format("Multiple data types exist with the name {0}. Using the first or default.", dataTypeName));
86 |
87 | return foundDataTypes.FirstOrDefault().Id.ToString();
88 | }
89 |
90 | return null;
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Tag.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using RestSharp;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 | using System.Windows.Media;
11 |
12 | namespace OpenDefinery
13 | {
14 | public class Tag
15 | {
16 | public string Id { get; set; }
17 | public Guid Uuid { get; set; }
18 | public string Name { get; set; }
19 |
20 | ///
21 | /// Creates a new Tag on Drupal
22 | ///
23 | /// The main Definery object provides the CSRF token
24 | /// The name for the new Tag
25 | /// The Tag ID of the newly created Tag as a string
26 | public static string Create(Definery definery, string tagName)
27 | {
28 | var client = new RestClient(Definery.BaseUrl + "taxonomy/term?_format=hal_json");
29 | client.Timeout = -1;
30 | var request = new RestRequest(Method.POST);
31 | request.AddHeader("Content-Type", "application/json");
32 | request.AddHeader("X-CSRF-Token", definery.CsrfToken);
33 | request.AddHeader("Authorization", "Basic " + definery.AuthCode);
34 | request.AddParameter("application/json",
35 | "{\"vid\": \"tags\"," +
36 | "\"name\": [" +
37 | "{\"value\": \"" + tagName + "\"}" +
38 | "]}",
39 | ParameterType.RequestBody);
40 | IRestResponse response = client.Execute(request);
41 |
42 | JObject json = JObject.Parse(response.Content);
43 |
44 | var tagId = json["tid"].FirstOrDefault()["value"].ToString();
45 |
46 | return tagId;
47 | }
48 |
49 | ///
50 | /// Retrieve the Tag ID from its name. Useful for passing into API calls where the ID is required.
51 | ///
52 | /// The main Definery object provides the basic auth code
53 | /// The name of the Tag
54 | /// The Tag ID as a string
55 | public static string GetIdFromName(Definery definery, string tagName)
56 | {
57 | var client = new RestClient(Definery.BaseUrl + string.Format("rest/tags/{0}?_format=json", tagName));
58 | client.Timeout = -1;
59 | var request = new RestRequest(Method.GET);
60 | request.AddHeader("Content-Type", "application/json");
61 | request.AddHeader("Authorization", "Basic " + definery.AuthCode);
62 | IRestResponse response = client.Execute(request);
63 |
64 | if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content != "[]")
65 | {
66 | var tags = JsonConvert.DeserializeObject>(response.Content);
67 |
68 | return tags.FirstOrDefault().Id;
69 | }
70 | if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content == "[]")
71 | {
72 | return "[]";
73 | }
74 | else
75 | {
76 | MessageBox.Show("There was an error getting the ID of " + tagName + ".");
77 | return null;
78 | }
79 | }
80 |
81 | ///
82 | /// Helper method to format tag names.
83 | ///
84 | /// The name of the Tag to format
85 | /// The formatted Tag Name
86 | public static string FormatName(string tagName)
87 | {
88 | var newTag = tagName;
89 |
90 | // Remove spaces
91 | newTag = newTag.Replace(" ", "");
92 |
93 | return newTag;
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Node.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace OpenDefinery
9 | {
10 | ///
11 | /// The Node class is a generic class for deserializing Drupal responses when modifying content
12 | ///
13 | class Node
14 | {
15 | [JsonProperty("nid")]
16 | public Nid[] Nid { get; set; }
17 |
18 | [JsonProperty("uuid")]
19 | public Uuid[] Uuid { get; set; }
20 |
21 | [JsonProperty("vid")]
22 | public Nid[] Vid { get; set; }
23 |
24 | [JsonProperty("langcode")]
25 | public Langcode[] Langcode { get; set; }
26 |
27 | [JsonProperty("type")]
28 | public TypeElement[] Type { get; set; }
29 |
30 | [JsonProperty("revision_timestamp")]
31 | public RevisionTimestamp[] RevisionTimestamp { get; set; }
32 |
33 | [JsonProperty("status")]
34 | public DefaultLangcode[] Status { get; set; }
35 |
36 | [JsonProperty("title")]
37 | public Langcode[] Title { get; set; }
38 |
39 | [JsonProperty("created")]
40 | public Changed[] Created { get; set; }
41 |
42 | [JsonProperty("changed")]
43 | public Changed[] Changed { get; set; }
44 |
45 | [JsonProperty("promote")]
46 | public DefaultLangcode[] Promote { get; set; }
47 |
48 | [JsonProperty("sticky")]
49 | public DefaultLangcode[] Sticky { get; set; }
50 |
51 | [JsonProperty("default_langcode")]
52 | public DefaultLangcode[] DefaultLangcode { get; set; }
53 |
54 | [JsonProperty("revision_translation_affected")]
55 | public DefaultLangcode[] RevisionTranslationAffected { get; set; }
56 |
57 | [JsonProperty("path")]
58 | public Path[] Path { get; set; }
59 |
60 | [JsonProperty("field_guid")]
61 | public FieldGuid[] FieldGuid { get; set; }
62 | }
63 |
64 | public partial class FieldGuid
65 | {
66 | [JsonProperty("value")]
67 | public Guid Value { get; set; }
68 | }
69 |
70 | public partial class Changed
71 | {
72 | [JsonProperty("value")]
73 | public DateTimeOffset Value { get; set; }
74 |
75 | [JsonProperty("lang")]
76 | public string Lang { get; set; }
77 |
78 | [JsonProperty("format")]
79 | public string Format { get; set; }
80 | }
81 |
82 | public partial class DefaultLangcode
83 | {
84 | [JsonProperty("value")]
85 | public bool Value { get; set; }
86 |
87 | [JsonProperty("lang")]
88 | public string Lang { get; set; }
89 | }
90 |
91 | public partial class Uuid
92 | {
93 | [JsonProperty("value")]
94 | public Guid Value { get; set; }
95 | }
96 |
97 | public partial class Langcode
98 | {
99 | [JsonProperty("value")]
100 | public string Value { get; set; }
101 |
102 | [JsonProperty("lang")]
103 | public string Lang { get; set; }
104 | }
105 |
106 | public partial class Nid
107 | {
108 | [JsonProperty("value")]
109 | public int Value { get; set; }
110 | }
111 |
112 | public partial class Path
113 | {
114 | [JsonProperty("alias")]
115 | public object Alias { get; set; }
116 |
117 | [JsonProperty("pid")]
118 | public object Pid { get; set; }
119 |
120 | [JsonProperty("langcode")]
121 | public string Langcode { get; set; }
122 |
123 | [JsonProperty("lang")]
124 | public string Lang { get; set; }
125 | }
126 |
127 | public partial class RevisionTimestamp
128 | {
129 | [JsonProperty("value")]
130 | public DateTimeOffset Value { get; set; }
131 |
132 | [JsonProperty("format")]
133 | public string Format { get; set; }
134 | }
135 |
136 | public partial class TypeElement
137 | {
138 | [JsonProperty("target_id")]
139 | public string TargetId { get; set; }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/OpenDefinery-DesktopApp/Group.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using RestSharp;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Text.RegularExpressions;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 |
12 | namespace OpenDefinery
13 | {
14 | public class Group
15 | {
16 | public List tid { get; set; }
17 | public List uuid { get; set; }
18 | public List revision_id { get; set; }
19 | public List langcode { get; set; }
20 | public List vid { get; set; }
21 | public List revision_created { get; set; }
22 | public List