Пример #1
0
        public static void LogEntityField(log4net.ILog log, object obj)
        {
            PropertyInfo[] propertyInfoAry = obj.GetType().GetProperties();

            foreach (PropertyInfo propertyInfo in propertyInfoAry)
            {
                log.Debug(obj.GetType() + "." + propertyInfo.Name + " : " + propertyInfo.GetValue(obj, null));
            }
        }
        /*
         * A utility class to create a File Geodatabase Workspace
         */
        public static IWorkspace createFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName)
        {
            log.Debug("Starting the process to create a new local File Geodatabase workspace.");

            // Instantiate a file geodatabase workspace factory and create a new file geodatabase.
            // The Create method returns a workspace name object.
            log.Debug("Initializing a new workspace factory to establish the FGB.");
            IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspaceName workspaceName = null;

            // verify the workspace does not already exist
            log.Debug("Determining if the workspace apready exists or not.");
            if (System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName))
            {
                // file geodatabase workspace already exist, throw warning
                log.Warn("File Geodatabase workspace already exists.");
                throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_createFileGeodatabaseWorkspace_exists);
            }
            else
            {
                // workspace doens't exist, good
                log.Debug("File Geodatabase does not exist.");

                // verify the directory exists
                log.Debug("Checking to see if the workspace directory exists or not (parent of the FGD).");
                if (!System.IO.Directory.Exists(workspaceDirectory))
                {
                    // workspace directory doens't exist, create the directory
                    log.Debug("Workspace folder/parent doesn't exist, creating the directory.");
                    System.IO.Directory.CreateDirectory(workspaceDirectory);
                }

                // create the workspace
                log.Debug("Creating the File Geodatabase workspace.");
                workspaceName = workspaceFactory.Create(workspaceDirectory, workspaceFolderName, null, 0);

                // Cast the workspace name object to the IName interface and open the workspace.
                log.Debug("Retreiving the workspace name.");
                IName name = (IName)workspaceName;

                // return the workspace
                log.Debug("Opening the workspace and returning it to the requestor.");
                return (IWorkspace)name.Open();
            }
        }
Пример #3
0
 private void Log(log4net.ILog logger, LogLevel logLevel, string message, Exception excpetion)
 {
     switch (logLevel)
     {
         case LogLevel.Debug:
             if (logger.IsDebugEnabled)
                 logger.Debug(message, excpetion);
             break;
         case LogLevel.Info:
             if (logger.IsInfoEnabled)
                 logger.Info(message, excpetion);
             break;
         case LogLevel.Warn:
             if (logger.IsWarnEnabled)
                 logger.Warn(message, excpetion);
             break;
         case LogLevel.Error:
             if (logger.IsErrorEnabled)
                 logger.Error(message, excpetion);
             break;
         case LogLevel.Fatal:
             if (logger.IsFatalEnabled)
                 logger.Fatal(message, excpetion);
             break;
         case LogLevel.Off:
             break;
         default:
             throw new Exception(string.Format("Unrecognized log level '{0}'.", logLevel.ToString()));
     }
 }
Пример #4
0
        private void LogCommon(string direction, log4net.ILog log)
        {
            System.Text.StringBuilder b = new System.Text.StringBuilder(direction);
            b.Append( ElementDef.Tag(SifVersion));
            b.Append(" (Status = ");

            SIF_Status stat = this.SIF_Status;
            if( stat != null )
            {
                b.Append( stat.SIF_Code );
            }
            else
            {
                b.Append( "none" );
            }

            SIF_Error err = this.SIF_Error;
            if (err != null)
            {
                b.Append("; 1 Error");
            }

            b.Append(")");
            log.Debug(b.ToString());

            if (err != null && (Adk.Debug & AdkDebugFlags.Messaging) != 0)
            {
                log.Debug(err.ToString());
            }

            if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed ) != 0)
            {
                string id = MsgId;
                log.Debug("  MsgId: " + ( id == null?"<none>":id));
                id = SIF_OriginalMsgId;
                log.Debug("  OrgId: " + ( id == null?"<none>":id));
            }
        }
