Example #1
0
        public ClientQueryInternal SelectSubQuery(ClientQueryInternal subQuery)
        {
            if (string.IsNullOrEmpty(subQuery.Name))
            {
                throw new ArgumentException("subQuery", Resources.GetString("RequestEmptyQueryName"));
            }
            ClientQueryProperty clientQueryProperty = null;

            if (this.m_properties.TryGetValue(subQuery.Name, out clientQueryProperty))
            {
                if (clientQueryProperty.ScalarPropertySet && clientQueryProperty.ScalarProperty)
                {
                    throw ClientUtility.CreateArgumentException("subQuery");
                }
                if (clientQueryProperty.Query != null && clientQueryProperty.Query != subQuery)
                {
                    throw ClientUtility.CreateArgumentException("subQuery");
                }
                clientQueryProperty.Query = subQuery;
            }
            else
            {
                clientQueryProperty              = new ClientQueryProperty();
                clientQueryProperty.Query        = subQuery;
                this.m_properties[subQuery.Name] = clientQueryProperty;
            }
            return(this);
        }
 public StreamInfo(string streamId, Stream stream)
 {
     if (string.IsNullOrEmpty(streamId))
     {
         throw new ArgumentNullException("streamId");
     }
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (stream.Length < 0L)
     {
         throw ClientUtility.CreateArgumentException("stream");
     }
     this.m_id     = streamId;
     this.m_stream = stream;
 }
Example #3
0
        internal string GetAuthenticationCookie(Uri url, bool refresh, bool alwaysThrowOnFailure)
        {
            if (url == null)
            {
                throw ClientUtility.CreateArgumentNullException("url");
            }
            if (!url.IsAbsoluteUri)
            {
                throw ClientUtility.CreateArgumentException("url");
            }
            Uri    uri  = new Uri(url, "/");
            string text = null;

            SharePointOnlineCredentials.CookieCacheEntry cookieCacheEntry = (SharePointOnlineCredentials.CookieCacheEntry) this.m_cachedCookies[uri];
            if (!refresh && cookieCacheEntry != null && cookieCacheEntry.IsValid)
            {
                ClientULS.SendTraceTag(3454916u, ClientTraceCategory.Authentication, ClientTraceLevel.Verbose, "Get cookie from cache for URL {0}", new object[]
                {
                    uri
                });
                return(cookieCacheEntry.Cookie);
            }
            if (refresh)
            {
                ISharePointOnlineAuthenticationProvider sharePointOnlineAuthenticationProvider = SharePointOnlineAuthenticationProviderHelper.CreateDefaultProvider();
                text = sharePointOnlineAuthenticationProvider.GetAuthenticationCookie(uri, this.m_userName, this.m_password, alwaysThrowOnFailure, this.ExecutingWebRequest);
                if (!string.IsNullOrEmpty(text))
                {
                    ClientULS.SendTraceTag(3454917u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "Put cookie in cache for URL {0}", new object[]
                    {
                        uri
                    });
                    lock (this.m_lock)
                    {
                        this.m_cachedCookies[uri] = new SharePointOnlineCredentials.CookieCacheEntry
                        {
                            Cookie  = text,
                            Expires = DateTime.UtcNow.AddHours(1.0)
                        };
                    }
                }
            }
            return(text);
        }
        protected internal void UpdateClientObjectPropertyType(string propertyName, object propertyValue, JsonReader reader)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw ClientUtility.CreateArgumentNullException("propertyName");
            }
            if (propertyValue == null)
            {
                throw ClientUtility.CreateArgumentNullException("propertyValue");
            }
            if (reader == null)
            {
                throw ClientUtility.CreateArgumentNullException("reader");
            }
            ClientObject clientObject = propertyValue as ClientObject;

            if (clientObject == null)
            {
                throw ClientUtility.CreateArgumentException("propertyValue");
            }
            if (!this.ObjectData.ClientObjectProperties.ContainsKey(propertyName))
            {
                throw ClientUtility.CreateArgumentException("propertyName");
            }
            string scriptType;

            if (reader.PeekTokenType() == JsonTokenType.ObjectStart && reader.PeekObjectType(out scriptType))
            {
                Type typeFromScriptType = ScriptTypeMap.GetTypeFromScriptType(scriptType);
                //Edited for .NET Core
                //if (typeFromScriptType != null && typeFromScriptType != propertyValue.GetType() && propertyValue.GetType().IsAssignableFrom(typeFromScriptType))
                if (typeFromScriptType != null && typeFromScriptType != propertyValue.GetType())
                {
                    ClientObject clientObject2 = ScriptTypeMap.CreateObjectFromScriptType(scriptType, this.Context) as ClientObject;
                    if (clientObject2 != null)
                    {
                        clientObject.SetTypedObject(clientObject2);
                        this.ObjectData.ClientObjectProperties[propertyName] = clientObject2;
                    }
                }
            }
        }
