示例#1
0
        public async Task <PictureShortDTO> GetMainByLinkedObject(LinkedObjectType type, int linkedObjectId)
        {
            try
            {
                var query = _context.Pictures.Where(p => (p.LinkedObjectId == linkedObjectId) &&
                                                    (p.LinkedObjectType == type) &&
                                                    (p.IsMain == true));
                if (!query.Any())
                {
                    query = _context.Pictures.Where(p => (p.LinkedObjectId == linkedObjectId) &&
                                                    (p.LinkedObjectType == type));
                }

                return(await query.Select(pic => new PictureShortDTO
                {
                    Id = pic.Id,
                    IsMain = pic.IsMain,
                    Filename = pic.Filename,
                    LinkedObjectId = pic.LinkedObjectId,
                    LinkedObjectType = pic.LinkedObjectType
                }).FirstOrDefaultAsync());
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT GET PICTURE", ex);
                throw;
            }
        }
示例#2
0
        public async Task <Picture> AddAsync(int tempFileId, bool isMain,
                                             int linkedObjectId, LinkedObjectType linkedObjectType)
        {
            Contracts.Assert(tempFileId != 0);
            Contracts.Assert(linkedObjectId != 0);

            try
            {
                var tempFile = await _context.TempFiles.FirstAsync(tf => tf.Id == tempFileId);

                Picture picture = new Picture
                {
                    Data             = tempFile.Data,
                    Filename         = tempFile.Filename,
                    IsMain           = isMain,
                    LinkedObjectId   = linkedObjectId,
                    LinkedObjectType = linkedObjectType
                };
                _context.Pictures.Add(picture);
                _context.TempFiles.Remove(tempFile);
                await _context.SaveChangesAsync();

                return(picture);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT ADD PICTURE", ex);
                throw;
            }
        }
示例#3
0
        public async Task SaveByFormIdAsync(string formId, int linkedObjectId, LinkedObjectType type)
        {
            var tempFileOperations = new TempFileOperations(_context);
            var tempfiles          = await tempFileOperations.GetByFormIdAsync(formId);

            foreach (var tempfile in tempfiles)
            {
                await AddAsync(tempfile.Id, tempfile.IsMain, linkedObjectId, type);
            }
            await tempFileOperations.RemoveAllByFormIdAsync(formId);
        }
        /// <summary>
        /// Create data on the server which can be retrieved later. For use when build custom outside processes and for some custom SQL filters on controls, such as the Document List and Form Data controls, which will replace tokens with a serialized Dictionary converted to JSON. See VisualVault's online help for more information.
        /// </summary>
        /// <param name="uniqueName">Can be an empty string. If a name is given, it must be unique to the scope. Used to retrieve data by name instead of by ID.</param>
        /// <param name="dataScope">User scope: Only the current user will have access. Global scope: all users have access.</param>
        /// <param name="data">Data to post. For objects, you may want to post them as JSON.</param>
        /// <param name="dataMimeType">For your own use. Indicates what format the data is in, such as text/xml or text/json</param>
        /// <param name="linkedObjectId">Not required. </param>
        /// <param name="linkedObjectType">Can be LinkedObjectType.None. Used to help indicate what object this item is dependent on. For example, if it is linked to a search, when that search ID is deleted (indicated by the linkedObjectId), this data will also be deleted.</param>
        /// <param name="expirationDateUtc">Can be null for never expires. The expiration date of the data after which a background service will remove the data from VisualVault.</param>
        /// <returns></returns>
        public PersistedClientData CreateData(string uniqueName, ScopeType dataScope, string data, string dataMimeType, string linkedObjectId, LinkedObjectType linkedObjectType, DateTime? expirationDateUtc)
        {
            dynamic postData = new ExpandoObject();
            postData.Name = uniqueName;
            postData.Scope = (int)dataScope;
            postData.PersistedData = data;
            postData.DataMimeType = dataMimeType;
            postData.LinkedObjectId = linkedObjectId;
            postData.LinkedObjectType = (int)linkedObjectType;
            postData.ExpirationDateUtc = expirationDateUtc;

            return HttpHelper.Post<PersistedClientData>(VVRestApi.GlobalConfiguration.Routes.PersistedData, string.Empty, GetUrlParts(), this.ClientSecrets, this.ApiTokens, postData);
        }
示例#5
0
 public async Task <IEnumerable <Picture> > GetByLinkedObject(LinkedObjectType type, int linkedObjectId)
 {
     try
     {
         return(await _context.Pictures.Where(p => (p.LinkedObjectId == linkedObjectId) &&
                                              (p.LinkedObjectType == type))
                .ToListAsync());
     }
     catch (Exception ex)
     {
         ErrorLogger.Log("CANNOT GET PICTURE", ex);
         throw;
     }
 }
