Example #1
0
        public string toJson(Guid?applicationId = null, bool profileImageUrl             = false,
                             bool highQualityProfileImageUrl = false, bool coverPhotoUrl = false, bool highQualityCoverPhotoUrl = false)
        {
            string imageUrl = !profileImageUrl ? string.Empty :
                              DocumentUtilities.get_personal_image_address(applicationId, UserID.HasValue ? UserID.Value : Guid.Empty);

            string hqImageUrl = !highQualityProfileImageUrl || !UserID.HasValue ? string.Empty :
                                DocumentUtilities.get_personal_image_address(applicationId, UserID.Value, highQuality: true);

            return("{\"UserID\":\"" + (UserID.HasValue ? UserID.ToString() : string.Empty) + "\"" +
                   ",\"UserName\":\"" + Base64.encode(UserName) + "\"" +
                   ",\"FirstName\":\"" + Base64.encode(FirstName) + "\"" +
                   ",\"LastName\":\"" + Base64.encode(LastName) + "\"" +
                   (!EnableNewsLetter.HasValue || !EnableNewsLetter.Value ? string.Empty :
                    ",\"EnableNewsLetter\":" + EnableNewsLetter.Value.ToString().ToLower()
                   ) +
                   (TwoStepAuthentication == TwoStepAuthentication.None ? string.Empty :
                    ",\"TwoStepAuthentication\":\"" + TwoStepAuthentication.ToString() + "\""
                   ) +
                   ",\"IncompleteProfile\":" + (!profileCompleted()).ToString().ToLower() +
                   (string.IsNullOrEmpty(JobTitle) ? string.Empty : ",\"JobTitle\":\"" + Base64.encode(JobTitle) + "\"") +
                   (string.IsNullOrEmpty(AvatarName) ? string.Empty : ",\"AvatarName\":\"" + AvatarName + "\"") +
                   (string.IsNullOrEmpty(imageUrl) ? string.Empty :
                    ",\"ProfileImageURL\":\"" + imageUrl + "\"" +
                    ",\"ImageURL\":\"" + imageUrl + "\""
                   ) +
                   (string.IsNullOrEmpty(hqImageUrl) ? string.Empty : ",\"HighQualityImageURL\":\"" + hqImageUrl + "\"") +
                   (!coverPhotoUrl || !UserID.HasValue ? string.Empty : ",\"CoverPhotoURL\":\"" +
                    DocumentUtilities.get_cover_photo_url(applicationId, UserID.Value, networkAddress: false, highQuality: false) + "\"") +
                   (!highQualityCoverPhotoUrl || !UserID.HasValue ? string.Empty : ",\"HighQualityCoverPhotoURL\":\"" +
                    DocumentUtilities.get_cover_photo_url(applicationId, UserID.Value, networkAddress: false, highQuality: true) + "\"") +
                   "}");
        }
