Example #1
0
        public static bool Move(IHierarchyItem item, IFolder target, string newName,
                                bool overwrite, LockCollection locks)
        {
            string sourcePath                 = item.Href.AbsolutePath;
            bool   isSourceFolder             = item is IFolder;
            List <LockUriTokenPair> lockPairs = GetLockPairs(item, locks);

            try
            {
                item.MoveTo(target, newName, overwrite,
                            (lockPairs != null) ? lockPairs.ToArray() : null);
                ChangeLocks(sourcePath, isSourceFolder, target, newName, locks);
                return(true);
            }
            catch (WebDavException ex)
            {
                WebDavHttpException exept = ex as WebDavHttpException;
                if (exept == null || exept.Multistatus.Responses.Length == 0)
                {
                    Informator.ShowError(item.DisplayName + ": " + ex.Message);
                }
                else
                {
                    return(false);
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
 public static void UpdateProperties(IHierarchyItem item, Property[] toAddOrUpdate, PropertyName[] toDelete, string lockToken)
 {
     try
     {
         item.UpdateProperties(toAddOrUpdate, toDelete, lockToken);
     }
     catch (Exception e)
     {
         Informator.ShowError(e.ToString());
     }
 }
Example #3
0
 public static IFolder GetFolder(IFolder folder, string name)
 {
     try
     {
         return(folder.GetFolder(name));
     }
     catch (Exception ex)
     {
         Informator.ShowError(name + ": " + ex.Message);
         return(null);
     }
 }
Example #4
0
 public static IHierarchyItem[] GetChildren(IFolder folder)
 {
     try
     {
         return(folder.GetChildren(false));
     }
     catch (Exception ex)
     {
         Exception e = ex.InnerException ?? ex;
         Informator.ShowError(folder.DisplayName + ": " + e.Message);
         return(new IHierarchyItem[0]);
     }
 }
Example #5
0
 public static bool Copy(IHierarchyItem item, IFolder target, bool overwrite)
 {
     try
     {
         item.CopyTo(target, item.DisplayName, true, overwrite);
         return(true);
     }
     catch (Exception ex)
     {
         Informator.ShowError(item.DisplayName + ": " + ex.Message);
         return(false);
     }
 }
Example #6
0
        public async Task <bool> Connect(string url, string username, string passw, string dom)
        {
            client = new Client(new NetworkCredential {
                UserName = username, Password = passw
            });
            client.BasePath = "/";
            client.Server   = url;
            c.Server        = url;
            c.User          = username;
            c.Pass          = passw;
            c.BasePath      = "/";
            try
            {
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Depth", "0");
                HttpResponseMessage response = null;

                Uri ServerAdress = new Uri(url);
                response = await client.HttpRequest(ServerAdress, Prop, headers, Encoding.UTF8.GetBytes(PropFindRequestContent)).ConfigureAwait(false);

                if (response.StatusCode != (HttpStatusCode)207)
                {
                    connectSuccess = false;
                    WebDAVException ex = new WebDAVException((int)response.StatusCode, string.Format("Не удалось подключиться к серверу (Status Code: {0})", response.StatusCode));
                    throw ex;
                }
                connectSuccess = true;
                //ConnectDiag.Hide();
            }
            catch (WebDAVException ex)
            {
                connectSuccess = false;
                //ConnectDiag.Hide();
                System.Console.WriteLine(ex.ToString());
                Informator.ShowError("Connection failure");
            }
            catch (WebException e)
            {
                //ConnectDiag.Hide();
                connectSuccess = false;
                Informator.ShowError(e.Message);
            }
            catch (Exception e)
            {
                //ConnectDiag.Hide();
                connectSuccess = false;
                Exception ex = e.InnerException ?? e;
                Informator.ShowError("Unable to connect to the remote server.\nReason: " + ex.Message, null);
            }
            return(connectSuccess);
        }
Example #7
0
 public static IHierarchyItem[] GetChildrenDeep(IFolder folder)
 {
     try
     {
         return(folder.GetChildren(true));
     }
     catch (ForbiddenException)
     {
         return(null);
     }
     catch (Exception ex)
     {
         Informator.ShowError(folder.DisplayName + ": " + ex.Message);
         return(new IHierarchyItem[0]);
     }
 }
Example #8
0
 public static bool UpdateToVersion(IResource item, IVersion version, string lockToken)
 {
     try
     {
         if (lockToken != null)
         {
             item.UpdateToVersion(version, lockToken);
         }
         else
         {
             item.UpdateToVersion(version);
         }
         return(true);
     }
     catch (Exception e)
     {
         WebDavHttpException ex = e as WebDavHttpException;
         string status          = (ex != null && ex.Status != null)
                             ? "\nStatus: " + ex.Status.Description
                             : string.Empty;
         Informator.ShowError(item.DisplayName + ": " + e.Message + status);
         return(false);
     }
 }