Пример #1
0
 public Employee(string firstName, string secondName, DateTime birthDay
                 , Document.DocumentType documentType, string serial, string number, Department department)
     : this(firstName, secondName, birthDay)
 {
     this.EmployeeDocument = new Document(serial, number, documentType);
     this.Department       = department;
 }
Пример #2
0
 public void ChangePersonalInfo(string firstName, string secondName, DateTime birthDay
                                , Document.DocumentType documentType, string serial, string number, Department department)
 {
     this.FirstName        = firstName;
     this.SecondName       = secondName;
     this.BirthDay         = birthDay.Date;
     this.EmployeeDocument = new Document(serial, number, documentType);
     this.Department       = department;
 }
Пример #3
0
        public static void RequireDocumentType(this ITaskItem item, Document.DocumentType requiredDocumentType)
        {
            Document.DocumentType documentType = item.RequireDocumentType();

            if (documentType != requiredDocumentType)
            {
                throw new ArgumentException(string.Format("Document was of type {0} but must be of type {1}", documentType, requiredDocumentType));
            }
        }
Пример #4
0
        private void documentsView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;
            Document d    = node.Tag as Document;

            Document.DocumentType type = d == null ? Document.DocumentType.Folder : d.Type;

            if (node.Nodes.Count > 0 && type == Document.DocumentType.Folder)
            {
                node.SelectedImageIndex = 1;
                node.ImageIndex         = 1;
            }
        }
Пример #5
0
            public Stream Download(ITaskItem document, string exportFormat)
            {
                Document.DocumentType documentType = document.RequireDocumentType();

                string baseUrl = document.RequireExportUri();

                if (!string.IsNullOrEmpty(exportFormat))
                {
                    baseUrl = this.BuildDocumentPartialExportUrl(baseUrl) + exportFormat;
                }
                Uri queryUri = new Uri(baseUrl);

                return(base.Service.Query(queryUri));
            }
Пример #6
0
 public override Employee GetEmployee(string firstName, string secondName, DateTime birthDay, Document.DocumentType documentType, string serial, string number)
 {
     return(new Programmer(firstName, secondName, birthDay, documentType, serial, number, new Department("dsf")));
 }
Пример #7
0
            public Stream Download(ITaskItem input, Document.DownloadType type, string baseDomain = null, int sheetNumber = 0)
            {
                input.LoadCustomMetadata();
                Document.DocumentType documentType = input.RequireDocumentType();

                Service s        = this.Service;
                string  queryUri = this.BuildDocumentPartialExportUrl(input.RequireExportUri());

                switch (documentType)
                {
                case Document.DocumentType.Spreadsheet:
                    s = this.Service;
                    switch (type)
                    {
                    case Document.DownloadType.xls:
                        queryUri += "xls";
                        break;

                    case Document.DownloadType.csv:
                        queryUri += "csv&gid=" + sheetNumber.ToString();
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ods:
                        queryUri += "ods";
                        break;

                    case Document.DownloadType.tsv:
                        queryUri += "tsv&gid=" + sheetNumber.ToString();;
                        break;

                    case Document.DownloadType.html:
                        queryUri += "html";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a spreadsheet");
                    }
                    break;

                case Document.DocumentType.Presentation:
                    switch (type)
                    {
                    case Document.DownloadType.swf:
                        queryUri += "swf";
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ppt:
                        queryUri += "ppt";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a presentation");
                    }
                    break;

                case Document.DocumentType.Unknown:
                    break;

                default:
                    queryUri += type.ToString();
                    break;
                }

                Uri target = new Uri(queryUri);

                return(s.Query(target));
            }
Пример #8
0
 public Programmer(string firstName, string secondName, DateTime birthDay, Document.DocumentType documentType
                   , string serial, string number, Department department)
     : base(firstName, secondName, birthDay, documentType, serial, number, department)
 {
 }