Example #2
0
        public string toJson(Guid applicationId, bool persianDate = false, bool includeRefElementId = false)
        {
            string strElementId = string.Empty;

            if (includeRefElementId)
            {
                strElementId = ElementID.HasValue ? ElementID.Value.ToString() : string.Empty;
            }
            else
            {
                strElementId = (RefElementID.HasValue ? RefElementID : ElementID).ToString();
            }

            return("{\"ElementID\":\"" + strElementId + "\"" +
                   ",\"InstanceID\":\"" + (FormInstanceID.HasValue ? FormInstanceID.ToString() : string.Empty) + "\"" +
                   (!includeRefElementId ? string.Empty :
                    ",\"RefElementID\":\"" + (RefElementID.HasValue ? RefElementID.ToString() : string.Empty) + "\""
                   ) +
                   (!TemplateElementID.HasValue ? string.Empty : ",\"TemplateElementID\":\"" + TemplateElementID.Value.ToString() + "\"") +
                   ",\"FormID\":\"" + (FormID.HasValue ? FormID.ToString() : string.Empty) + "\"" +
                   (!ChangeID.HasValue ? string.Empty : ",\"ChangeID\":\"" + ChangeID.Value.ToString() + "\"") +
                   ",\"Title\":\"" + Base64.encode(Title) + "\"" +
                   ",\"Name\":\"" + Base64.encode(Name) + "\"" +
                   ",\"Help\":\"" + Base64.encode(Help) + "\"" +
                   ",\"Type\":\"" + (Type.HasValue ? Type.ToString() : FormElementTypes.Text.ToString()) + "\"" +
                   ",\"Necessary\":" + (Necessary.HasValue && Necessary.Value).ToString().ToLower() +
                   ",\"UniqueValue\":" + (UniqueValue.HasValue && UniqueValue.Value).ToString().ToLower() +
                   ",\"SequenceNumber\":" + (SequenceNumber.HasValue ? SequenceNumber.Value : 0).ToString() +
                   ",\"Info\":\"" + Base64.encode(Info) + "\"" +
                   (!Weight.HasValue ? string.Empty : ",\"Weight\":" + Weight.ToString()) +
                   (string.IsNullOrEmpty(InitialValue) ? string.Empty : ",\"InitialValue\":\"" + Base64.encode(InitialValue) + "\"") +
                   ",\"TextValue\":\"" + Base64.encode(TextValue) + "\"" +
                   ",\"DateValue\":" + (!DateValue.HasValue ? "null" : "\"" + (persianDate ?
                                                                               PublicMethods.get_local_date(DateValue.Value) : DateValue.ToString()) + "\"") +
                   ",\"DateValue_Jalali\":" + (!DateValue.HasValue ? "null" : "\"" +
                                               PublicMethods.get_local_date(DateValue.Value) + "\"") +
                   ",\"FloatValue\":" + (!FloatValue.HasValue ? "null" : FloatValue.Value.ToString()) +
                   ",\"BitValue\":" + (!BitValue.HasValue ? "null" : BitValue.Value.ToString().ToLower()) +
                   ",\"GuidItems\":[" + string.Join(",", GuidItems.Select(u => u.toJson())) + "]" +
                   ",\"SelectedItems\":[" + string.Join(",", GuidItems.Select(u => u.toJson())) + "]" +
                   ",\"Filled\":" + (Filled.HasValue && Filled.Value).ToString().ToLower() +
                   (!Creator.UserID.HasValue || string.IsNullOrEmpty(Creator.UserName) ? string.Empty :
                    ",\"Creator\":{\"UserID\":\"" + Creator.UserID.ToString() + "\"" +
                    ",\"UserName\":\"" + Base64.encode(Creator.UserName) + "\"" +
                    ",\"FirstName\":\"" + Base64.encode(Creator.FirstName) + "\"" +
                    ",\"LastName\":\"" + Base64.encode(Creator.LastName) + "\"" +
                    ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address(applicationId,
                                                                                             Creator.UserID.Value) + "\"" +
                    "}"
                   ) +
                   ",\"CreationDate\":\"" + (CreationDate.HasValue ?
                                             PublicMethods.get_local_date(CreationDate.Value, true) : string.Empty) + "\"" +
                   ",\"LastModificationDate\":\"" + (LastModificationDate.HasValue ?
                                                     PublicMethods.get_local_date(LastModificationDate.Value, true) : string.Empty) + "\"" +
                   (AttachedFiles == null || AttachedFiles.Count == 0 ? string.Empty :
                    ",\"Files\":" + DocumentUtilities.get_files_json(applicationId, AttachedFiles, true)
                   ) +
                   ",\"EditionsCount\":" + (!EditionsCount.HasValue ? 0 : EditionsCount.Value).ToString() +
                   "}");
        }
Example #3
0
        public static bool import_form(Guid applicationId, Guid?instanceId, DocFileInfo uploadedFile,
                                       string map, Guid currentUserId, ref List <FormElement> savedElements, ref string nodeName,
                                       ref DocFileInfo logo, ref string errorMessage)
        {
            if (uploadedFile != null)
            {
                uploadedFile.FolderName = FolderNames.TemporaryFiles;
            }

            List <FormElement> nodeElements = new List <FormElement>();

            nodeElements.Add(new FormElement()
            {
                ElementID = Guid.NewGuid(), Name = "node_name", Type = FormElementTypes.Text
            });
            nodeElements.Add(new FormElement()
            {
                ElementID = Guid.NewGuid(), Name = "node_logo", Type = FormElementTypes.Text
            });

            if (!FGImport.import_form(applicationId, instanceId, uploadedFile,
                                      PublicMethods.fromJSON(map), currentUserId, ref savedElements, nodeElements, ref errorMessage))
            {
                return(false);
            }

            nodeName = nodeElements.Where(u => u.Name == "node_name").Select(x => x.TextValue).FirstOrDefault();
            string nodeLogo = nodeElements.Where(u => u.Name == "node_logo").Select(x => x.TextValue).FirstOrDefault();

            logo = DocumentUtilities.decode_base64_file_content(applicationId, null, nodeLogo, FileOwnerTypes.None);

            return(true);
        }