示例#6
0
        public async Task DeleteByLinkedObject(LinkedObjectType type, int linkedObjectId)
        {
            try
            {
                var pictures = await GetByLinkedObject(type, linkedObjectId);

                foreach (var picture in pictures)
                {
                    await DeleteAsync(picture.Id);
                }
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ErrorLogger.Log("CANNOT DELETE PICTURES", ex);
                throw;
            }
        }
示例#7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gather the information for the LinkedObjectInfo and return that
		/// </summary>
		/// <param name="hvoObj">Hvo of the object</param>
		/// <param name="hvoRel">Hvo of the related object</param>
		/// <param name="flidRel">Field id of the object in the related object</param>
		/// <param name="linkedObjectType"></param>
		/// <returns>LinkedObjectInfo object</returns>
		/// ------------------------------------------------------------------------------------
		private LinkedObjectInfo GetLinkedObjectInfo(int hvoObj, int hvoRel, int flidRel,
			LinkedObjectType linkedObjectType)
		{
			if (hvoRel <= 0 || flidRel == (int)CmObjectFields.kflidCmObject_Owner)
				return null;

			LinkedObjectInfo loi = new LinkedObjectInfo();
			loi.RelObjField = flidRel;
			FieldType type = GetFieldType(flidRel);
			loi.RelType = (int)type;
			if (!IncludeObject(linkedObjectType, type))
				return null;

			loi.ObjId = hvoObj;
			loi.ObjClass = GetClassOfObject(hvoObj);
			loi.OwnerDepth = 0;
			loi.RelObjId = hvoRel;
			loi.RelObjClass = GetClassOfObject(hvoRel);

			loi.RelOrder = m_odde.get_IntProp(hvoObj,
				(int)CmObjectFields.kflidCmObject_OwnOrd);

			// not doing the OrdKey calculation for now
			loi.OrdKey = null;
			return loi;
		}
示例#8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks wether to include the object or not
		/// </summary>
		/// <param name="desiredTypes">The desired types of objects to include</param>
		/// <param name="objType">The type of the field</param>
		/// <returns><c>true</c> to include this object, otherwise <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		private bool IncludeObject(LinkedObjectType desiredTypes, FieldType objType)
		{
			return (desiredTypes == LinkedObjectType.OwningAndReference
				||
				(desiredTypes == LinkedObjectType.Reference &&
				(objType == FieldType.kcptReferenceAtom ||
				objType == FieldType.kcptReferenceCollection ||
				objType == FieldType.kcptReferenceSequence))
				||
				(desiredTypes == LinkedObjectType.Owning &&
				(objType == FieldType.kcptOwningAtom ||
				objType == FieldType.kcptOwningCollection ||
				objType == FieldType.kcptOwningSequence)));
		}
示例#9
0
		private void SaveLinkedObjInfo(int hvoObj, CacheKey key, LinkedObjectType linkedObjectType, List<LinkedObjectInfo> result)
		{
			LinkedObjectInfo loi = GetLinkedObjectInfo(hvoObj, key.Hvo,
				key.Tag, linkedObjectType);
			if (loi != null)
				result.Add(loi);
		}
