示例#1
0
        static void Main(string[] args)
        {
            // The client code creates a builder object, passes it to the
            // director and then initiates the construction process. The end
            // result is retrieved from the builder object.
            var director    = new Director();
            var carBuilder  = new CarBuilder();
            var sportEngine = new SportEngine();
            var workEngine  = new WorkEngine();

            director.Builder = carBuilder;
            director.Engine  = workEngine;

            Console.WriteLine("Crear el carro:");
            director.CrearCarro();
            Console.WriteLine(carBuilder.GetResult().ListParts());


            var manualBuilder = new ManualBuilder();

            director.Builder = manualBuilder;
            director.Engine  = sportEngine;

            Console.WriteLine("Crear el manual:");
            director.CrearManual();
            Console.WriteLine(manualBuilder.GetResult().ListParts());

            Console.ReadKey();
        }
        public void RemoveSafely(string webUrl, string category, string key = null)
        {
            if (string.IsNullOrEmpty(webUrl) || string.IsNullOrEmpty(category))
            {
                return;
            }

            var data = new XElement("ClearCache",
                                    new XElement("Category", new XCData(category)),
                                    new XElement("Key", new XCData(key ?? string.Empty)));

            using (var weApi = new WorkEngine())
            {
                weApi.Url = webUrl + (webUrl.EndsWith("/") ? string.Empty : "/") + "_vti_bin/WorkEngine.asmx";
                weApi.UseDefaultCredentials = true;
                weApi.Execute("ClearCache", data.ToString());
            }
        }
        public static string ProcessActivity(ObjectKind objectKind, ActivityKind activityKind,
                                             Dictionary <string, object> data, SPWeb contextWeb)
        {
            try
            {
                string webUrl = contextWeb.Url;

                var request = new XElement("ProcessActivity",
                                           new XAttribute("ObjectKind", objectKind),
                                           new XAttribute("ActivityKind", activityKind),
                                           new XElement("Context",
                                                        new XAttribute("SiteId", contextWeb.Site.ID),
                                                        new XAttribute("WebId", contextWeb.ID),
                                                        new XAttribute("UserId", contextWeb.CurrentUser.ID)));

                foreach (var property in data)
                {
                    request.Add(new XElement(property.Key,
                                             new XAttribute("DataType", property.Value == null ? "NULL" : property.Value.GetType().Name),
                                             new XCData((property.Value ?? string.Empty).ToString())));
                }

                using (var api = new WorkEngine())
                {
                    api.Url = webUrl + (webUrl.EndsWith("/") ? string.Empty : "/") + "_vti_bin/WorkEngine.asmx";
                    api.UseDefaultCredentials = true;
                    return(api.Execute("SocialEngine_ProcessActivity", request.ToString()));
                }
            }
            catch (Exception exception)
            {
                new Logger().Log(objectKind, activityKind, data, contextWeb, exception);
            }

            return(null);
        }