Пример #5
0
    //http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011
    public static void UploadImages(string location, string folderTcmId, CoreService2010Client client, log4net.ILog Log)
    {
        //create a reference to the directory of where the images are
            DirectoryInfo directory = new DirectoryInfo(location);
            //create global Tridion Read Options
            ReadOptions readOptions = new ReadOptions();
            //use Expanded so that Tridion exposes the TcmId of the newly created component
            readOptions.LoadFlags = LoadFlags.Expanded;
            try
            {
                //loop through the files
                foreach (FileInfo fileInfo in directory.GetFiles())
                {
                    //only allow images
                    if (IsAllowedFileType(fileInfo.Extension))
                    {
                        try
                        {
                            //create a new multimedia component in the folder specified
                            ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(Tridion.ItemType.Component, folderTcmId);
                            multimediaComponent.Title = fileInfo.Name.ToLower();
                            multimediaComponent.ComponentType = ComponentType.Multimedia;
                            multimediaComponent.Schema.IdRef = ConfigurationManager.AppSettings["MultimediaSchemaId"];

                             //create a string to hold the temporary location of the image to use later
                            string tempLocation = "";

                            //use the StreamUpload2010Client to upload the image into Tridion
                            UploadResponse us = new UploadResponse();
                            using (Tridion.StreamUpload2010Client streamClient = new StreamUpload2010Client())
                            {
                                FileStream objfilestream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);
                                tempLocation = streamClient.UploadBinaryContent(fileInfo.Name.ToLower(), objfilestream);
                            }

                            //creat a new binary component
                            BinaryContentData binaryContent = new BinaryContentData();
                            //set this temporary upload location to the source of this binary
                            binaryContent.UploadFromFile = tempLocation;
                            binaryContent.Filename = fileInfo.Name.ToLower();

                            //get the multimedia type id
                            binaryContent.MultimediaType = new LinkToMultimediaTypeData() { IdRef = GetMultimediaTypeId(fileInfo.Extension) };

                            multimediaComponent.BinaryContent = binaryContent;

                            //save the image into a new object
                            IdentifiableObjectData savedComponent = client.Save(multimediaComponent, readOptions);

                            //check in using the Id of the new object
                            client.CheckIn(savedComponent.Id, null);
                        }
                        catch (Exception ex)
                        {
                            Log.Debug("Error creating image " + fileInfo.Name, ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error processing images", ex);
            }
            finally
            {
                //clean up temp objects
            }
    }
        /*
         * A utility function to open the File Geodatabase workspace
         */
        public static IWorkspace openFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName)
        {
            // attempting to open the file geodatabase
            log.Debug("Attempting to open the File Geodatabase.");
            log.Debug("Workspace: " + workspaceDirectory);
            log.Debug("Directory: " + workspaceFolderName);
            try
            {
                // verify the workspace does already exist
                log.Debug("Checking to see if the referenced File Geodatabase exists or not.");
                if (System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName))
                {
                    // File Geodatabase exist, create/configure a properties set
                    log.Debug("Creating a property set object.");
                    IPropertySet propertySet = new PropertySetClass();

                    // set the database value
                    log.Debug("Setting the DATABASE value of the property set.");
                    propertySet.SetProperty("DATABASE", workspaceDirectory + "\\" + workspaceFolderName);

                    // create a new workspace factory to open the FDGB
                    log.Debug("Creating a new workspace factory to open the file geodatabase.");
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();

                    // Open the FDGB and return it
                    log.Debug("Opening and returning the workspace.");
                    return workspaceFactory.Open(propertySet, 0);
                }
                else
                {
                    // Referenced File Geodatabase (FGDB) does ont exist
                    log.Warn("Referenced File Geodatabase (FGDB) does not exist");
                    throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_openFileGeodatabaseWorkspace_notfound);
                }
            }
            catch (System.Exception ex)
            {
                // an error occured, log and throw
                log.Error(ex);
                throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_openFileGeodatabaseWorkspace_unknown);
            }
        }
        /*
         * A utility class to delete a File Geodatabase (FGDB).
         */
        public static bool deleteFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName)
        {
            // attempt to delete the referenced File Geodatabase (FGDB)
            log.Debug("Attempting to delete the referenced File Geodatabase (FGDB).");
            log.Debug("workspaceDirectory: " + workspaceDirectory);
            log.Debug("workspaceFolderName: " + workspaceFolderName);
            try
            {
                // verify the workspace does already exist
                log.Debug("Verifying if the File Geodatabase exists.");
                if (!System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName))
                {
                    // the File Geodatabase does not exist
                    log.Warn("File Geodatabase does not exist.  Unable to delete.");
                    throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_notfound);
                }
                else
                {
                    // File Geodatabase exists, create a new DirecotryInfo object to represent the <name>.gdb
                    log.Debug("File Geodatabase exists, creating a new DirectoryInfo object to represent the .gdb.");
                    System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(workspaceDirectory + "\\" + workspaceFolderName);

                    // once again, verifying the folder itself exists
                    log.Debug("Checking again to see if the folder itself exists.");
                    if (dinfo.Exists)
                    {
                        // the File Geodatabase folder exists.  Attempt to delete it.
                        log.Debug("File Geodatabase folder exists, attempt to delete it.");
                        dinfo.Delete(true);

                        // return true
                        log.Debug("Returning true/successful.");
                        return true;
                    }
                    else
                    {
                        // the <name>.gdb folder does not exist, return false
                        log.Debug("File Geodatabase folder does not exist, return false.");
                        return false;
                    }
                }
            }
            catch (System.Exception ex)
            {
                // an unknown error occured, log and throw
                log.Error(ex);
                throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_unknown);
            }
        }