Example #4
0
        private static void AssertSearchBatch(
            string packageId,
            IndexBatch <KeyedDocument> batch,
            IndexActionType exDefault,
            IndexActionType exIncludePrerelease,
            IndexActionType exIncludeSemVer2,
            IndexActionType exIncludePrereleaseAndSemVer2)
        {
            Assert.Equal(4, batch.Actions.Count());
            var defaultSearch = Assert.Single(
                batch.Actions,
                x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.Default) == x.Document.Key);

            Assert.Equal(exDefault, defaultSearch.ActionType);
            var includePrereleaseSearch = Assert.Single(
                batch.Actions,
                x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludePrerelease) == x.Document.Key);

            Assert.Equal(exIncludePrerelease, includePrereleaseSearch.ActionType);
            var includeSemVer2Search = Assert.Single(
                batch.Actions,
                x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludeSemVer2) == x.Document.Key);

            Assert.Equal(exIncludeSemVer2, includeSemVer2Search.ActionType);
            var includePrereleaseAndSemVer2Search = Assert.Single(
                batch.Actions,
                x => DocumentUtilities.GetSearchDocumentKey(packageId, SearchFilters.IncludePrereleaseAndSemVer2) == x.Document.Key);

            Assert.Equal(exIncludePrereleaseAndSemVer2, includePrereleaseAndSemVer2Search.ActionType);
        }
Example #5
0
        public async void SetFieldsWith1Number1FixedLengthTextOn1000Documents()
        {
            // create fields
            var fields = new[]
            {
                await Storage.Metadata.CreateRandomFieldAsync(FieldType.Number),
                await Storage.Metadata.CreateRandomFieldAsync(FieldType.FixedLengthText)
            };
            // create documents
            var documents = new List <Document>();

            for (int i = 0; i < 1000; i++)
            {
                documents.Add(DocumentUtilities.GetRandomDocument(fields));
            }
            await Storage.Metadata.Document.CreateAsync(documents, CancellationToken.None);

            // set field value parameters
            var fieldValues = new Dictionary <string, object?>
            {
                { fields[0].Id, FieldUtilities.GetRandomValue(fields[0].Type) },
                { fields[1].Id, FieldUtilities.GetRandomValue(fields[1].Type) }
            };
            // set fields on documents
            var stopper = new System.Diagnostics.Stopwatch();

            stopper.Start();
            await Storage.Metadata.Document.SetFieldsAsync(documents.Select(document => document.Id), fieldValues, CancellationToken.None);

            output.WriteLine($"Update took: {stopper.ElapsedMilliseconds} ms");
        }
