Beispiel #1
0
 /// <summary>
 /// Opus on server
 /// </summary>
 public int GetDocumentId(bool ask = true)
 {
     if (ask)
     {
         if (!_documentId.HasValue || _documentId.GetValueOrDefault() == 0)
         {
             var getDocumentDlg = new GetDocument();
             if (getDocumentDlg.ShowDialog() == DialogResult.OK)
             {
                 if (getDocumentDlg.NewDocument && getDocumentDlg.ProjectId.HasValue)
                 {
                     if (getDocumentDlg.DocumentId.HasValue)
                     {
                         SetDocumentId(getDocumentDlg.DocumentId.Value);
                         // after we have the id we read the properties and store in the document service
                         GetDocumentSettings(_documentId.Value, (e) => {
                             ServicePool.Instance.GetService <DocumentService>().ListingSnippetDefault = e.ListingSnippetDefault;
                             ServicePool.Instance.GetService <DocumentService>().ChapterTextDefault    = e.ChapterDefault;
                             ServicePool.Instance.GetService <DocumentService>().SectionTextDefault    = e.SectionDefault;
                         });
                     }
                 }
             }
         }
     }
     return(_documentId.GetValueOrDefault());
 }
        public async void TestNotExistingDoc()
        {
            var getDoc = new GetDocument()
            {
                Type = "test-doc-type",
                Name = "test"
            };

            var returnDoc = new Document()
            {
                Type = "test-doc-type",
                Name = "test",
                Body = null
            };

            var jbClient = new Moq.Mock <JsonballClient>();

            jbClient.Setup(c => c.GetDocumentAsync(getDoc, CancellationToken.None)).ReturnsAsync(returnDoc);

            var dm  = new DocumentManager(jbClient.Object, true);
            var doc = await dm.GetDocumentAsync <SimpleDocument>("test");

            Assert.Null(doc);
            Assert.Equal(new ListenOnChangeDocument[]
            {
                new ListenOnChangeDocument()
                {
                    Type        = "test-doc-type",
                    Name        = "test",
                    Properties  = new string[] {},
                    NewDocument = true,
                },
            }, dm.BuildListenOnChange());
        }
        public IActionResult Load(long?ID, long?langId)
        {
            GetDocument operation = new GetDocument();

            operation.ID = ID;

            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <Document>)result));
            }
        }
 public Document GetDocument(GetDocument documentInfo)
 {
     return(new Document()
     {
         Id = documentInfo.Id,
         RawJsonValue = Documents.ContainsKey(documentInfo.Id) ? Documents[documentInfo.Id] : null,
     });
 }
Beispiel #5
0
        async Task <CommandResult <SimpleDocument> > HandleAsync(GetDocument command)
        {
            var projectUri      = command.ProjectId.ToKotoriProjectUri();
            var documentTypeUri = command.ProjectId.ToKotoriDocumentTypeUri(command.DocumentType, command.DocumentTypeId);

            var project = await FindProjectAsync(command.Instance, projectUri).ConfigureAwait(false);

            if (project == null)
            {
                throw new KotoriProjectException(command.ProjectId, "Project does not exist.")
                      {
                          StatusCode = System.Net.HttpStatusCode.NotFound
                      }
            }
            ;

            var d = await FindDocumentByIdAsync
                    (
                command.Instance,
                projectUri,
                command.ProjectId.ToKotoriDocumentUri(command.DocumentType, command.DocumentTypeId, command.DocumentId, command.Index),
                command.Version
                    ).ConfigureAwait(false);

            if (d == null)
            {
                if (command.Version.HasValue)
                {
                    throw new KotoriDocumentException(command.DocumentId, "Document version not found.")
                          {
                              StatusCode = System.Net.HttpStatusCode.NotFound
                          }
                }
                ;

                throw new KotoriDocumentException(command.DocumentId, "Document not found.")
                      {
                          StatusCode = System.Net.HttpStatusCode.NotFound
                      };
            }

            return(new CommandResult <SimpleDocument>
                   (
                       new SimpleDocument
                       (
                           new Uri(d.Identifier).ToKotoriDocumentIdentifier().DocumentId,
                           d.Slug,
                           d.Meta,
                           DocumentHelpers.PostProcessedContent(d.Content, d.Meta, command.Format),
                           d.Date.DateTime,
                           d.Modified.DateTime,
                           d.Draft,
                           d.Version
                       )
                   ));
        }
    }
}
Beispiel #6
0
 private byte[] GetDocumentOnDisk()
 {
     #region GetDocument
     GetDocument.ShowDialog();
     // convert doc to byte stream
     byte[] docBytes = StreamFile(GetDocument.FileName);
     #endregion
     return(docBytes);
 }
        public override async Task <Document> GetDocumentAsync(GetDocument doc, CancellationToken ct = default)
        {
            var request = new InvokeRequest();

            request.InvocationType = InvocationType.RequestResponse;
            request.FunctionName   = GetDocumentFunction;
            request.Payload        = JsonSerializer.Serialize(doc);
            var response = await _lambda.InvokeAsync(request, ct);

            return(await JsonSerializer.DeserializeAsync <Document>(response.Payload, _jsonDeserializeOptions, cancellationToken : ct));
        }
