コード例 #1
0
        public void Run()
        {
            _running = true;
            try
            {
                OriginHistory history = _origin.StartBatch(_folder);


                foreach (string file in scanFolder(_folder))
                {
                    Record record = _origin.NewRecord(history);

                    // We need to call this to trigger the Origin functionality to create a new folder
                    // and put this Record in the folder
                    _origin.AllocateContainer(record);

                    record.SetDocument(file);
                    record.Save();

                    File.Delete(file);
                }
            }
            finally
            {
                _running = false;
            }
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: raybelline/Community
        public static async Task CheckinFromDrive(this Record record, string driveId, string token, bool saveRecord = false)
        {
            string downloadUrl = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId);

            var fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);

            string filePath = Path.Combine(TrimApplication.WebServerWorkPath, fileResult.Name);


            await ODataHelper.GetItem <string>(downloadUrl, token, filePath);

            var inputDocument = new InputDocument(filePath);


            inputDocument.CheckinAs = record.SuggestedFileName;
            record.SetDocument(inputDocument, true, false, "checkin from Word Online");

            string pdfPath = Path.Combine(TrimApplication.WebServerWorkPath, Path.ChangeExtension(fileResult.Name, "pdf"));
            string pdfUrl  = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId, "pdf");
            await ODataHelper.GetItem <string>(pdfUrl, token, pdfPath);


            var rendition = record.ChildRenditions.NewRendition(pdfPath, RenditionType.Longevity, "Preview");


            if (saveRecord)
            {
                record.Save();

                File.Delete(filePath);
                File.Delete(pdfPath);
            }
            return;
        }
コード例 #3
0
        public async System.Threading.Tasks.Task <RecordDocument> Post(RecordDocument recordDocument)
        {
            // string result = await Request.Content.ReadAsStringAsync();

            string userUPN = await GetUser();

            string fileName = Path.Combine("c:\\junk", "WordAddin", $"{Guid.NewGuid()}.docx");

            using (var file = File.Create(fileName))
            {
                file.Write(recordDocument.Data, 0, recordDocument.Data.Length);
                file.Close();
            }

            long uri;

            if (Int64.TryParse(GetCustomProperty(fileName, "CM_Record_Uri"), out uri))
            {
                using (Database db = getDatabase(userUPN))
                {
                    Record record = new Record(db, uri);

                    //    byte[] data = Convert.FromBase64String(result);


                    record.SetDocument(new InputDocument(fileName), true, recordDocument.KeepBookedOut, null);
                    record.Save();

                    File.Delete(fileName);
                    return(new RecordDocument(record));
                }
            }

            throw new ApplicationException($"Error with document");
        }
コード例 #4
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string token = await getToken();


            RegisterFileResponse response = new RegisterFileResponse();

            Record record = new Record(this.Database, request.Uri);

            string driveId = record.ExternalReference;

            var registeredFile = new RegisterdFileResponse()
            {
                Id = driveId
            };


            request.Action = request.Action ?? "";

            if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.AddToFavorites();
            }

            if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.RemoveFromFavorites();
            }


            if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                var driveDetails = await ODataHelper.GetItem <string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token);

                record.SetDocument(new InputDocument(driveDetails), true, false, "checkin from Word Online");
            }

            if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                record.ExternalReference = "";
            }

            if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                record.SetAsFinal(false);
            }

            record.Save();

            updateFromRecord(registeredFile, record);

            response.Results = new List <RegisterdFileResponse>()
            {
                registeredFile
            };
            return(response);
        }