Example #5
0
        public SharePointOnlineCredentials(string username, SecureString password)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw ClientUtility.CreateArgumentNullException("username");
            }
            int num = username.IndexOf('@');

            if (num < 0 || num == username.Length - 1)
            {
                throw ClientUtility.CreateArgumentException("username");
            }
            if (password == null)
            {
                throw ClientUtility.CreateArgumentNullException("password");
            }
            SharePointOnlineAuthenticationModule.EnsureRegistered();
            this.m_userName = username;
            this.m_password = password;
        }
Example #6
0
        private static void LoadAssembliesDefinedInProgramFiles()
        {
            string text = ClientUtility.GetSetupDirectory();

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            text = Path.Combine(text, "TypeAssemblies");
            if (Directory.Exists(text))
            {
                string[] files = Directory.GetFiles(text, "ClientTypeAssembly.*.xml");
                for (int i = 0; i < files.Length; i++)
                {
                    string path = files[i];
                    try
                    {
                        using (TextReader textReader = System.IO.File.OpenText(path))
                        {
                            //XmlDocument xmlDocument = new XmlDocument();
                            //xmlDocument.Load(XmlReader.Create(textReader));
                            //foreach (XmlNode xmlNode in xmlDocument.DocumentElement.ChildNodes)
                            //{
                            //    if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "AssemblyName")
                            //    {
                            //        Assembly.Load(xmlNode.InnerText);
                            //    }
                            //}
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ScriptTypeMap.IsFatalException(ex))
                        {
                            throw;
                        }
                    }
                }
            }
        }
Example #7
0
        public T CastTo <T>(ClientObject obj) where T : ClientObject
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            ClientAction.CheckActionParameterInContext(this, obj);
            Type typeFromHandle = typeof(T);

            //Edited for .NET Core
            //if (!typeof(ClientObject).IsAssignableFrom(typeFromHandle))
            if (!typeof(ClientObject).GetTypeInfo().IsAssignableFrom(typeFromHandle))
            {
                throw new ArgumentException();
            }
            if (obj.Context != this)
            {
                throw new InvalidOperationException();
            }
            T t;

            //Edited for .NET Core
            //if (typeFromHandle.IsAssignableFrom(obj.GetType()))
            if (typeFromHandle.GetTypeInfo().IsAssignableFrom(obj.GetType()))
            {
                t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[]
                {
                    this,
                    obj.Path
                }));
                t.SetObjectDataFrom(obj);
                return(t);
            }
            //Edited for .NET Core
            //if (obj.ObjectData.AssociatedObject != null && typeFromHandle.IsAssignableFrom(obj.ObjectData.AssociatedObject.GetType()))
            if (obj.ObjectData.AssociatedObject != null && typeFromHandle.GetTypeInfo().IsAssignableFrom(obj.ObjectData.AssociatedObject.GetType()))
            {
                t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[]
                {
                    this,
                    obj.Path
                }));
                t.SetObjectDataFrom(obj);
                return(t);
            }
            //Edited for .NET Core
            //if (!obj.GetType().IsAssignableFrom(typeFromHandle))
            if (!obj.GetType().GetTypeInfo().IsAssignableFrom(typeFromHandle))
            {
                throw ClientUtility.CreateArgumentException("type");
            }
            //Edited for .NET Core
            //if (obj.ObjectData.AssociatedObject != null && !obj.ObjectData.AssociatedObject.GetType().IsAssignableFrom(typeFromHandle))
            if (obj.ObjectData.AssociatedObject != null && !obj.ObjectData.AssociatedObject.GetType().GetTypeInfo().IsAssignableFrom(typeFromHandle))
            {
                throw ClientUtility.CreateArgumentException("type");
            }
            t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[]
            {
                this,
                obj.Path
            }));
            t.SetObjectDataFrom(obj);
            object obj2;

            if (obj.ObjectData.AssociatedObject == null)
            {
                obj2 = obj;
            }
            else
            {
                obj2 = obj.ObjectData.AssociatedObject;
            }
            if (obj2 != null)
            {
                List <string> list = new List <string>();
                Dictionary <string, object> queryIdToObjectMap = this.PendingRequest.QueryIdToObjectMap;
                foreach (KeyValuePair <string, object> current in queryIdToObjectMap)
                {
                    if (object.ReferenceEquals(current.Value, obj2))
                    {
                        list.Add(current.Key);
                    }
                }
                foreach (string current2 in list)
                {
                    queryIdToObjectMap[current2] = t;
                }
                obj.ObjectData.AssociatedObject = t;
            }
            return(t);
        }