Пример #9
0
        /// <summary>
        /// Deletes an entry with a given id.
        /// </summary>
        /// <param name="entryId">ResourceId of the entry to be deleted.</param>
        /// <param name="entryType">Type of the entry (Document or Folder).</param>
        public static void DeleteEntry(string entryId, Document.DocumentType entryType)
        {
            Working = true;

            // we will only rename documents and folders
            if (entryType != Document.DocumentType.Document && entryType != Document.DocumentType.Folder)
            {
                throw new ArgumentException(string.Format("Invalid entryType ({0})", entryType));
            }

            var doc           = entryType == Document.DocumentType.Document ? AllDocuments[entryId] : AllFolders[entryId];
            var entryToDelete = doc.DocumentEntry;

            try
            {
                _documentService.ProtocolMajor = 3;
                entryToDelete.Delete();
            }
            catch (GDataRequestException exRequest)
            {
                var response = exRequest.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.PreconditionFailed &&
                    exRequest.ResponseString.ToLowerInvariant().Contains("etagsmismatch"))
                {
                    // ETags don't match -> this document has been updated outside this instance of Nocs
                    // or it was just saved -> let's update it and try renaming again
                    Debug.WriteLine(string.Format("ETags don't match, couldn't find {0} - updating it and trying delete again..", doc.ETag));
                    doc = GetUpdatedDocument(doc);
                    DeleteEntry(doc.ResourceId, doc.Type);
                }
                else
                {
                    var error = GetErrorMessage(exRequest);
                    if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                    {
                        throw new GDataRequestException("Couldn't delete entry, connection timed out");
                    }

                    var knownIssues = ConsecutiveKnownIssuesOccurred(DeleteEntryLock, "DeleteEntry", doc, error, ref _deleteEntryAttempts, 1);
                    if (knownIssues == KnownIssuesResult.Retry)
                    {
                        doc = GetUpdatedDocument(doc);
                        DeleteEntry(doc.ResourceId, doc.Type);
                        doc.Summary          = null;
                        _deleteEntryAttempts = 0;
                        return;
                    }
                    else if (knownIssues == KnownIssuesResult.LimitReached)
                    {
                        return;
                    }

                    Trace.WriteLine(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                    throw new GDataRequestException(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                }
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                throw new Exception(string.Format("Couldn't delete entry: {0} - {1}", doc.DocumentEntry.Title.Text, error));
            }
            finally
            {
                Working = false;
            }

            // let's update the appropriate dictionary
            if (entryType == Document.DocumentType.Document)
            {
                AllDocuments.Remove(entryId);
            }
            else
            {
                AllFolders.Remove(entryId);
            }
        }
Пример #10
0
        /// <summary>
        /// Renames an entry (Document or Folder) with a given id.
        /// </summary>
        /// <param name="entryId">ResourceId of the entry to be renamed.</param>
        /// <param name="newTitle">New title for the entry to be renamed.</param>
        /// <param name="entryType">Type of the entry (Document or Folder).</param>
        public static void RenameEntry(string entryId, string newTitle, Document.DocumentType entryType)
        {
            Working = true;

            // we will only rename documents and folders
            if (entryType != Document.DocumentType.Document && entryType != Document.DocumentType.Folder)
            {
                throw new ArgumentException(string.Format("Invalid entryType ({0})", entryType));
            }

            var doc             = entryType == Document.DocumentType.Document ? AllDocuments[entryId] : AllFolders[entryId];
            var entryToUpdate   = doc.DocumentEntry;
            var documentContent = doc.Content;

            try
            {
                _documentService.ProtocolMajor = 3;
                entryToUpdate.Title.Text       = newTitle;
                // AtomEntry shouldn't have any text in its content field, so let's reset it for now
                entryToUpdate.Content.Content = string.Empty;
                entryToUpdate = entryToUpdate.Update() as DocumentEntry;
            }
            catch (GDataRequestException exRequest)
            {
                var response = exRequest.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.PreconditionFailed &&
                    exRequest.ResponseString.ToLowerInvariant().Contains("etagsmismatch"))
                {
                    // ETags don't match -> this document has been updated outside this instance of Nocs
                    // or it was just saved -> let's update it and try renaming again
                    Debug.WriteLine(string.Format("ETags don't match, couldn't find {0} - updating it and trying rename again..", doc.ETag));
                    doc = GetUpdatedDocument(doc);
                    RenameEntry(doc.ResourceId, newTitle, doc.Type);
                }
                else
                {
                    var error = GetErrorMessage(exRequest);
                    if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                    {
                        throw new GDataRequestException("Couldn't rename entry, connection timed out");
                    }

                    var knownIssues = ConsecutiveKnownIssuesOccurred(RenameEntryLock, "RenameEntry", doc, error, ref _renameEntryAttempts, 1);
                    if (knownIssues == KnownIssuesResult.Retry)
                    {
                        doc = GetUpdatedDocument(doc);
                        RenameEntry(doc.ResourceId, newTitle, doc.Type);
                        doc.Summary          = null;
                        _renameEntryAttempts = 0;
                        return;
                    }
                    else if (knownIssues == KnownIssuesResult.LimitReached)
                    {
                        return;
                    }

                    Trace.WriteLine(string.Format("Couldn't rename {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                    throw new GDataRequestException(string.Format("Couldn't rename {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                }
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                throw new Exception(string.Format("Couldn't rename {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, error));
            }
            finally
            {
                Working = false;
            }

            // let's update the document (mostly for Etag) and update document dictionary
            if (entryToUpdate != null)
            {
                entryToUpdate.IsDraft = false;
                doc.AtomEntry         = entryToUpdate;
                doc.Content           = documentContent;
                if (entryType == Document.DocumentType.Document)
                {
                    AllDocuments[entryId] = doc;
                }
                else
                {
                    AllFolders[entryId] = doc;
                }
            }
        }
Пример #11
0
 public abstract Employee GetEmployee(string firstName, string secondName, DateTime birthDay
                                      , Document.DocumentType documentType, string serial, string number);