public bool FromJSonFile(GxFile file, GXBaseCollection <SdtMessages_Message> Messages)
 {
     if (file != null && file.Exists())
     {
         string s = file.ReadAllText(string.Empty);
         return(FromJSonString(s, Messages));
     }
     else
     {
         GXUtil.ErrorToMessages("FromJSon Error", "File does not exist", Messages);
         return(false);
     }
 }
        public bool Create(string name, GXProperties properties, ref GxStorageProvider storageProvider, ref GXBaseCollection <SdtMessages_Message> messages)
        {
            storageProvider = null;

            if (string.IsNullOrEmpty(name))
            {
                GXUtil.ErrorToMessages("Unsopported", "Provider cannot be empty", messages);
                return(false);
            }

            try
            {
                if (providerService == null || !string.Equals(providerService.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    providerService               = new GXService();
                    providerService.Type          = GXServices.STORAGE_SERVICE;
                    providerService.Name          = name;
                    providerService.AllowMultiple = false;
                    providerService.Properties    = new GXProperties();
                }

                preprocess(name, properties);

                GxKeyValuePair prop = properties.GetFirst();
                while (!properties.Eof())
                {
                    providerService.Properties.Set(prop.Key, prop.Value);
                    prop = properties.GetNext();
                }

                string typeFullName = providerService.ClassName;
                logger.Debug("Loading storage provider: " + typeFullName);
#if !NETCORE
                Type type = Type.GetType(typeFullName, true, true);
#else
                Type type = new AssemblyLoader(FileUtil.GetStartupDirectory()).GetType(typeFullName);
#endif
                this.provider = (ExternalProvider)Activator.CreateInstance(type, new object[] { providerService });
            }
            catch (Exception ex)
            {
                logger.Error("Couldn't connect to external storage provider. ", ex);
                StorageMessages(ex, messages);
                return(false);
            }

            storageProvider = this;
            return(true);
        }
        public bool FromJSonString(string s, GXBaseCollection <SdtMessages_Message> Messages)
        {
            _jsonArr = JSONHelper.ReadJSON <JArray>(s, Messages);
            bool result = _jsonArr != null;

            try
            {
                FromJSONObject((JArray)jsonArr);
                return(result);
            }
            catch (Exception ex)
            {
                GXUtil.ErrorToMessages("FromJson Error", ex, Messages);
                return(false);
            }
        }
Example #4
0
 public static T ReadJavascriptJSON <T>(string json, GXBaseCollection <SdtMessages_Message> Messages = null) where T : class
 {
     try
     {
         if (!string.IsNullOrEmpty(json))
         {
             return(GXJsonSerializer.Instance.ReadJSON <T>(json));
         }
         else
         {
             GXUtil.ErrorToMessages("FromJson Error", "Empty json", Messages);
             return(default(T));
         }
     }
     catch (Exception ex)
     {
         GXUtil.ErrorToMessages("FromJson Error", ex, Messages);
         GXLogging.Error(log, "FromJsonError ", ex);
         return(default(T));
     }
 }
 public static T ReadJSON <T>(string json, GXBaseCollection <SdtMessages_Message> Messages = null) where T : class
 {
     try
     {
         if (!string.IsNullOrEmpty(json))
         {
             Jayrock.Json.JsonTextReader reader = new Jayrock.Json.JsonTextReader(new StringReader(json));
             return((T)reader.DeserializeNext());
         }
         else
         {
             GXUtil.ErrorToMessages("FromJson Error", "Empty json", Messages);
             return(default(T));
         }
     }
     catch (Exception ex)
     {
         GXUtil.ErrorToMessages("FromJson Error", ex, Messages);
         GXLogging.Error(log, "FromJsonError ", ex);
         return(default(T));
     }
 }
Example #6
0
 public bool GetDirectory(string directoryFullName, GxDirectory externalDirectory, GXBaseCollection <SdtMessages_Message> messages)
 {
     try
     {
         ValidProvider();
         string path = provider.GetDirectory(directoryFullName);
         if (String.IsNullOrEmpty(path))
         {
             GXUtil.ErrorToMessages("Get Error", "Directory doesn't exists", messages);
             return(false);
         }
         else
         {
             externalDirectory.DirectoryInfo = new GxExternalDirectoryInfo(directoryFullName, path, provider);
             return(true);
         }
     }
     catch (Exception ex)
     {
         StorageMessages(ex, messages);
         return(false);
     }
 }
Example #7
0
 public bool GetPrivate(string storageobjectfullname, GxFile externalFile, int expirationMinutes, GXBaseCollection <SdtMessages_Message> messages)
 {
     try
     {
         ValidProvider();
         string url = provider.Get(storageobjectfullname, GxFileType.Private, expirationMinutes);
         if (String.IsNullOrEmpty(url))
         {
             GXUtil.ErrorToMessages("Get Error", "File doesn't exists", messages);
             return(false);
         }
         else
         {
             externalFile.FileInfo = new GxExternalFileInfo(storageobjectfullname, url, provider, GxFileType.Private);
             return(true);
         }
     }
     catch (Exception ex)
     {
         StorageMessages(ex, messages);
         return(false);
     }
 }
        public virtual bool FromXml(string s, GXBaseCollection <SdtMessages_Message> Messages, string sName, string sNamespace)
        {
            try
            {
                if (!string.IsNullOrEmpty(s))
                {
                    base.Clear();
                    GXBaseCollection <T> deserialized = GXXmlSerializer.Deserialize <GXBaseCollection <T> >(this.GetType(), s, sName, sNamespace, out List <string> serializationErrors);
                    GXXmlSerializer.SetSoapError(context, serializationErrors);
                    if (deserialized != null)
                    {
                        foreach (T item in deserialized)
                        {
                            item.context = context;
                            Add(item);
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                GXLogging.Error(log, "FromXml error", ex);

                context.nSOAPErr = -20006;
                GXXmlSerializer.SetSoapError(context, string.Format("Error reading {0}", this.GetType()));
                GXXmlSerializer.SetSoapError(context, ex.Message);
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                    GXXmlSerializer.SetSoapError(context, ex.Message);
                }
                GXUtil.ErrorToMessages("FromXML Error", ex, Messages);
                return(false);
            }
        }
Example #9
0
 protected void StorageMessages(Exception ex, GXBaseCollection <SdtMessages_Message> messages)
 {
     if (messages != null && ex != null)
     {
         SdtMessages_Message msg = new SdtMessages_Message();
         if (provider != null && provider.GetMessageFromException(ex, msg))
         {
             msg.gxTpr_Type = 1;
             StringBuilder str = new StringBuilder();
             str.Append(ex.Message);
             while (ex.InnerException != null)
             {
                 str.Append(ex.InnerException.Message);
                 ex = ex.InnerException;
             }
             msg.gxTpr_Description = str.ToString();
             messages.Add(msg);
         }
         else
         {
             GXUtil.ErrorToMessages("Storage Error", ex, messages);
         }
     }
 }