Exemplo n.º 1
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 += "]}";
        }
Exemplo n.º 2
0
        protected void get_forwarded_messages(Guid?messageId, int?count, int?lastId, ref string responseText)
        {
            //Privacy Check: OK
            if (!paramsContainer.GBEdit)
            {
                return;
            }

            if (!messageId.HasValue || !MSGController.has_message(paramsContainer.Tenant.Id,
                                                                  null, paramsContainer.CurrentUserID.Value, null, messageId))
            {
                responseText = "{\"ErrorText\":\"" + Messages.AccessDenied + "\"}";
                return;
            }

            List <Message> fwdMessages = MSGController.get_forwarded_messages(paramsContainer.Tenant.Id, messageId.Value);

            responseText = "{\"ForwardedMessages\": [";
            bool isFirst = true;

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

            List <Message> messageUsers = MSGController.get_message_receivers(paramsContainer.Tenant.Id,
                                                                              fwdMessages.Select(m => m.MessageID.Value).ToList(), count);

            foreach (Message msg in messageUsers)
            {
                Message ms = fwdMessages.Where(m => m.MessageID == msg.MessageID).FirstOrDefault();

                ms.ReceiverUsers  = msg.ReceiverUsers;
                ms.ReceiversCount = msg.ReceiversCount;
            }

            foreach (Message msg in fwdMessages)
            {
                responseText += (isFirst ? string.Empty : ",") +
                                "{\"ID\":\"" + msg.ID.ToString() + "\"" +
                                ",\"MessageID\":\"" + msg.MessageID.Value.ToString() + "\"" +
                                ",\"IsGroup\":" + (msg.IsGroup.HasValue && msg.IsGroup.Value).ToString().ToLower() +
                                ",\"SenderUserID\":\"" + msg.SenderUserID.ToString() + "\"" +
                                ",\"SenderUserName\":\"" + Base64.encode(msg.SenderUserName) + "\"" +
                                ",\"SenderFirstName\":\"" + Base64.encode(msg.SenderFirstName) + "\"" +
                                ",\"SenderLastName\":\"" + Base64.encode(msg.SenderLastName) + "\"" +
                                ",\"SenderProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address(
                    paramsContainer.Tenant.Id, msg.SenderUserID.Value) + "\"" +
                                ",\"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() : "") + "\"" +
                                ",\"AttachedFiles\":" + DocumentUtilities.get_files_json(paramsContainer.Tenant.Id, attachments.Where(u => u.OwnerID == msg.MessageID).ToList(), true) +
                                ",\"Level\":" + msg.Level.ToString().ToLower() +
                                ",\"ReceiversCount\":" + (msg.ReceiversCount.HasValue ? msg.ReceiversCount.Value : 0).ToString() +
                                ",\"ReceiverUsers\":[" +
                                ProviderUtil.list_to_string <string>(msg.ReceiverUsers.Select(
                                                                         u => "{\"UserID\":\"" + u.UserID.ToString() + "\"" +
                                                                         ",\"UserName\":\"" + Base64.encode(u.UserName) + "\"" +
                                                                         ",\"FirstName\":\"" + Base64.encode(u.FirstName) + "\"" +
                                                                         ",\"LastName\":\"" + Base64.encode(u.LastName) + "\"" +
                                                                         ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address(
                                                                             paramsContainer.Tenant.Id, u.UserID.Value) + "\"}").ToList()) +
                                "]}";
                isFirst = false;
            }

            responseText += "]}";
        }