コード例 #5
0
        public object Post(CommitRequest request)
        {
            // Locate record by URI
            long uri = request.Uri;

            if (uri <= 0)
            {
                throw new ApplicationException($"Invalid URI: {uri}");
            }

            Record   record       = new Record(Database, uri);
            Location trimUser     = Database.CurrentUser;
            Location checkedOutTo = record.CheckedOutTo;

            string checkoutPath = record.CheckedOutPath;

            // Abort if not checked out to current user.
            if (checkedOutTo == null || (checkedOutTo != null && checkedOutTo.Uri != trimUser.Uri))
            {
                throw new ApplicationException("Document is not checked out to requesting user.");
            }


            if (!checkoutPath.StartsWith(SHARED_DIR))
            {
                throw new ApplicationException("Document is not checked out to the shared path.");
            }

            if (!System.IO.File.Exists(checkoutPath))
            {
                throw new ApplicationException($"Document is already checked out to '{trimUser.Name}' but working copy can't be found in expected location '{checkoutPath}' on server.");
            }

            // Electronic document was found.  Now update revision, check in document and return response.
            InputDocument inpDoc = new InputDocument(checkoutPath);

            inpDoc.CheckinAs = Path.GetFileName(record.ESource); // Preserve original file name when checking back in
            record.SetDocument(inpDoc, request.NewRevision, request.KeepCheckedOut, request.Comments);
            record.Save();                                       // Calling record.SetCheckedOutPath(WEBDAV_CHECKOUT_PATH) below prevents the new revision from being saved, so save the record first.
            if (request.KeepCheckedOut)
            {
                // SetDocument overrides checkedoutpath, so call this function to set it back to how we want it and save the record again
                // TODO - ask Rory why it works this way
                record.SetCheckedOutPath(checkoutPath);
                record.Save();
            }
            // Remove document from webdav if checking back in
            if (!request.KeepCheckedOut)
            {
                File.Delete(checkoutPath);
            }

            return(new CommitResponse());
        }
