Example #1
0
 private DataEntityToken(string serializedDataSourceId)
 {
     _data = null;
     _dataInitialized = false;
     _serializedDataSourceId = serializedDataSourceId;
     _dataSourceId = null;
 }
        //public static string AttributeValue(this XElement element, XName attributeName)
        //{
        //    return element.Attributes(attributeName).Select(d => d.Value).FirstOrDefault();
        //}
        //public static string ElementValue(this XElement element, XName elementName)
        //{
        //    return element.Elements(elementName).Select(d => d.Value).FirstOrDefault();
        //}
        //public static IEnumerable<T> NotNull<T>(this IEnumerable<T> source)
        //{
        //    return source.Where(d => d != null);
        //}
        public static void DeleteActivity(this DataConnection conn, Guid activityId, DataSourceId dataSourceId)
        {
            try
            {
                var activity = conn.Get<IActivity>().Where(d => d.Id == activityId).FirstOrDefault();

                var activityChanges = conn.Get<IDataChanges>().Where(d => d.ActivityId == activityId).ToList();

                if (dataSourceId != null)
                {
                    if (dataSourceId.InterfaceType == typeof(IMediaFile))
                    {
                        try
                        {
                            var mediaFileId = dataSourceId.DataId.GetProperty<Guid>("Id");
                            var mediaFileActivityPath = CleanerFacade.GetMediaFileActivityPath(mediaFileId, activityId);
                            C1File.Delete(mediaFileActivityPath);
                        }
                        catch (Exception e)
                        {
                            Log.LogWarning(CleanerFacade.Title, e);
                        }
                    }
                }

                conn.Delete<IDataChanges>(activityChanges);
                conn.Delete(activity);

                Log.LogVerbose(CleanerFacade.Title, "Delete activity '{0}'".Push(activityId));
            }
            catch
            { }
        }
Example #3
0
 public MediaFileStore(string id, string title, string description, DataSourceId dataSourceId)
 {
     Id = id;
     Title = title;
     Description = description;
     DataSourceId = dataSourceId;
 }
Example #4
0
 /// <exclude />
 public WorkflowMediaFile()
 {
     Title = string.Empty;
     Description = string.Empty;
     MimeType = string.Empty;
     DataSourceId = new DataSourceId(typeof(IMediaFile));
 }
 public FileSystemMediaFileFolder(string path, string storeId, DataSourceId dataSourceId)
 {
     Id = Guid.NewGuid();
     _path = path;
     _storeId = storeId;
     _dataSourceId = dataSourceId;
     IsReadOnly = false;
 }
Example #6
0
 public FileSystemMediaFile(string systemPath, string fileName, string folderName, string storeId, DataSourceId dataSourceId)
 {
     Id = CalculateId(folderName, fileName);
     SystemPath = systemPath;
     FileName = fileName;
     FolderPath = folderName;
     StoreId = storeId;
     DataSourceId = dataSourceId;
 }
Example #7
0
        public MediaFileFolder(IMediaFolderData folder, string storeId, DataSourceId dataSourceId)
        {
            _dataSourceId = dataSourceId;

            Id = folder.Id;
            Description = folder.Description;
            Title = folder.Title;
            StoreId = storeId;
            Path = folder.Path;
        }
Example #8
0
        internal DataEntityToken(IData data)
        {
            Verify.ArgumentNotNull(data, "data");

            _data = data;
            _dataInitialized = true;            
            _serializedDataSourceId = null;
            _dataSourceId = _data.DataSourceId;
            Verify.ArgumentCondition(_dataSourceId != null, "data", "DataSourceId can not be null");

            _interfaceType = _dataSourceId.InterfaceType;
        }
Example #9
0
        public MediaFile(IMediaFileData file, string storeId, DataSourceId dataSourceId, string filePath)
        {
            _dataSourceId = dataSourceId;
            StoreId = storeId;

            this.Id = file.Id;
            this.FileName = file.FileName;
            this.FolderPath = file.FolderPath;
            this.Title = file.Title;
            this.Description = file.Description;
            this.MimeType = file.MimeType;
            this.Length = file.Length;
            this.IsReadOnly = false;
            this.Culture = file.CultureInfo;
            this.CreationTime = file.CreationTime;
            this.LastWriteTime = file.LastWriteTime;

            this.SystemPath = filePath;
        }
Example #10
0
        /// <exclude />
        public bool Equals(DataSourceId dataSourceId)
        {
            if (dataSourceId == null) return false;

            return dataSourceId.ToString() == ToString();
        }
Example #11
0
 internal void SetDataSourceId(DataSourceId dataSourceId)
 {
     _dataSourceId = dataSourceId;
 }
