Exemple #1
0
        private static void OnItemStatusChanged(SmartItem item)
        {
            string status = item.Status.ToString();

            if (status.Ends("Error"))
            {
                item.OptColor = SolidColors.DarkRed;
            }
            else if (status.Equal("Ignored"))
            {
                item.OptColor = SolidColors.DarkOrange;
            }
            else if (status.Ends("ed"))
            {
                item.OptColor = SolidColors.SolidBlue;
            }
            else
            {
                item.OptColor = SolidColors.DarkGreen;
            }
            item.Operation = AppLanguage.Get("LangOperation" + status);

            switch (item.Status)
            {
            case ItemStatus.Uploading: Counts.Files++; Counts.Update(); break;

            case ItemStatus.Created: Counts.Folders++; Counts.Update(); break;
            }
        }
Exemple #2
0
 internal static void ItemStatusChanged(SmartItem item)
 {
     if (OnItemStatusChanged != null)
     {
         new ItemStatusChangedHandler(OnItemStatusChanged)(item);
     }
 }
Exemple #3
0
 internal void RequestingAction(SmartItem existItem, bool canResume)
 {
     if (OnRequestingAction != null)
     {
         new RequestingActionHandler(OnRequestingAction)(existItem, canResume);
     }
 }
Exemple #4
0
        internal static async void RenameAsync(SmartItem item, string name)
        {
            Lock();
            await mainClient.RenameItemAsync(item, name);

            UnLock();
        }
