Example #1
0
        /// <summary>
        /// Gets the URL of SharePoint's email configuration.
        /// </summary>
        /// <returns></returns>
        public static string GetMailConfiugrationURL()
        {
            SPWebApplication webApp          = SharePointUtil.GetCentralAdminWebApplication();
            string           centralAdminUrl = webApp.Sites[0].RootWeb.Url;
            string           url             = String.Format("{0}/_admin/globalemailconfig.aspx", centralAdminUrl);

            return(url);
        }
Example #2
0
        /// <summary>
        /// Gets the SMTP settings for the current SharePoint instance.
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentSMTPSettings()
        {
            SPWebApplication webAppAdmin = SharePointUtil.GetCentralAdminWebApplication();

            if (webAppAdmin.OutboundMailServiceInstance == null)
            {
                return(null);
            }
            else
            {
                return(webAppAdmin.OutboundMailServiceInstance.Parent.Name);
            }
        }
Example #3
0
/// <summary>
/// Return true if Mobius can write to the specified file (usually in another user's Share area or SharePoint site) from the service side
/// </summary>
/// <param name="path"></param>
/// <returns></returns>

        public static bool CanWriteFileFromServiceAccount(string path)
        {
            try
            {
                if (path.StartsWith(@"\\"))
                {
                    string shareName = NetworkResourceUtil.NormalizeConnectionStringToUncShareName(path);
                    //bool shareConnected = NetworkResourceUtil.DirectoryExists(shareName); // just verifying directory is faster if share already connected
                    //if (!shareConnected)
                    //{

                    string userName, pw;

                    if (!AccountAccessMx.TryGetMobiusSystemWindowsAccount(out userName, out pw))
                    {
                        return(false);
                    }

                    NetworkResourceUtil.AddConnection(path, userName, pw, false);
                    //}

                    FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                    fs.Close();
                    return(true);
                }

                else if (SharePointUtil.IsSharePointName(path))
                {
                    string msg = SharePointUtil.CanWriteFile(path);                     // check for write, note: uses current user id not SystemAccountName
                    return(Lex.IsNullOrEmpty(msg));
                }

                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                DebugLog.Message("CanWriteFileFromServiceAccount failed for path: " + path + "\r\n" +
                                 ex.Message);
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// Retrieve the results of a background export
        /// Example: Retrieve Background Export 231243
        /// </summary>
        /// <param name="objectIdString">Id of BackgroundExport UserObject containing serialized ResultsFormat</param>
        /// <returns></returns>

        public static string RetrieveBackgroundExport(
            string objectIdString)
        {
            ResultsFormat rf;
            Query         q;
            int           objId;

            QbUtil.SetMode(QueryMode.Build);             // be sure in build mode

            if (!int.TryParse(objectIdString, out objId))
            {
                return("Invalid UserObjectId: " + objectIdString);
            }

            UserObject uo = UserObjectDao.Read(objId);

            if (uo == null)
            {
                return("RunInBackground UserObject not found: " + objectIdString);
            }
            if (uo.Type != UserObjectType.BackgroundExport)
            {
                return("Object is not the expected RunInBackground UserObject type");
            }

            rf = ResultsFormat.Deserialize(uo.Content);
            if (rf == null)
            {
                throw new Exception("Failed to deserialize ResultsFormat: " + objectIdString);
            }

            string clientFile = rf.OutputFileName;
            string serverFile = GetServerFileName(rf, objId);

            string ext    = Path.GetExtension(clientFile);
            string filter = "*" + ext + "|*" + ext;

            if (SharePointUtil.IsRegularFileSystemName(clientFile))
            {
                clientFile = UIMisc.GetSaveAsFilename("Retrieve Background Export File", clientFile, filter, ext);
            }

            else
            {
                clientFile =
                    SharePointFileDialog.GetSaveAsFilename("Retrieve Background Export File", clientFile, filter, ext);
            }

            if (String.IsNullOrEmpty(clientFile))
            {
                return("");
            }

            Progress.Show("Retrieving file...");
            try { ServerFile.CopyToClient(serverFile, clientFile); }
            catch (Exception ex)
            {
                string msg =
                    "Unable to retrieve cached export file: " + serverFile + "\n" +
                    "to client file: " + clientFile + "\n" +
                    DebugLog.FormatExceptionMessage(ex);
                ServicesLog.Message(msg);
                Progress.Hide();
                return(msg);
            }

            Progress.Hide();

            if (Lex.Eq(ext, ".xls") || Lex.Eq(ext, ".xlsx") || Lex.Eq(ext, ".doc") || Lex.Eq(ext, ".docx"))
            {
                DialogResult dr = MessageBoxMx.Show("Do you want to open " + clientFile + "?",
                                                    UmlautMobius.String, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    SystemUtil.StartProcess(clientFile);
                }
            }

            return("Background export file retrieved: " + clientFile);
        }
Example #5
0
        /// <summary>
        /// Copy file from client to server
        /// </summary>
        /// <param name="clientFile2"></param>
        /// <param name="serverFile"></param>

        public static void CopyToServer(
            string clientFile,
            string serverFile)
        {
            string clientFile2 = SharePointUtil.CacheLocalCopyIfSharePointFile(clientFile);

            if (ServiceFacade.UseRemoteServices)
            {
                FileStream fs = new FileStream(clientFile2, FileMode.Open, FileAccess.Read);
                while (true)
                {
                    byte[] buffer = new byte[UAL.ServerFile.TransferChunkSize];
                    int    bufLen = fs.Read(buffer, 0, buffer.Length);

                    if (bufLen < UAL.ServerFile.TransferChunkSize)                                     // at end
                    {
                        fs.Close();

                        byte[] buffer2 = new byte[bufLen];
                        Array.Copy(buffer, buffer2, bufLen);
                        buffer = buffer2;
                    }

                    NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                        ServiceCodes.MobiusFileService,
                        MobiusFileService.CopyToServer,
                        new object[] { buffer, serverFile });

                    if (bufLen < UAL.ServerFile.TransferChunkSize)
                    {
                        break;
                    }
                    serverFile = null;                                     // null for subsequent calls
                }
            }

            else             // direct call
            {
                FileStream fs = new FileStream(clientFile2, FileMode.Open, FileAccess.Read);
                while (true)
                {
                    byte[] buffer = new byte[UAL.ServerFile.TransferChunkSize];
                    int    bufLen = fs.Read(buffer, 0, buffer.Length);

                    if (bufLen < UAL.ServerFile.TransferChunkSize)                     // at end
                    {
                        fs.Close();

                        byte[] buffer2 = new byte[bufLen];
                        Array.Copy(buffer, buffer2, bufLen);
                        buffer = buffer2;
                    }

                    UAL.ServerFile.CopyToServer(serverFile, buffer);
                    if (bufLen < UAL.ServerFile.TransferChunkSize)
                    {
                        break;
                    }
                    serverFile = null;                     // null for subsequent calls
                }
            }

            if (clientFile2 != clientFile)
            {
                File.Delete(clientFile2);                                        // delete any temp file
            }
            return;
        }
Example #6
0
        /// <summary>
        /// Copy file from server to client
        /// </summary>
        /// <param name="serverFile"></param>
        /// <param name="clientFile2"></param>

        public static void CopyToClient(
            string serverFile,
            string clientFile)
        {
            FileStream fw = null;

            try
            {
                string tempFile = TempFile.GetTempFileName();

                if (ServiceFacade.UseRemoteServices)
                {
                    fw = new FileStream(tempFile, FileMode.Create, FileAccess.Write);
                    while (true)
                    {
                        NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                            ServiceCodes.MobiusFileService,
                            MobiusFileService.CopyToClient,
                            new object[] { serverFile });

                        byte[] buffer = (byte[])resultObject.Value;
                        if (buffer == null)
                        {
                            break;
                        }
                        fw.Write(buffer, 0, buffer.Length);
                        if (buffer.Length < UAL.ServerFile.TransferChunkSize)
                        {
                            break;
                        }
                        serverFile = null;                         // null to get subsequent chunks
                        System.Windows.Forms.Application.DoEvents();
                    }

                    fw.Close();
                }

                else                 // direct call
                {
                    fw = new FileStream(tempFile, FileMode.Create, FileAccess.Write);
                    while (true)
                    {
                        byte[] buffer = UAL.ServerFile.CopyToClient(serverFile);
                        if (buffer == null)
                        {
                            break;
                        }
                        fw.Write(buffer, 0, buffer.Length);
                        if (buffer.Length < UAL.ServerFile.TransferChunkSize)
                        {
                            break;
                        }
                        serverFile = null;                         // null to get subsequent chunks
                        System.Windows.Forms.Application.DoEvents();
                    }

                    fw.Close();
                }

                bool normalFile = !SharePointUtil.IsSharePointName(clientFile);
                if (normalFile)
                {                 // normal file, move temp file to dest file
                    FileUtil.ReplaceFile(clientFile, tempFile);
                }

                else                 // sharepoint
                {
                    SharePointUtil.CopyToSharePoint(tempFile, clientFile);
                    File.Delete(tempFile);                     // delete any temp file
                }
                return;
            }

            catch (Exception ex)             // close file on any exception
            {
                if (fw != null)
                {
                    try { fw.Close(); }     catch { }
                }
                throw new Exception(ex.Message, ex);
            }
        }