Example #6
0
        public string toJson(Guid?applicationId = null, bool iconUrl = false, bool simple = false)
        {
            bool showCreator = Creator != null && Creator.UserID.HasValue && !string.IsNullOrEmpty(Creator.UserName) &&
                               !(HideCreators.HasValue && HideCreators.Value) && (Status == Status.NotSet || Status == Status.Accepted);

            return("{\"NodeID\":\"" + (!NodeID.HasValue ? string.Empty : NodeID.Value.ToString()) + "\"" +
                   ",\"AdditionalID\":\"" + Base64.encode(AdditionalID) + "\"" +
                   ",\"NodeTypeID\":\"" + (!NodeTypeID.HasValue ? string.Empty : NodeTypeID.Value.ToString()) + "\"" +
                   ",\"Name\":\"" + Base64.encode(Name) + "\"" +
                   ",\"NodeType\":\"" + Base64.encode(NodeType) + "\"" +
                   (string.IsNullOrEmpty(AvatarName) ? string.Empty : ",\"AvatarName\":" + AvatarName) +
                   (simple ? string.Empty :
                    ",\"CreationDate\":\"" + (CreationDate.HasValue ? PublicMethods.get_local_date(CreationDate.Value) : string.Empty) + "\"" +
                    ",\"Status\":\"" + (Status == Status.NotSet ? string.Empty : Status.ToString()) + "\"" +
                    ",\"WFState\":\"" + Base64.encode(WFState) + "\"" +
                    ",\"HideCreators\":" + (HideCreators.HasValue && HideCreators.Value).ToString().ToLower() +
                    (VisitsCount.HasValue ? ",\"VisitsCount\":" + VisitsCount.Value.ToString() : string.Empty) +
                    (LikesCount.HasValue ? ",\"LikesCount\":" + LikesCount.Value.ToString() : string.Empty) +
                    ",\"HasChild\":" + (!HasChild.HasValue ? "null" : HasChild.Value.ToString().ToLower()) +
                    (!iconUrl || !applicationId.HasValue || !NodeID.HasValue ? string.Empty :
                     ",\"IconURL\":\"" + DocumentUtilities.get_icon_url(applicationId.Value,
                                                                        NodeID.Value, DefaultIconTypes.Node, NodeTypeID) + "\"") +
                    (!showCreator ? string.Empty :  ",\"Creator\":" + Creator.toJson(applicationId, true)) +
                    ",\"Archived\":" + (Archive.HasValue && Archive.Value).ToString().ToLower()
                   ) +
                   "}");
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string documentJson = await new StreamReader(req.Body).ReadToEndAsync();
                var    document     = JsonConvert.DeserializeObject <Dictionary <string, string> >(documentJson);

                if (document.ContainsKey("DatabaseName") && document.ContainsKey("ContainerName") && document.ContainsKey("PartitionKey") && document.ContainsKey("PartitionValue"))
                {
                    var cosmosDbDatabaseName  = document["DatabaseName"];
                    var cosmosDbContainerName = document["ContainerName"];
                    var cosmosDbPartitionKey  = document["PartitionKey"];
                    var partitionValue        = document["PartitionValue"];
                    var cosmosDbEndPoint      = Environment.GetEnvironmentVariable("endpointUri", EnvironmentVariableTarget.Process);
                    var cosmosDbAuthKey       = Environment.GetEnvironmentVariable("customerPrimaryKey", EnvironmentVariableTarget.Process);
                    var result = await DocumentUtilities.ReadDocumentsbyPartition(cosmosDbEndPoint, cosmosDbAuthKey, cosmosDbDatabaseName, cosmosDbContainerName, cosmosDbPartitionKey, StoredProcedureList.ReadByPartitionProcedure, partitionValue);

                    return(new OkObjectResult(result));
                }
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
                //var cosmosDbDatabaseName = Environment.GetEnvironmentVariable("databaseId", EnvironmentVariableTarget.Process);
                //var cosmosDbContainerName = Environment.GetEnvironmentVariable("containerId", EnvironmentVariableTarget.Process);
                //var cosmosDbPartitionKey = Environment.GetEnvironmentVariable("CustomerPartitionKey", EnvironmentVariableTarget.Process);
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Example #8
0
 public override bool SaveDocumentFile()
 {
     if (!this.IsOpen)
     {
         return(true);
     }
     return(DocumentUtilities.SaveDocument(this.Document, true, true, base.Services.MessageDisplayService()));
 }
Example #9
0
 public string toJson(Guid applicationId)
 {
     return("{\"UserID\":\"" + User.UserID.ToString() + "\"" +
            ",\"FirstName\":\"" + Base64.encode(User.FirstName) + "\"" +
            ",\"LastName\":\"" + Base64.encode(User.LastName) + "\"" +
            ",\"UserName\":\"" + Base64.encode(User.UserName) + "\"" +
            ",\"ImageURL\":\"" + DocumentUtilities.get_personal_image_address(applicationId, User.UserID.Value) + "\"" +
            "}");
 }
        public void AddMark(SDBookmark bookmark, IDocument document, int line)
        {
            int lineStartOffset = document.GetLineByNumber(line).Offset;
            int column          = 1 + DocumentUtilities.GetWhitespaceAfter(document, lineStartOffset).Length;

            bookmark.Location = new TextLocation(line, column);
            bookmark.FileName = FileName.Create(document.FileName);
            AddMark(bookmark);
        }
Example #11
0
        Point GetLinePosition(int index)
        {
            var  currentInsertionPoint = insertionPoints[index];
            var  textViewPosition      = new TextViewPosition(currentInsertionPoint.Location);
            bool isEmptyLine           = DocumentUtilities.IsEmptyLine(editor.Document, textViewPosition.Line);
            var  pos = editor.TextView.GetVisualPosition(textViewPosition, isEmptyLine ? VisualYPosition.LineMiddle : VisualYPosition.LineTop);

            return(pos - editor.TextView.ScrollOffset);
        }
 /// <summary>
 /// Inserts the PInvoke signature at the current cursor position.
 /// </summary>
 /// <param name="textArea">The text editor.</param>
 /// <param name="signature">A PInvoke signature string.</param>
 public void Generate(ITextEditor editor, string signature)
 {
     using (editor.Document.OpenUndoGroup()) {
         int startLine = editor.Document.GetLineByOffset(editor.SelectionStart).LineNumber;
         editor.SelectedText = DocumentUtilities.NormalizeNewLines(signature, editor.Document, startLine);
         int endLine = editor.Document.GetLineByOffset(editor.SelectionStart + editor.SelectionLength).LineNumber;
         editor.Language.FormattingStrategy.IndentLines(editor, startLine, endLine);
     }
 }
Example #13
0
 private static string _get_user_json(Guid applicationId, User user)
 {
     return("{\"UserID\":\"" + user.UserID.Value.ToString() + "\"" +
            ",\"UserName\":\"" + Base64.encode(user.UserName) + "\"" +
            ",\"FirstName\":\"" + Base64.encode(user.FirstName) + "\"" +
            ",\"LastName\":\"" + Base64.encode(user.LastName) + "\"" +
            ",\"ProfileImageURL\":\"" +
            DocumentUtilities.get_personal_image_address(applicationId, user.UserID.Value) + "\"" +
            ",\"IsOnline\":" + UserConnectionsDic.ContainsKey(user.UserID.Value).ToString().ToLower() +
            "}");
 }
        protected override void Run(ITextEditor editor, string clipboardText)
        {
            // TODO: reimplement as C#-specific refactoring with NR5;
            // because CodeDom introduces redundant parentheses
            CodeDomProvider codeDomProvider = null;
            IProject        project         = ProjectService.CurrentProject;

            if (project != null)
            {
                codeDomProvider = project.CreateCodeDomProvider();
            }
            if (codeDomProvider == null)
            {
                codeDomProvider = new CSharpCodeProvider();
            }

            CodeExpression expression = null;

            using (StringReader reader = new StringReader(clipboardText)) {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    CodeExpression newExpr = new CodePrimitiveExpression(line);
                    if (expression == null)
                    {
                        expression = newExpr;
                    }
                    else
                    {
                        expression = new CodeBinaryOperatorExpression(
                            expression,
                            CodeBinaryOperatorType.Add,
                            new CodePropertyReferenceExpression(
                                new CodeTypeReferenceExpression("Environment"),
                                "NewLine"
                                ));
                        expression = new CodeBinaryOperatorExpression(
                            expression, CodeBinaryOperatorType.Add, newExpr);
                    }
                }
            }
            if (expression == null)
            {
                return;
            }
            string indentation           = DocumentUtilities.GetIndentation(editor.Document, editor.Caret.Line);
            CodeGeneratorOptions options = new CodeGeneratorOptions();

            options.IndentString = editor.Options.IndentationString;
            StringWriter writer = new StringWriter();

            codeDomProvider.GenerateCodeFromExpression(expression, writer, options);
            editor.Document.Insert(editor.Caret.Offset, writer.ToString().Trim());
        }
 static string GetLineIndent(IDocument doc, IDocumentLine line)
 {
     if (line == null)
     {
         return(string.Empty);
     }
     else
     {
         return(DocumentUtilities.GetWhitespaceAfter(doc, line.Offset));
     }
 }
            public void BuildsGetOperationForSingleValidPackageId(string id)
            {
                ParsedQuery.Grouping[QueryField.PackageId] = new HashSet <string>(new[] { id });

                var actual = Build();

                Assert.Equal(IndexOperationType.Get, actual.Type);
                Assert.Equal(
                    DocumentUtilities.GetSearchDocumentKey(id, SearchFilters.Default),
                    actual.DocumentKey);
            }
            public void NormalizesVersion(string version, string normalized)
            {
                ParsedQuery.Grouping[QueryField.PackageId] = new HashSet <string>(new[] { Id });
                ParsedQuery.Grouping[QueryField.Version]   = new HashSet <string>(new[] { version });

                var actual = Build();

                Assert.Equal(IndexOperationType.Get, actual.Type);
                Assert.Equal(
                    DocumentUtilities.GetHijackDocumentKey(Id, normalized),
                    actual.DocumentKey);
            }
            public void BuildsGetOperationForSingleValidPackageIdAndSingleValidVersion(string id)
            {
                ParsedQuery.Grouping[QueryField.PackageId] = new HashSet <string>(new[] { id });
                ParsedQuery.Grouping[QueryField.Version]   = new HashSet <string>(new[] { Version });

                var actual = Build();

                Assert.Equal(IndexOperationType.Get, actual.Type);
                Assert.Equal(
                    DocumentUtilities.GetHijackDocumentKey(id, Version),
                    actual.DocumentKey);
            }
