Esempio n. 1
0
        /// <summary>
        /// Send request to server about read only acces to file
        /// </summary>
        /// <param name="selectedRow"></param
        private void SendReqToServerWithOpen(string fileNameWithoutFormat)
        {
            CommonFileContent file_content = SendReqToOpenFileAndReturnContentOfIt(new UserAndFileNamesPair()
            {
                FileName = fileNameWithoutFormat,
                UserName = client_name
            });

            OpenNewTabPage(fileNameWithoutFormat, file_content.FileContent1, file_content.IsEdited);
        }
Esempio n. 2
0
        private void CreateAndOpenNewFile()
        {
            CreateFileDialog createDialog = new CreateFileDialog();

            string fileNameFromUser = "";

            if (createDialog.ShowDialog(this) == DialogResult.OK)
            {
                fileNameFromUser = createDialog.getFileNameToCreate();
                createDialog.Dispose();
            }
            else
            {
                createDialog.Dispose();
                return;
            }

            if (isOnline)
            {
                if (MakePostRequest("TryCreate/", new { file_name = fileNameFromUser }))
                {
                    CommonFileContent file_content = SendReqToOpenFileAndReturnContentOfIt(new UserAndFileNamesPair()
                    {
                        FileName = fileNameFromUser,
                        UserName = client_name
                    });
                    OpenNewTabPage(fileNameFromUser, file_content.FileContent1, file_content.IsEdited);

                    UpdateFilesList();
                }
                return;
            }
            else
            {
                FullFileData fileData = filesListFromJson.Find(item => item.Name.Equals(fileNameFromUser));
                if (fileData == null)
                {
                    fileData = new FullFileData
                    {
                        EditorName  = client_name,
                        FileContent = "",
                        IsEdited    = false,
                        Name        = fileNameFromUser,
                        Version     = 0
                    };
                    filesListFromJson.Add(fileData);
                    OpenNewTabPage(fileNameFromUser, fileData.FileContent, fileData.IsEdited);
                    UpdateFilesList();
                    return;
                }
            }
            MessageBox.Show("Sorry You can't create this file");
        }
Esempio n. 3
0
        private CommonFileContent SendReqToOpenFileAndReturnContentOfIt(UserAndFileNamesPair userAndFileNames)
        {
            if (isOnline)
            {
                string strResponse = MakePutRequest("OpenFile/" + userAndFileNames.FileName + "/" + userAndFileNames.UserName);
                return(JsonConvert.DeserializeObject <CommonFileContent>(strResponse));
            }
            CommonFileContent fileFromDevice = new CommonFileContent();
            FullFileData      fileContent    = filesListFromJson.Find(item => item.Name.Equals(userAndFileNames.FileName));

            fileFromDevice.EditorName   = fileContent.EditorName;
            fileFromDevice.FileContent1 = fileContent.FileContent;
            fileFromDevice.FileId       = fileContent.FileId;
            fileFromDevice.IsEdited     = fileContent.IsEdited;
            fileFromDevice.Name         = fileContent.Name;
            return(fileFromDevice);
        }