Exemple #5
0
        internal static SmartItem[] SelectedItems(this ListView list, SmartCollection collection)
        {
            if (list.SelectedItems.Count == 0)
            {
                return(null);
            }
            SmartItem[] items = new SmartItem[list.SelectedItems.Count];

            try { list.SelectedItems.CopyTo(items, 0); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();
            if (items.Length == 0)
            {
                return(null);
            }

            List <SmartItem> itemsList = new List <SmartItem>();

            for (int i = 0; i < items.Length; i++)
            {
                if ((items[i].Status == ItemStatus.CreateError) || ((items[i].Status == ItemStatus.UploadError) && (items[i].Length == 0)))
                {
                    AppMessage.Add("\"" + items[i].ItemName + "\" Dose not Exist.", MessageType.Warning);
                    collection.Remove(items[i]);
                }
                else
                {
                    itemsList.Add(items[i]);
                }
            }

            return((itemsList.Count > 0) ? itemsList.ToArray() : null);
        }
        private static void transferHistoryLog(SmartItem item, string localFolder)
        {
            ItemStatus HistoryStatus = item.Status;

            switch (HistoryStatus)
            {
            case ItemStatus.Ignored:
                break;

            case ItemStatus.Uploading:
                HistoryStatus = (!item.HasError) ? ItemStatus.Uploaded : ItemStatus.UploadError;
                break;

            case ItemStatus.Downloading:
                HistoryStatus = (!item.HasError) ? ItemStatus.Downloaded : ItemStatus.DownloadError;
                break;

            case ItemStatus.Replacing:
                HistoryStatus = (!item.HasError) ? ItemStatus.Replaced : ItemStatus.ReplaceError;
                break;

            case ItemStatus.Resuming:
                HistoryStatus = (!item.HasError) ? ItemStatus.Resumed : ItemStatus.ResumeError;
                break;
            }

            AppHistory.Add(item.ItemName, item.Destination, localFolder, item.Destination, HistoryStatus);
        }
Exemple #7
0
        internal static SmartItem[] SelectedItems(this ListBox list)
        {
            if (list.SelectedItems.Count == 0)
            {
                return(null);
            }
            SmartItem[] items = new SmartItem[list.SelectedItems.Count];

            try { list.SelectedItems.CopyTo(items, 0); }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();

            return((items.Length > 0) ? items : null);
        }
Exemple #8
0
        internal static SmartItem SelectedItem(this ListView list)
        {
            if (list.SelectedItems.Count != 1)
            {
                return(null);
            }

            SmartItem item = null;

            try { item = list.SelectedItem as SmartItem; }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            list.UnselectAll();

            return(item);
        }
Exemple #9
0
        protected static SmartItem InsertItem(SmartItem item, bool checkPath = true)
        {
            if (checkPath && (item.ItemFolder != BrowsedPath))
            {
                return(null);
            }

            try
            {
                int id = Items.GetLastFolderID();
                Items.Insert(id, item);
                return(Items[id]);
            }
            catch (Exception exp) { ExceptionHelper.Log(exp); }

            return(null);
        }
Exemple #10
0
        protected async Task _uploadFileAsync()
        {
            string source = TransferEvent.Item.FullName;

            TransferEvent.Item.FullName   = TransferEvent.Item.Destination + TransferEvent.Item.ItemName;
            TransferEvent.Item.ItemFolder = TransferEvent.Item.Destination;
            bool notIgnored = (!TransferEvent.Item.HasError && (TransferEvent.Item.Status != ItemStatus.Ignored));

            if (notIgnored)
            {
                SmartItem item = GetServerItem(TransferEvent.Item.ItemName, TransferEvent.Item.ItemFolder, TransferEvent.Item);
                if (item != null)
                {
                    item.Modified           = DateTime.Now.Ticks;
                    item.LastModified       = null;
                    item.ProgressBarEnabled = (item.Length > 1048576);
                }

                await _sendFileAsync(source);
            }
        }
        private static void downloadEnded(SmartItem item, string localFolder)
        {
            transferHistoryLog(item, localFolder);

            SmartItem eitem = GetServerItem(item.ItemName, item.ItemFolder);

            if (eitem == null)
            {
                return;
            }

            eitem.Status             = item.Status;
            eitem.HasError           = item.HasError;
            eitem.ProgressBarEnabled = false;

            if (eitem.Status != ItemStatus.Ignored)
            {
                eitem.Status = (eitem.HasError) ? ItemStatus.DownloadError : ItemStatus.Downloaded;
            }
            TransferEvents.ItemStatusChanged(eitem);
        }
Exemple #12
0
        internal static async Task <string> GetNewName(this SmartItem[] items, SmartItem item)
        {
            if (items.Length == 0)
            {
                return(item.ItemName);
            }

            string oName        = item.ItemName;
            string name         = string.Empty;
            bool   hasExtension = item.IsFile && !item.Extension.NullEmpty();

            if (hasExtension)
            {
                oName = oName.Replace('.' + item.Extension, string.Empty);
            }

            await Task.Run(() =>
            {
                int i = 0;

                while (i < items.Length)
                {
                    name = oName + '_' + ++i;
                    if (GetItemID(items, item.ItemFolder + name +
                                  ((hasExtension) ? '.' + item.Extension : string.Empty)) == -1)
                    {
                        break;
                    }
                }
            });

            if (hasExtension)
            {
                name += '.' + item.Extension;
            }

            return(name);
        }
Exemple #13
0
        internal static SmartItem GetServerItem(string name, string path, SmartItem item = null, bool clearCacheAfter = false)
        {
            if ((path != BrowsedPath) || ((Items.Count == 0) && (item == null)))
            {
                return(null);
            }

            int id = Items.GetID(path + name);

            if (clearCacheAfter)
            {
                Items.ClearCache();
            }

            if (id == -1)
            {
                if (item != null)
                {
                    return(InsertItem(item, false));
                }
            }
            else
            {
                try
                {
                    if (item != null)
                    {
                        Items[id] = item;
                    }
                    return(Items[id]);
                }
                catch (Exception exp) { ExceptionHelper.Log(exp); }
            }

            return(null);
        }
        private static void uploadEnded(SmartItem item, string localFolder)
        {
            transferHistoryLog(item, localFolder);

            SmartItem eitem = GetServerItem(item.ItemName, item.ItemFolder);

            if (eitem == null)
            {
                return;
            }

            eitem.Status             = item.Status;
            eitem.Length             = eitem.Transferred;
            eitem.FileSize           = null;
            eitem.HasError           = item.HasError;
            eitem.ProgressBarEnabled = false;

            switch (eitem.Status)
            {
            case ItemStatus.Ignored:
                break;

            case ItemStatus.Uploading:
                eitem.Status = (eitem.HasError) ? ItemStatus.UploadError : ItemStatus.Uploaded;
                break;

            case ItemStatus.Replacing:
                eitem.Status = (eitem.HasError) ? ItemStatus.ReplaceError : ItemStatus.Replaced;
                break;

            case ItemStatus.Resuming:
                eitem.Status = (eitem.HasError) ? ItemStatus.ResumeError : ItemStatus.Resumed;
                break;
            }
            TransferEvents.ItemStatusChanged(eitem);
        }
Exemple #15
0
 internal virtual Task <bool> RenameItemAsync(SmartItem item, string toName)
 {
     throw new NotImplementedException();
 }
Exemple #16
0
 internal virtual Task <bool> ChangePermissionsync(SmartItem item, string permission)
 {
     throw new NotImplementedException();
 }
Exemple #17
0
 internal virtual Task <bool> DeleteItemAsync(SmartItem item)
 {
     throw new NotImplementedException();
 }
        internal async Task TransferItemsAsync(object items, string destination, bool IsUpload)
        {
            TransferEvent.IsUpload = IsUpload;
            TransferEvent.Starting();
            TransferEvent.Items = IsUpload ? await _prepareForUpload(items as string[], destination.TrimEnd('/') + '/') :
                                  await _prepareForDownload(items as SmartItem[], destination.TrimEnd('\\') + '\\');

            items = null;
            if (TransferEvent.Items.Length > 0)
            {
                SmartItem[] IIDP = new SmartItem[] { }; // Items In Destination Path
                TransferEvent.Action        = TransferAction.Unknown;
                TransferEvent.SessionAction = TransferAction.Unknown;
                string dstination = string.Empty; // Last Destination Path
                int    j          = -1;
                bool   hasParent  = false;
                bool   mayExist   = false;
                bool   samePath   = false;

                if (DefaultAction != TransferAction.Unknown)
                {
                    TransferEvents.TillCloseAction = DefaultAction;
                }

                TransferEvent.Started();
                for (int i = 0; i < TransferEvent.Items.Length; i++)
                {
                    if (IsCanceled)
                    {
                        break;
                    }
                    TransferEvent.Item          = TransferEvent.Items[i];
                    TransferEvent.Item.HasError = false;
                    //TransferEvent.Item.Status = ItemStatus.Unknown;
                    if (dstination != TransferEvent.Item.Destination)
                    {
                        dstination = TransferEvent.Item.Destination;
                        TransferEvent.PathChanged(TransferEvent.Item.ItemFolder, dstination);

                        hasParent = (TransferEvent.Item.ParentId != -1);
                        mayExist  = (!hasParent || TransferEvent.Items[TransferEvent.Item.ParentId].Exist);

                        if (mayExist)
                        {
                            if (IsUpload)
                            {
                                IIDP = await getServerItemsAsync(TransferEvent.Item.Destination);

                                if (IIDP == null)
                                {
                                    IIDP = new SmartItem[] { }
                                }
                                ;
                            }
                            else
                            {
                                IIDP = await _getLocalItemsAsync(TransferEvent.Item.Destination);
                            }

                            mayExist = (IIDP.Length != 0);
                        }
                    }

                    samePath = ((IsUpload ? TransferEvent.Item.Destination : TransferEvent.Item.ItemFolder) == BrowsedPath);

                    if (hasParent && TransferEvent.Items[TransferEvent.Item.ParentId].HasError)
                    {
                        TransferEvent.Item.HasError = true;
                        if (TransferEvent.Item.IsFile)
                        {
                            TransferEvent.TotalTransferredFiles++;
                        }
                        else
                        {
                            TransferEvent.TotalTransferredFolders++;
                        }
                        TransferEvent.Item.Status = ItemStatus.Ignored;
                        transferHistoryLog(TransferEvent.Item, TransferEvent.Item.ItemFolder);
                        if (samePath)
                        {
                            TransferEvents.ItemStatusChanged(TransferEvent.Item);
                        }
                        continue;
                    }

                    j = -1;
                    if (mayExist)
                    {
                        j = ListExtensions.GetItemID(IIDP, TransferEvent.Item.Destination + TransferEvent.Item.ItemName);
                        TransferEvent.Item.Exist = (j > -1);
                    }

                    if (TransferEvent.Item.IsFile)
                    {
                        await setTransferAction(IsUpload, IIDP, j);

                        if (samePath)
                        {
                            TransferEvents.ItemStatusChanged(TransferEvent.Item);
                        }

                        if (IsUpload)
                        {
                            string localFolder = TransferEvent.Item.ItemFolder;
                            await _uploadFileAsync();

                            uploadEnded(TransferEvent.Item, localFolder);
                        }
                        else
                        {
                            await _downloadFileAsync();

                            downloadEnded(TransferEvent.Item, TransferEvent.Item.ItemFolder);
                        }
                        TransferEvent.TotalTransferredFiles++;
                    }
                    else
                    {
                        if (IsUpload)
                        {
                            TransferEvent.Item.HasError = !(TransferEvent.Item.Exist || await CreateFolderAsync(TransferEvent.Item.ItemName, TransferEvent.Item.Destination, false));
                        }
                        else
                        {
                            TransferEvent.Item.HasError = !(TransferEvent.Item.Exist || (_createLocalFolder(TransferEvent.Item.Destination + TransferEvent.Item.ItemName)));
                            //TransferEvent.Item.Status = (!TransferEvent.Item.HasError) ? ItemStatus.Downloaded : ItemStatus.DownloadError;
                            //TransferEvents.ItemStatusChanged(TransferEvent.Item.FullName);
                        }

                        TransferEvent.TotalTransferredFolders++;
                    }
                }
            }
            TransferEvent.Ended();
        }
Exemple #19
0
 internal virtual Task <bool> MoveItemAsync(SmartItem item, string toPath)
 {
     throw new NotImplementedException();
 }
Exemple #20
0
        internal static async Task <bool> SetItemsAsync(string path)
        {
            if (path.NullEmpty())
            {
                return(false);
            }
            if ((path != LocalHelper.ThisPC) && !DirectoryHelper.Exists(path))
            {
                return(false);
            }

            fsw.EnableRaisingEvents = false;
            List <SmartItem> items  = new List <SmartItem>();
            bool             listed = false;
            await Task.Run(() =>
            {
                if (path == Home)
                {
                    SmartItem item = new SmartItem();
                    item.FullName  = item.ItemName = LocalHelper.ThisPC;
                    item.ItemIcon  = IconHelper.Get((int)ImageList.SpecialFolderCSIDL.DRIVES);

                    items.Add(item);
                    //items.Add(documentsPath);
                    listed = true;
                }

                if (path == LocalHelper.ThisPC)
                {
                    DriveInfo[] localDrives = DirectoryHelper.GetDrives();
                    try
                    {
                        for (int i = 0; i < localDrives.Length; i++)
                        {
                            SmartItem Ditem = new SmartItem(new DirectoryInfo(localDrives[i].Name));
                            Ditem.ItemName  = (localDrives[i].IsReady ? localDrives[i].VolumeLabel : string.Empty) + " (" + localDrives[i].Name.TrimEnd('\\') + ')' + (localDrives[i].IsReady ?
                                                                                                                                                                       " " + AppLanguage.Get("LangFreeSpaceX").FormatC(SizeUnit.Parse(localDrives[i].AvailableFreeSpace)) : string.Empty);
                            items.Add(Ditem);
                        }
                        listed = true;
                    }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }
                    localDrives = null;
                }
                else
                {
                    DirectoryInfo Localdir = null;
                    try { Localdir = new DirectoryInfo(path); }
                    catch (Exception exp) { ExceptionHelper.Log(exp); }

                    if (Localdir != null)
                    {
                        listed = true;
                        DirectoryInfo[] dirs = null;
                        try
                        {
                            dirs = Localdir.GetDirectories();
                            for (int i = 0; i < dirs.Length; i++)
                            {
                                if ((dirs[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    items.Add(new SmartItem(dirs[i]));
                                }
                            }
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        dirs = null;

                        FileInfo[] files = null;
                        try
                        {
                            files = Localdir.GetFiles();
                            for (int i = 0; i < files.Length; i++)
                            {
                                if ((files[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                                {
                                    items.Add(new SmartItem(files[i]));
                                }
                            }
                        }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                        files = null;
                    }
                    Localdir = null;
                }
            });

            if (listed)
            {
                if (DirectoryHelper.Exists(path))
                {
                    if (fsw.Path != path)
                    {
                        fsw.Path = path;
                    }
                    fsw.EnableRaisingEvents = true;
                }

                LastPath    = CurrentPath;
                CurrentPath = path;

                if (path == LocalHelper.ThisPC)
                {
                    ParentPath = Home;
                }
                else
                {
                    ParentPath = DirectoryHelper.GetParentPath(path);
                }

                Items = new ObservableCollection <SmartItem>(items);
                return(true);
            }
            else
            {
                return(false);
            }
        }