Beispiel #8
0
        public Document GetDocument(GetDocument documentInfo)
        {
            Configuration.DocumentsConfiguration config = this.configProvider.ReadConfiguration();
            Configuration.Document configDoc            = config.Documents.FirstOrDefault(c => c.Collection == documentInfo.Collection);
            if (configDoc == null)
            {
                return(null);
            }

            var result = new Document();

            result.RawJsonValue = dataProvider.GetDocument(documentInfo.Collection, documentInfo.Id);
            var document = JsonConvert.DeserializeObject <Dictionary <string, object> >(result.RawJsonValue);

            if (document == null)
            {
                return(null);
            }


            foreach (Configuration.Reference reference in configDoc.ReferringTo)
            {
                // TODO: use enum
                if (reference.Relation == "many" && document.ContainsKey(reference.PrimaryKey))
                {
                    string rawIds = document[reference.PrimaryKey].ToString();
                    foreach (string item in JsonConvert.DeserializeObject <string[]>(rawIds))
                    {
                        result.References.Add(new Reference()
                        {
                            Document   = reference.PrimaryKey,
                            Id         = item,
                            Collection = reference.Collection,
                        });
                    }
                }

                // TODO: use enum
                else if (reference.Relation == "single" && document.ContainsKey(reference.PrimaryKey))
                {
                    string id = document[reference.PrimaryKey].ToString();
                    result.References.Add(new Reference()
                    {
                        Document   = reference.PrimaryKey,
                        Id         = id,
                        Collection = reference.Collection
                    });
                }
            }

            return(result);
        }