Exemplo n.º 3
0
        private static void sync_nodes(Guid applicationId)
        {
            string baseUrl = "http://10.110.11.53";

            //login
            NameValueCollection vals = new NameValueCollection();

            vals.Add("username", "developer");
            vals.Add("password", "9B1aLrYSC_E^");

            string res = PublicMethods.web_request(baseUrl + "/Ajax/API.ashx?command=authenticate", vals);

            Dictionary <string, object> jsonRes = PublicMethods.fromJSON(res);

            string ticket      = jsonRes.ContainsKey("Ticket") ? (string)jsonRes["Ticket"] : null;
            string accessToken = jsonRes.ContainsKey("AccessToken") ? (string)jsonRes["AccessToken"] : null;

            if (string.IsNullOrEmpty(ticket) || string.IsNullOrEmpty(accessToken))
            {
                return;
            }
            //end of login

            List <Node> nodes = CNController.get_nodes(applicationId, null, null, null, null, null, 10, null, null, null);

            List <NodeInfo> nodeInfo = CNController.get_node_info(applicationId,
                                                                  nodes.Select(u => u.NodeID.Value).ToList(), null, true, true,
                                                                  null, null, null, null, null, null, null, null, null);

            List <DocFileInfo> attachments =
                DocumentsController.get_owner_files(applicationId, nodes.Select(u => u.NodeID.Value).ToList());

            foreach (Node nd in nodes)
            {
                NodeInfo inf = nodeInfo.Where(u => u.NodeID == nd.NodeID).FirstOrDefault();

                string newNodeUrl = baseUrl + "/Ajax/ManageNodes.ashx" +
                                    "?timeStamp=" + DateTime.Now.Ticks.ToString() + "&Command=RegisterNewNode";

                vals.Clear();

                vals.Add("Ticket", ticket);
                vals.Add("acstkn", accessToken);

                vals.Add("CurrentUserID", nd.Creator.UserID.ToString());
                vals.Add("CreationDate", nd.CreationDate.Value.Year.ToString() + "-" +
                         nd.CreationDate.Value.Month.ToString() + "-" + nd.CreationDate.Value.Day.ToString());
                vals.Add("NodeID", nd.NodeID.ToString());
                vals.Add("NodeTypeID", nd.NodeTypeID.ToString());
                vals.Add("Name", Base64.encode(nd.Name));
                if (inf != null && !string.IsNullOrEmpty(inf.Description))
                {
                    vals.Add("Description", Base64.encode(inf.Description));
                }
                if (inf != null && inf.Tags.Count > 0)
                {
                    vals.Add("Tags", string.Join("|", inf.Tags.Select(u => Base64.encode(u))));
                }

                res     = PublicMethods.web_request(newNodeUrl, vals);
                jsonRes = PublicMethods.fromJSON(res);

                if (jsonRes.ContainsKey("AccessToken"))
                {
                    accessToken = (string)jsonRes["AccessToken"];
                }

                foreach (DocFileInfo f in attachments.Where(u => u.OwnerID == nd.NodeID))
                {
                    string fileUploadUrl = baseUrl + "/Ajax/FileUpload.ashx" +
                                           "?timeStamp=" + DateTime.Now.Ticks.ToString() +
                                           "&command=uploadfile" +
                                           "&Ticket=" + ticket +
                                           "&acstkn=" + accessToken +
                                           "&FileID=" + f.FileID.ToString() +
                                           "&OwnerID=" + nd.NodeID.ToString() +
                                           "&OwnerType=" + f.OwnerType.ToString() +
                                           "&aa=2";

                    FileOwnerTypes attachmentType = f.OwnerType == FileOwnerTypes.WikiContent.ToString() ?
                                                    FileOwnerTypes.WikiContent : FileOwnerTypes.Node;

                    FolderNames folderName = DocumentUtilities.get_folder_name(attachmentType);
                    string      subFolder  = !DocumentUtilities.has_sub_folder(folderName) ? string.Empty :
                                             "\\" + DocumentUtilities.get_sub_folder(f.FileID.ToString());

                    string fileAddress = DocumentUtilities.map_path(applicationId, folderName) + subFolder +
                                         "\\" + f.FileName + (string.IsNullOrEmpty(f.Extension) ? string.Empty : "." + f.Extension);

                    res     = PublicMethods.upload_file(applicationId, fileUploadUrl, fileAddress);
                    jsonRes = PublicMethods.fromJSON(res);

                    if (jsonRes.ContainsKey("AccessToken"))
                    {
                        accessToken = (string)jsonRes["AccessToken"];
                    }
                }

                CNController.remove_node(applicationId, nd.NodeID.Value, false, nd.Creator.UserID.Value);
            }
        }