1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: //Espacios de nombres necesarios
7: using System.Collections;
8: using Microsoft.SharePoint;
9: using Microsoft.SharePoint.Administration;
10:
11: namespace SPPropertyBagsConfigurator
12: {
13: class Program
14: {
15: static void Main(string[] args)
16: {
17: Console.WriteLine("Introduzca el tipo de operación:");
18: Console.WriteLine("1 .- Visualizar las Property Bags");
19: Console.WriteLine("2 .- Crear una nueva Property Bag");
20: Console.WriteLine("3 .- Actualizar una Property Bag");
21: Console.WriteLine("4 .- Eliminar una Property Bag");
22:
23: string sOpcion = Console.ReadLine();
24: ManageFarmPropertyBags(sOpcion);
25: Console.ReadLine();
26: }
27: /// <summary>
28: /// Permite manegar las Property Bags a nivel de granja
29: /// </summary>
30: /// <param name="sOpcion">Operación a realizar</param>
31: static void ManageFarmPropertyBags(string sOpcion)
32: {
33: try
34: {
35: SPFarm spfGranja = SPFarm.Local;
36: switch (sOpcion)
37: {
38: //Visualizar Property Bags
39: case "1":
40: if (spfGranja.Properties!=null
41: && spfGranja.Properties.Count>0)
42: {
43: Console.WriteLine(
44: "-----------------------------------");
45: Console.WriteLine(
46: "Property Bags disponibles");
47: Console.WriteLine(
48: "-----------------------------------");
49: foreach (DictionaryEntry deEntry in spfGranja.Properties)
50: {
51: Console.WriteLine(
52: "Propiedad: {0} - Valor: {1}",
53: deEntry.Key,deEntry.Value);
54: }
55: }
56: else
57: {
58: Console.WriteLine(
59: "-----------------------------------");
60: Console.WriteLine(
61: "No hay Property Bags definidas a nivel de granja");
62: Console.WriteLine(
63: "-----------------------------------");
64: }
65:
66: break;
67: //Añadir una Property Bag
68: case "2":
69: spfGranja.Properties.Add("SPFarmKey", "SPFarmValue");
70: spfGranja.Update();
71: Console.WriteLine(
72: "-----------------------------------");
73: Console.WriteLine(
74: "Property Bag añadida");
75: Console.WriteLine(
76: "-----------------------------------");
77: break;
78: //Actualizar una Property Bag
79: case "3":
80: spfGranja.Properties["SPFarmKey"]="SPFarmValueUpdate";
81: spfGranja.Update();
82: Console.WriteLine(
83: "-----------------------------------");
84: Console.WriteLine(
85: "Property Bag Actualizada");
86: Console.WriteLine(
87: "-----------------------------------");
88: break;
89: //Borrar una Property Bag
90: case "4":
91: spfGranja.Properties["SPFarmKey"] = null;
92: spfGranja.Properties.Remove(
93: "SPFarmKey");
94: spfGranja.Update();
95: Console.WriteLine(
96: "-----------------------------------");
97: Console.WriteLine(
98: "Property Bag eliminada");
99: Console.WriteLine(
100: "-----------------------------------");
101: break;
102: default:
103: Console.WriteLine(
104: "-----------------------------------");
105: Console.WriteLine(
106: "Opción seleccionada no valida");
107: Console.WriteLine(
108: "-----------------------------------");
109: break;
110: }
111: Console.WriteLine();
112: Main(null);
113: }
114: catch (Exception ex)
115: {
116: Console.WriteLine("Error: {0}",
117: ex.Message);
118: }
119: }
120: }
121: }