Esempio n. 1
0
        public Tuple<IPlatformVersion, IPlatformFile> UploadNewVersion2(string fileName, int fileId, string groupUuid = "")
        {
            var isChunking = IsChunking(fileName);

            var data = CreateVersion(fileName, string.Empty, null, isChunking, fileId);
            var version = new PlatformVersion(Session, User, data, data.SelectToken("version").Value<int>());
            OfficePropertiesInterop.UpdateProperty(fileName, "WorkshareVersionId", version.Id.ToString());

            if (!string.IsNullOrEmpty(groupUuid))
            {
                OfficePropertiesInterop.UpdateProperty(fileName, "WorkshareGroupUuid", groupUuid);
                OfficePropertiesInterop.UpdateProperty(fileName, "WorkshareFileId", fileId.ToString());

            }

            if (isChunking)
            {
                UploadFileInChunks(fileName, data);
            }
            else
            {
                UploadWholeFile(fileName, data.SelectToken("complete_file").SelectToken("upload"));
            }
            var file = FinalizeUpload(data.SelectToken("id").Value<long>());
            version.Password = file.Password;

            return new Tuple<IPlatformVersion, IPlatformFile>(version,file);
        }
        private void socket_MessageReceived(object sender, SocketIOClient.MessageEventArgs e)
        {
            if (e.Message.MessageType == SocketIOMessageTypes.JSONMessage)
            {
                Logger.LogTrace(e.Message.MessageText);
                var json = JObject.Parse(e.Message.MessageText);
                var noun = json.SelectToken("noun").Value<string>();
                var verb = json.SelectToken("verb").Value<string>();
                var creatorUuid = json.SelectToken("creator").SelectToken("uuid").Value<string>();
                switch (noun)
                {
                    case "Comment":
                    {
                        var comment = json.SelectToken("comment");
                        var commentId = comment.SelectToken("id").Value<long>();
                        var fileId = comment.SelectToken("file_id").Value<int>();
                        var versionNumber = comment.SelectToken("file_version").Value<int>();
                        var body = comment.SelectToken("body").Value<string>();
                        switch (verb)
                        {
                            case "Create":
                                Events.GetEvent<FileCommentAddedEvent>().Publish(new CommentEventArgs()
                                {
                                    CommentId = commentId,
                                    FileId = fileId,
                                    VersionNumber = versionNumber,
                                    UserUuId = creatorUuid
                                });
                                break;

                            case "Delete":
                                Events.GetEvent<FileCommentRemovedEvent>().Publish(new CommentEventArgs()
                                {
                                    CommentId = commentId,
                                    FileId = fileId,
                                    VersionNumber = versionNumber,
                                    UserUuId = creatorUuid
                                });
                                break;

                            case "Update":
                                Events.GetEvent<FileCommentEditedEvent>().Publish(new CommentEventArgs()
                                {
                                    CommentId = commentId,
                                    FileId = fileId,
                                    VersionNumber = versionNumber,
                                    Body = body,
                                    UserUuId = creatorUuid
                                });
                                break;
                        }
                        break;
                    }

                    case "Visit":
                    {
                        var userId = json.SelectToken("visit").SelectToken("user_id").Value<string>();
                        var fileId = json.SelectToken("visit").SelectToken("file_id").Value<int?>().GetValueOrDefault();
                        var folderid = json.SelectToken("visit").SelectToken("folder_id").Value<int?>().GetValueOrDefault();
                        Events.GetEvent<UserVisitEvent>().Publish(new UserEventArgs()
                        {
                            UserId = userId,
                            UserUuid = creatorUuid,
                            FolderId = folderid,
                            FileId = fileId
                        });
                        break;
                    }

                    case "FileVersion":
                    {
                        switch (verb)
                        {
                            case "Update":
                            {
                                var newStatus = json.SelectToken("changes").SelectToken("status").SelectToken("new");


                                if (newStatus.Type == JTokenType.String &&
                                    string.Equals(newStatus.Value<string>(), "applied"))
                                {
                                    var creatorToken = json.SelectToken("file_version").SelectToken("creator");
                                    var creator = new PlatformUser(Session, creatorToken);
                                    var version = new PlatformVersion(Session, User, json.SelectToken("file_version"),
                                        -1);
                                    Events.GetEvent<FileVersionAddedEvent>().Publish(new VersionEventArgs()
                                    {
                                        VersionNumber = version.Number,
                                        FileId = version.FileId,
                                        Creator = creator,
                                        Version = version
                                    });

                                }
                                break;
                            }
                        }
                    }
                        break;

                    case "Member":
                    {
                        var memberToken = json.SelectToken("member");
                        var user = new PlatformUser(Session, memberToken);
                        var folderId = json.SelectToken("folder_id").Value<int?>().GetValueOrDefault();
                        switch (verb)
                        {
                            case "Create":
                            {
                                Events.GetEvent<MemberAddedEvent>().Publish(new MemberActionEventArgs()
                                {
                                    FolderId = folderId,
                                    Member = user,
                                    MemverUuid = user.Uuid
                                });
                                break;
                            }
                            case "Delete":
                            {
                                Events.GetEvent<MemberRemovedvent>().Publish(new MemberActionEventArgs()
                                {
                                    FolderId = folderId,
                                    Member = user,
                                    MemverUuid = user.Uuid
                                });
                                break;
                            }
                        }
                        break;
                    }

                    case "File" :
                    {
                        var fileId = json.SelectToken("file_id").Value<int>();
                        switch (verb)
                        {
                            case "Download":
                            {
                                Events.GetEvent<FileDownloadedEvent>().Publish(new FileActionArgs()
                                {
                                    FileId = fileId,
                                    UserUuid = creatorUuid
                                });
                                break;
                            }
                        }
                        break;
                    }

                }
            }
            else if (e.Message.MessageType == SocketIOMessageTypes.Event)
            {
                switch (e.Message.Event)
                {
                    case "file:openedByUser"    :
                    {
                        var jsom = JObject.Parse(e.Message.MessageText);
                        var data = jsom.SelectToken("args").First;
                        var userUuid = data.SelectToken("uuid").Value<string>();
                        var fileid = data.SelectToken("file_id").Value<int>();
                        var currentEditors = data.SelectToken("current_editors").Value<int>();
                        Events.GetEvent<FileOpenedEvent>().Publish(new FileOpenCloseArgs()
                        {
                            FileId = fileid,
                            UserUuid = userUuid,
                            CurrentEdotorsCount = currentEditors
                        });
                        break;
                    }

                    case "file:closedByUser":
                    {
                        var jsom = JObject.Parse(e.Message.MessageText);
                        var data = jsom.SelectToken("args").First;
                        var userUuid = data.SelectToken("uuid").Value<string>();
                        var fileid = data.SelectToken("file_id").Value<int>();
                        var currentEditors = data.SelectToken("current_editors").Value<int>();
                        Events.GetEvent<FileClosedEvent>().Publish(new FileOpenCloseArgs()
                        {
                            FileId = fileid,
                            UserUuid = userUuid,
                            CurrentEdotorsCount = currentEditors
                        });
                        break;
                    }

                }
            }

        }