Example #19
0
            public override void Execute(EditorRefactoringContext context)
            {
                SD.AnalyticsMonitor.TrackFeature(typeof(SuppressIssueContextAction), issueName);
                var lineNo   = context.CaretLocation.Line;
                var document = context.Editor.Document;

                var    line        = document.GetLineByNumber(lineNo);
                string indentation = DocumentUtilities.GetIndentation(document, lineNo);
                string newLine     = DocumentUtilities.GetLineTerminator(document, lineNo);

                document.Insert(line.Offset, indentation + "// disable once " + issueName + newLine);
            }
Example #20
0
        public async void CreateWith1Number1FixedLengthText()
        {
            // create fields
            var fields = new[]
            {
                await Storage.Metadata.CreateRandomFieldAsync(FieldType.Number),
                await Storage.Metadata.CreateRandomFieldAsync(FieldType.FixedLengthText)
            };

            // create document
            await Storage.Metadata.Document.CreateAsync(DocumentUtilities.GetRandomDocument(fields), CancellationToken.None);;
        }
Example #21
0
 public string toJson(Guid applicationId)
 {
     return("{\"UserID\":\"" + Member.UserID.ToString() + "\"" +
            ",\"FirstName\":\"" + Base64.encode(Member.FirstName) + "\"" +
            ",\"LastName\":\"" + Base64.encode(Member.LastName) + "\"" +
            ",\"UserName\":\"" + Base64.encode(Member.UserName) + "\"" +
            ",\"IsAdmin\":" + (IsAdmin.HasValue && IsAdmin.Value).ToString().ToLower() +
            ",\"IsPending\":" + (IsPending.HasValue && IsPending.Value).ToString().ToLower() +
            ",\"Status\":\"" + (string.IsNullOrEmpty(Status) ?
                                string.Empty : Status.ToString()) + "\"" +
            ",\"ImageURL\":\"" + DocumentUtilities.get_personal_image_address(applicationId, Member.UserID.Value) + "\"" +
            "}");
 }