Example #12
0
 // Overload
 /// <exclude />
 public static T GetKeyValue <T>(this DataSourceId dataSourceId, string keyName = null)
 {
     return((T)_implementation.GetKeyValue(dataSourceId.DataId, keyName));
 }
 /// <exclude />
 public bool Equals(DataSourceId dataSourceId)
 {
     return(dataSourceId != null && dataSourceId.ToString() == ToString());
 }
        private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException)
        {
            dataSourceId = null;

            var dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId);

            if (!dic.ContainsKey("_dataIdType_") ||
                !dic.ContainsKey("_dataId_") ||
                !dic.ContainsKey("_interfaceType_") ||
                !dic.ContainsKey("_dataScope_") ||
                !dic.ContainsKey("_localeScope_"))
            {
                if (throwException)
                {
                    throw new ArgumentException("The argument is not a serialized " + nameof(DataSourceId), nameof(serializedDataSourceId));
                }
                return(false);
            }

            string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]);
            string dataIdTypeName   = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]);

            string providerName = dic.ContainsKey("_providerName_")
                ? StringConversionServices.DeserializeValueString(dic["_providerName_"])
                : DataProviderRegistry.DefaultDynamicTypeDataProviderName;

            string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]);
            string dataScope         = StringConversionServices.DeserializeValueString(dic["_dataScope_"]);
            string localeScope       = StringConversionServices.DeserializeValueString(dic["_localeScope_"]);

            Type interfaceType = TypeManager.TryGetType(interfaceTypeName);

            if (interfaceType == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException($"The type '{interfaceTypeName}' could not be found");
                }
                return(false);
            }

            Type dataIdType = TypeManager.TryGetType(dataIdTypeName);

            if (dataIdType == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException($"The type '{dataIdTypeName}' could not be found");
                }
                return(false);
            }

            serializedDataId = FixSerializedDataId(serializedDataId, interfaceType);

            IDataId dataId = SerializationFacade.Deserialize <IDataId>(dataIdType, serializedDataId);

            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope);

            dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo);

            return(true);
        }
 /// <summary>
 /// Tries to deserialize a string as a DataSourceId.
 /// </summary>
 /// <param name="serializedDataSourceId">A serialized DataSourceId</param>
 /// <param name="dataSourceId">DataSourceId reference to set, if deserialization succeeded</param>
 /// <returns>True if the deserialization succeeded, otherwise false</returns>
 public static bool TryDeserialize(string serializedDataSourceId, out DataSourceId dataSourceId)
 {
     return(Deserialize(serializedDataSourceId, out dataSourceId, false));
 }
Example #16
0
        private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException)
        {
            dataSourceId = null;

            Dictionary<string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId);

            if ((dic.ContainsKey("_dataIdType_") == false) ||
                (dic.ContainsKey("_dataId_") == false) ||                
                (dic.ContainsKey("_interfaceType_") == false) ||
                (dic.ContainsKey("_dataScope_") == false) ||
                (dic.ContainsKey("_localeScope_") == false))
            {
                if (throwException)
                {
                    throw new ArgumentException("The serializedDataSourceId is not a serialized data source id", "serializedDataSourceId");
                }
                else
                {
                    return false;
                }
            }

            string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]);
            string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]);

            string providerName;
            if (dic.ContainsKey("_providerName_"))
            {
                providerName = StringConversionServices.DeserializeValueString(dic["_providerName_"]);
            }
            else
            {
                providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName;
            }            
            
            string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]);
            string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]);
            string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]);

            Type type = TypeManager.TryGetType(dataIdType);
            if (type == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType));
                }
                return false;
            }

            IDataId dataId = SerializationFacade.Deserialize<IDataId>(type, serializedDataId);

            Type interfaceType = TypeManager.TryGetType(interfaceTypeName);
            if (interfaceType == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException(string.Format("The type {0} could not be found", interfaceType));
                }
                return false;
            }

            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope);

            dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo);

            return true;
        }
Example #17
0
 // Overload
 /// <exclude />
 public static object GetKeyValue(this DataSourceId dataSourceId, string keyName = null)
 {
     return(_implementation.GetKeyValue(dataSourceId.DataId, keyName));
 }
Example #18
0
        private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException)
        {
            dataSourceId = null;

            Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId);

            if ((dic.ContainsKey("_dataIdType_") == false) ||
                (dic.ContainsKey("_dataId_") == false) ||
                (dic.ContainsKey("_interfaceType_") == false) ||
                (dic.ContainsKey("_dataScope_") == false) ||
                (dic.ContainsKey("_localeScope_") == false))
            {
                if (throwException)
                {
                    throw new ArgumentException("The serializedDataSourceId is not a serialized data source id", "serializedDataSourceId");
                }
                else
                {
                    return(false);
                }
            }

            string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]);
            string dataIdType       = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]);

            string providerName;

            if (dic.ContainsKey("_providerName_"))
            {
                providerName = StringConversionServices.DeserializeValueString(dic["_providerName_"]);
            }
            else
            {
                providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName;
            }

            string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]);
            string dataScope         = StringConversionServices.DeserializeValueString(dic["_dataScope_"]);
            string localeScope       = StringConversionServices.DeserializeValueString(dic["_localeScope_"]);

            Type type = TypeManager.TryGetType(dataIdType);

            if (type == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType));
                }
                return(false);
            }

            IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataId);

            Type interfaceType = TypeManager.TryGetType(interfaceTypeName);

            if (interfaceType == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException(string.Format("The type {0} could not be found", interfaceType));
                }
                return(false);
            }

            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope);

            dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo);

            return(true);
        }
Example #19
0
 private static string GetCacheKey(Guid id, DataSourceId dataSourceId)
 {
     return(GetCacheKey(id, Guid.Empty, dataSourceId));
 }
Example #20
0
 /// <summary>
 /// Tries to deserialize a string as a DataSourceId.
 /// </summary>
 /// <param name="serializedDataSourceId">A serialized DataSourceId</param>
 /// <param name="dataSourceId">DataSourceId reference to set, if deserialization succeeded</param>
 /// <returns>True if the deserialization succeeded, otherwise false</returns>
 public static bool TryDeserialize(string serializedDataSourceId, out DataSourceId dataSourceId)
 {
     return Deserialize(serializedDataSourceId, out dataSourceId, false);
 }