示例#10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Wraps the GetLinkedObjs$ stored procedure.
		/// </summary>
		/// <param name="ids">Array of ids to process.</param>
		/// <param name="linkedObjectType">Mask that indicates what types of related objects
		/// should be retrieved.</param>
		/// <param name="fIncludeBaseClasses">A flag that determines if the base classes of owned
		/// objects are included in the object list (e.g., rows for each object + all
		/// superclasses except CmObject. So if a CmPerson is included, it will also have a row
		/// for CmPossibility)</param>
		/// <param name="fIncludeSubClasses">A flag that determines if the sub classes of owned
		/// objects are included in the object list.</param>
		/// <param name="fRecurse">A flag that determines if the owning tree is traversed.
		/// </param>
		/// <param name="referenceDirection">Determines which reference directions will be
		/// included in the results.</param>
		/// <param name="filterByClass">only return objects of this class (including subclasses
		/// of this class). Zero (0) returns all classes.</param>
		/// <param name="fCalculateOrderKey">A flag that determines if the order key is
		/// calculated.</param>
		///
		/// <returns>A generic list that contains zero, or more, LinkedObjectInfo objects.</returns>
		/// <remarks>
		/// The <b>ids</b> parameter handles the first two parameters in the actual stored
		/// procedure (@ObjId and @hXMLDocObjList).
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		public override List<LinkedObjectInfo> GetLinkedObjects(List<int> ids, LinkedObjectType linkedObjectType,
			bool fIncludeBaseClasses, bool fIncludeSubClasses, bool fRecurse,
			ReferenceDirection referenceDirection, int filterByClass, bool fCalculateOrderKey)
		{
			CheckDisposed();
			List<LinkedObjectInfo> result = new List<LinkedObjectInfo>();
			Hashtable ht = ((NewCacheBase)m_odde).Hashtable;

			if (linkedObjectType == LinkedObjectType.Reference ||
				linkedObjectType == LinkedObjectType.OwningAndReference)
			{
				if (referenceDirection == ReferenceDirection.Inbound
					|| referenceDirection == ReferenceDirection.InboundAndOutbound)
				{
					// at the moment, we expect this method to get called only by
					// CmObject.BackReferences or CmObject.LinkedObjects.
					Debug.Assert(fCalculateOrderKey == false);
					Debug.Assert(filterByClass == 0);
					Debug.Assert(fIncludeBaseClasses == true);
					// NOTE: cacheEntry is a System.Collections.DictionaryEntry, which has NOTHING to do with
					// linguistic lexicon stuff!
					foreach (DictionaryEntry cacheEntry in ht)
					{
						CacheKey key = cacheEntry.Key as CacheKey;
						bool fOwningProp = IsOwningProperty(key.Tag);
						bool fFoundLinkedObj = false;
						if (cacheEntry.Value is int && ids.Contains((int)cacheEntry.Value))
						{
							fFoundLinkedObj = true;
							int hvoVal = (int)cacheEntry.Value;
							foreach (int id in ids)
							{
								if (id == hvoVal)
								{
									if (fOwningProp && key.Hvo == GetOwnerOfObject(id))
										fFoundLinkedObj = false;
									break;
								}
							}
							if (fFoundLinkedObj)
								SaveLinkedObjInfo(hvoVal, key, linkedObjectType, result);
						}
						else if (cacheEntry.Value is int[])
						{
							ArrayList hvos = new ArrayList((int[])cacheEntry.Value);
							foreach (int id in ids)
							{
								if (hvos.Contains(id) && !(fOwningProp && key.Hvo == GetOwnerOfObject(id)))
								{
									SaveLinkedObjInfo(id, key, linkedObjectType, result);
								}
							}
						}
					}
				}
				return result;
			}
			throw new NotImplementedException("Not yet implemented in NewFdoCache");
		}
示例#11
0
        /// <summary>
        /// Create data on the server which can be retrieved later. For use when build custom outside processes and for some custom SQL filters on controls, such as the Document List and Form Data controls, which will replace tokens with a serialized Dictionary converted to JSON. See VisualVault's online help for more information.
        /// </summary>
        /// <param name="uniqueName">Can be an empty string. If a name is given, it must be unique to the scope. Used to retrieve data by name instead of by ID.</param>
        /// <param name="dataScope">User scope: Only the current user will have access. Global scope: all users have access.</param>
        /// <param name="data">Data to post. For objects, you may want to post them as JSON.</param>
        /// <param name="dataMimeType">For your own use. Indicates what format the data is in, such as text/xml or text/json</param>
        /// <param name="linkedObjectId">Not required. </param>
        /// <param name="linkedObjectType">Can be LinkedObjectType.None. Used to help indicate what object this item is dependent on. For example, if it is linked to a search, when that search ID is deleted (indicated by the linkedObjectId), this data will also be deleted.</param>
        /// <param name="expirationDateUtc">Can be null for never expires. The expiration date of the data after which a background service will remove the data from VisualVault.</param>
        /// <returns></returns>
        public PersistedClientData CreateData(string uniqueName, ScopeType dataScope, string data, string dataMimeType, string linkedObjectId, LinkedObjectType linkedObjectType, DateTime?expirationDateUtc)
        {
            dynamic postData = new ExpandoObject();

            postData.Name              = uniqueName;
            postData.Scope             = (int)dataScope;
            postData.PersistedData     = data;
            postData.DataMimeType      = dataMimeType;
            postData.LinkedObjectId    = linkedObjectId;
            postData.LinkedObjectType  = (int)linkedObjectType;
            postData.ExpirationDateUtc = expirationDateUtc;

            return(HttpHelper.Post <PersistedClientData>(VVRestApi.GlobalConfiguration.Routes.PersistedData, string.Empty, GetUrlParts(), this.ClientSecrets, this.ApiTokens, postData));
        }