Beispiel #9
0
        public object GetDocumentList(GetDocument doc)
        {
            dynamic       TBDocumentistResult;
            List <object> DocumentListResult = new List <object>();
            DataSet       Result             = new DataSet();

            try
            {
                Result = DocumentSafe.GetDocumentList(doc);
                DataTable dt  = Result.Tables[0];
                DataTable dt1 = Result.Tables[1];

                List <DocumentList> res = new List <DocumentList>();

                if (dt.Rows.Count > 0)
                {
                    res = GlobalFuns.DataTableToList <DocumentList>(dt);

                    for (int i = 0; i < res.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(res[i].docURL))
                        {
                            string docURL = res[i].docURL.ToString();
                            string path   = ConfigurationManager.AppSettings["imgPath"] + "Documents/documentsafe/Group" + doc.grpID + "/";
                            res[i].docURL = path + docURL;
                        }
                    }
                }


                for (int i = 0; i < res.Count; i++)
                {
                    DocumentListResult.Add(new { DocumentList = res[i] });
                }

                if (res != null && res.Count != 0)
                {
                    TBDocumentistResult = new { status = "0", message = "success", smscount = dt1.Rows[0]["SMSCount"].ToString(), DocumentLsitResult = DocumentListResult };
                }
                else
                {
                    TBDocumentistResult = new { status = "1", message = "Record not found", smscount = dt1.Rows[0]["SMSCount"].ToString(), DocumentLsitResult = DocumentListResult };
                }
            }
            catch
            {
                TBDocumentistResult = new { status = "1", message = "failed", smscount = 0 };
            }

            return(new { TBDocumentistResult });
        }
        public async void TestTracing()
        {
            var getDoc = new GetDocument()
            {
                Type = "person",
                Name = "firstname",
            };

            var jbClient = new Mock <JsonballClient>();

            jbClient.Setup(c => c.GetDocumentAsync(getDoc, It.IsAny <CancellationToken>())).ReturnsAsync(
                new Document()
            {
                Type    = "person",
                Name    = "firstname",
                Version = 5,
                Body    = new Tracing.Person()
                {
                    Name = "firstname"
                }
            });

            var dm     = new DocumentManager(jbClient.Object, true);
            var preson = await dm.GetDocumentAsync <Tracing.IPerson>("person", "firstname");

            // with the following assert wie use the property "name"
            // it should be traced ...
            Assert.Equal("firstname", preson.Name);

            var listener = dm.BuildListenOnChange();

            Assert.Single(listener);
            Assert.Equal("person", listener[0].Type);
            Assert.Equal("firstname", listener[0].Name);
            Assert.Equal <uint>(5, listener[0].Version);
            Assert.Equal(new string[] { "/name" }, listener[0].Properties);
        }
        //private static TouchBaseWebAPI.Data.row_productionEntities _DBTouchbase = new TouchBaseWebAPI.Data.row_productionEntities();

        public static DataSet GetDocumentList(GetDocument doc)
        {
            try
            {
                //var groupId = new MySqlParameter("?groupId", doc.grpID);
                //var memId = new MySqlParameter("?memberProfileId", doc.memberProfileID);

                //var Result = _DBTouchbase.ExecuteStoreQuery<DocumentList>("CALL USPGetDocumentList(?groupId,?memberProfileId)", groupId, memId).ToList();

                //foreach (DocumentList document in Result)
                //{
                //    if (!string.IsNullOrEmpty(document.docURL))
                //    {
                //        string docURL = document.docURL.ToString();
                //        string path = ConfigurationManager.AppSettings["imgPath"] + "/Documents/documentsafe/Group" + doc.grpID + "/";
                //        document.docURL = path + docURL;
                //    }
                //}

                MySqlParameter[] param = new MySqlParameter[5];
                param[0] = new MySqlParameter("?groupId", doc.grpID);
                param[1] = new MySqlParameter("?memberProfileId", doc.memberProfileID);

                param[2] = new MySqlParameter("?searchText", string.IsNullOrEmpty(doc.searchText) ? "" : doc.searchText);
                param[3] = new MySqlParameter("?type", doc.type);
                param[4] = new MySqlParameter("?isAdmin", doc.isAdmin);

                DataSet Result = MySqlHelper.ExecuteDataset(GlobalVar.strAppConn, CommandType.StoredProcedure, "V7_USPGetDocumentList", param);

                return(Result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async void TestDocumentTypeAttribute()
        {
            var getDoc = new GetDocument()
            {
                Type = "test-doc-type",
                Name = "test"
            };

            var returnDoc = new Document()
            {
                Type = "test-doc-type",
                Name = "test",
                Body = new SimpleDocument()
            };

            var jbClient = new Moq.Mock <JsonballClient>();

            jbClient.Setup(c => c.GetDocumentAsync(getDoc, CancellationToken.None)).ReturnsAsync(returnDoc);

            var dm  = new DocumentManager(jbClient.Object);
            var doc = await dm.GetDocumentAsync <SimpleDocument>("test", CancellationToken.None);

            Assert.Equal <SimpleDocument>((SimpleDocument)returnDoc.Body, doc);
        }
Beispiel #13
0
 public async Task <Document> Get(GetDocument request)
 {
     return(await _mediator.Send(request));
 }
 public abstract Task <Document> GetDocumentAsync(GetDocument doc, CancellationToken ct = default);
Beispiel #15
0
        internal void PublishCommand(string strOfficeId, object parameter = null)
        {
            var    loggedOn = false;
            string cleanUpPath;

            try {
                GetDocument getDocumentDlg = null;
                switch (strOfficeId)
                {
                case "btnManageProject":
                    loggedOn = ServicePool.Instance.GetService <ServerService>().LogOn();
                    if (!loggedOn)
                    {
                        return;
                    }
                    getDocumentDlg = new GetDocument();
                    getDocumentDlg.ShowDialog();
                    break;

                case "btnCheckDocumentRaw": // check conversion and upload
                    ServicePool.Instance.GetService <DocumentService>().JustChecking = true;
                    ServicePool.Instance.GetService <DocumentService>().CheckDocument();
                    break;

                case "btnCheckDocument": // check conversion and upload
                    ServicePool.Instance.GetService <DocumentService>().CheckDocument();
                    break;

                case "splitbtnPublishRaw__btn":
                    ServicePool.Instance.GetService <DocumentService>().JustChecking = true;
                    goto case "splitbtnPublish__btn";

                case "btnPublishRaw": // check conversion (not loaded)
                    ServicePool.Instance.GetService <DocumentService>().JustChecking = true;
                    goto case "btnPublish";

                case "splitbtnPublish__btn":
                case "btnPublish": // check conversion
                    loggedOn = ServicePool.Instance.GetService <ServerService>().LogOn();
                    if (!loggedOn)
                    {
                        return;
                    }
                    string export;
                    try {
                        var name    = ServicePool.Instance.GetService <DocumentService>().CurrentDocument.Name;
                        var content = ServicePool.Instance.GetService <DocumentService>().GetDocumentContent(out cleanUpPath);
                        export = Convertor.Export(content, name, cleanUpPath);
                    } catch (Exception ex) {
                        MessageBox.Show(ex.Message, Resources.CommandService_PublishCommand_Error_Checking, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                    ServicePool.Instance.GetService <ServerService>().PublishDocument(export);
                    break;

                case "btnExportRaw": // check conversion
                case "btnExport":    // check conversion
                    if (ServicePool.Instance.GetService <DocumentService>().ConsistencyChecker())
                    {
                        try {
                            var name    = ServicePool.Instance.GetService <DocumentService>().CurrentDocument.Name;
                            var content = ServicePool.Instance.GetService <DocumentService>().GetDocumentContent(out cleanUpPath);
                            export = Convertor.Export(content, name, cleanUpPath);
                            if (export != null)
                            {
                                var sfd = new SaveFileDialog {
                                    Filter                       = Resources.CommandService_PublishCommand_Texxtoor_Backup,
                                    InitialDirectory             = RibbonTexxtoor.LOCAL_APPN_DATA_PATH,
                                    SupportMultiDottedExtensions = true,
                                    OverwritePrompt              = true
                                };
                                if (sfd.ShowDialog() == DialogResult.OK)
                                {
                                    File.WriteAllText(sfd.FileName, export);
                                }
                            }
                            else
                            {
                                throw new InvalidOperationException(Resources.CommandService_PublishCommand_Cannot_convert_document);
                            }
                        } catch (Exception ex) {
                            MessageBox.Show(ex.Message, Resources.CommandService_PublishCommand_Error_Checking, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Resources.CommandService_PublishCommand_Cannot_export_because, Resources.CommandService_PublishCommand_Error_Checking, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    break;

                default:
                    ExecuteMso(MsoCommands.Single(m => m.CommandId == strOfficeId).CommandId);
                    break;
                }
            } catch {
                return;
            }
        }