Example #22
0
        protected void get_messages(Guid?threadId, long?minId, int?count, ref string responseText)
        {
            //Privacy Check: OK
            if (!paramsContainer.GBEdit)
            {
                return;
            }

            if (!count.HasValue)
            {
                count = 0;
            }

            List <Message> messages = !threadId.HasValue ? new List <Message>() :
                                      MSGController.get_messages(paramsContainer.Tenant.Id,
                                                                 paramsContainer.CurrentUserID.Value, threadId, null, minId, count);

            responseText = "{\"MinID\":" + (messages.Count > 0 ? messages.Min(u => u.ID) : 0).ToString() +
                           ",\"Messages\":[";

            List <DocFileInfo> attachments = DocumentsController.get_owner_files(paramsContainer.Tenant.Id,
                                                                                 messages.Where(u => u.HasAttachment.HasValue && u.HasAttachment.Value).Select(v => v.MessageID.Value).ToList());

            bool isFirst = true;

            foreach (Message msg in messages)
            {
                responseText += (isFirst ? string.Empty : ",") +
                                "{\"ID\":\"" + msg.ID.ToString() + "\"" +
                                ",\"ThreadID\":\"" + msg.ThreadID.Value.ToString() + "\"" +
                                ",\"MessageID\":\"" + msg.MessageID.Value.ToString() + "\"" +
                                ",\"IsGroup\":" + (msg.IsGroup.HasValue && msg.IsGroup.Value).ToString().ToLower() +
                                ",\"IsSender\":" + (msg.IsSender.HasValue && msg.IsSender.Value).ToString().ToLower() +
                                ",\"Seen\":" + (msg.Seen.HasValue && msg.Seen.Value).ToString().ToLower() +
                                ",\"Title\":\"" + Base64.encode(msg.Title) + "\"" +
                                ",\"MessageText\":\"" + Base64.encode(msg.MessageText) + "\"" +
                                ",\"SendDate\":\"" + PublicMethods.get_local_date(msg.SendDate.Value, true) + "\"" +
                                ",\"ForwardedFrom\":\"" + (msg.ForwardedFrom.HasValue ? msg.ForwardedFrom.Value.ToString() : "") + "\"" +
                                ",\"SenderUserID\":\"" + msg.SenderUserID.ToString() + "\"" +
                                ",\"SenderUserName\":\"" + Base64.encode(msg.SenderUserName) + "\"" +
                                ",\"SenderFirstName\":\"" + Base64.encode(msg.SenderFirstName) + "\"" +
                                ",\"SenderLastName\":\"" + Base64.encode(msg.SenderLastName) + "\"" +
                                ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address(paramsContainer.Tenant.Id,
                                                                                                         msg.SenderUserID.Value) + "\"" +
                                ",\"AttachedFiles\":" + DocumentUtilities.get_files_json(paramsContainer.Tenant.Id, attachments.Where(u => u.OwnerID == msg.MessageID).ToList(), true) +
                                "}";
                isFirst = false;
            }

            responseText += "]}";
        }
        void SaveInitializeComponents(CodeMemberMethod codeMethod)
        {
            var            bodyRegion = initializeComponents.BodyRegion;
            DocumentScript script     = GetScript(bodyRegion.FileName);

            string newline     = DocumentUtilities.GetLineTerminator(script.OriginalDocument, bodyRegion.BeginLine);
            string indentation = DocumentUtilities.GetIndentation(script.OriginalDocument, bodyRegion.BeginLine);
            string code        = "{" + newline + GenerateInitializeComponents(codeMethod, indentation, newline) + indentation + "}";

            int startOffset = script.GetCurrentOffset(bodyRegion.Begin);
            int endOffset   = script.GetCurrentOffset(bodyRegion.End);

            script.Replace(startOffset, endOffset - startOffset, code);
        }
        void CreateField(CodeMemberField newField)
        {
            // insert new field below InitializeComponents()

            var            bodyRegion  = initializeComponents.BodyRegion;
            DocumentScript script      = GetScript(bodyRegion.FileName);
            string         newline     = DocumentUtilities.GetLineTerminator(script.OriginalDocument, bodyRegion.BeginLine);
            string         indentation = DocumentUtilities.GetIndentation(script.OriginalDocument, bodyRegion.BeginLine);

            var    insertionLocation = new TextLocation(bodyRegion.EndLine + 1, 1);
            int    insertionOffset   = script.GetCurrentOffset(insertionLocation);
            string code = indentation + GenerateField(newField) + newline;

            script.InsertText(insertionOffset, code);
        }
