Esempio n. 1
0
        protected override void OnLoad(EventArgs e)
        {
            string queryString = Attributes["sc_parameters"];

            if (!string.IsNullOrEmpty(queryString))
            {
                NameValueCollection param = WebUtil.ParseUrlParameters(queryString);

                if (!string.IsNullOrEmpty(param["Web"]))
                {
                    this.Web = param["Web"];
                }

                if (string.IsNullOrEmpty(this.Web))
                {
                    this.Web = SharepointUtils.CurrentWebPath;
                }

                if (!string.IsNullOrEmpty(param["Server"]))
                {
                    this.Server = param["Server"];
                }

                if (string.IsNullOrEmpty(this.ListName))
                {
                    this.ListName = param["List"];
                }

                this.ShowIfEmpty = MainUtil.GetBool(param["ShowIfEmpty"], false);
            }

            this.context = SpContextProviderBase.Instance.CreateUIContext(this.Server, this.Web);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommonEntity"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        protected CommonEntity([NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            this.Context = context;
            this.FillProperty(new EntityProperties());
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="List"/> class.
 /// </summary>
 /// <param name="propertyValues">The property values.</param>
 /// <param name="context">The context.</param>
 /// <param name="webUrl">The url of Web.</param>
 public List([NotNull] EntityValues propertyValues, [NotNull] SpContext context, [NotNull] Uri webUrl)
     : base(propertyValues, context, webUrl)
 {
     Assert.ArgumentNotNull(propertyValues, "propertyValues");
     Assert.ArgumentNotNull(context, "context");
     Assert.ArgumentNotNull(webUrl, "webUrl");
 }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Web"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        protected Web([NotNull] SpContext context)
            : base(context)
        {
            Assert.ArgumentNotNull(context, "context");

            this.websCache = new Dictionary <int, Web>();
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LibraryItem"/> class.
 /// </summary>
 /// <param name="listName">The list name.</param>
 /// <param name="webUrl">The url of Web.</param>
 /// <param name="context">The context.</param>
 protected LibraryItem([NotNull] string listName, [NotNull] Uri webUrl, [NotNull] SpContext context)
     : base(listName, webUrl, context)
 {
     Assert.ArgumentNotNull(listName, "listName");
     Assert.ArgumentNotNull(webUrl, "webUrl");
     Assert.ArgumentNotNull(context, "context");
 }
 public ItemCollection([NotNull] SpContext context, [NotNull] BaseList list, [NotNull] ItemsRetrievingOptions options)
     : base(context, list, options)
 {
     Assert.ArgumentNotNull(context, "context");
     Assert.ArgumentNotNull(list, "list");
     Assert.ArgumentNotNull(options, "options");
 }
 public SearchResultCollection([NotNull] XmlNode node, [NotNull] Query query, SpContext context)
 {
     Assert.ArgumentNotNull(node, "node");
     Assert.ArgumentNotNull(query, "query");
     Properties  = new StringDictionary();
     searchQuery = query;
     LoadItems(node, context);
 }
 private void LoadItems(XmlNode node, SpContext context)
 {
     foreach (XmlNode childNode in node.SelectNodes("//RelevantResults"))
     {
         SearchResult result = new SearchResult(childNode, context);
         this.Add(result);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Web"/> class.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="context">The context.</param>
        public Web([NotNull] EntityValues values, [NotNull] SpContext context)
            : base(values.Properties, context)
        {
            Assert.ArgumentNotNull(values, "values");
            Assert.ArgumentNotNull(context, "context");

            this.websCache = new Dictionary <int, Web>();
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebConnector"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="webUrl">The web URL.</param>
        public WebConnector([NotNull] SpContext context, [NotNull] Uri webUrl)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            this.WebsWebService = new Webs();
            this.WebsWebService.SetServer(webUrl, context);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemCollectionConnector"/> class.
        /// </summary>
        /// <param name="context">The specified context.</param>
        /// <param name="webUrl">The specified web URL.</param>
        public ItemCollectionConnector([NotNull] SpContext context, [NotNull] Uri webUrl)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            this.ListWebService = new Lists();
            this.ListWebService.SetServer(webUrl, context);
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommonEntity"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="context">The context.</param>
        protected CommonEntity([NotNull] EntityProperties property, [NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(property, "property");
            Assert.ArgumentNotNull(context, "context");

            this.Context = context;
            this.FillProperty(property);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchWSSConnector"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public SearchWSSConnector([NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            this.SearchWebService = new QueryService();
            //Should be refactored.
            this.SearchWebService.SetServer(new Uri(context.Url), context);
            this.Context = context;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentTypeCollection"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="list">The list.</param>
        public ContentTypeCollection([NotNull] SpContext context, [NotNull] BaseList list)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(list, "list");

            this.Connector = new ContentTypeCollectionConnector(context, list.WebUrl);
            this.Context   = context;
            this.List      = list;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ListCollection"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="webUrl">The web URL.</param>
        public ListCollection([NotNull] SpContext context, [NotNull] Uri webUrl)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            this.Connector = new ListCollectionConnector(context, webUrl);
            this.Context   = context;
            this.WebUrl    = webUrl;
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseList"/> class.
        /// </summary>
        /// <param name="propertyValues">
        /// The property Values.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="webUrl">
        /// The url of Web.
        /// </param>
        /// <param name="node">
        /// The node. Should be removed.
        /// </param>
        public BaseList([NotNull] EntityValues propertyValues, [NotNull] SpContext context, [NotNull] Uri webUrl)
            : base(propertyValues.Properties, context)
        {
            Assert.ArgumentNotNull(propertyValues, "propertyValues");
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            this.WebUrl = webUrl;
            this.fields = this.LoadFields(propertyValues["Fields"]);
        }
Esempio n. 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentType"/> class.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="list">The list.</param>
        /// <param name="context">The context.</param>
        public ContentType([NotNull] EntityValues values, [NotNull] BaseList list, [NotNull] SpContext context)
            : base(values.Properties, context)
        {
            Assert.ArgumentNotNull(values, "values");
            Assert.ArgumentNotNull(list, "list");
            Assert.ArgumentNotNull(context, "context");

            this.Context = context;
            List         = list;
            Connector    = new ContentTypeConnector(context, this.List.WebUrl);
        }
Esempio n. 18
0
        /// <summary>
        /// Write debug information into log.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        public static void LogDebugInfo(SpContext context, string message)
        {
            string userDomain = context.Credentials is NetworkCredential ? (context.Credentials as NetworkCredential).Domain : "";
            string userName   = context.Credentials is NetworkCredential ? (context.Credentials as NetworkCredential).UserName : "";

            if (string.IsNullOrEmpty(userDomain) || String.IsNullOrEmpty(userName))//(context.Credentials == CredentialCache.DefaultNetworkCredentials)
            {
                userName   = "******" + System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                userDomain = "";
            }
            Log.Info(string.Format("Sharepoint Debug:{0}\n Context:{1}", message, userDomain + "\\" + userName), context);
        }
Esempio n. 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseItem"/> class.
        /// </summary>
        /// <param name="listName">The list name.</param>
        /// <param name="webUrl">The url of Web.</param>
        /// <param name="context">The context.</param>
        protected BaseItem([NotNull] string listName, [NotNull] Uri webUrl, [NotNull] SpContext context)
            : base(context)
        {
            Assert.ArgumentNotNull(listName, "listName");
            Assert.ArgumentNotNull(webUrl, "webUrl");
            Assert.ArgumentNotNull(context, "context");

            this.ListName = listName;
            this.WebUrl   = webUrl;

            this.Initialize();
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemCollection"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="list">The list.</param>
        /// <param name="options">The options.</param>
        public ItemCollection([NotNull] SpContext context, [NotNull] BaseList list, [NotNull] ItemsRetrievingOptions options)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(list, "list");
            Assert.ArgumentNotNull(options, "options");

            this.Context               = context;
            this.List                  = list;
            this.Options               = options;
            this.PageIndex             = 1;
            this.PagingQueryCollection = new Dictionary <int, string>();
            this.PagingQueryCollection.Add(1, string.Empty);
        }
        public ItemCollection([NotNull] SpContext context, [NotNull] BaseList list, [NotNull] string serializationString)
            : this(context, list, new ItemsRetrievingOptions())
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(list, "list");
            Assert.ArgumentNotNull(serializationString, "serializationString");

            var objects = (Dictionary <string, object>) this.Deserialize(serializationString);

            this.Options               = (ItemsRetrievingOptions)objects[OptionsSerializationObjectName];
            this.PageIndex             = (int)objects[PageIndexSerializationObjectName];
            this.PagingQueryCollection = (Dictionary <int, string>)objects[PagingQueriesSerializationObjectName];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string queryString        = Attributes["sc_parameters"];
            NameValueCollection param = Sitecore.Web.WebUtil.ParseUrlParameters(queryString);

            if (!string.IsNullOrEmpty(queryString))
            {
                if (!string.IsNullOrEmpty(param["Web"]))
                {
                    this.Web = param["Web"];
                }

                if (!string.IsNullOrEmpty(param["Server"]))
                {
                    this.ServerUrl = param["Server"];
                }

                if (!string.IsNullOrEmpty(param["SharepointServerType"]))
                {
                    this.SharepointServerType = param["SharepointServerType"];
                }
            }

            if (string.IsNullOrEmpty(this.Web))
            {
                this.Web = SharepointUtils.CurrentWebPath;
            }

            if (string.IsNullOrEmpty(this.ServerUrl))
            {
                ServerUrl = SharepointUtils.CurrentSharepointServer;
            }

            this.SpContext = SpContextProviderBase.Instance.CreateUIContext(this.ServerUrl, this.Web);
            NetworkCredential headerCredential = SharepointExtension.GetCredentialsFromHeader(Request);

            if (headerCredential != null)
            {
                SpContext.Credentials = headerCredential;
            }

            if (!string.IsNullOrEmpty(queryString) && string.IsNullOrEmpty(this.ListName) && !string.IsNullOrEmpty(param["List"]))
            {
                var list = ObjectModel.Entities.Lists.BaseList.GetList(SpContext.Url, param["List"], SpContext);
                if (list != null)
                {
                    this.ListName = list is ObjectModel.Entities.Lists.List ? "Lists/" + list.Name : list.Name;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentItemConnector"/> class.
        /// </summary>
        /// <param name="context">
        /// Sharepoint context to be used to connect to web services
        /// </param>
        /// <param name="document">
        /// Document that will use this connector
        /// </param>
        public DocumentItemConnector([NotNull] SpContext context, [NotNull] DocumentItem document)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(document, "document");

            this.ListsWebService = new Lists();
            this.ListsWebService.SetServer(document.WebUrl, context);

            this.CopyWebService = new Copy();
            this.CopyWebService.SetServer(document.WebUrl, context);

            this.context  = context;
            this.document = document;
        }
Esempio n. 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="View"/> class.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="list">The list.</param>
        /// <param name="context">The context.</param>
        public View([NotNull] EntityValues values, [NotNull] BaseList list, [NotNull] SpContext context)
            : base(values.Properties, context)
        {
            Assert.ArgumentNotNull(values, "values");
            Assert.ArgumentNotNull(list, "list");
            Assert.ArgumentNotNull(context, "context");

            this.Connector = new ViewConnector(context, list.WebUrl);
            this.Context   = context;
            this.List      = list;

            if (values["ViewFields"].Length > 0 && values.Properties["RowLimit"] != null)
            {
                this.Initialize(values);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemConnector"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="webUrl">The web URL.</param>
        /// <exception cref="Exception"><c>Throws exception if connector can't be created.</c>.</exception>
        public ItemConnector([NotNull] SpContext context, [NotNull] Uri webUrl)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            try
            {
                this.ListsWebService = new Lists();
                this.ListsWebService.SetServer(webUrl, context);
            }
            catch (Exception ex)
            {
                string errorMessage = "List item connector can't be created. Additional info:\n Server URL: {0}, webUrl: {1} ".FormatWith(context.Url, webUrl);
                Log.Error(errorMessage, ex, this);

                throw new Exception(errorMessage, ex);
            }
        }
Esempio n. 26
0
        protected static Uri GetUrlOfWeb([NotNull] string webName, [NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(webName, "webName");
            Assert.ArgumentNotNull(context, "context");

            string url;

            if (webName.Contains("://"))
            {
                url = webName;
            }
            else
            {
                url = StringUtil.EnsurePostfix('/', context.Url) + StringUtil.RemovePrefix('/', webName);
            }

            return(new Uri(url));
        }
Esempio n. 27
0
        public static Server Connect([NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            Dictionary <int, Server> cache = Sitecore.Context.Items[CacheKey] as Dictionary <int, Server>;

            if (cache == null)
            {
                cache = new Dictionary <int, Server>();
                Sitecore.Context.Items[CacheKey] = cache;
            }

            if (cache.ContainsKey(context.Hash))
            {
                return(cache[context.Hash]);
            }

            Server server = new Server(context);

            cache[context.Hash] = server;
            return(server);
        }
Esempio n. 28
0
        public static BaseItem GetItem([NotNull] string uniqueID, [NotNull] SpContext context, string viewName = null)
        {
            Assert.ArgumentNotNull(uniqueID, "uniqueID");
            Assert.ArgumentNotNull(context, "context");

            string[] values   = StringUtil.Split(uniqueID, '|', true);
            string   webUrl   = values[0];
            string   listName = values[1];
            string   id       = values[2];
            string   folder   = values[3];

            string wherePart = string.Format("<Eq><FieldRef Name=\"{0}\"/><Value Type=\"Integer\">{1}</Value></Eq>", "ID", id);
            var    itemsRetrievingOptions = new ItemsRetrievingOptions
            {
                WherePart = wherePart,
                ViewName  = viewName
            };

            if (!string.IsNullOrEmpty(folder))
            {
                itemsRetrievingOptions.Folder = folder;
            }

            BaseList       list  = BaseList.GetList(webUrl, listName, context);
            ItemCollection items = list.GetItems(itemsRetrievingOptions);

            if (items.Count == 1)
            {
                return(items[0]);
            }

            if (items.Count > 1)
            {
                throw new Exception("More than document has been found by ID");
            }

            throw new Exception("Document can't be found");
        }
Esempio n. 29
0
        /// <summary>Creates context.</summary>
        /// <param name="sharepointServer">The SharePoint server.</param>
        /// <param name="web">The web.</param>
        /// <param name="predefinedContext">The predefined context.</param>
        /// <param name="credentials">The credentials.</param>
        /// <param name="connectionConfiguration">The connection configuration.</param>
        /// <returns>The <see cref="SpContext"/>.</returns>
        protected virtual SpContext CreateContext(string sharepointServer, string web, string predefinedContext, ICredentials credentials = null, string connectionConfiguration = null)
        {
            var context = new SpContext
            {
                Url                     = !string.IsNullOrEmpty(sharepointServer) ? sharepointServer : SharepointUtils.CurrentSharepointServer,
                Credentials             = credentials,
                ConnectionConfiguration = connectionConfiguration
            };

            if (!string.IsNullOrEmpty(context.ConnectionConfiguration) && context.Credentials != null)
            {
                return(context);
            }

            ServerEntry serverEntry = this.GetServerEntry(StringUtil.EnsurePostfix('/', sharepointServer) + StringUtil.RemovePrefix('/', web), predefinedContext);

            if (serverEntry != null)
            {
                if (string.IsNullOrEmpty(context.ConnectionConfiguration))
                {
                    context.ConnectionConfiguration = serverEntry.ConnectionConfiguration;
                }

                if (context.Credentials == null)
                {
                    context.Credentials = serverEntry.Credentials;
                }
            }

            if (context.Credentials == null)
            {
                context.Credentials = this.DefaultCredentials;
                SharepointUtils.LogDebugInfo(context, "Using DefaultNetworkCredentials");
            }

            return(context);
        }
Esempio n. 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchBase"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public SearchBase([NotNull] SpContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            this.Context = context;
        }