コード例 #6
0
        private static void Migrate()
        {
            string connectionString = "Data Source=yfdev.cloudapp.net;Initial Catalog=SCC_ECM;Persist Security Info=True;User ID=EPL;Password=Password1!";
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                using (SqlCommand command = new SqlCommand("SELECT top 25 * FROM View_1", con))
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    using (Database db = new Database())
                    {
                        db.Id = "03";
                        db.Connect();
                        while (reader.Read())
                        {
                            RecordType rt = new RecordType(db, 16);
                            Record rCont = GetFolderUri(reader.GetString(6), reader.GetString(7), db);
                            if (rCont != null)
                            {

                                Record r = new Record(rt);
                                r.Container = rCont;
                                r.LongNumber = reader.GetInt32(0).ToString();
                                r.Title = reader.GetString(1);
                                r.DateCreated = (TrimDateTime)reader.GetDateTime(2);
                                string loc = "D:\\" + reader.GetString(3);
                                if (File.Exists(loc))
                                {
                                    InputDocument id = new InputDocument(loc);
                                    r.SetDocument(id, false, false, "Migrated from ECM t1");
                                }

                                r.Save();
                                Console.WriteLine("Record Created: " + r.Number);
                            }
                            else
                            {
                                Console.WriteLine("Could not find folder");
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: CreateDoc.cs プロジェクト: hayans/MF-Code
        private void btnCreateDoc_Click(object sender, EventArgs e)
        {
            try
            {
                using (Database db = new Database())
                {
                    db.Id = ConfigurationManager.AppSettings["dbid"];
                    if (db.IsValid)//check whether db is valid, if not show error message
                    {
                        FileInfo fi = new FileInfo(txtFilePath.Text.Trim());

                        //define record type
                        RecordType recType = new RecordType(db, ConfigurationManager.AppSettings["recordType"]);

                        HP.HPTRIM.SDK.Record rd = new Record(recType);
                        rd.Title = fi.Name;

                        HP.HPTRIM.SDK.InputDocument objDoc = new InputDocument();
                        objDoc.SetAsFile(txtFilePath.Text.Trim());


                        rd.Author = db.CurrentUser;
                        rd.SetDocument(objDoc, false, false, "Created via SDK");
                        rd.Save();

                        MessageBox.Show("Newly created document Record Number: " + rd.Number.ToString());
                        //nullify used objects before exit, so that  GC can collect it
                        rd     = null;
                        objDoc = null;
                    }
                    else
                    {
                        MessageBox.Show("Loader database error: " + db.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #8
0
        private static long CreateNewRMRecord(string FileLoc, long cont, Database db)
        {
            long uri = 0;
            string newtitle = null;
            try
            {
                if (File.Exists(FileLoc))
                {
                    RecordType rt = null;
                   // Console.WriteLine("Document location: " + FileLoc);
                    string strExt = Path.GetExtension(FileLoc);
                    switch (strExt)
                    {
                        //Documents
                        case ".PDF":
                        case ".pdf":
                        case ".DOC":
                        case ".doc":
                        case ".XLS":
                        case ".xls":
                        case ".DOCX":
                        case ".docx":
                        case ".XLSX":
                        case ".xlsx":
                        case ".ppt":
                        case ".PPT":
                        case ".pptx":
                        case ".PPTX":
                        case ".DOTX":
                        case ".dotx":
                        case ".TXT":
                        case ".txt":
                        case ".CSV":
                        case ".csv":
                        case ".PUB":
                        case ".pub":
                        case ".HTML":
                        case ".html":
                        case ".HTM":
                        case ".htm":
                        case ".DWG":
                        case ".dwg":
                        case ".RTF":
                        case ".rtf":
                        case ".XLSM":
                        case ".xlsm":
                        case ".MP4":
                        case ".mp4":
                        case ".DOT":
                        case ".dot":
                        case ".VSD":
                        case ".vsd":
                        case ".ZIP":
                        case ".zip":
                        case ".PSD":
                        case ".psd":
                        case ".RDL":
                        case ".rdl":
                        case ".XML":
                        case ".xml":
                        case ".INDD":
                        case ".MHT": //NS
                        case ".MPP": //NS
                        case ".CFM": //NS
                        case ".XLTM": //NS
                        case ".SHX": //NS   
                        case ".PPSX": //NS
                        case ".CSS": //NS
                        case ".XLTX": //NS
                        case ".JS": //NS"
                        case ".OTF": //NS
                        case ".VST": //NS
                        case ".WMV": //NS
                        case ".WMZ": //NS
                        case ".OFT": //NS
                        case ".MOV": //NS
                        case ".PPS": //NS
                        case ".MDB": //NS
                        case ".EPS": //NS
                        case ".XPS": //NS
                        case ".XLSB": //NS
                        case ".MID": //NS
                        case ".THMX": //NS
                        case ".TMP": //NS 
                        case ".TTF": //NS
                        case ".MXD": //NS
                        case ".ICS": //NS
                        case ".DOCM": //NS
                        case ".BPMN": //NS
                        case ".AI": //NS
                        case ".AVI": //NS
                        case ".DXF": //NS
                        case ".INI": //NS
                        case ".LOG": //NS
                        case ".LST": //NS
                        case ".ODT": //NS
                        case ".PARTIAL": //NS
                        case ".POT": //NS
                        case ".POTX": //NS
                        case ".VSDX": //NS
                        case ".SKP": //NS
                        case ".SHS": //NS
                        case ".RPT": //NS
                        case ".XLA": //NS

                            rt = new RecordType(db, 2);
                            break;
                        //Images
                        case ".JPG":
                        case ".TIF":
                        case ".jpg":
                        case ".tif":
                        case ".PNG":
                        case ".png":
                        case ".JPEG":
                        case ".jpeg":
                        case ".GIF":
                        case ".gif":
                        case ".BMP":
                        case ".bmp":
                        case ".MPEG":
                        case ".TIFF": 
                            rt = new RecordType(db, 14);
                            break;
                        //Mail
                        case ".EML":
                        case ".eml":
                        case ".msg":
                        case ".MSG":
                            rt = new RecordType(db, 3);
                            newtitle = SetEmailTitle(FileLoc);
                            break;
                    }


                        Record rcont = new Record(db, cont);
                        Record r = new Record(rt);
                        Location lo = new Location(db, 5503);
                        if (newtitle != null)
                            r.Title = newtitle;
                        r.SetDocument(FileLoc);
                        r.SetAssignee(lo);
                        r.SetOwnerLocation(lo);
                        r.Container = rcont;
                    
                        r.Save();
                        uri = r.Uri;
                        Console.WriteLine("Migrated document from: " + FileLoc + " and saved as " + r.Number);
                        db.LogExternalEvent("Document migrated from: " + FileLoc, BaseObjectTypes.Record, uri, true);
                }
                else
                {
                    Console.WriteLine("Document location does not exist: " + FileLoc);
                    db.LogExternalEvent("Document location does not exist: "+FileLoc, BaseObjectTypes.Record, Convert.ToInt64(cont), true);
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error: " + exp.Message.ToString());
                db.LogExternalEvent("Error migrating: " + FileLoc+" Error: "+exp.Message.ToString(), BaseObjectTypes.Record, Convert.ToInt64(cont), true);
            }
            return uri;
        }
コード例 #9
0
        public async Task <object> Post(DriveFileOperation request)
        {
            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.SpURL;

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }


                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        //	filePath = Path.Combine(TrimApplication.WebServerWorkPath, record.SuggestedFileName);


                        //using (var stream = new FileStream(filePath, FileMode.Append))
                        //{
                        //	stream.Write(request.Data, 0, request.Data.Length);
                        //}

                        //if (request.LastDataSlice == true)
                        //{
                        //	record.SetDocument(new InputDocument(filePath), true, false, "checkin from Word Online");
                        //} else
                        //{
                        //	response.Results = new List<RegisterdFileResponse>() { registeredFile };
                        //	return response;
                        //}
                        //	var driveDetails = await ODataHelper.GetItem<string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token, filePath);

                        var inputDocument = new InputDocument(request.FileName);


                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token);

                    record.SpURL = "";
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(request.FileName))
                {
                    File.Delete(request.FileName);
                }
            }
        }
コード例 #10
0
        public async Task <object> Post(DriveFileOperation request)
        {
            string fileName = request.FileName;

            try
            {
                RegisterFileResponse response = new RegisterFileResponse();

                Record record = new Record(this.Database, request.Uri);
                record.Refresh();

                string driveId = record.GetDriveId();

                var registeredFile = new RegisterdFileResponse()
                {
                    Id = driveId
                };


                request.Action = request.Action ?? "";

                if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.AddToFavorites();
                }

                if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.RemoveFromFavorites();
                }

                if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1 &&
                    request.Action.IndexOf("checkin-requst-del", StringComparison.InvariantCultureIgnoreCase) < 1)
                {
                    string token = await getToken();

                    if (!string.IsNullOrWhiteSpace(request.FileName))
                    {
                        if (!Path.IsPathRooted(request.FileName))
                        {
                            fileName = Path.Combine(this.ServiceDefaults.UploadBasePath, request.FileName);
                        }

                        var inputDocument = new InputDocument(fileName);

                        inputDocument.CheckinAs = request.WebUrl;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                    else
                    {
                        string downloadUrl = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId);

                        var fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null);

                        string filePath = Path.Combine(TrimApplication.WebServerWorkPath, fileResult.Name);


                        await ODataHelper.GetItem <string>(downloadUrl, token, filePath);



                        var inputDocument = new InputDocument(filePath);


                        inputDocument.CheckinAs = record.SuggestedFileName;
                        record.SetDocument(inputDocument, true, false, "checkin from Word Online");
                    }
                }

                if (request.Action.IndexOf("request-del", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetDeleteNow(!record.GetDeleteNow());
                }

                if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    string token = await getToken();

                    await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrlForDelete(driveId), token);

                    record.SetDriveId("");
                }

                if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    record.SetAsFinal(false);
                }

                record.Save();

                updateFromRecord(registeredFile, record);

                response.Results = new List <RegisterdFileResponse>()
                {
                    registeredFile
                };
                return(response);
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
コード例 #11
0
 private static object findmessagid(FileInfo f)
 {
     string msgid = null;
     using(Database db = new Database())
     {
         RecordType rt = new RecordType(db, 3);
         Record r = new Record(rt);
         r.Container = new Record(db, 172739);
         r.Title = f.Name;
         r.SetDocument(f.FullName);
         r.Save();
         msgid = r.MessageId;
         r.Delete();
     }
     return msgid;
 }
コード例 #12
0
        static void ProcessApplication(string Name)
        {
            TrimApplication.Initialize();
            using (Database db = new Database())
            {
                db.Id = "10";
                db.Connect();
                JsonSerializer s = new JsonSerializer();
                try
                {
                    T1Application t1 = null;
                    using (StreamReader sr = new StreamReader(Name))
                    {
                        using (JsonTextReader reader = new JsonTextReader(sr))
                        {
                            //T1Integration t1 = new T1Integration();
                            t1 = (T1Application)s.Deserialize(reader, typeof(T1Application));
                        }
                    }
                    if (t1 != null)
                    {
                        FieldDefinition fdPropertyAddress = new FieldDefinition(db, 502);
                        if (t1.EddieUri == 0)
                        {
                            RecordType rt = new RecordType(db, 2);
                            Record rec = new Record(rt);
                            if (t1.PropertyNumber != 0)
                            {
                                Record cont = new Record(db, t1.PropertyNumber);
                                rec.Container = cont;
                            }
                            //FieldDefinition fdPropertyNo = new FieldDefinition(db, 504);
                            rec.Title = "Application - " + t1.ApplicationNumber;
                            //rec.SetFieldValue(fdPropertyNo, new UserFieldValue(t1.PropertyNumber));
                            //rec.SetFieldValue(fdPropertyAddress, new UserFieldValue(t1.PropertyAddress));
                            //Classification c = new Classification(db, 2616);
                            //rec.Classification = c;
                            FileInfo f = new FileInfo(t1.documentLoc);
                            if (f.Exists)
                            {
                                rec.SetDocument(new InputDocument(t1.documentLoc), false, false, "");
                            }
                            rec.Save();
                            t1.EddieUri = rec.Uri;
                            t1.EddieRecordUrl = rec.WebURL;
                            Console.WriteLine("New application record created ok - number: " + rec.Number);
                        }
                        else
                        {
                            //RecordType rt = new RecordType(db, 2);
                            Record rec = new Record(db, t1.EddieUri);
                            //Record cont = new Record(db, t1.lEddieUri);
                            //rec.Container = cont;
                            //rec.Title = "Application - " + t1.ApplicationNo;
                            //if (t1.propertyLoc != null)
                            //{
                            //    rec.SetDocument(t1.propertyLoc);
                            //}
                            //rec.SetFieldValue(fdPropertyAddress, new UserFieldValue(t1.PropertyAddress));
                            FileInfo f1 = new FileInfo(t1.documentLoc);
                            if (f1.Exists)
                            {
                                rec.SetDocument(new InputDocument(t1.documentLoc), true, false, "");
                            }
                            rec.Save();
                            //t1.EddieUri = rec.Uri;
                            t1.EddieRecordUrl = rec.WebURL;
                            Console.WriteLine("Application record upgrades - number: " + rec.Number);
                        }
                        using (StreamWriter sw = new StreamWriter(pathout + "T1 Application - " + t1.PropertyNumber.ToString() + ".txt"))
                        {
                            using (JsonWriter writer = new JsonTextWriter(sw))
                            {
                                s.Serialize(writer, t1);
                                Console.WriteLine("Application file returned");
                            }
                        };
                        FileInfo f2 = new FileInfo(Name);
                        if (f2.Exists)
                            f2.Delete();
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine("Error: " + exp.Message.ToString());
                    throw;
                }

            }

        }