Example #25
0
 /// <inheritdoc/>
 public bool MoveNext()
 {
     if (lineDirty)
     {
         DocumentUtilities.SmartReplaceLine(doc, line, text);
         lineDirty = false;
     }
     ++num;
     if (num > maxLine)
     {
         return(false);
     }
     line = doc.GetLineByNumber(num);
     text = doc.GetText(line);
     return(true);
 }
            public void IgnoresFiltersWithSpecificPackageIdAndVersion()
            {
                V2SearchRequest.IncludePrerelease = false;
                V2SearchRequest.IncludeSemVer2    = false;
                var prereleaseSemVer2 = "1.0.0-beta.1";

                ParsedQuery.Grouping[QueryField.PackageId] = new HashSet <string>(new[] { Id });
                ParsedQuery.Grouping[QueryField.Version]   = new HashSet <string>(new[] { prereleaseSemVer2 });

                var actual = Build();

                Assert.Equal(IndexOperationType.Get, actual.Type);
                Assert.Equal(
                    DocumentUtilities.GetHijackDocumentKey(Id, prereleaseSemVer2),
                    actual.DocumentKey);
            }
Example #27
0
        public string toJson(Guid?applicationId = null, bool iconUrl = false)
        {
            bool hasDefaultPattern = !HasDefaultPattern.HasValue ? true : HasDefaultPattern.Value;

            if (applicationId.HasValue && iconUrl && NodeTypeID.HasValue)
            {
                if (string.IsNullOrEmpty(IconURL))
                {
                    IconURL = DocumentUtilities.get_icon_url(applicationId.Value, NodeTypeID.Value);
                }
                if (string.IsNullOrEmpty(HighQualityIconURL))
                {
                    HighQualityIconURL = DocumentUtilities.get_icon_url(applicationId.Value, NodeTypeID.Value, null, true);
                }
            }

            return("{\"NodeTypeID\":\"" + (!NodeTypeID.HasValue ? string.Empty : NodeTypeID.ToString()) + "\"" +
                   ",\"AdditionalID\":\"" + Base64.encode(NodeTypeAdditionalID) + "\"" +
                   ",\"TypeName\":\"" + Base64.encode(Name) + "\"" +
                   (!ParentID.HasValue ? string.Empty :
                    ",\"ParentID\":\"" + ParentID.ToString() + "\"") +
                   (string.IsNullOrEmpty(AdditionalIDPattern) ? string.Empty :
                    ",\"AdditionalIDPattern\":\"" + AdditionalIDPattern + "\"") +
                   (!AdditionalID.HasValue ? string.Empty :
                    ",\"IsDefault\":" + AdditionalID.HasValue.ToString().ToLower()) +
                   (!Hidden.HasValue || !Hidden.Value ? string.Empty :
                    ",\"Hidden\":" + Hidden.Value.ToString().ToLower()) +
                   (!Archive.HasValue || !Archive.Value ? string.Empty :
                    ",\"IsArchive\":" + Archive.Value.ToString().ToLower()) +
                   (!hasDefaultPattern ? string.Empty :
                    ",\"HasDefaultPattern\":" + hasDefaultPattern.ToString().ToLower()) +
                   (string.IsNullOrEmpty(AvatarName) ? string.Empty : ",\"AvatarName\":" + AvatarName) +
                   (string.IsNullOrEmpty(IconURL) ? string.Empty :
                    ",\"IconURL\":\"" + IconURL + "\"") +
                   (string.IsNullOrEmpty(HighQualityIconURL) ? string.Empty :
                    ",\"HighQualityIconURL\":\"" + HighQualityIconURL + "\"") +
                   (!HasChild.HasValue || !HasChild.Value ? string.Empty :
                    ",\"HasChild\":" + HasChild.Value.ToString().ToLower()) +
                   (!IsService.HasValue || !IsService.Value ? string.Empty :
                    ",\"IsService\":" + IsService.Value.ToString().ToLower()) +
                   (!IsCategory ? string.Empty :
                    ",\"IsCategory\":" + IsCategory.ToString().ToLower()) +
                   (Sub == null || Sub.Count == 0 ? string.Empty :
                    ",\"Sub\":[" + string.Join(",", Sub.Select(s => s.toJson(applicationId, iconUrl))) + "]") +
                   "}");
        }
        public void ProcessRequest(HttpContext context)
        {
            paramsContainer = new ParamsContainer(context, nullTenantResponse: true);
            if (!paramsContainer.ApplicationID.HasValue)
            {
                return;
            }

            string responseText = string.Empty;
            string command      = string.IsNullOrEmpty(context.Request.Params["Command"]) ? string.Empty : context.Request.Params["Command"];

            switch (command)
            {
            /*
             * case "ImportData":
             *  string attachedFile = string.IsNullOrEmpty(context.Request.Params["AttachedFile"]) ? string.Empty :
             *      context.Request.Params["AttachedFile"];
             *
             *  string strGuidName = attachedFile.Split(',')[0];
             *  string folderAddress = DocumentUtilities.map_path(paramsContainer.Tenant.Id,
             *      FolderNames.TemporaryFiles);
             *
             *  handle_imported_file(folderAddress + "\\" + strGuidName, ref responseText);
             *  _return_response(ref responseText);
             *  return;
             */
            case "ImportData":
                List <DocFileInfo> files = DocumentUtilities.get_files_info(context.Request.Params["AttachedFile"]);

                if (files == null || files.Count != 1)
                {
                    responseText = "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}";
                }
                else
                {
                    files[0].FolderName = FolderNames.TemporaryFiles;

                    handle_imported_file(files[0], ref responseText);
                }

                _return_response(ref responseText);
                return;
            }

            paramsContainer.return_response(PublicConsts.BadRequestResponse);
        }
