Exemple #1
0
        public void OnProviderDownloadStatisticsUpdated(CloudMount mount, StatisticUpdateReason reason, AStatisticFileInfo info)
        {
            var cloud = mount.CloudInfo;

            switch (reason)
            {
            case StatisticUpdateReason.DownloadAdded:
            {
                var item = new FileItemInfo(cloud.Id, info.Id)
                {
                    CloudIcon    = mount.Instance.CloudServiceIcon,
                    FileName     = info.FileName,
                    FullPath     = $"{mount.MountLetter}:{info.Path}",
                    ErrorMessage = info.ErrorMessage,
                    Total        = info.Total,
                    CloudName    = cloud.Name
                };
                DownloadFiles.Remove(item);
                DownloadFiles.Add(item);
            }

            break;

            case StatisticUpdateReason.DownloadFinished:
            {
                DownloadFiles.Remove(new FileItemInfo(cloud.Id, info.Id));
            }

            break;

            case StatisticUpdateReason.DownloadFailed:
            {
                var item = UploadFiles.Single(f => f.Id == info.Id && f.CloudId == cloud.Id);
                item.ErrorMessage = info.ErrorMessage;
                DownloadFiles.Remove(item);
                DownloadFailedFiles.Add(item);
                if (DownloadFailedFiles.Count > 10)
                {
                    DownloadFailedFiles.RemoveAt(DownloadFailedFiles.Count - 1);
                }
            }

            break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private void Save()
        {
            if (DetailsViewEditItem.CurrentMode == DetailsViewMode.Insert)
            {
                Logger.LogInfo("DetailsViewEditItem.CurrentMode == DetailsViewMode.Insert", "DownloadFiles");
                try
                {
                    //DetailsViewEditItem.InsertItem(false);
                    DownloadFile downloadFile = new DownloadFile();
                    var fu = DetailsViewEditItem.FindControl("fuFile") as FileUpload;
                    if (fu != null && fu.HasFile)
                    {
                        downloadFile.FileName = fu.PostedFile.FileName;
                        downloadFile.MimeType = fu.PostedFile.ContentType;
                        string path = WebConfigurationManager.AppSettings["DownloadFilesPath"];
                        string filePath = Path.Combine(path, downloadFile.FileName);
                        Logger.LogInfo("FileUpload exists", "DownloadFiles");
                        fu.PostedFile.SaveAs(filePath);
                        Logger.LogInfo("File was saved " + filePath, "DownloadFiles");
                    }
                    var txtName = DetailsViewEditItem.FindControl("txtName") as TextBox;
                    if (txtName != null)
                    {
                        Logger.LogInfo("txtName exists ", "DownloadFiles");
                        downloadFile.Name = txtName.Text;
                    }
                    var txtDescription = DetailsViewEditItem.FindControl("txtDescription") as TextBox;
                    if (txtDescription != null)
                    {
                        downloadFile.Description = txtDescription.Text;
                    }
                    var ddl = DetailsViewEditItem.FindControl("ddlCategory") as DropDownList;
                    if (ddl != null)
                    {
                        downloadFile.TypeId = Convert.ToInt32(ddl.SelectedValue);
                    }
                    DownloadFiles m = new DownloadFiles();
                    Logger.LogInfo("Saving DownloadFiles ", "DownloadFiles");
                    m.Add(downloadFile);
                    Logger.LogInfo("Saved DownloadFiles ", "DownloadFiles");
                    ID = downloadFile.ID;
                    uploadImage();

                    //    DetailsViewEditItem.ChangeMode(DetailsViewMode.Edit);
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex, "DownloadFiles");
                    ShowError(ex);
                }

            }
            else if (DetailsViewEditItem.CurrentMode == DetailsViewMode.Edit)
            {
                Logger.LogInfo("DetailsViewEditItem.CurrentMode == DetailsViewMode.Edit", "DownloadFiles");
                DetailsViewEditItem.UpdateItem(false);
            }
        }
        /// <summary>
        /// Deserializes the object from XML.
        /// </summary>
        /// <param name="reader">The xml reader from which to deserialize the object.</param>
        public void ReadXml(XmlReader reader)
        {
            bool booIsEmpty = reader.IsEmptyElement;

            if (booIsEmpty)
            {
                return;
            }
            reader.ReadStartElement();

            reader.ReadStartElement("sourceUri");
            XmlSerializer xsrSerializer = new XmlSerializer(typeof(string));

            SourceUri = new Uri((string)xsrSerializer.Deserialize(reader));
            reader.ReadEndElement();

            reader.ReadStartElement("sourcePath");
            xsrSerializer = new XmlSerializer(typeof(string));
            SourcePath    = (string)xsrSerializer.Deserialize(reader);
            reader.ReadEndElement();

            booIsEmpty = reader.IsEmptyElement;
            try
            {
                reader.ReadStartElement("sourceName");

                if (!booIsEmpty)
                {
                    while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "string")
                    {
                        xsrSerializer = new XmlSerializer(typeof(string));
                        SourceName.Add((string)xsrSerializer.Deserialize(reader));
                    }
                    reader.ReadEndElement();
                }
            }
            catch
            {
            }
            finally
            {
                if (SourceName.Count == 0)
                {
                    SourceName.Add("Default");
                }
            }

            reader.ReadStartElement("defaultSourcePath");
            xsrSerializer     = new XmlSerializer(typeof(string));
            DefaultSourcePath = (string)xsrSerializer.Deserialize(reader);
            reader.ReadEndElement();


            try
            {
                reader.ReadStartElement("status");
                xsrSerializer = new XmlSerializer(typeof(TaskStatus));
                Status        = (TaskStatus)xsrSerializer.Deserialize(reader);
                reader.ReadEndElement();
            }
            catch
            {
                Status = TaskStatus.Paused;
            }

            booIsEmpty = reader.IsEmptyElement;
            reader.ReadStartElement("downloadFiles");
            if (!booIsEmpty)
            {
                while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "file")
                {
                    DownloadFiles.Add(new Uri(reader["path"]));
                    booIsEmpty = reader.IsEmptyElement;
                    reader.ReadStartElement("file");
                    if (!booIsEmpty)
                    {
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
            }

            booIsEmpty = reader.IsEmptyElement;
            reader.ReadStartElement("downloadedFiles");
            if (!booIsEmpty)
            {
                while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "file")
                {
                    DownloadedFiles.Add(reader["path"]);
                    booIsEmpty = reader.IsEmptyElement;
                    reader.ReadStartElement("file");
                    if (!booIsEmpty)
                    {
                        reader.ReadEndElement();
                    }
                }
                reader.ReadEndElement();
            }

            reader.ReadEndElement();
        }