Example #29
0
        void Microsoft.Expression.Framework.Documents.IDocumentContainer.DocumentSaveCompleted(IDocument document, bool saveSucceeded)
        {
            this.UpdateFileInformation();
            KnownProjectBase project = base.Project as KnownProjectBase;

            if (project != null)
            {
                project.EnableWatchingForChanges();
                if (saveSucceeded)
                {
                    IProjectItem codeBehindItem = this.CodeBehindItem;
                    if (codeBehindItem != null && !codeBehindItem.FileExists && codeBehindItem.IsOpen)
                    {
                        DocumentUtilities.SaveDocument(codeBehindItem.Document, true, true, base.Services.MessageDisplayService());
                    }
                }
            }
        }
        private bool TryGetHijackDocumentByKey(
            SearchRequest request,
            ParsedQuery parsed,
            out IndexOperation indexOperation)
        {
            if (PagedToFirstItem(request) &&
                parsed.Grouping.Count == 2 &&
                TryGetSinglePackageId(parsed, out var packageId) &&
                TryGetSingleVersion(parsed, out var normalizedVersion))
            {
                var documentKey = DocumentUtilities.GetHijackDocumentKey(packageId, normalizedVersion);

                indexOperation = IndexOperation.Get(documentKey);
                return(true);
            }

            indexOperation = null;
            return(false);
        }